3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.10 2002/12/15 02:02:22 joko |
7 |
|
# + fixed logging-message |
8 |
|
# |
9 |
|
# Revision 1.9 2002/12/05 07:58:20 joko |
10 |
|
# + now using Tie::SecureHash as a base for the COREHANDLE |
11 |
|
# + former public COREHANDLE becomes private _COREHANDLE now |
12 |
|
# |
13 |
|
# Revision 1.8 2002/12/01 22:20:43 joko |
14 |
|
# + sub createDb (from Storage.pm) |
15 |
|
# |
16 |
|
# Revision 1.7 2002/12/01 07:09:09 joko |
17 |
|
# + sub getListFiltered (dummy redirecting to getListUnfiltered) |
18 |
|
# |
19 |
|
# Revision 1.6 2002/12/01 04:46:01 joko |
20 |
|
# + sub eraseAll |
21 |
|
# |
22 |
# Revision 1.5 2002/11/29 05:00:26 joko |
# Revision 1.5 2002/11/29 05:00:26 joko |
23 |
# + sub getListUnfiltered |
# + sub getListUnfiltered |
24 |
# + sub sendQuery |
# + sub sendQuery |
81 |
#use Data::Dumper; print Dumper($self->{dbi}); |
#use Data::Dumper; print Dumper($self->{dbi}); |
82 |
|
|
83 |
eval { |
eval { |
84 |
$self->{COREHANDLE} = DBI->connect( $dsn, '', '', $self->{locator}->{dbi} ); |
$self->{_COREHANDLE} = DBI->connect( $dsn, '', '', $self->{locator}->{dbi} ); |
85 |
if (!$self->{COREHANDLE}) { |
if (!$self->{_COREHANDLE}) { |
86 |
$logger->warning( __PACKAGE__ . "->connect failed: " . DBI::errstr ); |
$logger->warning( __PACKAGE__ . "->connect failed: " . DBI::errstr ); |
87 |
return; |
return; |
88 |
} |
} |
104 |
|
|
105 |
$logger->debug( __PACKAGE__ . "->configureCOREHANDLE" ); |
$logger->debug( __PACKAGE__ . "->configureCOREHANDLE" ); |
106 |
|
|
107 |
|
return if !$self->{_COREHANDLE}; |
108 |
|
|
109 |
# apply configured modifications to DBI-handle |
# apply configured modifications to DBI-handle |
110 |
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}) { |
111 |
$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}); |
112 |
} |
} |
113 |
if (exists $self->{locator}->{dbi}->{RaiseError}) { |
if (exists $self->{locator}->{dbi}->{RaiseError}) { |
114 |
$self->{COREHANDLE}->{RaiseError} = $self->{locator}->{dbi}->{RaiseError}; |
$self->{_COREHANDLE}->{RaiseError} = $self->{locator}->{dbi}->{RaiseError}; |
115 |
} |
} |
116 |
if (exists $self->{locator}->{dbi}->{PrintError}) { |
if (exists $self->{locator}->{dbi}->{PrintError}) { |
117 |
$self->{COREHANDLE}->{PrintError} = $self->{locator}->{dbi}->{PrintError}; |
$self->{_COREHANDLE}->{PrintError} = $self->{locator}->{dbi}->{PrintError}; |
118 |
} |
} |
119 |
if (exists $self->{locator}->{dbi}->{HandleError}) { |
if (exists $self->{locator}->{dbi}->{HandleError}) { |
120 |
$self->{COREHANDLE}->{HandleError} = $self->{locator}->{dbi}->{HandleError}; |
$self->{_COREHANDLE}->{HandleError} = $self->{locator}->{dbi}->{HandleError}; |
121 |
} |
} |
122 |
|
|
123 |
} |
} |
128 |
|
|
129 |
# two-level handling for implicit connect: |
# two-level handling for implicit connect: |
130 |
# if there's no corehandle ... |
# if there's no corehandle ... |
131 |
if (!$self->{COREHANDLE}) { |
if (!$self->{_COREHANDLE}) { |
132 |
# ... try to connect, but ... |
# ... try to connect, but ... |
133 |
$self->connect(); |
$self->connect(); |
134 |
# ... 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 |
135 |
if (!$self->{COREHANDLE}) { |
if (!$self->{_COREHANDLE}) { |
136 |
return; |
return; |
137 |
} |
} |
138 |
} |
} |
139 |
|
|
140 |
#print "prepare sql: $sql\n"; |
#print "prepare sql: $sql\n"; |
141 |
|
|
142 |
my $sth = $self->{COREHANDLE}->prepare($sql); |
my $sth = $self->{_COREHANDLE}->prepare($sql); |
143 |
$sth->execute(); |
$sth->execute(); |
144 |
return $sth; |
return $sth; |
145 |
} |
} |
158 |
my $self = shift; |
my $self = shift; |
159 |
my @nodes; |
my @nodes; |
160 |
$logger->debug( __PACKAGE__ . "->getChildNodes()" ); |
$logger->debug( __PACKAGE__ . "->getChildNodes()" ); |
161 |
|
my $locator = $self->{locator}; |
162 |
|
#print Dumper($locator); exit; |
163 |
if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) { |
if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) { |
164 |
my $dbname = getDbNameByDsn($self->{locator}->{dbi}->{dsn}); |
my $dbname = getDbNameByDsn($self->{locator}->{dbi}->{dsn}); |
165 |
my $key = "Tables_in_$dbname"; |
my $key = "Tables_in_$dbname"; |
186 |
sub sendQuery { |
sub sendQuery { |
187 |
my $self = shift; |
my $self = shift; |
188 |
my $query = shift; |
my $query = shift; |
189 |
|
|
190 |
|
$logger->debug( __PACKAGE__ . "->sendQuery" ); |
191 |
|
|
192 |
#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}';"; |
193 |
#my $result = $self->{metainfo}->{$descent}->{storage}->sendCommand($sql); |
#my $result = $self->{metainfo}->{$descent}->{storage}->sendCommand($sql); |
194 |
my @crits; |
my @crits; |
205 |
return $self->sendCommand($sql); |
return $self->sendCommand($sql); |
206 |
} |
} |
207 |
|
|
208 |
|
sub eraseAll { |
209 |
|
my $self = shift; |
210 |
|
my $classname = shift; |
211 |
|
$logger->debug( __PACKAGE__ . "->eraseAll" ); |
212 |
|
my $sql = "DELETE FROM $classname"; |
213 |
|
$self->sendCommand($sql); |
214 |
|
} |
215 |
|
|
216 |
|
# TODO: actually implement the filtering functionality using $this->sendQuery |
217 |
|
sub getListFiltered { |
218 |
|
my $self = shift; |
219 |
|
my $nodename = shift; |
220 |
|
return $self->getListUnfiltered($nodename); |
221 |
|
} |
222 |
|
|
223 |
|
# TODO: do this via a parametrized "$self->connect(<connect just to database server - don't select database>)" |
224 |
|
sub createDb { |
225 |
|
|
226 |
|
my $self = shift; |
227 |
|
|
228 |
|
# get dsn from Data::Storage::Locator instance |
229 |
|
my $dsn = $self->{locator}->{dbi}->{dsn}; |
230 |
|
|
231 |
|
$logger->debug( __PACKAGE__ . "->createDb( dsn $dsn )" ); |
232 |
|
|
233 |
|
# remove database setting from dsn-string |
234 |
|
$dsn =~ s/database=(.+?);//; |
235 |
|
|
236 |
|
# remember extracted database name to know what actually to create right now |
237 |
|
my $database_name = $1; |
238 |
|
|
239 |
|
# flag to indicate goodness |
240 |
|
my $ok; |
241 |
|
|
242 |
|
# connect to database server - don't select/use any specific database |
243 |
|
#if ( my $dbh = DBI->connect($dsn, '', '', { PrintError => 0 } ) ) { |
244 |
|
if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) { |
245 |
|
|
246 |
|
if ($database_name) { |
247 |
|
if ($dbh->do("CREATE DATABASE $database_name")) { |
248 |
|
$ok = 1; |
249 |
|
} |
250 |
|
} |
251 |
|
|
252 |
|
$dbh->disconnect(); |
253 |
|
|
254 |
|
} |
255 |
|
|
256 |
|
return $ok; |
257 |
|
|
258 |
|
} |
259 |
|
|
260 |
|
sub getCOREHANDLE2 { |
261 |
|
my $self = shift; |
262 |
|
return $self->{_COREHANDLE}; |
263 |
|
} |
264 |
|
|
265 |
1; |
1; |