| 1 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | Quiq::Database::Api::Dbi::Connection - DBI Datenbank-Verbindung | ||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | =head1 BASE CLASS | ||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | L<Quiq::Hash> | ||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | Ein Objekt der Klasse Quiq::Database::Api::Dbi::Connection repräsentiert eine | ||||||||||||||||||||||||||||||||||
| 16 | Verbindung zu einer Relationalen Datenbank über den DBI-Layer. | ||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | =over 4 | ||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | =item dbh => $dbh | ||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | DBI Database Handle. | ||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | =item dbms => $dbms | ||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | Name des DBMS, für DBMS-spezifische Fallunterscheidungen. | ||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | =back | ||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | package Quiq::Database::Api::Dbi::Connection; | ||||||||||||||||||||||||||||||||||
| 37 | 6 | ▶ | use base qw/Quiq::Hash/; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | 6 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 40 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 41 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | 6 | our $VERSION = '1.240'; | |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | 6 | ▶ | use Quiq::Option; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 46 | 6 | ▶ | use DBI (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 47 | 6 | ▶ | use Quiq::Database::Api::Dbi::Cursor; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | =head1 METHODS | ||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | =head2 Konstruktor/Destruktor | ||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | =head3 new() - Öffne Datenbankverbindung | ||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | $db = $class->new($udlObj,@opt); | ||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | =head4 Options | ||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | =over 4 | ||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | =item -autoCommit => $bool (Default: 0) | ||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | Öffne die Verbindung im Autocommit-Modus. | ||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | =item -handle => $handle | ||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | =item utf8 => $bool (Default: 0) | ||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | =back | ||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | =head4 Description | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | Instantiiere eine Datenbankverbindung und liefere eine Referenz | ||||||||||||||||||||||||||||||||||
| 78 | auf dieses Objekt zurück. | ||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | =cut | ||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 12 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=17 SCAR=42.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 85 | 12 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 86 | 12 | my $udlObj = shift; | |||||||||||||||||||||||||||||||||
| 87 | # @_: @opt | ||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | # Optionen | ||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||
| 91 | 12 | my $autoCommit = 0; | |||||||||||||||||||||||||||||||||
| 92 | 12 | my $handle = undef; | |||||||||||||||||||||||||||||||||
| 93 | 12 | my $utf8 = 0; | |||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||
| 95 | 12 | Quiq::Option->extract(\@_, | |||||||||||||||||||||||||||||||||
| 96 | -autoCommit => \$autoCommit, | ||||||||||||||||||||||||||||||||||
| 97 | -handle => \$handle, | ||||||||||||||||||||||||||||||||||
| 98 | -utf8 => \$utf8, | ||||||||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | 12 | my $dsn = $udlObj->dsn; | |||||||||||||||||||||||||||||||||
| 102 | 12 | my $dbms = $udlObj->dbms; | |||||||||||||||||||||||||||||||||
| 103 | 12 | my $user = $udlObj->user; | |||||||||||||||||||||||||||||||||
| 104 | 12 | my $passw = $udlObj->password; | |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | 12 | ▶ | if ($dbms eq 'sqlite') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 107 | # SQLite3: AutoCommit muss angeschaltet sein, sonst gibt | ||||||||||||||||||||||||||||||||||
| 108 | # es "database is locked" Fehler mit jedem SQL-Statement. | ||||||||||||||||||||||||||||||||||
| 109 | # Transaktionen müssen mit BEGIN begonnen werden und enden | ||||||||||||||||||||||||||||||||||
| 110 | # mit COMMIT oder ROLLBACK. Ob dies hier gewährleistet ist, | ||||||||||||||||||||||||||||||||||
| 111 | # sollte beizeiten gezielt geprüft werden. | ||||||||||||||||||||||||||||||||||
| 112 | 12 | $autoCommit = 1; | |||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | 68 | ▶ | my $errSub = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=22 SCAR=45.4
| |||||||||||||||||||||||||||||||||||
| 116 | 68 | my $msg = shift; | |||||||||||||||||||||||||||||||||
| 117 | 68 | my $h = shift; | |||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||
| 119 | # Bei PostgreSQL liefern $h->err und $h->errstr | ||||||||||||||||||||||||||||||||||
| 120 | # bei einem fehlgeschlagenen Verbindungsaufbau undef. | ||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||
| 122 | 68 | ▶ | my $err = $h->err || 0; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$h->err || 0
MC/DC0%0/1
$h->err || 0
$h->err
Truth table50%1/2
A
A= $h->err
| |||||||||||||||||||||||||||||||||||
| 123 | 68 | ▶ | my $errstr = $h->errstr || 'Unknown Error'; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$h->errstr || 'Unknown Error'
MC/DC0%0/1
$h->errstr || 'Unknown Error'
$h->errstr
Truth table50%1/2
A
A= $h->errstr
| |||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | 68 | my ($stmt,$pos); | |||||||||||||||||||||||||||||||||
| 126 | 68 | ▶ | $stmt = $1 if $msg =~ /\[for statement [`'"]+(.+)[`'"]+\]/si; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | 68 | my $stdErr = 0; | |||||||||||||||||||||||||||||||||
| 129 | 68 | ▶ | if ($dbms eq 'mysql') { | ||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ($err == 1062) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 131 | 0 | $stdErr = 4; | |||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||
| 133 | 0 | $msg = sprintf('MYSQL-%05d: %s',$err,$errstr); | |||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||
| 135 | elsif ($dbms eq 'oracle') { | ||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ($err == 1) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 137 | 0 | $stdErr = 4; | |||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | $pos = $1 if $errstr =~ /at char (\d+)/; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 140 | 0 | $errstr =~ s|\s*\(DBD.*||s; | |||||||||||||||||||||||||||||||||
| 141 | 0 | $msg = $errstr; | |||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||
| 143 | elsif ($dbms eq 'postgresql') { | ||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | if ($errstr =~ /unique.constraint/i) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 145 | 0 | $stdErr = 4; | |||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||
| 148 | # MEMO: Die Positionsangabe ist (immer?) um 45 | ||||||||||||||||||||||||||||||||||
| 149 | # Zeichen zu groß. Man kann im Server-Log sehen, | ||||||||||||||||||||||||||||||||||
| 150 | # dass den Statements dort entsprechend viel | ||||||||||||||||||||||||||||||||||
| 151 | # Whitespace vorangestellt ist. | ||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | $pos = $1-45 if $msg =~ /at character (\d+)/si; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||
| 155 | # FIXME: $err ist immer 7. Warum? | ||||||||||||||||||||||||||||||||||
| 156 | 0 | $msg = sprintf('PGSQL-%05d: %s',$err,$errstr); | |||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||
| 158 | elsif ($dbms eq 'sqlite') { | ||||||||||||||||||||||||||||||||||
| 159 | 68 | ▶ | if ($err == 19) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 160 | 1 | $stdErr = 4; | |||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||
| 162 | #elsif ($err == 1) { | ||||||||||||||||||||||||||||||||||
| 163 | # # Fehler unterdrücken: | ||||||||||||||||||||||||||||||||||
| 164 | # return; | ||||||||||||||||||||||||||||||||||
| 165 | #} | ||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||
| 167 | 68 | $errstr =~ s| at.*?$||; # " at FILE.c line N" entf. | |||||||||||||||||||||||||||||||||
| 168 | 68 | $errstr =~ s|\(\d+\)$||; # "(1)" entf. | |||||||||||||||||||||||||||||||||
| 169 | 68 | $msg = sprintf('SQLITE-%05d: %s',$err,$errstr); | |||||||||||||||||||||||||||||||||
| 170 | 68 | ▶ | if ($err == 14) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 171 | 0 | my ($file) = $dsn =~ /=(.*)/; | |||||||||||||||||||||||||||||||||
| 172 | 0 | $msg .= " ($file)"; | |||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||
| 175 | elsif ($dbms eq 'mssql') { | ||||||||||||||||||||||||||||||||||
| 176 | 0 | $msg = sprintf('MSSQL-%05d: %s',$err,$errstr); | |||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||
| 178 | elsif ($dbms eq 'access') { | ||||||||||||||||||||||||||||||||||
| 179 | 0 | $msg = sprintf('ACCESS-%05d: %s',$err,$errstr); | |||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||
| 181 | elsif ($dbms eq 'jdbc') { | ||||||||||||||||||||||||||||||||||
| 182 | 0 | $msg = sprintf('JDBC-%05d: %s',$err,$errstr); | |||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||
| 185 | 68 | ▶ | if ($stmt) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 186 | 68 | ▶ | substr($stmt,$pos,0) = '<*>' if $pos; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 187 | 68 | $stmt =~ s|^\s+||; | |||||||||||||||||||||||||||||||||
| 188 | 68 | $stmt =~ s|\s+$||; | |||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||
| 191 | 68 | ▶ | if ($stdErr) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 192 | 1 | my $stdMsg; | |||||||||||||||||||||||||||||||||
| 193 | 1 | ▶ | if ($stdErr == 4) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 194 | 1 | $stdMsg = "DB-00004: Constraint verletzt"; | |||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||
| 196 | 1 | $class->throw($stdMsg,Internal=>$msg,Command=>$stmt); | |||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||
| 198 | else { | ||||||||||||||||||||||||||||||||||
| 199 | 67 | $class->throw($msg,Command=>$stmt); | |||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||
| 201 | 12 | }; | |||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||
| 203 | 12 | my ($dbh,$strict); | |||||||||||||||||||||||||||||||||
| 204 | 12 | ▶ | if ($handle) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 205 | 0 | $dbh = $handle; # bereits aufgebaute Db-Verbindung | |||||||||||||||||||||||||||||||||
| 206 | 0 | $strict = 0; | |||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||
| 208 | else { | ||||||||||||||||||||||||||||||||||
| 209 | 12 | $dbh = DBI->connect($dsn,$user,$passw,{ | |||||||||||||||||||||||||||||||||
| 210 | HandleError => $errSub, | ||||||||||||||||||||||||||||||||||
| 211 | RaiseError => 1, | ||||||||||||||||||||||||||||||||||
| 212 | ShowErrorStatement => 1, | ||||||||||||||||||||||||||||||||||
| 213 | AutoCommit => $autoCommit, | ||||||||||||||||||||||||||||||||||
| 214 | Warn => 0, | ||||||||||||||||||||||||||||||||||
| 215 | }); | ||||||||||||||||||||||||||||||||||
| 216 | 12 | $strict = 1; | |||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | 12 | ▶ | if (!$handle) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 220 | 12 | ▶ | if ($dbms eq 'oracle') { | ||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||
| 221 | 0 | $dbh->{'LongReadLen'} = 3*1024*1024; # 3MB | |||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if ($utf8) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 223 | 0 | $dbh->{'ora_charset'} = 'AL32UTF8'; | |||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||
| 226 | elsif ($dbms eq 'postgresql') { | ||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | if ($utf8) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 228 | 0 | $dbh->{'pg_enable_utf8'} = 1; | |||||||||||||||||||||||||||||||||
| 229 | # $dbh->do('SET client_encoding TO utf8'); | ||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||
| 231 | else { | ||||||||||||||||||||||||||||||||||
| 232 | 0 | $dbh->{'pg_enable_utf8'} = 0; | |||||||||||||||||||||||||||||||||
| 233 | # scheinbar nötig | ||||||||||||||||||||||||||||||||||
| 234 | 0 | $dbh->do('SET client_encoding TO latin1'); | |||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||
| 236 | # keine \-Escapes in String-Literalen zulassen | ||||||||||||||||||||||||||||||||||
| 237 | 0 | $dbh->do("SET standard_conforming_strings = ON"); | |||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||
| 239 | elsif ($dbms eq 'mysql') { | ||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if ($utf8) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 241 | 0 | $dbh->{'mysql_enable_utf8'} = 1; | |||||||||||||||||||||||||||||||||
| 242 | 0 | $dbh->do('SET NAMES utf8'); | |||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||
| 244 | # Schalte in den "Strict SQL Mode" | ||||||||||||||||||||||||||||||||||
| 245 | 0 | $dbh->do("SET sql_mode = 'STRICT_TRANS_TABLES'"); | |||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||
| 247 | elsif ($dbms eq 'sqlite') { | ||||||||||||||||||||||||||||||||||
| 248 | 12 | ▶ | if ($utf8) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 249 | # $dbh->{'unicode'} = 1; | ||||||||||||||||||||||||||||||||||
| 250 | 12 | $dbh->{'sqlite_unicode'} = 1; | |||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||
| 252 | 12 | $dbh->do('PRAGMA foreign_keys = ON'); # Schalte Foreign Keys ein | |||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||
| 254 | elsif ($dbms eq 'access') { | ||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ($utf8) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 256 | 0 | $dbh->{'odbc_utf8_on'} = 1; | |||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||
| 259 | elsif ($dbms eq 'mssql') { | ||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | if ($utf8) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 261 | 0 | $dbh->{'odbc_utf8_on'} = 1; | |||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||
| 263 | 0 | $dbh->{LongTruncOk} = 0; # RuV Auftrags-DB | |||||||||||||||||||||||||||||||||
| 264 | # RuV Auftrags-DB | ||||||||||||||||||||||||||||||||||
| 265 | 0 | $dbh->{LongReadLen} = 3*1024*1024; # 3MB / 32768; | |||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||
| 267 | elsif ($dbms eq 'jdbc') { | ||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||
| 269 | else { | ||||||||||||||||||||||||||||||||||
| 270 | 0 | $class->throw('Not implemented'); | |||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||
| 274 | 12 | return $class->SUPER::new( | |||||||||||||||||||||||||||||||||
| 275 | dbh => $dbh, | ||||||||||||||||||||||||||||||||||
| 276 | dbms => $dbms, | ||||||||||||||||||||||||||||||||||
| 277 | # Strict-Umschaltung | ||||||||||||||||||||||||||||||||||
| 278 | strict => $strict, | ||||||||||||||||||||||||||||||||||
| 279 | errSub => $errSub, | ||||||||||||||||||||||||||||||||||
| 280 | HandleError => undef, | ||||||||||||||||||||||||||||||||||
| 281 | RaiseError => undef, | ||||||||||||||||||||||||||||||||||
| 282 | ShowErrorStatement => undef, | ||||||||||||||||||||||||||||||||||
| 283 | AutoCommit => undef, | ||||||||||||||||||||||||||||||||||
| 284 | Warn => undef, | ||||||||||||||||||||||||||||||||||
| 285 | ); | ||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||
| 288 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||
| 290 | =head3 destroy() - Schließe Datenbankverbindung | ||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||
| 292 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||
| 294 | $db->destroy; | ||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||
| 296 | =head4 Description | ||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||
| 298 | Schließe die Datenbankverbindung. Die Methode liefert keinen Wert zurück. | ||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||
| 300 | =cut | ||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||
| 302 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | sub destroy { | ||||||||||||||||||||||||||||||||
|
Subroutine
destroy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 305 | #my ($self) = @_; | ||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||
| 307 | #if (my $dbh = $self->get('dbh')) { | ||||||||||||||||||||||||||||||||||
| 308 | # $dbh->disconnect; | ||||||||||||||||||||||||||||||||||
| 309 | #} | ||||||||||||||||||||||||||||||||||
| 310 | 0 | $_[0] = undef; | |||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||
| 312 | 0 | return; | |||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||
| 315 | #sub DESTROY { | ||||||||||||||||||||||||||||||||||
| 316 | # my $self = shift; | ||||||||||||||||||||||||||||||||||
| 317 | # if (my $dbh = $self->get('dbh')) { | ||||||||||||||||||||||||||||||||||
| 318 | # $dbh->disconnect; | ||||||||||||||||||||||||||||||||||
| 319 | # } | ||||||||||||||||||||||||||||||||||
| 320 | # return; | ||||||||||||||||||||||||||||||||||
| 321 | #} | ||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||
| 323 | 12 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||
| 324 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 325 | 12 | ▶ | if ($self->{'dbms'} eq 'sqlite') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 326 | # $self->sql('BEGIN'); | ||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||
| 330 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||
| 332 | =head2 Objektmethoden | ||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||
| 334 | =head3 strict() - Schalte Datenbankverbindung in den Strict-Modus | ||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||
| 336 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||
| 338 | $bool = $db->strict; | ||||||||||||||||||||||||||||||||||
| 339 | $bool = $db->strict($bool); | ||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||
| 341 | =head4 Description | ||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||
| 343 | Ist der Strict-Modus eingeschaltet, führen alle Datenbank-Fehler | ||||||||||||||||||||||||||||||||||
| 344 | zu einer Exception. Diese Methode schaltet den Strict-Modus ein | ||||||||||||||||||||||||||||||||||
| 345 | oder stellt den ursprüngliche Modus wieder her. | ||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||
| 347 | =cut | ||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||
| 349 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | sub strict { | ||||||||||||||||||||||||||||||||
|
Subroutine
strict: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 352 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 353 | # @_: $bool | ||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 356 | 0 | my $bool = shift; | |||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||
| 358 | 0 | my $strict = $self->{'strict'}; | |||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | if ($bool xor $strict) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/4
$bool xor $strict
MC/DC0%0/2
$bool xor $strict
$bool
$strict
Truth table0%0/4
A xor B
A= $boolB= $strict
| |||||||||||||||||||||||||||||||||||
| 360 | 0 | my $dbh = $self->{'dbh'}; | |||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | if ($bool) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 362 | # Aktuelle $dbh-Einstellungen sichern | ||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||
| 364 | 0 | $self->{'HandleError'} = $dbh->{'HandleError'}; | |||||||||||||||||||||||||||||||||
| 365 | 0 | $self->{'RaiseError'} = $dbh->{'RaiseError'}; | |||||||||||||||||||||||||||||||||
| 366 | 0 | $self->{'ShowErrorStatement'} = $dbh->{'ShowErrorStatement'}; | |||||||||||||||||||||||||||||||||
| 367 | 0 | $self->{'AutoCommit'} = $dbh->{'AutoCommit'}; | |||||||||||||||||||||||||||||||||
| 368 | 0 | $self->{'Warn'} = $dbh->{'Warn'}; | |||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||
| 370 | # Strict-Mode aktivieren | ||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||
| 372 | 0 | $dbh->{'HandleError'} = $self->{'errSub'}; | |||||||||||||||||||||||||||||||||
| 373 | 0 | $dbh->{'RaiseError'} = 1; | |||||||||||||||||||||||||||||||||
| 374 | 0 | $dbh->{'ShowErrorStatement'} = 1; | |||||||||||||||||||||||||||||||||
| 375 | 0 | $dbh->{'AutoCommit'} = 0; | |||||||||||||||||||||||||||||||||
| 376 | 0 | $dbh->{'Warn'} = 0; | |||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||
| 378 | 0 | $self->{'strict'} = 1; | |||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||
| 380 | else { | ||||||||||||||||||||||||||||||||||
| 381 | # Ursprüngliche $dbh-Einstellungen wiederherstellen | ||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||
| 383 | 0 | $dbh->{'HandleError'} = $self->{'HandleError'}; | |||||||||||||||||||||||||||||||||
| 384 | 0 | $dbh->{'RaiseError'} = $self->{'RaiseError'}; | |||||||||||||||||||||||||||||||||
| 385 | 0 | $dbh->{'ShowErrorStatement'} = $self->{'ShowErrorStatement'}; | |||||||||||||||||||||||||||||||||
| 386 | 0 | $dbh->{'AutoCommit'} = $self->{'AutoCommit'}; | |||||||||||||||||||||||||||||||||
| 387 | 0 | $dbh->{'Warn'} = $self->{'Warn'}; | |||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||
| 389 | 0 | $self->{'strict'} = 0; | |||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||
| 394 | 0 | return $self->{'strict'}; | |||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||
| 397 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||
| 399 | =head3 maxBlobSize() - Liefere/Setze maximale Größe eines BLOB/TEXT-Werts (Oracle) | ||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||
| 401 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||
| 403 | $n = $db->maxBlobSize; | ||||||||||||||||||||||||||||||||||
| 404 | $n = $db->maxBlobSize($n); | ||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||
| 406 | =head4 Description | ||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||
| 408 | Liefere/Setze die maximale Größe eines BLOB/TEXT-Werts auf $n Bytes. | ||||||||||||||||||||||||||||||||||
| 409 | Defaulteinstellung ist 1024*1024 Bytes (1MB). | ||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||
| 411 | Dieser Wert ist nur für Oracle relevant und wird bei der Selektion | ||||||||||||||||||||||||||||||||||
| 412 | von BLOB/TEXT-Kolumnen benötigt. Ist der Wert einer BLOB/TEXT-Kolumne | ||||||||||||||||||||||||||||||||||
| 413 | größer als die angegebene Anzahl an Bytes wird eine Exception | ||||||||||||||||||||||||||||||||||
| 414 | ausgelöst. | ||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||
| 416 | Bei anderen DBMSen als Oracle hat das Setzen keinen Effekt und der | ||||||||||||||||||||||||||||||||||
| 417 | Returnwert ist immer 0. | ||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||
| 419 | =cut | ||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||
| 421 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||
| 423 | 2 | ▶ | sub maxBlobSize { | ||||||||||||||||||||||||||||||||
|
Subroutine
maxBlobSize: called CC=3 SCAR=16.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 424 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 425 | # @_: $n | ||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||
| 427 | 2 | ▶ | if ($self->{'dbms'} ne 'oracle') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 428 | 2 | return 0; | |||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 432 | 0 | $self->{'dbh'}->{'LongReadLen'} = shift; | |||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||
| 435 | 0 | return $self->{'dbh'}->{'LongReadLen'}; | |||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||
| 438 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||
| 440 | =head3 sql() - Führe SQL-Statement aus | ||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||
| 442 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||
| 444 | $cur = $db->sql($stmt,$forceExec); | ||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||
| 446 | =head4 Description | ||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||
| 448 | Führe SQL-Statement $stmt auf der Datenbank $db aus, instantiiere ein | ||||||||||||||||||||||||||||||||||
| 449 | Resultat-Objekt $cur und liefere eine Referenz auf dieses Objekt | ||||||||||||||||||||||||||||||||||
| 450 | zurück. | ||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||
| 452 | Ist Parameter $forceExec angegeben und wahr, wird die Ausführung | ||||||||||||||||||||||||||||||||||
| 453 | des Statements forciert. Dies kann bei Oracle PL/SQL Code notwendig | ||||||||||||||||||||||||||||||||||
| 454 | sein (siehe Doku zu Quiq::Database::Connection/sql). | ||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||
| 456 | =cut | ||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||
| 458 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||
| 460 | 273 | ▶ | sub sql { | ||||||||||||||||||||||||||||||||
|
Subroutine
sql: called CC=15 SCAR=29.7
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 461 | 273 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 462 | 273 | my $stmt = shift; | |||||||||||||||||||||||||||||||||
| 463 | 273 | my $forceExec = shift; | |||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||
| 465 | 273 | my ($dbh,$dbms) = $self->get(qw/dbh dbms/); | |||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||
| 467 | 273 | my $sth = undef; | |||||||||||||||||||||||||||||||||
| 468 | 273 | my $bindVars = 0; | |||||||||||||||||||||||||||||||||
| 469 | # my $titles = []; | ||||||||||||||||||||||||||||||||||
| 470 | 273 | my @titles; | |||||||||||||||||||||||||||||||||
| 471 | 273 | my $hits = 0; | |||||||||||||||||||||||||||||||||
| 472 | 273 | my $id = 0; | |||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||
| 474 | 273 | ▶ | if (!$stmt) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 475 | # Leeres Statement: nichts tun und Pseudocursor liefern | ||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||
| 477 | ▶ | elsif ($dbms eq 'postgresql' && $stmt =~ /^\s*(COMMIT|ROLLBACK)\s*$/i) { | |||||||||||||||||||||||||||||||||
|
Condition33%1/3
$dbms eq "postgresql" and $stmt =~ /^\s*(COMMIT|ROLLBACK)\s*$/i
MC/DC0%0/2
$dbms eq "postgresql" and $stmt =~ /^\s*(COMMIT|ROLLBACK)\s*$/i
$dbms eq "postgresql"
$stmt =~ /^\s*(COMMIT|ROLLBACK)\s*$/i
Truth table33%1/3
A and B
A= $dbms eq "postgresql"B= $stmt =~ /^\s*(COMMIT|ROLLBACK)\s*$/i
| |||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||
| 479 | # DBD::Pg hat Methoden für COMMIT und ROLLBACK. Diese *müssen* | ||||||||||||||||||||||||||||||||||
| 480 | # benutzt werden. Wir rufen sie hier auf und liefern einen | ||||||||||||||||||||||||||||||||||
| 481 | # Pseudocursor. | ||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | if ($stmt =~ /COMMIT/i) { $dbh->commit } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 484 | 0 | else { $dbh->rollback } | |||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||
| 486 | else { | ||||||||||||||||||||||||||||||||||
| 487 | 211 | $sth = $dbh->prepare($stmt); # MEMO: hängt auf kopc02 bei Fehler | |||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||
| 489 | 190 | ▶ | if ($dbms ne 'access') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 490 | # FIXME: im Falle von access ist nach Ausführung folgender | ||||||||||||||||||||||||||||||||||
| 491 | # Zeile eine Ausführung einer Selektion nicht mehr möglich! | ||||||||||||||||||||||||||||||||||
| 492 | # D.h. nach aktuellem Stand kann ein SQL-Statement via | ||||||||||||||||||||||||||||||||||
| 493 | # access keine Platzhalter enthalten. | ||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||
| 495 | 190 | $bindVars = $sth->{'NUM_OF_PARAMS'}; # Anzahl Bind-Variablen | |||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||
| 498 | 190 | ▶ | if (!$bindVars || $forceExec) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $bindVars or $forceExec
MC/DC50%1/2
not $bindVars or $forceExec
not $bindVars
$forceExec
Truth table66%2/3
not(A) or B
A= not $bindVarsB= $forceExec
| |||||||||||||||||||||||||||||||||||
| 499 | 179 | $sth->execute; | |||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||
| 501 | # Id. 0, wenn nicht verfügbar. Diese Abfrage muss unmittelbar | ||||||||||||||||||||||||||||||||||
| 502 | # nach dem execute() erfolgen! | ||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||
| 504 | 132 | ▶ | if ($dbms eq 'mysql') { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 505 | 0 | $id = $dbh->{'mysql_insertid'}; | |||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||
| 507 | elsif ($dbms eq 'sqlite') { | ||||||||||||||||||||||||||||||||||
| 508 | # Sind wir über die DBD::Proxy Schnittstelle verbunden, | ||||||||||||||||||||||||||||||||||
| 509 | # ist die Methode zur Ermittelung der rowid nicht definiert | ||||||||||||||||||||||||||||||||||
| 510 | 132 | ▶ | if ($dbh->can('sqlite_last_insert_rowid')) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 511 | # $id = $dbh->func('last_insert_rowid'); | ||||||||||||||||||||||||||||||||||
| 512 | 132 | $id = $dbh->sqlite_last_insert_rowid; | |||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||
| 516 | # Hits. -1, wenn unbekannt oder nicht verfügbar. Wir mappen auf 0. | ||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||
| 518 | 132 | $hits = $sth->rows; | |||||||||||||||||||||||||||||||||
| 519 | 132 | ▶ | $hits = 0 if $hits < 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||
| 521 | 143 | ▶ | if ($sth->{'NUM_OF_FIELDS'}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 522 | # Anmerkungen: | ||||||||||||||||||||||||||||||||||
| 523 | # * Bei SELECT mit Bind-Variablen sind die | ||||||||||||||||||||||||||||||||||
| 524 | # Kolumnentitel erst nach dem Aufruf von bind() verfügbar. | ||||||||||||||||||||||||||||||||||
| 525 | # * DBD::SQLite liefert undef, daher initialisieren wir | ||||||||||||||||||||||||||||||||||
| 526 | # hier als Fallback im Zweifel auf ein leeres Array. | ||||||||||||||||||||||||||||||||||
| 527 | # * In exotischen Fällen können Kolumnennamen nicht-\w-Zeichen | ||||||||||||||||||||||||||||||||||
| 528 | # enthalten. Daher konvertieren wir nicht nur in | ||||||||||||||||||||||||||||||||||
| 529 | # Kleinschreibung, sondern nicht-\w-Zeichen nach '_'. | ||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||
| 531 | # $titles = $sth->{'NAME_lc'} || []; | ||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||
| 533 | # Ersetze alle \W-Zeichen durch _, damit automatische | ||||||||||||||||||||||||||||||||||
| 534 | # Akzessoren möglich sind | ||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||
| 536 | 54 | ▶ | for (@{$sth->{'NAME_lc'} || []}) { | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$sth->{'NAME_lc'} || []
MC/DC0%0/1
$sth->{'NAME_lc'} || []
$sth->{'NAME_lc'}
Truth table50%1/2
A
A= $sth->{'NAME_lc'}
| |||||||||||||||||||||||||||||||||||
| 537 | 116 | (my $title = $_) =~ s/\W/_/g; | |||||||||||||||||||||||||||||||||
| 538 | 116 | push @titles,$title; | |||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||
| 541 | 54 | $hits = 0; # es wurden noch keine Datensätze gelesen | |||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||
| 545 | 205 | return Quiq::Database::Api::Dbi::Cursor->new( | |||||||||||||||||||||||||||||||||
| 546 | sth => $sth, | ||||||||||||||||||||||||||||||||||
| 547 | bindVars => $bindVars, | ||||||||||||||||||||||||||||||||||
| 548 | db => $self, | ||||||||||||||||||||||||||||||||||
| 549 | # titles => $titles, | ||||||||||||||||||||||||||||||||||
| 550 | titles => \@titles, | ||||||||||||||||||||||||||||||||||
| 551 | hits => $hits, | ||||||||||||||||||||||||||||||||||
| 552 | id => $id, | ||||||||||||||||||||||||||||||||||
| 553 | ); | ||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||
| 556 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||
| 558 | =head1 VERSION | ||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||
| 560 | 1.240 | ||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||
| 562 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||
| 564 | Frank Seitz, L<http://fseitz.de/> | ||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||
| 566 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||
| 568 | Copyright (C) 2026 Frank Seitz | ||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||
| 570 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||
| 572 | This code is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||
| 573 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||
| 575 | =cut | ||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||
| 577 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||
| 579 | 6 | 1; | |||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||
| 581 | # eof | ||||||||||||||||||||||||||||||||||