Quiq/Database/Cursor.pm

filter: Statementstmt 68.5% 122 / 178 Branchbran 38.4% 20 / 52 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 87.1% 34 / 39 Podpod 100% 21 / 21 totaltotal 66.2% 202 / 305 CC 30 SCAR 28.5
CC
30
Cov
61%
fetch
65.3
export
30.0
fetchAll
11.0
CRAP 17.3
« Quiq/Database/Api/Dbi/Cursor.pm ↑ Summary Quiq/Confluence/Client.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Database::Cursor - Datenbank-Cursor
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 DESCRIPTION
14  
15 Ein Objekt der Klasse repräsentiert das Resultat einer
16 Statement-Ausführung auf einer Relationalen Datenbank.
17  
18 =cut
19  
20 # -----------------------------------------------------------------------------
21  
22 package Quiq::Database::Cursor;
23 6 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 6 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 6 our $VERSION = '1.240';
30  
31 6 ▶use Quiq::Database::Row::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 6 ▶use Quiq::Database::Row::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 6 ▶use Quiq::Database::ResultSet::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 6 ▶use Quiq::Database::ResultSet::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 6 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36 6 ▶use Quiq::Database::Cursor;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 6 ▶use Quiq::FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 6 ▶use Quiq::PostgreSql::CopyFormat;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 6 ▶use Quiq::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 6 ▶use Quiq::Digest;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 6 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 # -----------------------------------------------------------------------------
44  
45 =head1 METHODS
46  
47 =head2 Konstruktor/Destruktor
48  
49 =head3 new() - Instantiiere Cursor
50  
51 =head4 Synopsis
52  
53 $cur = $class->new(@keyVal);
54  
55 =head4 Description
56  
57 Instantiiere ein Cursor-Objekt mit den Attributen @keyVal
58 und liefere dieses zurück.
59  
60 =cut
61  
62 # -----------------------------------------------------------------------------
63  
64 218 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
65 218 my $class = shift;
66 # @_: @keyVal
67  
68 218 my $self = $class->SUPER::new(
69 apiCur => undef,
70 bindVars => 0,
71 cacheFile => undef,
72 cacheFh => undef,
73 cacheOp => '', # damit einfach mit eq verglichen werden kann
74 db => undef,
75 hits => 0,
76 id => 0,
77 # Attribut rowOperation wird bei save() gesetzt: 0, 'I', 'U', 'D'
78 rowOperation => 0,
79 rowClass => undef,
80 tableClass => undef,
81 titles => [],
82 stmt => undef,
83 startTime => scalar(Time::HiRes::gettimeofday),
84 execTime => 0,
85 curName => undef,
86 chunkSize => 0,
87 chunkPos => 0,
88 );
89  
90 218 $self->set(@_);
91 218 $self->weaken('db');
92  
93 218 return $self;
94 }
95  
96 # -----------------------------------------------------------------------------
97  
98 =head3 close() - Schließe Cursor
99  
100 =head4 Synopsis
101  
102 $cur->close;
103  
104 =head4 Alias
105  
106 destroy()
107  
108 =head4 Description
109  
110 Schließe Cursor. Die Methode liefert keinen Wert zurück.
111  
112 =cut
113  
114 # -----------------------------------------------------------------------------
115  
116 46 ▶sub close {
Subroutine close: called CC=2 SCAR=7.6
Pod documented
117 46 my ($self) = @_;
118  
119 46 ▶ if (my $curName = $self->{'curName'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $curName = $self->{"curName"}) 0 46 46
120 0 $self->{'db'}->sql("CLOSE $curName",-log=>0); # PostgreSQL
121 }
122  
123 46 $_[0] = undef;
124 }
125  
126 {
127 6 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
128 6 *destroy = \&close;
129 }
130  
131 # -----------------------------------------------------------------------------
132  
133 =head2 Akzessoren
134  
135 =head3 bindVars() - Liefere Anzahl der Bind-Variablen
136  
137 =head4 Synopsis
138  
139 $n = $cur->bindVars;
140  
141 =cut
142  
143 # -----------------------------------------------------------------------------
144  
145 13 ▶sub bindVars {
Subroutine bindVars: called CC=1 SCAR=0.0
Pod documented
146 13 return shift->{'bindVars'};
147 }
148  
149 # -----------------------------------------------------------------------------
150  
151 =head3 bindTypes() - Setze/Liefere Datentypen der Bind-Variablen
152  
153 =head4 Synopsis
154  
155 @arr|$arr = $cur->bindTypes(@dataTypes);
156 @arr|$arr = $cur->bindTypes;
157  
158 =cut
159  
160 # -----------------------------------------------------------------------------
161  
162 3 ▶sub bindTypes {
Subroutine bindTypes: called CC=1 SCAR=0.0
Pod documented
163 3 return shift->{'apiCur'}->bindTypes(@_);
164 }
165  
166 # -----------------------------------------------------------------------------
167  
168 =head3 db() - Liefere Datenbankverbindung
169  
170 =head4 Synopsis
171  
172 $db = $cur->db;
173  
174 =cut
175  
176 # -----------------------------------------------------------------------------
177  
178 1 ▶sub db {
Subroutine db: called CC=1 SCAR=0.0
Pod documented
179 1 return shift->{'db'};
180 }
181  
182 # -----------------------------------------------------------------------------
183  
184 =head3 hits() - Liefere Anzahl der getroffenen Datensätze
185  
186 =head4 Synopsis
187  
188 $n = $cur->hits;
189  
190 =head4 Description
191  
192 Liefere die Anzahl der von einem INSERT, UPDATE oder DELETE
193 getroffenen Datesätze.
194  
195 =cut
196  
197 # -----------------------------------------------------------------------------
198  
199 3 ▶sub hits {
Subroutine hits: called CC=1 SCAR=0.0
Pod documented
200 3 return shift->{'hits'};
201 }
202  
203 # -----------------------------------------------------------------------------
204  
205 =head3 id() - Liefere Wert der Autoincrement-Kolumne
206  
207 =head4 Synopsis
208  
209 $id = $cur->id;
210  
211 =head4 Alias
212  
213 insertId()
214  
215 =head4 Description
216  
217 Liefere den Wert der Autoinkrement-Kolumne nach einem INSERT.
218  
219 =cut
220  
221 # -----------------------------------------------------------------------------
222  
223 8 ▶sub id {
Subroutine id: called CC=1 SCAR=0.0
Pod documented
224 8 return shift->{'id'};
225 }
226  
227 {
228 6 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
229 6 *insertId = \&id;
230 }
231  
232 # -----------------------------------------------------------------------------
233  
234 =head3 rowOperation() - Liefere die Datensatz-Operation
235  
236 =head4 Synopsis
237  
238 $op = $cur->rowOperation;
239  
240 =head4 Description
241  
242 Liefere die von save() durchgeführte Datensatz-Operation: 0, 'I', 'U'
243 oder 'D'.
244  
245 =cut
246  
247 # -----------------------------------------------------------------------------
248  
249 0 ▶sub rowOperation {
Subroutine rowOperation: not called CC=1 SCAR=6.9
Pod documented
250 0 return shift->{'rowOperation'};
251 }
252  
253 # -----------------------------------------------------------------------------
254  
255 =head3 rowClass() - Liefere Namen der Datensatz-Klasse
256  
257 =head4 Synopsis
258  
259 $rowClass = $cur->rowClass;
260  
261 =cut
262  
263 # -----------------------------------------------------------------------------
264  
265 1 ▶sub rowClass {
Subroutine rowClass: called CC=1 SCAR=0.0
Pod documented
266 1 return shift->{'rowClass'};
267 }
268  
269 # -----------------------------------------------------------------------------
270  
271 =head3 stmt() - Liefere SQL-Statement
272  
273 =head4 Synopsis
274  
275 $stmt = $cur->stmt;
276  
277 =head4 Description
278  
279 Liefere das SQL-Statement, wie es an das DBMS übermittelt und von
280 ihm ausgeführt wurde. Das von der Methode gelieferte Statement
281 kann von dem Statement, das beim Aufruf angegeben wurde, verschieden
282 sein, da ggf. interne Transformationsschritte auf das Statement
283 anwendet wurden.
284  
285 =cut
286  
287 # -----------------------------------------------------------------------------
288  
289 16 ▶sub stmt {
Subroutine stmt: called CC=1 SCAR=0.0
Pod documented
290 16 return shift->{'stmt'};
291 }
292  
293 # -----------------------------------------------------------------------------
294  
295 =head3 titles() - Liefere Liste der Kolumnentitel
296  
297 =head4 Synopsis
298  
299 @titles | $titlesA = $cur->titles;
300  
301 =head4 Description
302  
303 Liefere die Liste der Kolumnenwerte. Im Skalarkontext liefere
304 eine Referenz auf die Liste.
305  
306 =cut
307  
308 # -----------------------------------------------------------------------------
309  
310 4 ▶sub titles {
Subroutine titles: called CC=2 SCAR=6.9
Pod documented
311 4 my $self = shift;
312 4 ▶ return wantarray? @{$self->{'titles'}}: $self->{'titles'};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 3 4
313 }
314  
315 # -----------------------------------------------------------------------------
316  
317 =head3 width() - Anzahl der Kolumnen
318  
319 =head4 Synopsis
320  
321 $width = $cur->width;
322  
323 =head4 Description
324  
325 Liefere die Anzahl der Kolumnen.
326  
327 =cut
328  
329 # -----------------------------------------------------------------------------
330  
331 0 ▶sub width {
Subroutine width: not called CC=1 SCAR=6.9
Pod documented
332 0 my $self = shift;
333 0 return scalar @{$self->{'titles'}};
334 }
335  
336 # -----------------------------------------------------------------------------
337  
338 =head2 Tests
339  
340 =head3 fromCache() - Liefert der Cursor Datensätze aus dem Cache?
341  
342 =head4 Synopsis
343  
344 $bool = $cur->fromCache;
345  
346 =head4 Description
347  
348 Liefere wahr, wenn der Cursor Datensätze aus dem Cache liefert,
349 andernfalls falsch.
350  
351 =cut
352  
353 # -----------------------------------------------------------------------------
354  
355 0 ▶sub fromCache {
Subroutine fromCache: not called CC=2 SCAR=17.9
Pod documented
356 0 ▶ return shift->{'cacheOp'} eq 'r'? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{'cacheOp'} eq 'r' ? : 0 0 0
357 }
358  
359 # -----------------------------------------------------------------------------
360  
361 =head3 isSelect() - Liefert der Cursor Datensätze?
362  
363 =head4 Synopsis
364  
365 $bool = $cur->isSelect;
366  
367 =head4 Description
368  
369 Liefere wahr, wenn der Cursor Datensätze liefert,
370 andernfalls falsch.
371  
372 =cut
373  
374 # -----------------------------------------------------------------------------
375  
376 0 ▶sub isSelect {
Subroutine isSelect: not called CC=2 SCAR=17.9
Pod documented
377 0 ▶ return @{shift->{'titles'}}? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
@{+(shift())->{'titles'};} ? : 0 0 0
378 }
379  
380 # -----------------------------------------------------------------------------
381  
382 =head2 Zeitmessung
383  
384 =head3 startTime() - Liefere Startzeitpunkt der Statement-Ausführung
385  
386 =head4 Synopsis
387  
388 $time = $cur->startTime;
389  
390 =cut
391  
392 # -----------------------------------------------------------------------------
393  
394 1 ▶sub startTime {
Subroutine startTime: called CC=1 SCAR=0.0
Pod documented
395 1 return shift->{'startTime'};
396 }
397  
398 # -----------------------------------------------------------------------------
399  
400 =head3 execTime() - Liefere Dauer der Statement-Ausführung
401  
402 =head4 Synopsis
403  
404 $time = $cur->execTime;
405  
406 =cut
407  
408 # -----------------------------------------------------------------------------
409  
410 1 ▶sub execTime {
Subroutine execTime: called CC=1 SCAR=0.0
Pod documented
411 1 return shift->{'execTime'};
412 }
413  
414 # -----------------------------------------------------------------------------
415  
416 =head3 elapsed() - Liefere Dauer seit Start der Statement-Ausführung
417  
418 =head4 Synopsis
419  
420 $time = $cur->elapsed;
421  
422 =head4 Alias
423  
424 time()
425  
426 =cut
427  
428 # -----------------------------------------------------------------------------
429  
430 3 ▶sub elapsed {
Subroutine elapsed: called CC=1 SCAR=0.0
Pod documented
431 3 my $self = shift;
432 3 return Time::HiRes::gettimeofday-$self->{'startTime'};
433 }
434  
435 {
436 6 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
437 6 *time = \&elapsed;
438 }
439  
440 # -----------------------------------------------------------------------------
441  
442 =head2 Bind
443  
444 =head3 bind() - Binde Werte an Statement und führe Statement aus
445  
446 =head4 Synopsis
447  
448 $cur2 = $cur->bind(@vals);
449  
450 =head4 Description
451  
452 Binde eine Liste von Werten an die Platzhalter eines zuvor
453 präparierten SQL-Statements und führe dieses Statement auf der
454 Datenbank aus. Die Anzahl der Werte muß ein Vielfaches der Anzahl der
455 Bind-Variablen sein.
456  
457 =cut
458  
459 # -----------------------------------------------------------------------------
460  
461 12 ▶sub bind {
Subroutine bind: called CC=1 SCAR=0.0
Pod documented
462 12 my $self = shift;
463 # @_: @opt,@vals
464  
465 # Werte binden und Statement ausführen
466  
467 12 my $startTime = Time::HiRes::gettimeofday;
468 12 my $apiCur = $self->{'apiCur'}->bind(@_);
469 12 my $execTime = Time::HiRes::gettimeofday-$startTime;
470  
471 # Attribute Lowlevel-Cursor abfragen
472  
473 12 my $bindVars = 0;
474 12 my $hits = $apiCur->hits;
475 12 my $titles = $apiCur->titles;
476 12 my $id = $apiCur->id;
477  
478 return Quiq::Database::Cursor->new(
479 apiCur => $apiCur,
480 bindVars => $bindVars,
481 db => $self, # schwache Referenz, siehe Cursor-Konstruktor
482 hits => $hits,
483 id => $id,
484 12 rowClass => $self->{'rowClass'},
485 titles => $titles,
486 startTime => $startTime,
487 execTime => $execTime,
488 );
489 }
490  
491 # -----------------------------------------------------------------------------
492  
493 =head2 Fetch
494  
495 =head3 export() - Schreibe Datensätze in Datei
496  
497 =head4 Synopsis
498  
499 $cur->export($file,@opt);
500  
501 =head4 Arguments
502  
503 =over 4
504  
505 =item $file
506  
507 Pfad der Datei. Im Falle von '-' STDOUT.
508  
509 =back
510  
511 =head4 Options
512  
513 =over 4
514  
515 =item -limit => $n (Default: 0)
516  
517 Schreibe maximal $n Datensätze. 0 = Keine Begrenzung.
518  
519 =item -titles => $bool (Default: 0)
520  
521 Schreibe als erste Zeile die Kolumentitel.
522  
523 =back
524  
525 =head4 Description
526  
527 Exportiere die Datenesätze des Cursors in Datei $file. Die Datensätze
528 werden im COPY-Format geschrieben, d.h. Kolumnentrenner ist C<\t> und
529 Zeilentrenner ist C<\n>.
530  
531 =cut
532  
533 # -----------------------------------------------------------------------------
534  
535 0 ▶sub export {
Subroutine export: not called CC=5 SCAR=34.0
Pod documented
536 0 my ($self,$file) = splice @_,0,2;
537  
538 # Optionen
539  
540 0 my $limit = 0;
541 0 my $titles = 0;
542  
543 0 $self->parameters(\@_,
544 -limit => \$limit,
545 -titles => \$titles,
546 );
547  
548 # Operation ausführen
549  
550 0 my $fh = Quiq::FileHandle->new('>',$file);
551 0 ▶ if ($self->db->utf8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->db->utf8) 0 0 0
552 0 $fh->setEncoding('utf8');
553 }
554  
555 0 my $cpy = Quiq::PostgreSql::CopyFormat->new($self->width);
556  
557 0 ▶ if ($titles) {
Branch: 1 branch
BranchTrueFalseTotal
if ($titles) 0 0 0
558 0 my $titleA = $self->titles;
559 0 print $fh $cpy->arrayToLine($titleA),"\n";
560 }
561 0 my $i = 0;
562 0 ▶ while (my $row = $self->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $self->fetch) 0 0 0
563 0 print $cpy->arrayToLine($row),"\n";
564 0 ▶ if (++$i == $limit) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$i == $limit) 0 0 0
565 0 last;
566 }
567 }
568 0 $fh->close;
569  
570 0 return;
571 }
572  
573 # -----------------------------------------------------------------------------
574  
575 =head3 fetch() - Liefere nächsten Datensatz der Ergebnismenge
576  
577 =head4 Synopsis
578  
579 $row = $cur->fetch;
580  
581 =head4 Description
582  
583 Liefere den nächsten Datensatz aus der Ergebnismenge. Ist das Ende der
584 Ergebnismenge erreicht, liefere undef.
585  
586 =cut
587  
588 # -----------------------------------------------------------------------------
589  
590 102 ▶sub fetch {
Subroutine fetch: called CC=13 SCAR=41.8
Pod documented
591 102 my $self = shift;
592  
593 102 my ($cacheOp,$rowClass,$titleA) = $self->get(qw/cacheOp rowClass titles/);
594  
595 102 my $arr;
596 102 ▶ if ($cacheOp eq 'r') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cacheOp eq 'r') { } 0 102 102
597 # Wir holen die Datensätze aus dem Cache
598  
599 0 my $fh = $self->{'cacheFh'};
600  
601 # Cachedatei ist bereits geschlossen
602 0 ▶ return undef if !$fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 0 0
603  
604 # Datensatz aus Cachedatei lesen
605  
606 0 my $width = @$titleA;
607 0 my $utf8 = $self->{'db'}->utf8;
608  
609 0 my @arr;
610 0 ▶ for (my $i = 0; $i < $width; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $width) 0 0 0
611 0 my $data = $fh->readData;
612 0 ▶ if (!defined $data) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data) 0 0 0
613 # Ende Cachedatei erreicht, diese schließen
614  
615 0 $self->{'cacheFh'}->close;
616 0 return undef;
617 }
618 0 ▶ if ($utf8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($utf8) 0 0 0
619 0 $data = Encode::decode('utf-8',$data);
620 }
621 0 push @arr,$data;
622 }
623 0 $arr = \@arr;
624 }
625 else {
626 # Wir holen die Datensätze von der Datenbank
627  
628 102 my ($apiCur,$curName,$chunkSize) =
629 $self->get(qw/apiCur curName chunkSize/);
630  
631 # Lowlevel-Cursor ist bereits zu
632 102 ▶ return undef if !$apiCur;
Branch: 1 branch
BranchTrueFalseTotal
unless $apiCur 0 102 102
633  
634 # Datensatz fetchen
635 102 $arr = $apiCur->fetch($curName,$chunkSize,\$self->{'chunkPos'});
636  
637 102 ▶ if ($cacheOp eq 'w') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cacheOp eq "w") 0 102 102
638 # Datensatz in Cache speichern
639  
640 0 ▶ if (!$arr) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $arr) { } 0 0 0
641 # Ende erreicht. Cachedatei schließen und umbenennen,
642 # so dass sie mit dem Schließen des Cursors nicht
643 # automatisch gelöscht wird.
644  
645 0 $self->{'cacheFh'}->close;
646  
647 0 my $p = Quiq::Path->new;
648 0 my $cacheFile = $self->{'cacheFile'};
649  
650 0 my ($dir) = $p->split($cacheFile);
651 my $newCacheFile = $dir.'/'.
652 0 Quiq::Digest->md5($self->{'stmt'});
653 0 $p->rename($cacheFile,$newCacheFile);
654 0 $self->{'cacheFile'} = $newCacheFile;
655 }
656 else {
657 0 my $utf8 = $self->{'db'}->utf8;
658 0 my $width = @$titleA;
659 0 ▶ for (my $i = 0; $i < $width; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $width) 0 0 0
660 0 my $data = $arr->[$i];
661 0 ▶ if ($utf8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($utf8) 0 0 0
662 0 $data = Encode::encode('utf-8',$data);
663 }
664 0 $self->{'cacheFh'}->writeData($data);
665 }
666 }
667 }
668  
669 # Ende erreicht, Lowlevel-Cursor schließen
670  
671 102 ▶ if (!$arr) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($arr) 37 65 102
672 37 $self->{'apiCur'}->destroy;
673 37 return undef;
674 }
675  
676 }
677  
678 # Datensatz-Objekt instantiieren
679  
680 65 my $row = $rowClass->new($titleA,$arr);
681 65 ▶ if ($row->can('rowStatus')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row->can("rowStatus")) 28 37 65
682 28 $row->rowStatus(0);
683 }
684  
685 65 return $row;
686 }
687  
688 # -----------------------------------------------------------------------------
689  
690 =head3 fetchAll() - Liefere gesamte Ergebnismenge
691  
692 =head4 Synopsis
693  
694 @rows | $tab = $cur->fetchAll;
695 @rows | $tab = $cur->fetchAll($autoClose);
696 @rows | $tab = $cur->fetchAll($autoClose,$limit);
697  
698 =head4 Arguments
699  
700 =over 4
701  
702 =item $autoClose (Default: 0)
703  
704 Ist Parameter $autoClose angegeben und wahr, schließe den Cursor
705 automatisch.
706  
707 =item $limit (Default: 0)
708  
709 Fetche maximal $limit Datensätze. Falls 0, fetche alle Datensätze.
710  
711 =back
712  
713 =head4 Returns
714  
715 Liste der Datensätze (List-Kontext) der ein Resultset-Objekt
716 (Skalar-Kontect).
717  
718 =head4 Description
719  
720 Liefere die Ergebnismenge als Liste von Datensätzen oder als
721 Tabelle. Ist der Parameter $autoClose angegeben und "wahr" schließe
722 den Cursor automatisch.
723  
724 =cut
725  
726 # -----------------------------------------------------------------------------
727  
728 10 ▶sub fetchAll {
Subroutine fetchAll: called CC=10 SCAR=24.0
Pod documented
729 10 my ($self,$autoClose,$limit) = @_;
730  
731 # Alle oder maximal $limit Datensätze fetchen
732  
733 10 my @rows;
734 10 my $i = 0;
735 10 ▶ while (my $row = $self->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $self->fetch) 29 10 39
736 29 $i++;
737 29 push @rows,$row;
738 29 ▶ if ($limit && $i >= $limit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit and $i >= $limit) 0 29 29
Condition33%1/3
$limit and $i >= $limit
!ll&&!rl&&r
2900
MC/DC0%0/2
$limit and $i >= $limit
$limit $i >= $limit
Truth table33%1/3
A and B
A= $limitB= $i >= $limit
ABresult
0X0
100
111
739 0 last;
740 }
741 }
742  
743 # Table-Objekt instantiieren, wenn skalarer Wert erwartet wird
744  
745 10 my $tab;
746 10 ▶ if (!wantarray && defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (not wantarray and defined wantarray) 3 7 10
Condition66%2/3
not wantarray and defined wantarray
!ll&&!rl&&r
703
MC/DC50%1/2
not wantarray and defined wantarray
not wantarray defined wantarray
Truth table66%2/3
not(A) and B
A= not wantarrayB= defined wantarray
ABresult
0X0
100
111
747 3 my $rowClass = $self->{'rowClass'};
748 3 my $tableClass = $self->{'tableClass'};
749  
750 $tab = $tableClass->new($rowClass,$self->{'titles'},\@rows,
751 stmt => $self->{'stmt'},
752 hits => $self->{'hits'},
753 startTime => $self->{'startTime'},
754 3 ▶ execTime => $self->{'execTime'},
Branch: 1 branch
BranchTrueFalseTotal
$limit && $self->fetch ? : 0 3 3
Condition33%1/3
$limit and $self->fetch
!ll&&!rl&&r
300
MC/DC0%0/2
$limit and $self->fetch
$limit $self->fetch
Truth table33%1/3
A and B
A= $limitB= $self->fetch
ABresult
0X0
100
111
755 fetchTime => $self->time,
756 moreRowsExist => $limit && $self->fetch? 1: 0,
757 );
758 }
759  
760 # Cursor schließen, falls $autoClose
761  
762 10 ▶ if ($autoClose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($autoClose) 9 1 10
763 9 $self->close
764 }
765  
766 10 ▶ return wantarray? @rows: $tab;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 3 10
767 }
768  
769 # -----------------------------------------------------------------------------
770  
771 =head1 VERSION
772  
773 1.240
774  
775 =head1 AUTHOR
776  
777 Frank Seitz, L<http://fseitz.de/>
778  
779 =head1 COPYRIGHT
780  
781 Copyright (C) 2026 Frank Seitz
782  
783 =head1 LICENSE
784  
785 This code is free software; you can redistribute it and/or modify
786 it under the same terms as Perl itself.
787  
788 =cut
789  
790 # -----------------------------------------------------------------------------
791  
792 6 1;
793  
794 # eof
« Quiq/Database/Api/Dbi/Cursor.pm ↑ Summary Quiq/Confluence/Client.pm »