Quiq/Dbms.pm

filter: Statementstmt 100% 33 / 33 Branchbran 95.4% 21 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 100% 10 / 10 totaltotal 98.7% 78 / 79 CC 12 SCAR 6.7
CC
12
Cov
98%
new
3.0
dbmsNames
2.0
dbmsTestVector
2.0
CRAP 2.0
« Quiq/File/Image.pm ↑ Summary Quiq/ApplicationPaths.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Dbms - Datenbanksystem
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 SYNOPSIS
14  
15 use Quiq::Dbms;
16
17 # Instantiierung
18 my $d = Quiq::Dbms->new($dbms);
19
20 # Namen der unterstützten Datenbanksysteme
21 my @names = Quiq::Dbms->dbmsNames;
22
23 # Boolsche Variable für Tests
24
25 ($oracle,$postgresql,$sqlite,$mysql,$access,$mssql,$jdbc) =
26 $d->dbmsTestVector;
27
28 # Test-Methoden
29
30 $bool = $d->isOracle;
31 $bool = $d->isPostgreSQL;
32 $bool = $d->isSQLite;
33 $bool = $d->isMySQL;
34 $bool = $d->isAccess;
35 $bool = $d->isMSSQL;
36 $bool = $d->isJDBC;
37  
38 =head1 DESCRIPTION
39  
40 Ein Objekt der Klasse repräsentiert ein Datenbanksystem, bestehend
41 (lediglich) aus dem Namen des Datenbanksystems und dessen Version.
42 Die Klasse stellt Testmethoden für die Art des DBMS zur Verfügung
43 und ist daher vor allem als Basisklasse nützlich, z.B. für Klassen,
44 die SQL-Code generieren oder analysieren.
45  
46 =head1 ATTRIBUTES
47  
48 =over 4
49  
50 =item dbms => $dbmsName
51  
52 Name des DBMS.
53  
54 =item version => $version
55  
56 Versionsnummer des DBMS.
57  
58 =back
59  
60 =cut
61  
62 # -----------------------------------------------------------------------------
63  
64 package Quiq::Dbms;
65 10 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67 10 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71 10 our $VERSION = '1.240';
72  
73 # -----------------------------------------------------------------------------
74  
75 =head1 METHODS
76  
77 =head2 Klassenmethoden
78  
79 =head3 new() - Konstruktor
80  
81 =head4 Synopsis
82  
83 $d = $class->new($dbms);
84 $d = $class->new($dbms,$version);
85 $d = $class->new($db);
86  
87 =head4 Arguments
88  
89 =over 4
90  
91 =item $dbms
92  
93 Name des DBMS.
94  
95 =item $version
96  
97 Versionsnummer des DBMS.
98  
99 =back
100  
101 =head4 Returns
102  
103 DBMS-Objekt
104  
105 =head4 Description
106  
107 Instantiiere ein DBMS-Objekt für DBMS $dbms und liefere eine
108 Referenz auf dieses Objekt zurück. Die Liste der unterstützten
109 DBMSe siehe $class->L<dbmsNames|"dbmsNames() - Liste der Namen der unterstützten Datenbanksysteme">().
110  
111 =cut
112  
113 # -----------------------------------------------------------------------------
114  
115 115 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
116 115 my $class = shift;
117 115 ▶ my $dbms = ref $_[0]? shift->dbms: shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 115 115
118 115 my $version = shift;
119  
120 # DBMS-Namen case insensitive suchen
121  
122 115 my ($dbmsName) = grep {lc($dbms) eq lc($_)} $class->dbmsNames;
123 115 ▶ if (!$dbmsName) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbmsName) 1 114 115
124 1 $class->throw(
125 '-00001: Unknown DBMS',
126 Dbms => $dbms,
127 );
128 }
129  
130 # Objekt instantiieren
131  
132 114 return $class->SUPER::new(
133 dbms => $dbmsName,
134 version => $version,
135 );
136 }
137  
138 # -----------------------------------------------------------------------------
139  
140 =head2 Klassenmethoden
141  
142 =head3 dbmsNames() - Liste der Namen der unterstützten Datenbanksysteme
143  
144 =head4 Synopsis
145  
146 $namesA | @names = $this->dbmsNames;
147  
148 =head4 Description
149  
150 Liefere folgende Liste von DBMS-Namen (in dieser Reihenfolge):
151  
152 Oracle
153 PostgreSQL
154 SQLite
155 MySQL
156 Access
157 MSSQL
158 JDBC
159  
160 =cut
161  
162 # -----------------------------------------------------------------------------
163  
164 10 my @DbmsNames = qw/Oracle PostgreSQL SQLite MySQL Access MSSQL JDBC/;
165  
166 329 ▶sub dbmsNames {
Subroutine dbmsNames: called CC=2 SCAR=6.9
Pod documented
167 329 ▶ return wantarray? @DbmsNames: \@DbmsNames;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 328 1 329
168 }
169  
170 # -----------------------------------------------------------------------------
171  
172 =head2 Objektmethoden
173  
174 =head3 dbmsTestVector() - Vektor für DBMS-Tests
175  
176 =head4 Synopsis
177  
178 ($oracle,$postgresql,$sqlite,$mysql,$access,$mssql,$jdbc) = $d->dbmsTestVector;
179  
180 =head4 Description
181  
182 Liefere einen Vektor von boolschen Werten, von denen genau einer
183 wahr ist, und zwar derjenige, der dem DBMS entspricht, auf den das
184 Objekt instantiiert ist.
185  
186 Die Methode ist für Programmcode nützlich, der DBMS-spezifische
187 Unterscheidungen macht. Der Code braucht dann lediglich auf den
188 Wert einer Variable prüfen
189  
190 if ($oracle) ...
191  
192 statt einen umständlichen und fehleranfälligen Stringvergleich
193 durchzuführen
194  
195 if ($dbms eq 'Oracle') ...
196  
197 =cut
198  
199 # -----------------------------------------------------------------------------
200  
201 210 ▶sub dbmsTestVector {
Subroutine dbmsTestVector: called CC=2 SCAR=6.9
Pod documented
202 210 my $self = shift;
203 210 ▶ return map {$_ eq $self->{'dbms'}? 1: 0} $self->dbmsNames;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq $self->{'dbms'} ? : 210 1260 1470
204 }
205  
206 # -----------------------------------------------------------------------------
207  
208 =head3 isOracle() - Teste auf Oracle
209  
210 =head4 Synopsis
211  
212 $bool = $d->isOracle;
213  
214 =head4 Description
215  
216 Prüfe, ob das Datenbanksystem Oracle ist. Wenn ja, liefere wahr,
217 sonst falsch.
218  
219 =cut
220  
221 # -----------------------------------------------------------------------------
222  
223 18 ▶sub isOracle {
Subroutine isOracle: called CC=2 SCAR=6.9
Pod documented
224 18 ▶ return shift->{'dbms'} eq 'Oracle'? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{'dbms'} eq 'Oracle' ? : 3 15 18
225 }
226  
227 # -----------------------------------------------------------------------------
228  
229 =head3 isPostgreSQL() - Teste auf PostgreSQL
230  
231 =head4 Synopsis
232  
233 $bool = $d->isPostgreSQL;
234  
235 =head4 Description
236  
237 Prüfe, ob das Datenbanksystem PostgreSQL ist. Wenn ja, liefere wahr,
238 sonst falsch.
239  
240 =cut
241  
242 # -----------------------------------------------------------------------------
243  
244 404 ▶sub isPostgreSQL {
Subroutine isPostgreSQL: called CC=2 SCAR=6.9
Pod documented
245 404 ▶ return shift->{'dbms'} eq 'PostgreSQL'? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{'dbms'} eq 'PostgreSQL' ? : 14 390 404
246 }
247  
248 # -----------------------------------------------------------------------------
249  
250 =head3 isSQLite() - Teste auf SQLite
251  
252 =head4 Synopsis
253  
254 $bool = $d->isSQLite;
255  
256 =head4 Description
257  
258 Prüfe, ob das Datenbanksystem SQLite ist. Wenn ja, liefere wahr,
259 sonst falsch.
260  
261 =cut
262  
263 # -----------------------------------------------------------------------------
264  
265 160 ▶sub isSQLite {
Subroutine isSQLite: called CC=2 SCAR=6.9
Pod documented
266 160 ▶ return shift->{'dbms'} eq 'SQLite'? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{'dbms'} eq 'SQLite' ? : 122 38 160
267 }
268  
269 # -----------------------------------------------------------------------------
270  
271 =head3 isMySQL() - Teste auf MySQL
272  
273 =head4 Synopsis
274  
275 $bool = $d->isMySQL;
276  
277 =head4 Description
278  
279 Prüfe, ob das Datenbanksystem MySQL ist. Wenn ja, liefere wahr,
280 sonst falsch.
281  
282 =cut
283  
284 # -----------------------------------------------------------------------------
285  
286 167 ▶sub isMySQL {
Subroutine isMySQL: called CC=2 SCAR=6.9
Pod documented
287 167 ▶ return shift->{'dbms'} eq 'MySQL'? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{'dbms'} eq 'MySQL' ? : 10 157 167
288 }
289  
290 # -----------------------------------------------------------------------------
291  
292 =head3 isAccess() - Teste auf Access
293  
294 =head4 Synopsis
295  
296 $bool = $d->isAccess;
297  
298 =head4 Description
299  
300 Prüfe, ob das Datenbanksystem Access ist. Wenn ja, liefere wahr,
301 sonst falsch.
302  
303 =cut
304  
305 # -----------------------------------------------------------------------------
306  
307 3 ▶sub isAccess {
Subroutine isAccess: called CC=2 SCAR=6.9
Pod documented
308 3 ▶ return shift->{'dbms'} eq 'Access'? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{'dbms'} eq 'Access' ? : 1 2 3
309 }
310  
311 # -----------------------------------------------------------------------------
312  
313 =head3 isMSSQL() - Teste auf MSSQL
314  
315 =head4 Synopsis
316  
317 $bool = $d->isMSSQL;
318  
319 =head4 Description
320  
321 Prüfe, ob das Datenbanksystem MSSQL ist. Wenn ja, liefere wahr,
322 sonst falsch.
323  
324 =cut
325  
326 # -----------------------------------------------------------------------------
327  
328 3 ▶sub isMSSQL {
Subroutine isMSSQL: called CC=2 SCAR=6.9
Pod documented
329 3 ▶ return shift->{'dbms'} eq 'MSSQL'? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{'dbms'} eq 'MSSQL' ? : 1 2 3
330 }
331  
332 # -----------------------------------------------------------------------------
333  
334 =head3 isJDBC() - Teste auf JDBC
335  
336 =head4 Synopsis
337  
338 $bool = $d->isJDBC;
339  
340 =head4 Description
341  
342 Prüfe, ob das Datenbanksystem JDBC ist. Wenn ja, liefere wahr,
343 sonst falsch.
344  
345 =cut
346  
347 # -----------------------------------------------------------------------------
348  
349 3 ▶sub isJDBC {
Subroutine isJDBC: called CC=2 SCAR=6.9
Pod documented
350 3 ▶ return shift->{'dbms'} eq 'JDBC'? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{'dbms'} eq 'JDBC' ? : 1 2 3
351 }
352  
353 # -----------------------------------------------------------------------------
354  
355 =head1 VERSION
356  
357 1.240
358  
359 =head1 AUTHOR
360  
361 Frank Seitz, L<http://fseitz.de/>
362  
363 =head1 COPYRIGHT
364  
365 Copyright (C) 2026 Frank Seitz
366  
367 =head1 LICENSE
368  
369 This code is free software; you can redistribute it and/or modify
370 it under the same terms as Perl itself.
371  
372 =cut
373  
374 # -----------------------------------------------------------------------------
375  
376 10 1;
377  
378 # eof
« Quiq/File/Image.pm ↑ Summary Quiq/ApplicationPaths.pm »