Quiq/Database/Api.pm

filter: Statementstmt 100% 21 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 100% 28 / 28 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Quiq/Zugferd.pm ↑ Summary Quiq/Diff.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Database::Api - Lowlevel Datenbank-Schnittstelle
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Object>
12  
13 =head1 DESCRIPTION
14  
15 Eine grundlegende Datenbank-Schnittstelle Quiq::Database::Api::*
16 wird durch zwei Klassen definiert:
17  
18 B<< Quiq::Database::Api::*::Connection >>
19  
20 $db = $class->new($udlObj); # Datenbankverbindung aufbauen
21 $cur = $db->sql($stmt); # SQL-Statement ausführen
22 $db->destroy; # Datenbankverbindung abbauen
23  
24 B<< Quiq::Database::Api::*::Cursor >>
25  
26 $cur = $class->new(@keyVal); # Cursor instantiieren
27
28 $n = $cur->bindVars; # Anzahl Bind-Variablen
29 $n = $cur->hits; # Anzahl "Treffer"
30 $id = $cur->id; # Generierter Autoinkrement-Wert
31 $titlesA = $cur->titles; # Kolumnentitel
32
33 $cur2 = $cur->bind(@vals); # Platzhalter einsetzen
34 $row = $cur->fetch; # nächsten Datensatz lesen
35
36 $cur->destroy; # Cursor schließen
37  
38 Die bislang einzige Lowlevel-Datenbank-Schnittstelle ist DBI, die
39 die beiden Klassen umfasst:
40  
41 =over 2
42  
43 =item *
44  
45 Quiq::Database::Api::Dbi::Connection
46  
47 =item *
48  
49 Quiq::Database::Api::Dbi::Cursor
50  
51 =back
52  
53 Potentielle andere Lowlevel-Datenbank-Schnittstellen müssen
54 die gleichen Methoden implementieren.
55  
56 =cut
57  
58 # -----------------------------------------------------------------------------
59  
60 package Quiq::Database::Api;
61 6 ▶use base qw/Quiq::Object/;
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 6 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67 6 our $VERSION = '1.240';
68  
69 6 ▶use Quiq::Database::Api::Dbi::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71 # -----------------------------------------------------------------------------
72  
73 =head1 METHODS
74  
75 =head2 Verbindungsaufbau
76  
77 =head3 connect() - Instantiiere Lowlevel-Datenbankverbindung
78  
79 =head4 Synopsis
80  
81 $db = $class->connect($udlObj);
82  
83 =head4 Description
84  
85 Instantiiere eine Lowlevel-Datenbankverbindung auf Basis von
86 UDL-Objekt $udlObj und liefere eine Referenz auf die
87 Datenbankverbindung zurück.
88  
89 =head4 Example
90  
91 use Quiq::Database::Api;
92
93 my $udl = 'dbi#mysql:test%root';
94 my $udlObj = Quiq::Udl->new($udl);
95 my $db = Quiq::Database::Api->connect($udlObj);
96 print ref($db),"\n";
97 __END__
98 Quiq::Database::Api::Dbi::Connection
99  
100 =cut
101  
102 # -----------------------------------------------------------------------------
103  
104 12 ▶sub connect {
Subroutine connect: called CC=1 SCAR=0.0
Pod documented
105 12 my $class = shift;
106 12 my ($udlObj) = @_;
107  
108 12 my $apiName = ucfirst $udlObj->api;
109 12 my $apiClass = $class.'::'.$apiName.'::Connection';
110  
111 12 return $apiClass->new(@_);
112 }
113  
114 # -----------------------------------------------------------------------------
115  
116 =head1 VERSION
117  
118 1.240
119  
120 =head1 AUTHOR
121  
122 Frank Seitz, L<http://fseitz.de/>
123  
124 =head1 COPYRIGHT
125  
126 Copyright (C) 2026 Frank Seitz
127  
128 =head1 LICENSE
129  
130 This code is free software; you can redistribute it and/or modify
131 it under the same terms as Perl itself.
132  
133 =cut
134  
135 # -----------------------------------------------------------------------------
136  
137 6 1;
138  
139 # eof
« Quiq/Zugferd.pm ↑ Summary Quiq/Diff.pm »