| 1 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | Quiq::Udl - Universal Database Locator | ||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | =head1 BASE CLASS | ||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | L<Quiq::Hash> | ||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | Klasse laden: | ||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | use Quiq::Udl; | ||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | Objekt instantiieren: | ||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | my $udlStr = 'dbi#oracle:xyz%xyz_admin:koala3@pluto.gaga.de:1521'; | ||||||||||||||||||||||||||||||||||
| 22 | my $udl = Quiq::Udl->new($udlStr); | ||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | UDL aus Konfigurationsdatei: | ||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | my $udl = Quiq::Udl->new('test-db'); | ||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | UDL-Komponenten: | ||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | print $udl->api,"\n"; # dbi | ||||||||||||||||||||||||||||||||||
| 31 | print $udl->dbms,"\n"; # oracle | ||||||||||||||||||||||||||||||||||
| 32 | print $udl->db,"\n"; # xyz | ||||||||||||||||||||||||||||||||||
| 33 | print $udl->user,"\n"; # xyz_admin | ||||||||||||||||||||||||||||||||||
| 34 | print $udl->password,"\n"; # koala3 | ||||||||||||||||||||||||||||||||||
| 35 | print $udl->host,"\n"; # pluto.gaga.de | ||||||||||||||||||||||||||||||||||
| 36 | print $udl->port,"\n"; # 1521 | ||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | my $optionH = $udl->options; | ||||||||||||||||||||||||||||||||||
| 39 | while (($key,$val) = each %$optionH) { | ||||||||||||||||||||||||||||||||||
| 40 | print "$key=$val\n"; | ||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | UDL als String: | ||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | print $udl->asString,"\n"; # $udlStr | ||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | Ein Universal Database Locator (UDL) adressiert eine Datenbank, | ||||||||||||||||||||||||||||||||||
| 50 | wie ein Universal Resource Locator eine Web-Resource adressiert. | ||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | Ein UDL hat den Aufbau: | ||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | api#dbms:db%user:password@host:port;options | ||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | Ein Objekt der Klasse kapselt einen UDL und bietet Methoden, | ||||||||||||||||||||||||||||||||||
| 57 | um auf die einzelnen Komponenten zuzugreifen. Kommen Metazeichen | ||||||||||||||||||||||||||||||||||
| 58 | im Passwort oder den Options vor, können diese mit \ maskiert werden. | ||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | =over 4 | ||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | =item api => $str | ||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | Der Name der Schnittstelle (z.B. "dbi"). | ||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | =item dbms => $str | ||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | Der Name der Datenbanksystems (z.B. oracle, postgresql, sqlite, mysql). | ||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||
| 72 | =item db => $str | ||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | Der Name der Datenbank. | ||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | =item user => $str | ||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||
| 78 | Der Name des Benutzers. | ||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | =item password => $str | ||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | Das Passwort des Benutzers. | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | =item host => $str | ||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | Der Name des Hosts, auf dem die Datenbank sich befindet. | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | =item port = $str | ||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | Der Port, über welchen die Netzverbindung aufgebaut wird. | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | =item options => \%hash | ||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | Referenz auf Hash mit optionalen Angaben. | ||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | =back | ||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||
| 100 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | package Quiq::Udl; | ||||||||||||||||||||||||||||||||||
| 103 | 8 | ▶ | use base qw/Quiq::Hash/; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||
| 105 | 8 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 106 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 107 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 108 | 8 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||
| 110 | 8 | our $VERSION = '1.240'; | |||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | 8 | ▶ | use Quiq::Hash; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 113 | 8 | ▶ | use Quiq::Database::Config; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 114 | 8 | ▶ | use Quiq::Option; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 115 | 8 | ▶ | use Quiq::Path; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||
| 117 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||
| 119 | =head1 METHODS | ||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | =head2 Konstruktor | ||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||
| 123 | =head3 new() - Instantiiere UDL-Objekt | ||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||
| 127 | $udl = $class->new; | ||||||||||||||||||||||||||||||||||
| 128 | $udl = $class->new($udlStr); | ||||||||||||||||||||||||||||||||||
| 129 | $udl = $class->new(@keyVal); | ||||||||||||||||||||||||||||||||||
| 130 | $udl = $class->new($name); | ||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | =head4 Arguments | ||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||
| 134 | =over 4 | ||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | =item $udlStr | ||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||
| 138 | UDL als Zeichenkette. | ||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||
| 140 | =item @keyVal | ||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||
| 142 | UDL-Komponenten. | ||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||
| 144 | =item $name | ||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||
| 146 | Name aus Konfigurationsdatei C<~/.db.conf>. | ||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||
| 148 | =back | ||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||
| 150 | =head4 Returns | ||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||
| 152 | UDL-Objekt | ||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||
| 154 | =head4 Description | ||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | Instantiiere ein UDL-Objekt und liefere eine Referenz auf | ||||||||||||||||||||||||||||||||||
| 157 | dieses Objekt zurück. | ||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||
| 161 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||
| 163 | 31 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 164 | 31 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 165 | # @_: $udlStr -or- @keyVal -or- $name | ||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||
| 167 | 31 | my $self = $class->SUPER::new( | |||||||||||||||||||||||||||||||||
| 168 | api => '', | ||||||||||||||||||||||||||||||||||
| 169 | dbms => '', | ||||||||||||||||||||||||||||||||||
| 170 | db => '', | ||||||||||||||||||||||||||||||||||
| 171 | user => '', | ||||||||||||||||||||||||||||||||||
| 172 | password => '', | ||||||||||||||||||||||||||||||||||
| 173 | host => '', | ||||||||||||||||||||||||||||||||||
| 174 | port => '', | ||||||||||||||||||||||||||||||||||
| 175 | # FIXME: auf Quiq::Hash::Ordered umstellen | ||||||||||||||||||||||||||||||||||
| 176 | options => Quiq::Hash->new->unlockKeys, | ||||||||||||||||||||||||||||||||||
| 177 | ); | ||||||||||||||||||||||||||||||||||
| 178 | 31 | ▶ | if (@_ == 1 && $_[0] !~ /^[a-z]+#/) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
@_ == 1 and not $_[0] =~ /^[a-z]+#/
MC/DC0%0/2
@_ == 1 and not $_[0] =~ /^[a-z]+#/
@_ == 1
not $_[0] =~ /^[a-z]+#/
Truth table66%2/3
A and not(B)
A= @_ == 1B= not $_[0] =~ /^[a-z]+#/
| |||||||||||||||||||||||||||||||||||
| 179 | # Argument ist kein UDL. Wir interpretieren das Argument | ||||||||||||||||||||||||||||||||||
| 180 | # als Name, suchen diesen in der Konfiguration und | ||||||||||||||||||||||||||||||||||
| 181 | # nutzen den UDL des Eintrags. | ||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||
| 183 | 0 | my $udlStr = Quiq::Database::Config->new->udl(shift); | |||||||||||||||||||||||||||||||||
| 184 | 0 | $self->udl($udlStr); | |||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||
| 186 | elsif (@_) { | ||||||||||||||||||||||||||||||||||
| 187 | 28 | $self->udl(@_); | |||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | 31 | return $self; | |||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||
| 193 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||
| 195 | =head2 Akzessoren | ||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||
| 197 | =head3 api() - Setze/Liefere Wert des Attributs api | ||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||
| 199 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||
| 201 | $api = $udl->api; | ||||||||||||||||||||||||||||||||||
| 202 | $api = $udl->api($api); | ||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||
| 204 | =cut | ||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||
| 206 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||
| 208 | 64 | ▶ | sub api { | ||||||||||||||||||||||||||||||||
|
Subroutine
api: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 209 | 64 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||
| 211 | 64 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 212 | 28 | ▶ | $self->{'api'} = defined $_[0]? shift: ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||
| 215 | 64 | return $self->{'api'}; | |||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||
| 218 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||
| 220 | =head3 dbms() - Setze/Liefere Wert des Attributs dbms | ||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||
| 222 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||
| 224 | $dbms = $udl->dbms; | ||||||||||||||||||||||||||||||||||
| 225 | $dbms = $udl->dbms($dbms); | ||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||
| 227 | =cut | ||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||
| 229 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||
| 231 | 86 | ▶ | sub dbms { | ||||||||||||||||||||||||||||||||
|
Subroutine
dbms: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 232 | 86 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||
| 234 | 86 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 235 | 28 | ▶ | $self->{'dbms'} = defined $_[0]? shift: ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||
| 238 | 86 | return $self->{'dbms'}; | |||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||
| 241 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||
| 243 | =head3 db() - Setze/Liefere Wert des Attributs db | ||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||
| 245 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||
| 247 | $db = $udl->db; | ||||||||||||||||||||||||||||||||||
| 248 | $db = $udl->db($db); | ||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||
| 250 | =cut | ||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||
| 252 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||
| 254 | 54 | ▶ | sub db { | ||||||||||||||||||||||||||||||||
|
Subroutine
db: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 255 | 54 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||
| 257 | 54 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 258 | 28 | ▶ | $self->{'db'} = defined $_[0]? shift: ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||
| 261 | 54 | return $self->{'db'}; | |||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||
| 264 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||
| 266 | =head3 user() - Setze/Liefere Wert des Attributs user | ||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||
| 268 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||
| 270 | $user = $udl->user; | ||||||||||||||||||||||||||||||||||
| 271 | $user = $udl->user($user); | ||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||
| 273 | =cut | ||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||
| 275 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||
| 277 | 64 | ▶ | sub user { | ||||||||||||||||||||||||||||||||
|
Subroutine
user: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 278 | 64 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||
| 280 | 64 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 281 | 28 | ▶ | $self->{'user'} = defined $_[0]? shift: ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||
| 284 | 64 | return $self->{'user'}; | |||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||
| 287 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||
| 289 | =head3 password() - Setze/Liefere Wert des Attributs password | ||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||
| 291 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||
| 293 | $password = $udl->password; | ||||||||||||||||||||||||||||||||||
| 294 | $password = $udl->password($password); | ||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||
| 296 | =cut | ||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||
| 298 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||
| 300 | 63 | ▶ | sub password { | ||||||||||||||||||||||||||||||||
|
Subroutine
password: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 301 | 63 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||
| 303 | 63 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 304 | 28 | ▶ | $self->{'password'} = defined $_[0]? shift: ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||
| 307 | 63 | return $self->{'password'}; | |||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||
| 310 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||
| 312 | =head3 host() - Setze/Liefere Wert des Attributs host | ||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||
| 314 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||
| 316 | $host = $udl->host; | ||||||||||||||||||||||||||||||||||
| 317 | $host = $udl->host($host); | ||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||
| 319 | =cut | ||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||
| 321 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||
| 323 | 51 | ▶ | sub host { | ||||||||||||||||||||||||||||||||
|
Subroutine
host: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 324 | 51 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||
| 326 | 51 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 327 | 28 | ▶ | $self->{'host'} = defined $_[0]? shift: ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||
| 330 | 51 | return $self->{'host'}; | |||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||
| 333 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||
| 335 | =head3 port() - Setze/Liefere Wert des Attributs port | ||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||
| 337 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||
| 339 | $port = $udl->port; | ||||||||||||||||||||||||||||||||||
| 340 | $port = $udl->port($port); | ||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||
| 342 | =cut | ||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||
| 344 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||
| 346 | 49 | ▶ | sub port { | ||||||||||||||||||||||||||||||||
|
Subroutine
port: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 347 | 49 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||
| 349 | 49 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 350 | 26 | ▶ | $self->{'port'} = defined $_[0]? shift: ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||
| 353 | 49 | return $self->{'port'}; | |||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||
| 356 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||
| 358 | =head3 options() - Setze/Liefere Option-Hash | ||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||
| 360 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||
| 362 | $hash = $udl->options; | ||||||||||||||||||||||||||||||||||
| 363 | $hash = $udl->options($str); | ||||||||||||||||||||||||||||||||||
| 364 | $hash = $udl->options(@keyVal); | ||||||||||||||||||||||||||||||||||
| 365 | $hash = $udl->options(\%hash); | ||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||
| 367 | =head4 Description | ||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||
| 369 | Setze/Liefere Hash mit den UDL-Optionen. | ||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||
| 371 | =cut | ||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||
| 373 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||
| 375 | 67 | ▶ | sub options { | ||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 376 | 67 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 377 | # @_: Argument | ||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||
| 379 | 67 | my $optH = $self->{'options'}; | |||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||
| 381 | 67 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 382 | 21 | ▶ | if (ref $_[0]) { # HashRef | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 383 | 1 | $optH = $self->{'options'} = shift; | |||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||
| 385 | elsif (@_ > 1) { # KeyVal | ||||||||||||||||||||||||||||||||||
| 386 | 17 | %$optH = @_; | |||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||
| 388 | else { # String | ||||||||||||||||||||||||||||||||||
| 389 | 3 | %$optH = (); | |||||||||||||||||||||||||||||||||
| 390 | 3 | for my $pair (split /;/,shift) { | |||||||||||||||||||||||||||||||||
| 391 | 5 | my ($key,$val) = split /=/,$pair; | |||||||||||||||||||||||||||||||||
| 392 | 5 | $optH->{$key} = $val; | |||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||
| 397 | 67 | return $optH; | |||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||
| 400 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||
| 402 | =head2 Klassenmethoden | ||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||
| 404 | =head3 split() - Setze/Liefere UDL als Ganzes | ||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||
| 406 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||
| 408 | ($api,$dbms,$db,$user,$password,$host,$port,$options) = | ||||||||||||||||||||||||||||||||||
| 409 | $udl->split($udl); | ||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||
| 411 | =head4 Description | ||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||
| 413 | Zerlege den UDL $udl in seine Komponenten und liefere diese zurück. | ||||||||||||||||||||||||||||||||||
| 414 | Für eine Komponente, die nicht im URL enthalten ist, wird ein | ||||||||||||||||||||||||||||||||||
| 415 | Leerstring ('') geliefert. | ||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||
| 417 | =cut | ||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||
| 419 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | sub split { | ||||||||||||||||||||||||||||||||
|
Subroutine
split: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 422 | 0 | my ($class,$udl) = @_; | |||||||||||||||||||||||||||||||||
| 423 | 0 | return $class->new($udl)->components; | |||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||
| 426 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||
| 428 | =head2 Objektmethoden | ||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||
| 430 | =head3 apiClass() - API-Klasse | ||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||
| 432 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||
| 434 | $apiClass = $udl->apiClass; | ||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||
| 436 | =head4 Description | ||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||
| 438 | Liefere die Datanbank API-Klasse. Über diese findet intern der | ||||||||||||||||||||||||||||||||||
| 439 | Verbindungsaufbau zur Datenbank statt. | ||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||
| 441 | Die API-Klasse für das DBI-API ist: | ||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||
| 443 | Quiq::Database::Api::Dbi::Connection | ||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||
| 445 | =cut | ||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||
| 447 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||
| 449 | 1 | ▶ | sub apiClass { | ||||||||||||||||||||||||||||||||
|
Subroutine
apiClass: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 450 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 451 | 1 | return 'Quiq::Database::Api::'.ucfirst($self->api).'::Connection'; | |||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||
| 454 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||
| 456 | =head3 asString() - UDL als String | ||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||
| 458 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||
| 460 | $udlStr = $udl->asString; | ||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||
| 462 | =head4 Options | ||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||
| 464 | =over 4 | ||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||
| 466 | =item -secure => $bool (Default: 0) | ||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||
| 468 | Ersetze das Passwort durch einen Stern. | ||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||
| 470 | =back | ||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||
| 472 | =cut | ||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||
| 474 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||
| 476 | 5 | ▶ | sub asString { | ||||||||||||||||||||||||||||||||
|
Subroutine
asString: called CC=17 SCAR=28.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 477 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||
| 479 | # Optionen | ||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||
| 481 | 5 | my $secure = 0; | |||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||
| 483 | 5 | Quiq::Option->extract(\@_, | |||||||||||||||||||||||||||||||||
| 484 | -secure => \$secure, | ||||||||||||||||||||||||||||||||||
| 485 | ); | ||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||
| 487 | 5 | my $str = ''; | |||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||
| 489 | # api | ||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||
| 491 | 5 | my $api = $self->api; | |||||||||||||||||||||||||||||||||
| 492 | 5 | ▶ | if ($api) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 493 | 4 | $str .= $api.'#'; | |||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||
| 496 | # dbms, db | ||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||
| 498 | 5 | my $dbms = $self->dbms; | |||||||||||||||||||||||||||||||||
| 499 | 5 | my $db = $self->db; | |||||||||||||||||||||||||||||||||
| 500 | 5 | ▶ | if ($dbms || $db) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$dbms or $db
MC/DC50%1/2
$dbms or $db
$dbms
$db
Truth table66%2/3
A or B
A= $dbmsB= $db
| |||||||||||||||||||||||||||||||||||
| 501 | 4 | ▶ | if ($dbms) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 502 | 4 | $str .= $dbms; | |||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||
| 504 | 4 | ▶ | if ($db) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 505 | 4 | $str .= ":$db"; | |||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||
| 509 | # user, password | ||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||
| 511 | 5 | my $user = $self->user; | |||||||||||||||||||||||||||||||||
| 512 | 5 | my $password = $self->password; | |||||||||||||||||||||||||||||||||
| 513 | 5 | ▶ | if ($user || $password) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$user or $password
MC/DC50%1/2
$user or $password
$user
$password
Truth table66%2/3
A or B
A= $userB= $password
| |||||||||||||||||||||||||||||||||||
| 514 | 2 | $str .= '%'; | |||||||||||||||||||||||||||||||||
| 515 | 2 | ▶ | if ($user) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 516 | 2 | $str .= $user; | |||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||
| 518 | 2 | ▶ | if ($password) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 519 | 2 | ▶ | if ($secure) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 520 | 1 | $password = '*'; | |||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||
| 522 | 2 | $str .= ":$password"; | |||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||
| 526 | # host, port | ||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||
| 528 | 5 | my $host = $self->host; | |||||||||||||||||||||||||||||||||
| 529 | 5 | my $port = $self->port; | |||||||||||||||||||||||||||||||||
| 530 | 5 | ▶ | if ($host || $port) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$host or $port
MC/DC50%1/2
$host or $port
$host
$port
Truth table66%2/3
A or B
A= $hostB= $port
| |||||||||||||||||||||||||||||||||||
| 531 | 2 | $str .= '@'; | |||||||||||||||||||||||||||||||||
| 532 | 2 | ▶ | if ($host) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 533 | 2 | $str .= $host; | |||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||
| 535 | 2 | ▶ | if ($port) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 536 | 0 | $str .= ":$port"; | |||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||
| 540 | # options | ||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||
| 542 | 5 | my $optionH = $self->options; | |||||||||||||||||||||||||||||||||
| 543 | 5 | ▶ | while (my ($key,$val) = each %$optionH) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 544 | 3 | ▶ | if ($str) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 545 | 3 | $str .= ';'; | |||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||
| 547 | 3 | $str .= "$key=$val"; | |||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||
| 550 | 5 | return $str; | |||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||
| 553 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||
| 555 | =head3 components() - Komponenten des UDL | ||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||
| 557 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||
| 559 | ($api,$dbms,$db,$user,$password,$host,$port,$options) = $udl->components; | ||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||
| 561 | =head4 Description | ||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||
| 563 | Liefere die Komponenten des UDL in der oben angegebenen Reihenfolge. | ||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||
| 565 | =cut | ||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||
| 567 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||
| 569 | 12 | ▶ | sub components { | ||||||||||||||||||||||||||||||||
|
Subroutine
components: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 570 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||
| 572 | return ( | ||||||||||||||||||||||||||||||||||
| 573 | 12 | $self->api, | |||||||||||||||||||||||||||||||||
| 574 | $self->dbms, | ||||||||||||||||||||||||||||||||||
| 575 | $self->db, | ||||||||||||||||||||||||||||||||||
| 576 | $self->user, | ||||||||||||||||||||||||||||||||||
| 577 | $self->password, | ||||||||||||||||||||||||||||||||||
| 578 | $self->host, | ||||||||||||||||||||||||||||||||||
| 579 | $self->port, | ||||||||||||||||||||||||||||||||||
| 580 | $self->options, | ||||||||||||||||||||||||||||||||||
| 581 | ); | ||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||
| 584 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||
| 586 | =head3 dsn() - DBI DSN-String | ||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||
| 588 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||
| 590 | $dsn = $udl->dsn; | ||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||
| 592 | =head4 Description | ||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||
| 594 | Liefere den DSN-String, um per DBI->connect() eine | ||||||||||||||||||||||||||||||||||
| 595 | Verbindung zur Datenbank aufzubauen. | ||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||
| 597 | =cut | ||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||
| 599 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||
| 601 | 12 | ▶ | sub dsn { | ||||||||||||||||||||||||||||||||
|
Subroutine
dsn: called CC=16 SCAR=47.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 602 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||
| 604 | 12 | my ($api,$dbms,$db,$user,$passw,$host,$port,$options) = $self->components; | |||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||
| 606 | 12 | ▶ | if ($api ne 'dbi') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 607 | 0 | $self->throw( | |||||||||||||||||||||||||||||||||
| 608 | 'UDL-00001: DSN defined for DBI API only', | ||||||||||||||||||||||||||||||||||
| 609 | API => $api, | ||||||||||||||||||||||||||||||||||
| 610 | ); | ||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||
| 613 | 12 | my $dsn; | |||||||||||||||||||||||||||||||||
| 614 | 12 | ▶ | if ($dbms eq 'mysql') { | ||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||
| 615 | 0 | $dsn = "DBI:mysql:database=$db"; | |||||||||||||||||||||||||||||||||
| 616 | 0 | ▶ | if ($host) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 617 | 0 | $dsn .= ";host=$host"; | |||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||
| 619 | 0 | ▶ | if ($port) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 620 | 0 | $dsn .= ";port=$port"; | |||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||
| 623 | elsif ($dbms eq 'oracle') { | ||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | if ($host) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 625 | # Connect ohne tnsnames.ora, siehe DBD::Oracle, | ||||||||||||||||||||||||||||||||||
| 626 | # wird konkret benötigt für FINO. | ||||||||||||||||||||||||||||||||||
| 627 | # FIXME: Wie wird der Port eingestellt? | ||||||||||||||||||||||||||||||||||
| 628 | 0 | $dsn = "DBI:Oracle:host=$host;sid=$db"; | |||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||
| 630 | else { | ||||||||||||||||||||||||||||||||||
| 631 | 0 | $dsn = "DBI:Oracle:$db"; | |||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||
| 634 | elsif ($dbms eq 'postgresql') { | ||||||||||||||||||||||||||||||||||
| 635 | 0 | $dsn = "DBI:Pg:dbname=$db"; | |||||||||||||||||||||||||||||||||
| 636 | 0 | ▶ | if ($host) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 637 | 0 | $dsn .= ";host=$host"; | |||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||
| 639 | 0 | ▶ | if ($port) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 640 | 0 | $dsn .= ";port=$port"; | |||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||
| 643 | elsif ($dbms eq 'sqlite') { | ||||||||||||||||||||||||||||||||||
| 644 | 12 | $db = Quiq::Path->expandTilde($db); | |||||||||||||||||||||||||||||||||
| 645 | 12 | $dsn = "DBI:SQLite:dbname=$db"; | |||||||||||||||||||||||||||||||||
| 646 | 12 | ▶ | if ($host) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 647 | # Wenn Host (und Port) angegeben sind, bauen wir | ||||||||||||||||||||||||||||||||||
| 648 | # eine Verbindung über den DBIProxy auf (der remote | ||||||||||||||||||||||||||||||||||
| 649 | # laufen muss) | ||||||||||||||||||||||||||||||||||
| 650 | 0 | $dsn = "DBI:Proxy:hostname=$host;port=$port;dsn=$dsn"; | |||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||
| 653 | elsif ($dbms eq 'access') { | ||||||||||||||||||||||||||||||||||
| 654 | 0 | $dsn = "DBI:ODBC:$db"; | |||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||
| 656 | elsif ($dbms eq 'mssql') { | ||||||||||||||||||||||||||||||||||
| 657 | 0 | $dsn = "DBI:ODBC:$db"; | |||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||
| 659 | elsif ($dbms eq 'jdbc') { | ||||||||||||||||||||||||||||||||||
| 660 | 0 | $dsn = "DBI:JDBC:hostname=$host;port=$port"; | |||||||||||||||||||||||||||||||||
| 661 | 0 | for my $key (keys %$options) { | |||||||||||||||||||||||||||||||||
| 662 | 0 | $dsn .= ";$key=$options->{$key}"; | |||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||
| 665 | else { | ||||||||||||||||||||||||||||||||||
| 666 | 0 | $self->throw( | |||||||||||||||||||||||||||||||||
| 667 | 'UDL-00002: DBMS not supported', | ||||||||||||||||||||||||||||||||||
| 668 | Dbms => $dbms, | ||||||||||||||||||||||||||||||||||
| 669 | ); | ||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||
| 672 | 12 | return $dsn; | |||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||
| 675 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||
| 677 | =head3 udl() - Setze/Liefere UDL als Ganzes | ||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||
| 679 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||
| 681 | $udl->udl($udlStr); | ||||||||||||||||||||||||||||||||||
| 682 | $udl->udl(@keyVal); | ||||||||||||||||||||||||||||||||||
| 683 | $udlStr = $udl->udl; | ||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||
| 685 | =head4 Description | ||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||
| 687 | Liefere UDL oder setze UDL als Ganzes aus String oder Liste von | ||||||||||||||||||||||||||||||||||
| 688 | Schlüssel/Wert-Paaren. Die Methode liefert keinen Wert zurück. | ||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||
| 690 | Der Aufruf ohne Parameter ist identisch zum Aufruf von asString(). | ||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||
| 692 | =cut | ||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||
| 694 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||
| 696 | 28 | ▶ | sub udl { | ||||||||||||||||||||||||||||||||
|
Subroutine
udl: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 697 | 28 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||
| 699 | 28 | ▶ | if (!@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 700 | 0 | return $self->asString; | |||||||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||
| 703 | # UDL neu aufsetzen | ||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||
| 705 | 28 | $self->set(api=>'',dbms=>'',db=>'',user=>'',password=>'',host=>'', | |||||||||||||||||||||||||||||||||
| 706 | port=>''); | ||||||||||||||||||||||||||||||||||
| 707 | 28 | %{$self->{'options'}} = (); | |||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||
| 709 | 28 | ▶ | if (@_ == 1) { # $udlStr | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 710 | 26 | my $udl = shift; | |||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||
| 712 | # Zerlege UDL auf den Metazeichen: #%@; | ||||||||||||||||||||||||||||||||||
| 713 | # Mit \ können die Metazeichen maskiert werden. | ||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||
| 715 | 26 | my @arr = split /((?<!\\)[#%@;])/,$udl; | |||||||||||||||||||||||||||||||||
| 716 | 26 | $self->api(shift @arr); | |||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||
| 718 | 26 | my ($dbms,$db,$user,$password,$host,$port,@options); | |||||||||||||||||||||||||||||||||
| 719 | 26 | ▶ | while (@arr) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 720 | 54 | my $key = shift @arr; | |||||||||||||||||||||||||||||||||
| 721 | 54 | my $val = shift @arr; | |||||||||||||||||||||||||||||||||
| 722 | 54 | $val =~ s|\\([#%@;])|$1|g; # #%@; entmaskieren | |||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||
| 724 | 54 | ▶ | if ($key eq '#') { | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 725 | 26 | ($dbms,$db) = split /:/,$val,2; | |||||||||||||||||||||||||||||||||
| 726 | 26 | ▶ | if (!defined $dbms) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 727 | 0 | $dbms = ''; | |||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||
| 730 | elsif ($key eq '%') { | ||||||||||||||||||||||||||||||||||
| 731 | 4 | ($user,$password) = split /:/,$val,2; | |||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||
| 733 | elsif ($key eq '@') { | ||||||||||||||||||||||||||||||||||
| 734 | 4 | ($host,$port) = split /:/,$val,2; | |||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||
| 736 | else { # ; | ||||||||||||||||||||||||||||||||||
| 737 | 20 | push @options,split /=/,$val,2; | |||||||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||
| 741 | # Alte Implementierung. Wegen neuer Möglichkeit zur Maskierung | ||||||||||||||||||||||||||||||||||
| 742 | # der Metazeichen durch \, durch obige Implementierung ersetzt. | ||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||
| 744 | #if ($udl =~ s|^([a-z]+)#||) { | ||||||||||||||||||||||||||||||||||
| 745 | # $self->api($1); | ||||||||||||||||||||||||||||||||||
| 746 | #} | ||||||||||||||||||||||||||||||||||
| 747 | #if ($udl =~ s|;(.*)||) { | ||||||||||||||||||||||||||||||||||
| 748 | # $self->options($1); | ||||||||||||||||||||||||||||||||||
| 749 | #} | ||||||||||||||||||||||||||||||||||
| 750 | #if ($udl =~ s|\@([^%]+)||) { | ||||||||||||||||||||||||||||||||||
| 751 | # my ($host,$port) = split(/:/,$1,2); | ||||||||||||||||||||||||||||||||||
| 752 | # $self->host($host); | ||||||||||||||||||||||||||||||||||
| 753 | # $self->port($port); | ||||||||||||||||||||||||||||||||||
| 754 | #} | ||||||||||||||||||||||||||||||||||
| 755 | #my ($dbms,$db,$user,$password); | ||||||||||||||||||||||||||||||||||
| 756 | #if ($udl =~ s|%([^@]+)||) { | ||||||||||||||||||||||||||||||||||
| 757 | # ($user,$password) = split(/:/,$1,2); | ||||||||||||||||||||||||||||||||||
| 758 | #} | ||||||||||||||||||||||||||||||||||
| 759 | #($dbms,$db) = split(/:/,$udl,2); | ||||||||||||||||||||||||||||||||||
| 760 | #if (!defined $dbms) { | ||||||||||||||||||||||||||||||||||
| 761 | # $dbms = ''; | ||||||||||||||||||||||||||||||||||
| 762 | #} | ||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||
| 764 | # Rückwärtskompatibilität | ||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||
| 766 | 26 | ▶ | if (!grep { $dbms eq $_ } qw/oracle postgresql sqlite mysql | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 767 | access mssql jdbc/) { | ||||||||||||||||||||||||||||||||||
| 768 | 1 | ($dbms,$db,$user,$password) = ($user,$password,$dbms,$db); | |||||||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||
| 771 | 26 | $self->user($user); | |||||||||||||||||||||||||||||||||
| 772 | 26 | $self->password($password); | |||||||||||||||||||||||||||||||||
| 773 | 26 | $self->dbms($dbms); | |||||||||||||||||||||||||||||||||
| 774 | 26 | $self->db($db); | |||||||||||||||||||||||||||||||||
| 775 | 26 | $self->host($host); | |||||||||||||||||||||||||||||||||
| 776 | 26 | $self->port($port); | |||||||||||||||||||||||||||||||||
| 777 | 26 | $self->options(@options); | |||||||||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||||||||
| 779 | else { # @keyVal | ||||||||||||||||||||||||||||||||||
| 780 | 2 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 781 | 14 | my $key = shift; | |||||||||||||||||||||||||||||||||
| 782 | 14 | $self->$key(shift); | |||||||||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||||||||
| 784 | } | ||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||
| 786 | 28 | return; | |||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||
| 789 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||
| 791 | =head1 VERSION | ||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||
| 793 | 1.240 | ||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||
| 795 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||
| 797 | Frank Seitz, L<http://fseitz.de/> | ||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||
| 799 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||
| 801 | Copyright (C) 2026 Frank Seitz | ||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||
| 803 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||
| 805 | This code is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||
| 806 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||
| 808 | =cut | ||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||
| 810 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||
| 812 | 8 | 1; | |||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||
| 814 | # eof | ||||||||||||||||||||||||||||||||||