3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.9 2002/12/05 07:58:20 joko |
7 |
|
# + now using Tie::SecureHash as a base for the COREHANDLE |
8 |
|
# + former public COREHANDLE becomes private _COREHANDLE now |
9 |
|
# |
10 |
|
# Revision 1.8 2002/12/01 22:20:43 joko |
11 |
|
# + sub createDb (from Storage.pm) |
12 |
|
# |
13 |
|
# Revision 1.7 2002/12/01 07:09:09 joko |
14 |
|
# + sub getListFiltered (dummy redirecting to getListUnfiltered) |
15 |
|
# |
16 |
# Revision 1.6 2002/12/01 04:46:01 joko |
# Revision 1.6 2002/12/01 04:46:01 joko |
17 |
# + sub eraseAll |
# + sub eraseAll |
18 |
# |
# |
78 |
#use Data::Dumper; print Dumper($self->{dbi}); |
#use Data::Dumper; print Dumper($self->{dbi}); |
79 |
|
|
80 |
eval { |
eval { |
81 |
$self->{COREHANDLE} = DBI->connect( $dsn, '', '', $self->{locator}->{dbi} ); |
$self->{_COREHANDLE} = DBI->connect( $dsn, '', '', $self->{locator}->{dbi} ); |
82 |
if (!$self->{COREHANDLE}) { |
if (!$self->{_COREHANDLE}) { |
83 |
$logger->warning( __PACKAGE__ . "->connect failed: " . DBI::errstr ); |
$logger->warning( __PACKAGE__ . "->connect failed: " . DBI::errstr ); |
84 |
return; |
return; |
85 |
} |
} |
101 |
|
|
102 |
$logger->debug( __PACKAGE__ . "->configureCOREHANDLE" ); |
$logger->debug( __PACKAGE__ . "->configureCOREHANDLE" ); |
103 |
|
|
104 |
|
return if !$self->{_COREHANDLE}; |
105 |
|
|
106 |
# apply configured modifications to DBI-handle |
# apply configured modifications to DBI-handle |
107 |
if (exists $self->{locator}->{dbi}->{trace_level} && exists $self->{locator}->{dbi}->{trace_file}) { |
if (exists $self->{locator}->{dbi}->{trace_level} && exists $self->{locator}->{dbi}->{trace_file}) { |
108 |
$self->{COREHANDLE}->trace($self->{locator}->{dbi}->{trace_level}, $self->{locator}->{dbi}->{trace_file}); |
$self->{_COREHANDLE}->trace($self->{locator}->{dbi}->{trace_level}, $self->{locator}->{dbi}->{trace_file}); |
109 |
} |
} |
110 |
if (exists $self->{locator}->{dbi}->{RaiseError}) { |
if (exists $self->{locator}->{dbi}->{RaiseError}) { |
111 |
$self->{COREHANDLE}->{RaiseError} = $self->{locator}->{dbi}->{RaiseError}; |
$self->{_COREHANDLE}->{RaiseError} = $self->{locator}->{dbi}->{RaiseError}; |
112 |
} |
} |
113 |
if (exists $self->{locator}->{dbi}->{PrintError}) { |
if (exists $self->{locator}->{dbi}->{PrintError}) { |
114 |
$self->{COREHANDLE}->{PrintError} = $self->{locator}->{dbi}->{PrintError}; |
$self->{_COREHANDLE}->{PrintError} = $self->{locator}->{dbi}->{PrintError}; |
115 |
} |
} |
116 |
if (exists $self->{locator}->{dbi}->{HandleError}) { |
if (exists $self->{locator}->{dbi}->{HandleError}) { |
117 |
$self->{COREHANDLE}->{HandleError} = $self->{locator}->{dbi}->{HandleError}; |
$self->{_COREHANDLE}->{HandleError} = $self->{locator}->{dbi}->{HandleError}; |
118 |
} |
} |
119 |
|
|
120 |
} |
} |
125 |
|
|
126 |
# two-level handling for implicit connect: |
# two-level handling for implicit connect: |
127 |
# if there's no corehandle ... |
# if there's no corehandle ... |
128 |
if (!$self->{COREHANDLE}) { |
if (!$self->{_COREHANDLE}) { |
129 |
# ... try to connect, but ... |
# ... try to connect, but ... |
130 |
$self->connect(); |
$self->connect(); |
131 |
# ... if this still fails, there's something wrong probably, so we won't continue |
# ... if this still fails, there's something wrong probably, so we won't continue |
132 |
if (!$self->{COREHANDLE}) { |
if (!$self->{_COREHANDLE}) { |
133 |
return; |
return; |
134 |
} |
} |
135 |
} |
} |
136 |
|
|
137 |
#print "prepare sql: $sql\n"; |
#print "prepare sql: $sql\n"; |
138 |
|
|
139 |
my $sth = $self->{COREHANDLE}->prepare($sql); |
my $sth = $self->{_COREHANDLE}->prepare($sql); |
140 |
$sth->execute(); |
$sth->execute(); |
141 |
return $sth; |
return $sth; |
142 |
} |
} |
155 |
my $self = shift; |
my $self = shift; |
156 |
my @nodes; |
my @nodes; |
157 |
$logger->debug( __PACKAGE__ . "->getChildNodes()" ); |
$logger->debug( __PACKAGE__ . "->getChildNodes()" ); |
158 |
|
my $locator = $self->{locator}; |
159 |
|
#print Dumper($locator); exit; |
160 |
if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) { |
if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) { |
161 |
my $dbname = getDbNameByDsn($self->{locator}->{dbi}->{dsn}); |
my $dbname = getDbNameByDsn($self->{locator}->{dbi}->{dsn}); |
162 |
my $key = "Tables_in_$dbname"; |
my $key = "Tables_in_$dbname"; |
206 |
$self->sendCommand($sql); |
$self->sendCommand($sql); |
207 |
} |
} |
208 |
|
|
209 |
|
# TODO: actually implement the filtering functionality using $this->sendQuery |
210 |
|
sub getListFiltered { |
211 |
|
my $self = shift; |
212 |
|
my $nodename = shift; |
213 |
|
return $self->getListUnfiltered($nodename); |
214 |
|
} |
215 |
|
|
216 |
|
# TODO: do this via a parametrized "$self->connect(<connect just to database server - don't select database>)" |
217 |
|
sub createDb { |
218 |
|
|
219 |
|
my $self = shift; |
220 |
|
|
221 |
|
# get dsn from Data::Storage::Locator instance |
222 |
|
my $dsn = $self->{locator}->{dbi}->{dsn}; |
223 |
|
|
224 |
|
$logger->debug( __PACKAGE__ . "->createDb( dsn $dsn )" ); |
225 |
|
|
226 |
|
# remove database setting from dsn-string |
227 |
|
$dsn =~ s/database=(.+?);//; |
228 |
|
|
229 |
|
# remember extracted database name to know what actually to create right now |
230 |
|
my $database_name = $1; |
231 |
|
|
232 |
|
# flag to indicate goodness |
233 |
|
my $ok; |
234 |
|
|
235 |
|
# connect to database server - don't select/use any specific database |
236 |
|
#if ( my $dbh = DBI->connect($dsn, '', '', { PrintError => 0 } ) ) { |
237 |
|
if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) { |
238 |
|
|
239 |
|
if ($database_name) { |
240 |
|
if ($dbh->do("CREATE DATABASE $database_name")) { |
241 |
|
$ok = 1; |
242 |
|
} |
243 |
|
} |
244 |
|
|
245 |
|
$dbh->disconnect(); |
246 |
|
|
247 |
|
} |
248 |
|
|
249 |
|
return $ok; |
250 |
|
|
251 |
|
} |
252 |
|
|
253 |
|
sub getCOREHANDLE2 { |
254 |
|
my $self = shift; |
255 |
|
return $self->{_COREHANDLE}; |
256 |
|
} |
257 |
|
|
258 |
1; |
1; |