line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::DataSource; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
594
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
4
|
use vars qw($VERSION @ISA @EXPORT_OK $errstr); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
60
|
|
5
|
1
|
|
|
1
|
|
6
|
use Exporter; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
346
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
8
|
|
|
|
|
|
|
@EXPORT_OK = qw( create_database drop_database ); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.02'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
DBIx::DataSource - Database-independant create and drop functions |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use DBIx::DataSource qw( create_database drop_database ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
create_database( $data_source, $username, $password ) |
21
|
|
|
|
|
|
|
or warn $DBIx::DataSource::errstr; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
drop_database( $data_source, $username, $password ) |
24
|
|
|
|
|
|
|
or warn $DBIx::DataSource::errstr; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This module implements create_database and drop_database functions for |
29
|
|
|
|
|
|
|
databases. It aims to provide a common interface to database creation and |
30
|
|
|
|
|
|
|
deletion regardless of the actual database being used. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Currently supported databases are MySQL and PostgreSQL. Assistance adding |
33
|
|
|
|
|
|
|
support for other databases is welcomed and relatively simple - see |
34
|
|
|
|
|
|
|
L. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 FUNCTIONS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=over 4 |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item create_database DATA_SOURCE USERNAME PASSWORD |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Create the database specified by the given DBI data source. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub create_database { |
47
|
0
|
|
|
0
|
1
|
|
my( $dsn, $user, $pass ) = @_; |
48
|
0
|
|
|
|
|
|
my $driver = _load_driver($dsn); |
49
|
|
|
|
|
|
|
eval "DBIx::DataSource::$driver->create_database( \$dsn, \$user, \$pass )" |
50
|
0
|
0
|
|
|
|
|
or do { $errstr=$@ if $@; ''; }; |
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item drop_database DATA_SOURCE |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Drop the database specified by the given DBI data source. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub drop_database { |
60
|
0
|
|
|
0
|
1
|
|
my( $dsn, $user, $pass ) = @_; |
61
|
0
|
|
|
|
|
|
my $driver = _load_driver($dsn); |
62
|
|
|
|
|
|
|
eval "DBIx::DataSource::$driver->drop_database( \$dsn, \$user, \$pass )" |
63
|
0
|
0
|
|
|
|
|
or do { $errstr=$@ if $@; ''; }; |
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _load_driver { |
67
|
0
|
|
|
0
|
|
|
my $datasrc = shift; |
68
|
0
|
0
|
|
|
|
|
$datasrc =~ s/^dbi:(\w*?)(?:\((.*?)\))?://i #nicked from DBI->connect |
69
|
|
|
|
|
|
|
or '' =~ /()/; # ensure $1 etc are empty if match fails |
70
|
0
|
0
|
|
|
|
|
my $driver = $1 or die "can't parse data source: $datasrc"; |
71
|
0
|
|
|
|
|
|
require "DBIx/DataSource/$driver.pm"; |
72
|
0
|
|
|
|
|
|
$driver; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=back |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 AUTHOR |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Ivan Kohler |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 COPYRIGHT |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Copyright (c) 2000 Ivan Kohler |
84
|
|
|
|
|
|
|
Copyright (c) 2000 Mail Abuse Prevention System LLC |
85
|
|
|
|
|
|
|
All rights reserved. |
86
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under |
87
|
|
|
|
|
|
|
the same terms as Perl itself. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 BUGS |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
If DBI data sources were objects, these functions would be methods. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SEE ALSO |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
L, L, L, |
96
|
|
|
|
|
|
|
L |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |