3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.11 2002/12/19 16:31:05 joko |
7 |
|
# + sub dropDb |
8 |
|
# + sub rebuildDb |
9 |
|
# |
10 |
|
# Revision 1.10 2002/12/15 02:02:22 joko |
11 |
|
# + fixed logging-message |
12 |
|
# |
13 |
|
# Revision 1.9 2002/12/05 07:58:20 joko |
14 |
|
# + now using Tie::SecureHash as a base for the COREHANDLE |
15 |
|
# + former public COREHANDLE becomes private _COREHANDLE now |
16 |
|
# |
17 |
# Revision 1.8 2002/12/01 22:20:43 joko |
# Revision 1.8 2002/12/01 22:20:43 joko |
18 |
# + sub createDb (from Storage.pm) |
# + sub createDb (from Storage.pm) |
19 |
# |
# |
85 |
#use Data::Dumper; print Dumper($self->{dbi}); |
#use Data::Dumper; print Dumper($self->{dbi}); |
86 |
|
|
87 |
eval { |
eval { |
88 |
$self->{COREHANDLE} = DBI->connect( $dsn, '', '', $self->{locator}->{dbi} ); |
$self->{_COREHANDLE} = DBI->connect( $dsn, '', '', $self->{locator}->{dbi} ); |
89 |
if (!$self->{COREHANDLE}) { |
if (!$self->{_COREHANDLE}) { |
90 |
$logger->warning( __PACKAGE__ . "->connect failed: " . DBI::errstr ); |
$logger->warning( __PACKAGE__ . "->connect failed: " . DBI::errstr ); |
91 |
return; |
return; |
92 |
} |
} |
108 |
|
|
109 |
$logger->debug( __PACKAGE__ . "->configureCOREHANDLE" ); |
$logger->debug( __PACKAGE__ . "->configureCOREHANDLE" ); |
110 |
|
|
111 |
return if !$self->{COREHANDLE}; |
return if !$self->{_COREHANDLE}; |
112 |
|
|
113 |
# apply configured modifications to DBI-handle |
# apply configured modifications to DBI-handle |
114 |
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}) { |
115 |
$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}); |
116 |
} |
} |
117 |
if (exists $self->{locator}->{dbi}->{RaiseError}) { |
if (exists $self->{locator}->{dbi}->{RaiseError}) { |
118 |
$self->{COREHANDLE}->{RaiseError} = $self->{locator}->{dbi}->{RaiseError}; |
$self->{_COREHANDLE}->{RaiseError} = $self->{locator}->{dbi}->{RaiseError}; |
119 |
} |
} |
120 |
if (exists $self->{locator}->{dbi}->{PrintError}) { |
if (exists $self->{locator}->{dbi}->{PrintError}) { |
121 |
$self->{COREHANDLE}->{PrintError} = $self->{locator}->{dbi}->{PrintError}; |
$self->{_COREHANDLE}->{PrintError} = $self->{locator}->{dbi}->{PrintError}; |
122 |
} |
} |
123 |
if (exists $self->{locator}->{dbi}->{HandleError}) { |
if (exists $self->{locator}->{dbi}->{HandleError}) { |
124 |
$self->{COREHANDLE}->{HandleError} = $self->{locator}->{dbi}->{HandleError}; |
$self->{_COREHANDLE}->{HandleError} = $self->{locator}->{dbi}->{HandleError}; |
125 |
} |
} |
126 |
|
|
127 |
} |
} |
132 |
|
|
133 |
# two-level handling for implicit connect: |
# two-level handling for implicit connect: |
134 |
# if there's no corehandle ... |
# if there's no corehandle ... |
135 |
if (!$self->{COREHANDLE}) { |
if (!$self->{_COREHANDLE}) { |
136 |
# ... try to connect, but ... |
# ... try to connect, but ... |
137 |
$self->connect(); |
$self->connect(); |
138 |
# ... 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 |
139 |
if (!$self->{COREHANDLE}) { |
if (!$self->{_COREHANDLE}) { |
140 |
return; |
return; |
141 |
} |
} |
142 |
} |
} |
143 |
|
|
144 |
#print "prepare sql: $sql\n"; |
#print "prepare sql: $sql\n"; |
145 |
|
|
146 |
my $sth = $self->{COREHANDLE}->prepare($sql); |
my $sth = $self->{_COREHANDLE}->prepare($sql); |
147 |
$sth->execute(); |
$sth->execute(); |
148 |
return $sth; |
return $sth; |
149 |
} |
} |
162 |
my $self = shift; |
my $self = shift; |
163 |
my @nodes; |
my @nodes; |
164 |
$logger->debug( __PACKAGE__ . "->getChildNodes()" ); |
$logger->debug( __PACKAGE__ . "->getChildNodes()" ); |
165 |
|
my $locator = $self->{locator}; |
166 |
|
#print Dumper($locator); exit; |
167 |
if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) { |
if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) { |
168 |
my $dbname = getDbNameByDsn($self->{locator}->{dbi}->{dsn}); |
my $dbname = getDbNameByDsn($self->{locator}->{dbi}->{dsn}); |
169 |
my $key = "Tables_in_$dbname"; |
my $key = "Tables_in_$dbname"; |
190 |
sub sendQuery { |
sub sendQuery { |
191 |
my $self = shift; |
my $self = shift; |
192 |
my $query = shift; |
my $query = shift; |
193 |
|
|
194 |
|
$logger->debug( __PACKAGE__ . "->sendQuery" ); |
195 |
|
|
196 |
#my $sql = "SELECT cs FROM $self->{metainfo}->{$descent}->{node} WHERE $self->{metainfo}->{$descent}->{IdentProvider}->{arg}='$self->{entry}->{source}->{ident}';"; |
#my $sql = "SELECT cs FROM $self->{metainfo}->{$descent}->{node} WHERE $self->{metainfo}->{$descent}->{IdentProvider}->{arg}='$self->{entry}->{source}->{ident}';"; |
197 |
#my $result = $self->{metainfo}->{$descent}->{storage}->sendCommand($sql); |
#my $result = $self->{metainfo}->{$descent}->{storage}->sendCommand($sql); |
198 |
my @crits; |
my @crits; |
212 |
sub eraseAll { |
sub eraseAll { |
213 |
my $self = shift; |
my $self = shift; |
214 |
my $classname = shift; |
my $classname = shift; |
215 |
|
$logger->debug( __PACKAGE__ . "->eraseAll" ); |
216 |
my $sql = "DELETE FROM $classname"; |
my $sql = "DELETE FROM $classname"; |
217 |
$self->sendCommand($sql); |
$self->sendCommand($sql); |
218 |
} |
} |
261 |
|
|
262 |
} |
} |
263 |
|
|
264 |
|
sub getCOREHANDLE2 { |
265 |
|
my $self = shift; |
266 |
|
return $self->{_COREHANDLE}; |
267 |
|
} |
268 |
|
|
269 |
|
sub dropDb { |
270 |
|
my $self = shift; |
271 |
|
my $dsn = $self->{locator}->{dbi}->{dsn}; |
272 |
|
|
273 |
|
$logger->debug( __PACKAGE__ . "->dropDb( dsn $dsn )" ); |
274 |
|
|
275 |
|
$dsn =~ s/database=(.+?);//; |
276 |
|
my $database_name = $1; |
277 |
|
|
278 |
|
my $ok; |
279 |
|
|
280 |
|
if ( my $dbh = DBI->connect($dsn, '', '', { |
281 |
|
PrintError => 0, |
282 |
|
} ) ) { |
283 |
|
if ($database_name) { |
284 |
|
if ($dbh->do("DROP DATABASE $database_name;")) { |
285 |
|
$ok = 1; |
286 |
|
} |
287 |
|
} |
288 |
|
|
289 |
|
$dbh->disconnect(); |
290 |
|
|
291 |
|
} |
292 |
|
|
293 |
|
return $ok; |
294 |
|
} |
295 |
|
|
296 |
|
sub rebuildDb { |
297 |
|
my $self = shift; |
298 |
|
$logger->info( __PACKAGE__ . "->rebuildDb()" ); |
299 |
|
my @results; |
300 |
|
|
301 |
|
# sum up results (bool (0/1)) in array |
302 |
|
#push @results, $self->retreatSchema(); |
303 |
|
push @results, $self->dropDb(); |
304 |
|
push @results, $self->createDb(); |
305 |
|
#push @results, $self->deploySchema(); |
306 |
|
|
307 |
|
# scan array for "bad ones" |
308 |
|
my $res = 1; |
309 |
|
map { |
310 |
|
$res = 0 if (!$_); |
311 |
|
} @results; |
312 |
|
|
313 |
|
return $res; |
314 |
|
} |
315 |
|
|
316 |
1; |
1; |