line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ZConf::DBI::utils; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23442
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
5
|
1
|
|
|
1
|
|
1079
|
use DBIx::Admin::TableInfo; |
|
1
|
|
|
|
|
66388
|
|
|
1
|
|
|
|
|
32
|
|
6
|
1
|
|
|
1
|
|
1157
|
use DBIx::Admin::CreateTable; |
|
1
|
|
|
|
|
3949
|
|
|
1
|
|
|
|
|
2112
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
ZConf::DBI::utils - Assorted utilities for ZConf::DBI. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.0.0 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.0.0'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This is primarily meant for quick small things. If you are going to calling a lot |
24
|
|
|
|
|
|
|
of stuff here repeatively/heavily, you are probally going to be better off making use of what |
25
|
|
|
|
|
|
|
ever is being called by the function directly. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 METHODS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 new |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
This initiates the object. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
One arguement is required and it is the 'ZConf::DBI' object. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $foo=ZConf::DBI::util->new($zcdbi); |
36
|
|
|
|
|
|
|
if($foo->error){ |
37
|
|
|
|
|
|
|
warn('error code:'.$foo->error.': '.$foo->errorString); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new{ |
43
|
0
|
|
|
0
|
1
|
|
my $zcdbi=$_[1]; |
44
|
0
|
|
|
|
|
|
my $function='new'; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $self={error=>undef, |
47
|
|
|
|
|
|
|
perror=>undef, |
48
|
|
|
|
|
|
|
errorString=>undef, |
49
|
|
|
|
|
|
|
module=>'ZConf-DBI-util', |
50
|
|
|
|
|
|
|
zcdbi=>$zcdbi, |
51
|
|
|
|
|
|
|
}; |
52
|
0
|
|
|
|
|
|
bless $self; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
#make sure a object was not passed |
55
|
0
|
0
|
|
|
|
|
if (!defined( $self->{zcdbi} )) { |
56
|
0
|
|
|
|
|
|
$self->{perror}=1; |
57
|
0
|
|
|
|
|
|
$self->{error}=1; |
58
|
0
|
|
|
|
|
|
$self->{errorString}='No ZConf::DBI object passed'; |
59
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
60
|
0
|
|
|
|
|
|
return $self; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#make sure it is the correct type of object |
64
|
0
|
0
|
|
|
|
|
if (ref($self->{zcdbi}) ne 'ZConf::DBI') { |
65
|
0
|
|
|
|
|
|
$self->{perror}=1; |
66
|
0
|
|
|
|
|
|
$self->{error}=2; |
67
|
0
|
|
|
|
|
|
$self->{errorString}='No ZConf::DBI object passed'; |
68
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
69
|
0
|
|
|
|
|
|
return $self; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
return $self; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 create_table |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This creates a new table using DBIx::Admin::CreateTable->create_table. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Three arguements are required. The first is the data source name. The second is |
80
|
|
|
|
|
|
|
the table name. The third is a SQL string describing the columns. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$foo->create_table('whatever', 'sometable', 'id char(32) primary key, data varchar(255) not null'); |
83
|
|
|
|
|
|
|
if($foo->error){ |
84
|
|
|
|
|
|
|
warn('error code:'.$error.': '.$foo->errorString); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub create_table{ |
90
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
91
|
0
|
|
|
|
|
|
my $dsName=$_[1]; |
92
|
0
|
|
|
|
|
|
my $table=$_[2]; |
93
|
0
|
|
|
|
|
|
my $sql=$_[3]; |
94
|
0
|
|
|
|
|
|
my $function='create_table'; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
#makes sure we have a data source |
97
|
0
|
0
|
|
|
|
|
if (!defined($dsName)) { |
98
|
0
|
|
|
|
|
|
$self->{error}=3; |
99
|
0
|
|
|
|
|
|
$self->{errorString}='No data source name specified'; |
100
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
101
|
0
|
|
|
|
|
|
return undef; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
#makes sure we have a table |
105
|
0
|
0
|
|
|
|
|
if (!defined($table)) { |
106
|
0
|
|
|
|
|
|
$self->{error}=5; |
107
|
0
|
|
|
|
|
|
$self->{errorString}='No table name specified'; |
108
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
109
|
0
|
|
|
|
|
|
return undef; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
#makes sure we have a table |
113
|
0
|
0
|
|
|
|
|
if (!defined($sql)) { |
114
|
0
|
|
|
|
|
|
$self->{error}=7; |
115
|
0
|
|
|
|
|
|
$self->{errorString}='No SQL defined'; |
116
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
117
|
0
|
|
|
|
|
|
return undef; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
#connect |
121
|
0
|
|
|
|
|
|
my $dbh=$self->{zcdbi}->connect($dsName); |
122
|
0
|
0
|
|
|
|
|
if ($self->{zcdbi}->error) { |
123
|
0
|
|
|
|
|
|
$self->{error}=6; |
124
|
0
|
|
|
|
|
|
$self->{errorString}='Connect errored'; |
125
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
126
|
0
|
|
|
|
|
|
return undef; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
#create the dbix object |
130
|
0
|
|
|
|
|
|
my($admin) = DBIx::Admin::CreateTable->new( |
131
|
|
|
|
|
|
|
dbh=>$dbh, |
132
|
|
|
|
|
|
|
); |
133
|
0
|
0
|
|
|
|
|
if (!defined($admin)) { |
134
|
0
|
|
|
|
|
|
$self->{error}=4; |
135
|
0
|
|
|
|
|
|
$self->{errorString}='DBIx::Admin::CreateTable->new returned undef'; |
136
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
137
|
0
|
|
|
|
|
|
return undef; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
#create it |
141
|
0
|
|
|
|
|
|
my $returned=$admin->create_table('create table '.$table.' ( '.$sql.' )'); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#if the returned value is empty, but defined, it worked |
144
|
0
|
0
|
|
|
|
|
if ($returned eq '') { |
145
|
0
|
|
|
|
|
|
return 1; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
#it did not work as the returned value is not equal to '' |
149
|
0
|
|
|
|
|
|
$self->{error}=8; |
150
|
0
|
|
|
|
|
|
$self->{errorString}='DBIx::Admin::CreateTable->create_table errored. error="'.$returned.'"'; |
151
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
152
|
0
|
|
|
|
|
|
return undef; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 do |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This executes the do statement on a DBH created from the data source. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Two arguements are required. The first is the data source. The second |
160
|
|
|
|
|
|
|
is the SQL. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
$foo->create_table('whatever', 'drop sequence fubar;'); |
163
|
|
|
|
|
|
|
if($foo->error){ |
164
|
|
|
|
|
|
|
warn('error code:'.$error.': '.$foo->errorString); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub do{ |
170
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
171
|
0
|
|
|
|
|
|
my $dsName=$_[1]; |
172
|
0
|
|
|
|
|
|
my $sql=$_[2]; |
173
|
0
|
|
|
|
|
|
my $function='do'; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
#makes sure we have a data source |
176
|
0
|
0
|
|
|
|
|
if (!defined($dsName)) { |
177
|
0
|
|
|
|
|
|
$self->{error}=3; |
178
|
0
|
|
|
|
|
|
$self->{errorString}='No data source name specified'; |
179
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
180
|
0
|
|
|
|
|
|
return undef; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
#makes sure we have a table |
184
|
0
|
0
|
|
|
|
|
if (!defined($sql)) { |
185
|
0
|
|
|
|
|
|
$self->{error}=7; |
186
|
0
|
|
|
|
|
|
$self->{errorString}='No SQL defined'; |
187
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
188
|
0
|
|
|
|
|
|
return undef; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
#connect |
192
|
0
|
|
|
|
|
|
my $dbh=$self->{zcdbi}->connect($dsName); |
193
|
0
|
0
|
|
|
|
|
if ($self->{zcdbi}->error) { |
194
|
0
|
|
|
|
|
|
$self->{error}=6; |
195
|
0
|
|
|
|
|
|
$self->{errorString}='Connect errored'; |
196
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
197
|
0
|
|
|
|
|
|
return undef; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
return $dbh->do($sql); |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head2 drop_table |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
This drops a table using DBIx::Admin::CreateTable->drop_table. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Two arguements are required. The first is the data source name. The second is |
208
|
|
|
|
|
|
|
the table name. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
$foo->create_table('whatever', 'sometable'); |
211
|
|
|
|
|
|
|
if($foo->error){ |
212
|
|
|
|
|
|
|
warn('error code:'.$error.': '.$foo->errorString); |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=cut |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub drop_table{ |
218
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
219
|
0
|
|
|
|
|
|
my $dsName=$_[1]; |
220
|
0
|
|
|
|
|
|
my $table=$_[2]; |
221
|
0
|
|
|
|
|
|
my $function='drop_table'; |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
#makes sure we have a data source |
224
|
0
|
0
|
|
|
|
|
if (!defined($dsName)) { |
225
|
0
|
|
|
|
|
|
$self->{error}=3; |
226
|
0
|
|
|
|
|
|
$self->{errorString}='No data source name specified'; |
227
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
228
|
0
|
|
|
|
|
|
return undef; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
#makes sure we have a table |
232
|
0
|
0
|
|
|
|
|
if (!defined($table)) { |
233
|
0
|
|
|
|
|
|
$self->{error}=5; |
234
|
0
|
|
|
|
|
|
$self->{errorString}='No table name specified'; |
235
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
236
|
0
|
|
|
|
|
|
return undef; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
#connect |
240
|
0
|
|
|
|
|
|
my $dbh=$self->{zcdbi}->connect($dsName); |
241
|
0
|
0
|
|
|
|
|
if ($self->{zcdbi}->error) { |
242
|
0
|
|
|
|
|
|
$self->{error}=6; |
243
|
0
|
|
|
|
|
|
$self->{errorString}='Connect errored'; |
244
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
245
|
0
|
|
|
|
|
|
return undef; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
#create the dbix object |
249
|
0
|
|
|
|
|
|
my($admin) = DBIx::Admin::CreateTable->new( |
250
|
|
|
|
|
|
|
dbh=>$dbh, |
251
|
|
|
|
|
|
|
); |
252
|
0
|
0
|
|
|
|
|
if (!defined($admin)) { |
253
|
0
|
|
|
|
|
|
$self->{error}=4; |
254
|
0
|
|
|
|
|
|
$self->{errorString}='DBIx::Admin::CreateTable->new returned undef'; |
255
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
256
|
0
|
|
|
|
|
|
return undef; |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
#create it |
260
|
0
|
|
|
|
|
|
my $returned=$admin->drop_table($table); |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
#if the returned value is empty, but defined, it worked |
263
|
0
|
0
|
|
|
|
|
if ($returned eq '') { |
264
|
0
|
|
|
|
|
|
return 1; |
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
#it did not work as the returned value is not equal to '' |
268
|
0
|
|
|
|
|
|
$self->{error}=8; |
269
|
0
|
|
|
|
|
|
$self->{errorString}='DBIx::Admin::CreateTable->drop_table errored. error="'.$returned.'"'; |
270
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
271
|
0
|
|
|
|
|
|
return undef; |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head2 error |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
Returns the current error code and true if there is an error. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
If there is no error, undef is returned. |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
my $error=$foo->error; |
281
|
|
|
|
|
|
|
if($error){ |
282
|
|
|
|
|
|
|
warn('error code:'.$error.': '.$foo->errorString); |
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=cut |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
sub error{ |
288
|
0
|
|
|
0
|
1
|
|
return $_[0]->{error}; |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=head2 errorString |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
Returns the error string if there is one. If there is not, |
294
|
|
|
|
|
|
|
it will return undef. |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
my $error=$foo->error; |
297
|
|
|
|
|
|
|
if($error){ |
298
|
|
|
|
|
|
|
warn('error code:'.$error.': '.$foo->errorString); |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=cut |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
sub errorString{ |
304
|
0
|
|
|
0
|
1
|
|
return $_[0]->{errorString}; |
305
|
|
|
|
|
|
|
} |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=head2 table_columns |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
This returns a array reference of table column names found by |
310
|
|
|
|
|
|
|
DBIx::Admin::TableInfo->columns. |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
There are three arguements taken. The first, and required, is the data source name. |
313
|
|
|
|
|
|
|
The second, and optional, is the schema name. The third, and optional, is the schema. |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
my $tables=$foo->table_columns('tigerline', 'geometry_columns'); |
316
|
|
|
|
|
|
|
if($foo->error){ |
317
|
|
|
|
|
|
|
warn('error code:'.$foo->error.': '.$foo->errorString); |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
=cut |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
sub table_columns{ |
323
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
324
|
0
|
|
|
|
|
|
my $dsName=$_[1]; |
325
|
0
|
|
|
|
|
|
my $table=$_[2]; |
326
|
0
|
|
|
|
|
|
my $schema=$_[3]; |
327
|
0
|
|
|
|
|
|
my $function='table_columns'; |
328
|
|
|
|
|
|
|
|
329
|
0
|
0
|
|
|
|
|
if (!defined($dsName)) { |
330
|
0
|
|
|
|
|
|
$self->{error}=3; |
331
|
0
|
|
|
|
|
|
$self->{errorString}='No data source name specified'; |
332
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
333
|
0
|
|
|
|
|
|
return undef; |
334
|
|
|
|
|
|
|
} |
335
|
|
|
|
|
|
|
|
336
|
0
|
0
|
|
|
|
|
if (!defined($table)) { |
337
|
0
|
|
|
|
|
|
$self->{error}=5; |
338
|
0
|
|
|
|
|
|
$self->{errorString}='No table name specified'; |
339
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
340
|
0
|
|
|
|
|
|
return undef; |
341
|
|
|
|
|
|
|
} |
342
|
|
|
|
|
|
|
|
343
|
0
|
|
|
|
|
|
my $dbh=$self->{zcdbi}->connect($dsName); |
344
|
|
|
|
|
|
|
|
345
|
0
|
|
|
|
|
|
my($admin) = DBIx::Admin::TableInfo->new( |
346
|
|
|
|
|
|
|
dbh=>$dbh, |
347
|
|
|
|
|
|
|
schema=>$schema, |
348
|
|
|
|
|
|
|
); |
349
|
|
|
|
|
|
|
|
350
|
0
|
0
|
|
|
|
|
if (!defined($admin)) { |
351
|
0
|
|
|
|
|
|
$self->{error}=4; |
352
|
0
|
|
|
|
|
|
$self->{errorString}='DBIx::Admin::TableInfo->new returned undef'; |
353
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
354
|
0
|
|
|
|
|
|
return undef; |
355
|
|
|
|
|
|
|
} |
356
|
|
|
|
|
|
|
|
357
|
0
|
|
|
|
|
|
return $admin->columns($table); |
358
|
|
|
|
|
|
|
} |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
=head2 table_info |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
This returns a hash reference of table column names found by |
363
|
|
|
|
|
|
|
DBIx::Admin::TableInfo->info. |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
There are two arguements taken. The first, and required, is the data source name. |
366
|
|
|
|
|
|
|
The second, and optional, is the schema name. |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
my $tables=$foo->table_info('tigerline', 'geometry_columns'); |
369
|
|
|
|
|
|
|
if($foo->error){ |
370
|
|
|
|
|
|
|
warn('error "'.$foo->error.'"'); |
371
|
|
|
|
|
|
|
} |
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
=cut |
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
sub table_info{ |
376
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
377
|
0
|
|
|
|
|
|
my $dsName=$_[1]; |
378
|
0
|
|
|
|
|
|
my $schema=$_[2]; |
379
|
0
|
|
|
|
|
|
my $function='table_info'; |
380
|
|
|
|
|
|
|
|
381
|
0
|
0
|
|
|
|
|
if (!defined($dsName)) { |
382
|
0
|
|
|
|
|
|
$self->{error}=3; |
383
|
0
|
|
|
|
|
|
$self->{errorString}='No data source name specified'; |
384
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
385
|
0
|
|
|
|
|
|
return undef; |
386
|
|
|
|
|
|
|
} |
387
|
|
|
|
|
|
|
|
388
|
0
|
|
|
|
|
|
my $dbh=$self->{zcdbi}->connect($dsName); |
389
|
|
|
|
|
|
|
|
390
|
0
|
|
|
|
|
|
my($admin) = DBIx::Admin::TableInfo->new( |
391
|
|
|
|
|
|
|
dbh=>$dbh, |
392
|
|
|
|
|
|
|
schema=>$schema, |
393
|
|
|
|
|
|
|
); |
394
|
|
|
|
|
|
|
|
395
|
0
|
0
|
|
|
|
|
if (!defined($admin)) { |
396
|
0
|
|
|
|
|
|
$self->{error}=4; |
397
|
0
|
|
|
|
|
|
$self->{errorString}='DBIx::Admin::TableInfo->new returned undef'; |
398
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
399
|
0
|
|
|
|
|
|
return undef; |
400
|
|
|
|
|
|
|
} |
401
|
|
|
|
|
|
|
|
402
|
0
|
|
|
|
|
|
return $admin->info; |
403
|
|
|
|
|
|
|
} |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
=head2 tables |
406
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
This returns a array refernce of table names found by |
408
|
|
|
|
|
|
|
DBIx::Admin::TableInfo->tables. |
409
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
There are two arguements taken. The first, and required, is the data source name. |
411
|
|
|
|
|
|
|
The second, and optional, is the schema name. |
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
my $tables=$foo->tables('tigerline'); |
414
|
|
|
|
|
|
|
if($foo->error){ |
415
|
|
|
|
|
|
|
warn('error "'.$foo->error.'"'); |
416
|
|
|
|
|
|
|
} |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
=cut |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
sub tables{ |
421
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
422
|
0
|
|
|
|
|
|
my $dsName=$_[1]; |
423
|
0
|
|
|
|
|
|
my $schema=$_[2]; |
424
|
0
|
|
|
|
|
|
my $function='tables'; |
425
|
|
|
|
|
|
|
|
426
|
0
|
0
|
|
|
|
|
if (!defined($dsName)) { |
427
|
0
|
|
|
|
|
|
$self->{error}=3; |
428
|
0
|
|
|
|
|
|
$self->{errorString}='No data source name specified'; |
429
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
430
|
0
|
|
|
|
|
|
return undef; |
431
|
|
|
|
|
|
|
} |
432
|
|
|
|
|
|
|
|
433
|
0
|
|
|
|
|
|
my $dbh=$self->{zcdbi}->connect($dsName); |
434
|
|
|
|
|
|
|
|
435
|
0
|
|
|
|
|
|
my($admin) = DBIx::Admin::TableInfo->new( |
436
|
|
|
|
|
|
|
dbh=>$dbh, |
437
|
|
|
|
|
|
|
schema=>$schema, |
438
|
|
|
|
|
|
|
); |
439
|
|
|
|
|
|
|
|
440
|
0
|
0
|
|
|
|
|
if (!defined($admin)) { |
441
|
0
|
|
|
|
|
|
$self->{error}=4; |
442
|
0
|
|
|
|
|
|
$self->{errorString}='DBIx::Admin::TableInfo->new returned undef'; |
443
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); |
444
|
0
|
|
|
|
|
|
return undef; |
445
|
|
|
|
|
|
|
} |
446
|
|
|
|
|
|
|
|
447
|
0
|
|
|
|
|
|
return $admin->tables; |
448
|
|
|
|
|
|
|
} |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
=head2 errorblank |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
This blanks the error storage and is only meant for internal usage. |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
It does the following. |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
$self->{error}=undef; |
457
|
|
|
|
|
|
|
$self->{errorString}=undef; |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
=cut |
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
#blanks the error flags |
462
|
|
|
|
|
|
|
sub errorblank{ |
463
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
464
|
|
|
|
|
|
|
|
465
|
0
|
0
|
|
|
|
|
if ($self->{perror}) { |
466
|
0
|
|
|
|
|
|
warn('ZConf-DevTemplate errorblank: A permanent error is set'); |
467
|
0
|
|
|
|
|
|
return undef; |
468
|
|
|
|
|
|
|
} |
469
|
|
|
|
|
|
|
|
470
|
0
|
|
|
|
|
|
$self->{error}=undef; |
471
|
0
|
|
|
|
|
|
$self->{errorString}=undef; |
472
|
|
|
|
|
|
|
|
473
|
0
|
|
|
|
|
|
return 1; |
474
|
|
|
|
|
|
|
} |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
=head1 ERROR CODES |
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
=head2 1 |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
No ZConf::DBI object passed. |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
=head2 2 |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
The passed object is not a ZConf::DBI object. |
485
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
=head2 3 |
487
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
No data source name specified. |
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
=head2 4 |
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
DBIx::Admin::TableInfo->new returned undef. |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
=head2 5 |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
No table specified. |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
=head2 6 |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
Connect errored. |
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
=head2 7 |
503
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
No SQL defined. |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
=head2 8 |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
Creating the table frailed. |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
=head2 9 |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
Dropping the table failed. |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
=head1 AUTHOR |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
Zane C. Bowers, C<< >> |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
=head1 BUGS |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
521
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
522
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
523
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
=head1 SUPPORT |
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
perldoc ZConf::DBI::utils |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
You can also look for information at: |
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
=over 4 |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
539
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
L |
541
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
543
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
L |
545
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
=item * CPAN Ratings |
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
L |
549
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
=item * Search CPAN |
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
L |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
=back |
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
558
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
Copyright 2010 Zane C. Bowers, all rights reserved. |
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
565
|
|
|
|
|
|
|
under the same terms as Perl itself. |
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
=cut |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
1; # End of ZConf::DBI::utils |