| 1 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | Quiq::Database::Row - Basisklasse Datensatz (abstrakt) | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | =head1 BASE CLASS | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | L<Quiq::Object> | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | Ein Objekt der Klasse repräsentiert einen Datensatz. | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | package Quiq::Database::Row; | ||||||||||||||||||||
| 22 | 13 | ▶ | use base qw/Quiq::Object/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 13 | ▶ | use v5.10; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | 13 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 26 | 13 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 13 | our $VERSION = '1.240'; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 13 | ▶ | use Quiq::Perl; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | 13 | ▶ | use Quiq::Database::ResultSet::Object; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | =head1 METHODS | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | =head2 Miscellaneous | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | =head3 tableClass() - Liefere Namen der Tabellenklasse | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | =head4 Synopsis | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | $tableClass = $this->tableClass; | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | =head4 Returns | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | Name der Tabellenklasse (String) | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | =head4 Description | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | Ermittele den Namen der Tabellenklasse zur Datensatzklasse | ||||||||||||||||||||
| 52 | und liefere diesen zurück. | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =head4 Details | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | Eine Tabellenklasse speichert die Ergebnismenge einer Selektion. | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | Die bei einer Selektion verwendete Tabellenklasse hängt von der | ||||||||||||||||||||
| 59 | Datensatz-Klasse ab. Es gelten die Defaults: | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | =over 2 | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | =item * | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | Tabellenklasse bei Objekt-Datensätzen: C<< Quiq::Database::ResultSet::Object >> | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | =item * | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | Tabellenklasse bei Array-Datensätzen: C<< Quiq::Database::ResultSet::Array >> | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | =back | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | Abweichend vom Default kann eine abgeleitete Datensatzklasse die | ||||||||||||||||||||
| 74 | Tabellenklasse über die Klassenvariable | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | our $TableClass = '...'; | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | festlegen. | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | Ferner ist es möglich, die Tabellenklasse bei der Selektion per | ||||||||||||||||||||
| 81 | Option festzulegen: | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | $tab = $rowClass->select($db, | ||||||||||||||||||||
| 84 | -tableClass => $tableClass, | ||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =cut | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 13 | my %cache; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 209 | ▶ | sub tableClass { | ||||||||||||||||||
|
Subroutine
tableClass: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||
| 94 | 209 | ▶ | my $class = ref $_[0] || $_[0]; | ||||||||||||||||||
|
Condition33%1/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | # FXIME: auf Klasse ClassConfig umstellen (?) | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | # state %cache; | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 209 | ▶ | if (!$cache{$class}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | 13 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 102 | 10 | my $found = 0; | |||||||||||||||||||
| 103 | 10 | for ($class,Quiq::Perl->baseClassesISA($class)) { | |||||||||||||||||||
| 104 | 13 | my $ref = *{"$_\::TableClass"}{SCALAR}; | |||||||||||||||||||
| 105 | 13 | ▶ | if ($$ref) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | 10 | $cache{$class} = $$ref; | |||||||||||||||||||
| 107 | 10 | $found = 1; | |||||||||||||||||||
| 108 | 10 | last; | |||||||||||||||||||
| 109 | } | ||||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | # Paranoia-Test | ||||||||||||||||||||
| 112 | 10 | ▶ | if (!$found) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 113 | 0 | $class->throw( | |||||||||||||||||||
| 114 | 'ROW-00001: Datensatz-Klasse definiert keine Tabellenklasse', | ||||||||||||||||||||
| 115 | RowClass => $class, | ||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||
| 117 | } | ||||||||||||||||||||
| 118 | } | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 209 | return $cache{$class}; | |||||||||||||||||||
| 121 | } | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | =head3 makeTable() - Erzeuge Datensatz-Tabelle | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | =head4 Synopsis | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | $tab = $class->makeTable(\@titles,\@data); | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | =head4 Description | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | Erzeuge eine Datensatz-Tabelle mit Kolumnentiteln @titles und den | ||||||||||||||||||||
| 134 | Datensätzen @rows und liefere eine Referenz auf dieses Objekt zurück. | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | =head4 Example | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | Instanttierung über spezifische Datensatz-Klasse: | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | $tab = Person->makeTable( | ||||||||||||||||||||
| 141 | [qw/per_id per_vorname per_nachname per_geburtsdatum/], | ||||||||||||||||||||
| 142 | qw/1 Rudi Ratlos 1971-04-23/, | ||||||||||||||||||||
| 143 | qw/2 Erika Mustermann 1955-03-16/, | ||||||||||||||||||||
| 144 | qw/3 Harry Hirsch 1948-07-22/, | ||||||||||||||||||||
| 145 | qw/3 Susi Sorglos 1992-10-23/, | ||||||||||||||||||||
| 146 | ); | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | Instanttierung über anonyme Datensatz-Klasse: | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | $tab = Quiq::Database::Row::Object->makeTable( | ||||||||||||||||||||
| 151 | [qw/per_id per_vorname per_nachname per_geburtsdatum/], | ||||||||||||||||||||
| 152 | qw/1 Rudi Ratlos 1971-04-23/, | ||||||||||||||||||||
| 153 | qw/2 Erika Mustermann 1955-03-16/, | ||||||||||||||||||||
| 154 | qw/3 Harry Hirsch 1948-07-22/, | ||||||||||||||||||||
| 155 | qw/3 Susi Sorglos 1992-10-23/, | ||||||||||||||||||||
| 156 | ); | ||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | =cut | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | 1 | ▶ | sub makeTable { | ||||||||||||||||||
|
Subroutine
makeTable: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 163 | 1 | my $class = shift; | |||||||||||||||||||
| 164 | 1 | my $titles = shift; | |||||||||||||||||||
| 165 | # @_: @rows; | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | 1 | my $n = scalar @$titles; | |||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | 1 | my @rows; | |||||||||||||||||||
| 170 | 1 | ▶ | while (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 171 | 4 | my @arr = splice @_,0,$n; | |||||||||||||||||||
| 172 | 4 | push @rows,$class->new($titles,\@arr); | |||||||||||||||||||
| 173 | } | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | 1 | return $class->tableClass->new($class,$titles,\@rows); | |||||||||||||||||||
| 176 | } | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | =head1 VERSION | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | 1.240 | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | =head1 AUTHOR | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | Frank Seitz, L<http://fseitz.de/> | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | =head1 COPYRIGHT | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | Copyright (C) 2026 Frank Seitz | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | =head1 LICENSE | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | This code is free software; you can redistribute it and/or modify | ||||||||||||||||||||
| 195 | it under the same terms as Perl itself. | ||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | =cut | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 200 | |||||||||||||||||||||
| 201 | 13 | 1; | |||||||||||||||||||
| 202 | |||||||||||||||||||||
| 203 | # eof | ||||||||||||||||||||