| 1 | # ----------------------------------------------------------------------------- | ||||||||||
| 2 | |||||||||||
| 3 | =encoding utf8 | ||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Quiq::PostgreSql::Catalog - PostgreSQL Catalog-Operationen | ||||||||||
| 8 | |||||||||||
| 9 | =head1 BASE CLASS | ||||||||||
| 10 | |||||||||||
| 11 | L<Quiq::Object> | ||||||||||
| 12 | |||||||||||
| 13 | =cut | ||||||||||
| 14 | |||||||||||
| 15 | # ----------------------------------------------------------------------------- | ||||||||||
| 16 | |||||||||||
| 17 | package Quiq::PostgreSql::Catalog; | ||||||||||
| 18 | 1 | ▶ | use base qw/Quiq::Object/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 1 | ▶ | use v5.10; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 1 | our $VERSION = '1.240'; | |||||||||
| 25 | |||||||||||
| 26 | 1 | ▶ | use Quiq::Unindent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | # ----------------------------------------------------------------------------- | ||||||||||
| 29 | |||||||||||
| 30 | =head1 METHODS | ||||||||||
| 31 | |||||||||||
| 32 | =head2 Konstruktor | ||||||||||
| 33 | |||||||||||
| 34 | =head3 new() - Konstruktor | ||||||||||
| 35 | |||||||||||
| 36 | =head4 Synopsis | ||||||||||
| 37 | |||||||||||
| 38 | $cat = $class->new; | ||||||||||
| 39 | |||||||||||
| 40 | =head4 Description | ||||||||||
| 41 | |||||||||||
| 42 | Instantiiere ein Objekt der Klasse und liefere eine Referenz auf dieses | ||||||||||
| 43 | Objekt zurück. Da die Klasse ausschließlich Klassenmethoden enthält, | ||||||||||
| 44 | hat das Objekt lediglich die Funktion, eine abkürzende Aufrufschreibweise | ||||||||||
| 45 | zu ermöglichen. | ||||||||||
| 46 | |||||||||||
| 47 | =cut | ||||||||||
| 48 | |||||||||||
| 49 | # ----------------------------------------------------------------------------- | ||||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 52 | 0 | my $class = shift; | |||||||||
| 53 | 0 | return bless \(my $dummy),$class; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | # ----------------------------------------------------------------------------- | ||||||||||
| 57 | |||||||||||
| 58 | =head2 Datenbank-Anfragen | ||||||||||
| 59 | |||||||||||
| 60 | =head3 functions() - Selektiere Informationen über Funktionen | ||||||||||
| 61 | |||||||||||
| 62 | =head4 Synopsis | ||||||||||
| 63 | |||||||||||
| 64 | @rows | $tab = $class->functions($db,@select); | ||||||||||
| 65 | |||||||||||
| 66 | =head4 Arguments | ||||||||||
| 67 | |||||||||||
| 68 | =over 4 | ||||||||||
| 69 | |||||||||||
| 70 | =item @select | ||||||||||
| 71 | |||||||||||
| 72 | Klauseln und Optionen. Siehe Quiq::Database::Connection->select(). | ||||||||||
| 73 | |||||||||||
| 74 | =back | ||||||||||
| 75 | |||||||||||
| 76 | =head4 Returns | ||||||||||
| 77 | |||||||||||
| 78 | Liste der Funktions-Datensätze. Im Skalarkontext ein ResultSet-Objekt. | ||||||||||
| 79 | |||||||||||
| 80 | =head4 Description | ||||||||||
| 81 | |||||||||||
| 82 | Suche Datenbank-Funktionen und liefere die Ergebnismenge zurück. | ||||||||||
| 83 | |||||||||||
| 84 | =cut | ||||||||||
| 85 | |||||||||||
| 86 | # ----------------------------------------------------------------------------- | ||||||||||
| 87 | |||||||||||
| 88 | 0 | ▶ | sub functions { | ||||||||
|
Subroutine
functions: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 89 | 0 | my ($class,$db) = splice @_,0,2; | |||||||||
| 90 | # @_: @select | ||||||||||
| 91 | 0 | return $db->select(-with,$class->functionSelect,@_); | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | # ----------------------------------------------------------------------------- | ||||||||||
| 95 | |||||||||||
| 96 | =head3 objects() - Selektiere Informationen über Objekte | ||||||||||
| 97 | |||||||||||
| 98 | =head4 Synopsis | ||||||||||
| 99 | |||||||||||
| 100 | @rows | $tab = $class->objects($db,@select); | ||||||||||
| 101 | |||||||||||
| 102 | =head4 Arguments | ||||||||||
| 103 | |||||||||||
| 104 | =over 4 | ||||||||||
| 105 | |||||||||||
| 106 | =item @select | ||||||||||
| 107 | |||||||||||
| 108 | Klauseln und Optionen. Siehe Quiq::Database::Connection->select(). | ||||||||||
| 109 | |||||||||||
| 110 | =back | ||||||||||
| 111 | |||||||||||
| 112 | =head4 Returns | ||||||||||
| 113 | |||||||||||
| 114 | Liste der Objekt-Datensätze. Im Skalarkontext ein ResultSet-Objekt. | ||||||||||
| 115 | |||||||||||
| 116 | =head4 Description | ||||||||||
| 117 | |||||||||||
| 118 | Suche Objekte und liefere die Ergebnismenge zurück. | ||||||||||
| 119 | |||||||||||
| 120 | =cut | ||||||||||
| 121 | |||||||||||
| 122 | # ----------------------------------------------------------------------------- | ||||||||||
| 123 | |||||||||||
| 124 | 0 | ▶ | sub objects { | ||||||||
|
Subroutine
objects: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 125 | 0 | my ($class,$db) = splice @_,0,2; | |||||||||
| 126 | # @_: @select | ||||||||||
| 127 | 0 | return $db->select(-with,$class->objectSelect,@_); | |||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | # ----------------------------------------------------------------------------- | ||||||||||
| 131 | |||||||||||
| 132 | =head3 views() - Selektiere Informationen über Views | ||||||||||
| 133 | |||||||||||
| 134 | =head4 Synopsis | ||||||||||
| 135 | |||||||||||
| 136 | @rows | $tab = $class->views($db,@select); | ||||||||||
| 137 | |||||||||||
| 138 | =head4 Arguments | ||||||||||
| 139 | |||||||||||
| 140 | =over 4 | ||||||||||
| 141 | |||||||||||
| 142 | =item @select | ||||||||||
| 143 | |||||||||||
| 144 | Klauseln und Optionen. Siehe Quiq::Database::Connection->select(). | ||||||||||
| 145 | |||||||||||
| 146 | =back | ||||||||||
| 147 | |||||||||||
| 148 | =head4 Returns | ||||||||||
| 149 | |||||||||||
| 150 | Liste der View-Datensätze. Im Skalarkontext ein ResultSet-Objekt. | ||||||||||
| 151 | |||||||||||
| 152 | =head4 Description | ||||||||||
| 153 | |||||||||||
| 154 | Suche Views und liefere die Ergebnismenge zurück. | ||||||||||
| 155 | |||||||||||
| 156 | =cut | ||||||||||
| 157 | |||||||||||
| 158 | # ----------------------------------------------------------------------------- | ||||||||||
| 159 | |||||||||||
| 160 | 0 | ▶ | sub views { | ||||||||
|
Subroutine
views: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 161 | 0 | my ($class,$db) = splice @_,0,2; | |||||||||
| 162 | # @_: @select | ||||||||||
| 163 | 0 | return $db->select(-with,$class->viewSelect,@_); | |||||||||
| 164 | } | ||||||||||
| 165 | |||||||||||
| 166 | # ----------------------------------------------------------------------------- | ||||||||||
| 167 | |||||||||||
| 168 | =head2 Hilfsmethoden | ||||||||||
| 169 | |||||||||||
| 170 | =head3 correctFunctionDef() - Korrigiere Quelltext einer Funktionsdefinition | ||||||||||
| 171 | |||||||||||
| 172 | =head4 Synopsis | ||||||||||
| 173 | |||||||||||
| 174 | $newSql = $class->correctFunctionDef($sql); | ||||||||||
| 175 | |||||||||||
| 176 | =head4 Arguments | ||||||||||
| 177 | |||||||||||
| 178 | =over 4 | ||||||||||
| 179 | |||||||||||
| 180 | =item $sql | ||||||||||
| 181 | |||||||||||
| 182 | CREATE FUNCTION Statement, das von pg_get_functiondef(oid) | ||||||||||
| 183 | geliefert wurde. | ||||||||||
| 184 | |||||||||||
| 185 | =back | ||||||||||
| 186 | |||||||||||
| 187 | =head4 Returns | ||||||||||
| 188 | |||||||||||
| 189 | Umgeschriebenes CREATE FUNCTION Statement (String) | ||||||||||
| 190 | |||||||||||
| 191 | =head4 Description | ||||||||||
| 192 | |||||||||||
| 193 | PostgreSQL stellt die Funktion pg_get_functiondef(oid) zur Verfügung, | ||||||||||
| 194 | die den Quelltext einer Datenbankfunktion liefert. Leider ist | ||||||||||
| 195 | der Quelltext manchmal fehlerbehaftet, zumindest in der Version 8.3. | ||||||||||
| 196 | Diese Methode korrigiert diese Fehler. | ||||||||||
| 197 | |||||||||||
| 198 | =cut | ||||||||||
| 199 | |||||||||||
| 200 | # ----------------------------------------------------------------------------- | ||||||||||
| 201 | |||||||||||
| 202 | 0 | ▶ | sub correctFunctionDef { | ||||||||
|
Subroutine
correctFunctionDef: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 203 | 0 | my ($class,$sql) = @_; | |||||||||
| 204 | |||||||||||
| 205 | # 1) LANGUAGE korrigieren: Enthält der Quelltext kein BEGIN, | ||||||||||
| 206 | # setzen wird sql statt plpgsql als Sprache. | ||||||||||
| 207 | |||||||||||
| 208 | 0 | ▶ | if ($sql !~ /\bBEGIN\b/i) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 209 | 0 | $sql =~ s/plpgsql/sql/; | |||||||||
| 210 | } | ||||||||||
| 211 | |||||||||||
| 212 | # 2) VOLATILESECURITY korrigieren: Der erzeugte Code enthält | ||||||||||
| 213 | # gelegentlich den Ausdruck Q{VOLATILESECURITY}. Dieser ist syntaktisch | ||||||||||
| 214 | # falsch, richtig ist Q{VOLATILE SECURITY}. | ||||||||||
| 215 | |||||||||||
| 216 | 0 | $sql =~ s/VOLATILESECURITY/VOLATILE SECURITY/i; | |||||||||
| 217 | |||||||||||
| 218 | # $sql =~ s/character varying\(-4\)/character varying(4)/ig; | ||||||||||
| 219 | |||||||||||
| 220 | 0 | return $sql; | |||||||||
| 221 | } | ||||||||||
| 222 | |||||||||||
| 223 | # ----------------------------------------------------------------------------- | ||||||||||
| 224 | |||||||||||
| 225 | =head2 SQL-Statements | ||||||||||
| 226 | |||||||||||
| 227 | =head3 functionSelect() - Statement: Selektiere Funktionen | ||||||||||
| 228 | |||||||||||
| 229 | =head4 Synopsis | ||||||||||
| 230 | |||||||||||
| 231 | $stmt = $class->functionSelect; | ||||||||||
| 232 | |||||||||||
| 233 | =head4 Returns | ||||||||||
| 234 | |||||||||||
| 235 | SQL-Statement (String) | ||||||||||
| 236 | |||||||||||
| 237 | =head4 Description | ||||||||||
| 238 | |||||||||||
| 239 | Liefere ein SELECT-Statement, das Informationen über Funktionen | ||||||||||
| 240 | abfragt. Folgende Information wird geliefert: | ||||||||||
| 241 | |||||||||||
| 242 | =over 4 | ||||||||||
| 243 | |||||||||||
| 244 | =item fnc_oid | ||||||||||
| 245 | |||||||||||
| 246 | PostgreSQL-Objekt-Id der Funktion. | ||||||||||
| 247 | |||||||||||
| 248 | =item fnc_owner | ||||||||||
| 249 | |||||||||||
| 250 | Name des Owners der Funktion. | ||||||||||
| 251 | |||||||||||
| 252 | =item fnc_schema | ||||||||||
| 253 | |||||||||||
| 254 | Name des Schemas, in dem sich die Funktion befindet. | ||||||||||
| 255 | |||||||||||
| 256 | =item fnc_name | ||||||||||
| 257 | |||||||||||
| 258 | Name der Funktion. | ||||||||||
| 259 | |||||||||||
| 260 | =item fnc_arguments | ||||||||||
| 261 | |||||||||||
| 262 | Argumentliste der Funktion als kommaseparierte Liste der Typ-Namen. | ||||||||||
| 263 | |||||||||||
| 264 | =item fnc_signature | ||||||||||
| 265 | |||||||||||
| 266 | Name plus Argumentliste der Funktion in der Form: | ||||||||||
| 267 | |||||||||||
| 268 | FUNCTION(TYPE,...) | ||||||||||
| 269 | |||||||||||
| 270 | =item fnc_source | ||||||||||
| 271 | |||||||||||
| 272 | Der vollständige Quelltext der Funktion. B<ACHTUNG:> Der Quelltext | ||||||||||
| 273 | kann (zumindest bei PostgreSQL 8.3) Fehler enthalten, siehe Methode | ||||||||||
| 274 | L<correctFunctionDef|"correctFunctionDef() - Korrigiere Quelltext einer Funktionsdefinition">(), die ggf. auf die Werte der Kolumne | ||||||||||
| 275 | angewendet werden sollte. | ||||||||||
| 276 | |||||||||||
| 277 | =back | ||||||||||
| 278 | |||||||||||
| 279 | Wird das Statement in eine WITH- oder FROM-Klausel Klausel eingebettet, | ||||||||||
| 280 | können auch die Suchkriterien über obige Kolumnennamen formuliert werden: | ||||||||||
| 281 | |||||||||||
| 282 | $tab = $db->select( | ||||||||||
| 283 | -with => Quiq::PostgreSql::Catalog->functionSelect, | ||||||||||
| 284 | -select => 'fnc_source', | ||||||||||
| 285 | -where, fnc_name = 'rv_copy_to', | ||||||||||
| 286 | fnc_arguments = 'text, text, text', | ||||||||||
| 287 | ); | ||||||||||
| 288 | |||||||||||
| 289 | =cut | ||||||||||
| 290 | |||||||||||
| 291 | # ----------------------------------------------------------------------------- | ||||||||||
| 292 | |||||||||||
| 293 | 0 | ▶ | sub functionSelect { | ||||||||
|
Subroutine
functionSelect: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 294 | 0 | my $class = shift; | |||||||||
| 295 | |||||||||||
| 296 | # pg_get_functiondef() funktioniert nicht auf Aggregat-Funktionen, | ||||||||||
| 297 | # daher "WHERE fnc.proisagg is false" | ||||||||||
| 298 | |||||||||||
| 299 | 0 | return Quiq::Unindent->trim(q~ | |||||||||
| 300 | SELECT | ||||||||||
| 301 | fnc.oid AS fnc_oid | ||||||||||
| 302 | , usr.usename AS fnc_owner | ||||||||||
| 303 | , nsp.nspname AS fnc_schema | ||||||||||
| 304 | , fnc.proname AS fnc_name | ||||||||||
| 305 | , pg_get_function_identity_arguments(fnc.oid) AS fnc_arguments | ||||||||||
| 306 | , fnc.proname || '(' || | ||||||||||
| 307 | COALESCE(pg_get_function_identity_arguments(fnc.oid), '') | ||||||||||
| 308 | || ')' AS fnc_signature | ||||||||||
| 309 | , pg_get_functiondef(fnc.oid) AS fnc_source | ||||||||||
| 310 | FROM | ||||||||||
| 311 | pg_proc AS fnc | ||||||||||
| 312 | JOIN pg_namespace AS nsp | ||||||||||
| 313 | ON fnc.pronamespace = nsp.oid | ||||||||||
| 314 | JOIN pg_user usr | ||||||||||
| 315 | ON fnc.proowner = usr.usesysid | ||||||||||
| 316 | WHERE | ||||||||||
| 317 | fnc.proisagg is false | ||||||||||
| 318 | ~); | ||||||||||
| 319 | } | ||||||||||
| 320 | |||||||||||
| 321 | # ----------------------------------------------------------------------------- | ||||||||||
| 322 | |||||||||||
| 323 | =head3 objectSelect() - Statement: Selektiere Objekte | ||||||||||
| 324 | |||||||||||
| 325 | =head4 Synopsis | ||||||||||
| 326 | |||||||||||
| 327 | $stmt = $class->objectSelect; | ||||||||||
| 328 | |||||||||||
| 329 | =head4 Returns | ||||||||||
| 330 | |||||||||||
| 331 | SQL-Statement (String) | ||||||||||
| 332 | |||||||||||
| 333 | =head4 Description | ||||||||||
| 334 | |||||||||||
| 335 | Liefere ein SELECT-Statement, das Informationen über Objekte | ||||||||||
| 336 | abfragt. Folgende Information wird geliefert: | ||||||||||
| 337 | |||||||||||
| 338 | =over 4 | ||||||||||
| 339 | |||||||||||
| 340 | =item obj_oid | ||||||||||
| 341 | |||||||||||
| 342 | PostgreSQL-Objekt-Id des Objekts. | ||||||||||
| 343 | |||||||||||
| 344 | =item obj_type | ||||||||||
| 345 | |||||||||||
| 346 | Typ des Objekts. | ||||||||||
| 347 | |||||||||||
| 348 | =item obj_owner | ||||||||||
| 349 | |||||||||||
| 350 | Name des Owners des Objekts. | ||||||||||
| 351 | |||||||||||
| 352 | =item obj_schema | ||||||||||
| 353 | |||||||||||
| 354 | Name des Schemas, in dem sich das Objekt befindet. | ||||||||||
| 355 | |||||||||||
| 356 | =item obj_name | ||||||||||
| 357 | |||||||||||
| 358 | Name des Objekts. | ||||||||||
| 359 | |||||||||||
| 360 | =item obj_longname | ||||||||||
| 361 | |||||||||||
| 362 | Vollständiger Name des Objekts. Im Falle einer Funktion dessen | ||||||||||
| 363 | Signatur. Bei allen anderen Objekten identisch zu obj_name. | ||||||||||
| 364 | |||||||||||
| 365 | =item obj_source | ||||||||||
| 366 | |||||||||||
| 367 | Der Quelltext des Objekts im Falle von Funktionen und Views. | ||||||||||
| 368 | |||||||||||
| 369 | =back | ||||||||||
| 370 | |||||||||||
| 371 | Wird das Statement in eine WITH- oder FROM-Klausel Klausel eingebettet, | ||||||||||
| 372 | können auch die Suchkriterien über obige Kolumnennamen formuliert werden: | ||||||||||
| 373 | |||||||||||
| 374 | $tab = $db->select( | ||||||||||
| 375 | -with => Quiq::PostgreSql::Catalog->objectSelect, | ||||||||||
| 376 | ... | ||||||||||
| 377 | ); | ||||||||||
| 378 | |||||||||||
| 379 | =cut | ||||||||||
| 380 | |||||||||||
| 381 | # ----------------------------------------------------------------------------- | ||||||||||
| 382 | |||||||||||
| 383 | 0 | ▶ | sub objectSelect { | ||||||||
|
Subroutine
objectSelect: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 384 | 0 | my $class = shift; | |||||||||
| 385 | |||||||||||
| 386 | # pg_get_functiondef() funktioniert nicht auf Aggregat-Funktionen, | ||||||||||
| 387 | # daher "WHERE fnc.proisagg is false" | ||||||||||
| 388 | |||||||||||
| 389 | 0 | return Quiq::Unindent->trim(q~ | |||||||||
| 390 | SELECT | ||||||||||
| 391 | cls.oid AS obj_oid | ||||||||||
| 392 | , cls.relkind AS obj_type | ||||||||||
| 393 | , usr.usename AS obj_owner | ||||||||||
| 394 | , nsp.nspname AS obj_schema | ||||||||||
| 395 | , cls.relname AS obj_name | ||||||||||
| 396 | , cls.relname AS obj_longname | ||||||||||
| 397 | , CASE | ||||||||||
| 398 | WHEN cls.relkind = 'v' THEN pg_get_viewdef(cls.oid, true) | ||||||||||
| 399 | ELSE '' | ||||||||||
| 400 | END AS obj_source | ||||||||||
| 401 | FROM | ||||||||||
| 402 | pg_class AS cls | ||||||||||
| 403 | JOIN pg_namespace AS nsp | ||||||||||
| 404 | ON cls.relnamespace = nsp.oid | ||||||||||
| 405 | JOIN pg_user usr | ||||||||||
| 406 | ON cls.relowner = usr.usesysid | ||||||||||
| 407 | UNION | ||||||||||
| 408 | SELECT | ||||||||||
| 409 | fnc.oid AS fnc_oid | ||||||||||
| 410 | , 'F' AS fnc_type | ||||||||||
| 411 | , usr.usename AS fnc_owner | ||||||||||
| 412 | , nsp.nspname AS fnc_schema | ||||||||||
| 413 | , fnc.proname AS fnc_name | ||||||||||
| 414 | , fnc.proname || '(' || | ||||||||||
| 415 | COALESCE(pg_get_function_identity_arguments(fnc.oid), '') | ||||||||||
| 416 | || ')' AS fnc_longname | ||||||||||
| 417 | , pg_get_functiondef(fnc.oid) AS fnc_source | ||||||||||
| 418 | FROM | ||||||||||
| 419 | pg_proc AS fnc | ||||||||||
| 420 | JOIN pg_namespace AS nsp | ||||||||||
| 421 | ON fnc.pronamespace = nsp.oid | ||||||||||
| 422 | JOIN pg_user usr | ||||||||||
| 423 | ON fnc.proowner = usr.usesysid | ||||||||||
| 424 | WHERE | ||||||||||
| 425 | fnc.proisagg is false -- keine Aggregat-Funktionen | ||||||||||
| 426 | ~); | ||||||||||
| 427 | } | ||||||||||
| 428 | |||||||||||
| 429 | # ----------------------------------------------------------------------------- | ||||||||||
| 430 | |||||||||||
| 431 | =head3 viewSelect() - Statement: Selektiere Views | ||||||||||
| 432 | |||||||||||
| 433 | =head4 Synopsis | ||||||||||
| 434 | |||||||||||
| 435 | $stmt = $class->viewSelect; | ||||||||||
| 436 | |||||||||||
| 437 | =head4 Returns | ||||||||||
| 438 | |||||||||||
| 439 | SQL-Statement (String) | ||||||||||
| 440 | |||||||||||
| 441 | =head4 Description | ||||||||||
| 442 | |||||||||||
| 443 | Liefere ein SELECT-Statement, das Informationen über Views | ||||||||||
| 444 | abfragt. Folgende Information wird geliefert: | ||||||||||
| 445 | |||||||||||
| 446 | =over 4 | ||||||||||
| 447 | |||||||||||
| 448 | =item viw_oid | ||||||||||
| 449 | |||||||||||
| 450 | PostgreSQL-Objekt-Id der View. | ||||||||||
| 451 | |||||||||||
| 452 | =item viw_owner | ||||||||||
| 453 | |||||||||||
| 454 | Name des Owners der View. | ||||||||||
| 455 | |||||||||||
| 456 | =item viw_schema | ||||||||||
| 457 | |||||||||||
| 458 | Name des Schemas, in dem sich die View befindet. | ||||||||||
| 459 | |||||||||||
| 460 | =item viw_name | ||||||||||
| 461 | |||||||||||
| 462 | Name der View. | ||||||||||
| 463 | |||||||||||
| 464 | =item viw_source | ||||||||||
| 465 | |||||||||||
| 466 | Der Quelltext der View. | ||||||||||
| 467 | |||||||||||
| 468 | =back | ||||||||||
| 469 | |||||||||||
| 470 | Wird das Statement in eine WITH- oder FROM-Klausel Klausel eingebettet, | ||||||||||
| 471 | können auch die Suchkriterien über obige Kolumnennamen formuliert werden: | ||||||||||
| 472 | |||||||||||
| 473 | $tab = $db->select( | ||||||||||
| 474 | -with => Quiq::PostgreSql::Catalog->viewSelect, | ||||||||||
| 475 | -select => 'viw_source', | ||||||||||
| 476 | -where, viw_name = 'dd_rh_invoice_add', | ||||||||||
| 477 | ); | ||||||||||
| 478 | |||||||||||
| 479 | =cut | ||||||||||
| 480 | |||||||||||
| 481 | # ----------------------------------------------------------------------------- | ||||||||||
| 482 | |||||||||||
| 483 | 0 | ▶ | sub viewSelect { | ||||||||
|
Subroutine
viewSelect: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 484 | 0 | my $class = shift; | |||||||||
| 485 | |||||||||||
| 486 | 0 | return Quiq::Unindent->trim(q~ | |||||||||
| 487 | SELECT | ||||||||||
| 488 | cls.oid AS viw_oid | ||||||||||
| 489 | , usr.usename AS viw_owner | ||||||||||
| 490 | , nsp.nspname AS viw_schema | ||||||||||
| 491 | , cls.relname AS viw_name | ||||||||||
| 492 | , pg_get_viewdef(cls.oid, true) AS viw_source | ||||||||||
| 493 | FROM | ||||||||||
| 494 | pg_class AS cls | ||||||||||
| 495 | JOIN pg_namespace AS nsp | ||||||||||
| 496 | ON cls.relnamespace = nsp.oid | ||||||||||
| 497 | JOIN pg_user usr | ||||||||||
| 498 | ON cls.relowner = usr.usesysid | ||||||||||
| 499 | WHERE | ||||||||||
| 500 | cls.relkind = 'v' | ||||||||||
| 501 | ~); | ||||||||||
| 502 | } | ||||||||||
| 503 | |||||||||||
| 504 | # ----------------------------------------------------------------------------- | ||||||||||
| 505 | |||||||||||
| 506 | =head1 VERSION | ||||||||||
| 507 | |||||||||||
| 508 | 1.240 | ||||||||||
| 509 | |||||||||||
| 510 | =head1 AUTHOR | ||||||||||
| 511 | |||||||||||
| 512 | Frank Seitz, L<http://fseitz.de/> | ||||||||||
| 513 | |||||||||||
| 514 | =head1 COPYRIGHT | ||||||||||
| 515 | |||||||||||
| 516 | Copyright (C) 2026 Frank Seitz | ||||||||||
| 517 | |||||||||||
| 518 | =head1 LICENSE | ||||||||||
| 519 | |||||||||||
| 520 | This code is free software; you can redistribute it and/or modify | ||||||||||
| 521 | it under the same terms as Perl itself. | ||||||||||
| 522 | |||||||||||
| 523 | =cut | ||||||||||
| 524 | |||||||||||
| 525 | # ----------------------------------------------------------------------------- | ||||||||||
| 526 | |||||||||||
| 527 | 1 | 1; | |||||||||
| 528 | |||||||||||
| 529 | # eof | ||||||||||