| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package FabForce::DBDesigner4::Table; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
27819
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
41
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
31
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use Exporter; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
130
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
|
10
|
|
|
|
|
|
|
IDENTIFYING_1_TO_1 |
|
11
|
|
|
|
|
|
|
IDENTIFYING_1_TO_N |
|
12
|
|
|
|
|
|
|
NON_IDENTIFYING_1_TO_N |
|
13
|
|
|
|
|
|
|
NON_IDENTIFYING_1_TO_1 |
|
14
|
|
|
|
|
|
|
); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
|
17
|
|
|
|
|
|
|
'const' => [@EXPORT_OK] |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use constant { |
|
21
|
1
|
|
|
|
|
2392
|
IDENTIFYING_1_TO_1 => 0, |
|
22
|
|
|
|
|
|
|
IDENTIFYING_1_TO_N => 1, |
|
23
|
|
|
|
|
|
|
NON_IDENTIFYING_1_TO_N => 2, |
|
24
|
|
|
|
|
|
|
NON_IDENTIFYING_1_TO_1 => 5, |
|
25
|
1
|
|
|
1
|
|
6
|
}; |
|
|
1
|
|
|
|
|
2
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new{ |
|
30
|
0
|
|
|
0
|
1
|
|
my ($class,%args) = @_; |
|
31
|
0
|
|
|
|
|
|
my $self = {}; |
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
bless $self,$class; |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$self->{COORDS} = []; |
|
36
|
0
|
|
|
|
|
|
$self->{COLUMNS} = []; |
|
37
|
0
|
|
|
|
|
|
$self->{COLUMNS_DETAILS} = []; |
|
38
|
0
|
|
|
|
|
|
$self->{NAME} = ''; |
|
39
|
0
|
|
|
|
|
|
$self->{RELATIONS} = []; |
|
40
|
0
|
|
|
|
|
|
$self->{KEY} = []; |
|
41
|
0
|
|
|
|
|
|
$self->{ATTRIBUTE} = {}; |
|
42
|
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
$self->{COORDS} = $args{-coords} if(_checkArg('coords' , $args{-coords} )); |
|
44
|
0
|
0
|
|
|
|
|
$self->{COLUMNS} = $args{-columns} if(_checkArg('columns' , $args{-columns} )); |
|
45
|
0
|
0
|
|
|
|
|
$self->{COLUMNS_DETAILS} = $args{-column_details} if(_checkArg('columnsdetails', $args{-columnsdetails})); |
|
46
|
0
|
0
|
|
|
|
|
$self->{NAME} = $args{-name} if(_checkArg('name' , $args{-name} )); |
|
47
|
0
|
0
|
|
|
|
|
$self->{RELATIONS} = $args{-relations} if(_checkArg('relations' , $args{-relations} )); |
|
48
|
0
|
0
|
|
|
|
|
$self->{KEY} = $args{-key} if(_checkArg('key' , $args{-key} )); |
|
49
|
0
|
0
|
|
|
|
|
$self->{INDEX} = $args{-index} if(_checkArg('index' , $args{-index} )); |
|
50
|
0
|
0
|
|
|
|
|
$self->{ATTRIBUTE} = $args{-attr} if(_checkArg('attribute' , $args{-attr} )); |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return $self; |
|
53
|
|
|
|
|
|
|
}# new |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub columns{ |
|
56
|
0
|
|
|
0
|
1
|
|
my ($self,$ar) = @_; |
|
57
|
0
|
0
|
0
|
|
|
|
unless($ar && _checkArg('columns',$ar)){ |
|
58
|
0
|
|
|
|
|
|
my @columns; |
|
59
|
0
|
|
|
|
|
|
for my $col(@{$self->{COLUMNS}}){ |
|
|
0
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $string = join('',keys(%$col)); |
|
61
|
0
|
|
|
|
|
|
for my $val(values(%$col)){ |
|
62
|
0
|
|
|
|
|
|
for my $elem(@$val){ |
|
63
|
0
|
0
|
|
|
|
|
if( defined $elem ){ |
|
64
|
0
|
0
|
|
|
|
|
$elem = 'VARCHAR(255)' if $elem =~ /^varchar$/i; |
|
65
|
0
|
0
|
|
|
|
|
$elem = "ENUM('1','0') DEFAULT '0'" if $elem =~ /^enum$/i; |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$string .= " ".$elem; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
} |
|
71
|
0
|
|
|
|
|
|
push(@columns,$string); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
0
|
|
|
|
|
|
return @columns; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
0
|
|
|
|
|
|
$self->{COLUMNS} = $ar; |
|
76
|
0
|
|
|
|
|
|
return 1; |
|
77
|
|
|
|
|
|
|
}# columns |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub column_details { |
|
80
|
0
|
|
|
0
|
1
|
|
my ($self, $details) = @_; |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
0
|
0
|
|
|
|
if ( $details && _checkArg('columndetails', $details) ) { |
|
83
|
0
|
|
|
|
|
|
$self->{COLUMNS_DETAILS} = $details; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
return $self->{COLUMNS_DETAILS}; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub column_names{ |
|
90
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
91
|
0
|
|
|
|
|
|
my @names; |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
for my $col ( @{ $self->{COLUMNS} } ){ |
|
|
0
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
push @names, join '', keys %$col; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
return @names; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub columnType{ |
|
101
|
0
|
|
|
0
|
1
|
|
my ($self,$name) = @_; |
|
102
|
0
|
0
|
|
|
|
|
return unless($name); |
|
103
|
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my $type = ''; |
|
105
|
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
for(0..scalar(@{$self->{COLUMNS}})-1){ |
|
|
0
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my ($key) = keys(%{$self->{COLUMNS}->[$_]}); |
|
|
0
|
|
|
|
|
|
|
|
108
|
0
|
0
|
|
|
|
|
if($key eq $name){ |
|
109
|
0
|
|
|
|
|
|
$type = $self->{COLUMNS}->[$_]->{$key}->[0]; |
|
110
|
0
|
|
|
|
|
|
last; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
} |
|
113
|
0
|
|
|
|
|
|
return $type; |
|
114
|
|
|
|
|
|
|
}# columnType |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub columnInfo{ |
|
117
|
0
|
|
|
0
|
1
|
|
my ($self,$nr) = @_; |
|
118
|
0
|
|
|
|
|
|
return $self->{COLUMNS}->[$nr]; |
|
119
|
|
|
|
|
|
|
}# columnInfo |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub addColumn{ |
|
122
|
0
|
|
|
0
|
1
|
|
my ($self,$ar) = @_; |
|
123
|
0
|
0
|
0
|
|
|
|
return unless($ar && ref($ar) eq 'ARRAY'); |
|
124
|
0
|
|
|
|
|
|
push(@{$self->{COLUMNS}},{$ar->[0] => [@{$ar}[1,2]]}); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
return 1; |
|
126
|
|
|
|
|
|
|
}# addColumn |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub stringsToTableCols{ |
|
129
|
0
|
|
|
0
|
1
|
|
my ($self,@array) = @_; |
|
130
|
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my @returnArray; |
|
132
|
0
|
|
|
|
|
|
for my $col(@array){ |
|
133
|
0
|
|
|
|
|
|
$col =~ s!,\s*?$!!; |
|
134
|
0
|
|
|
|
|
|
$col =~ s!^\s*!!; |
|
135
|
0
|
0
|
0
|
|
|
|
next if((not defined $col) or $col eq ''); |
|
136
|
0
|
|
|
|
|
|
my ($name,$type,$info) = split(/\s+/,$col,3); |
|
137
|
0
|
|
|
|
|
|
push(@returnArray,{$name => [$type,$info]}); |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
return @returnArray; |
|
141
|
|
|
|
|
|
|
}# arrayToTableCols |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub coords{ |
|
144
|
0
|
|
|
0
|
1
|
|
my ($self,$ar) = @_; |
|
145
|
0
|
0
|
0
|
|
|
|
return @{$self->{COORDS}} unless($ar && _checkArg('coords',$ar)); |
|
|
0
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
$self->{COORDS} = $ar; |
|
147
|
0
|
|
|
|
|
|
return 1; |
|
148
|
|
|
|
|
|
|
}# start |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub name{ |
|
151
|
0
|
|
|
0
|
1
|
|
my ($self,$value) = @_; |
|
152
|
0
|
0
|
0
|
|
|
|
return $self->{NAME} unless($value && _checkArg('name',$value)); |
|
153
|
0
|
|
|
|
|
|
$self->{NAME} = $value; |
|
154
|
0
|
|
|
|
|
|
return 1; |
|
155
|
|
|
|
|
|
|
}# name |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub relations{ |
|
158
|
0
|
|
|
0
|
1
|
|
my ($self,$value) = @_; |
|
159
|
0
|
0
|
0
|
|
|
|
return @{$self->{RELATIONS}} unless($value && _checkArg('relations',$value)); |
|
|
0
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
$self->{RELATIONS} = $value; |
|
161
|
0
|
|
|
|
|
|
return 1; |
|
162
|
|
|
|
|
|
|
}# relations |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub addRelation{ |
|
165
|
0
|
|
|
0
|
1
|
|
my ($self,$value) = @_; |
|
166
|
0
|
0
|
0
|
|
|
|
return unless($value && ref($value) eq 'ARRAY' && scalar(@$value) == 4); |
|
|
|
|
0
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
push(@{$self->{RELATIONS}},$value); |
|
|
0
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
return 1; |
|
169
|
|
|
|
|
|
|
}# addRelation |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub removeRelation{ |
|
172
|
0
|
|
|
0
|
1
|
|
my ($self,$index) = @_; |
|
173
|
0
|
0
|
0
|
|
|
|
return unless(defined $index or $index > (scalar(@{$self->{RELATIONS}})-1)); |
|
|
0
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
splice(@{$self->{RELATIONS}},$index,1); |
|
|
0
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
}# removeRelation |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub changeRelation{ |
|
178
|
0
|
|
|
0
|
1
|
|
my ($self,$index,$value) = @_; |
|
179
|
0
|
0
|
0
|
|
|
|
return unless(defined $index and defined $value); |
|
180
|
0
|
|
|
|
|
|
$self->{RELATIONS}->[$index]->[0] = $value; |
|
181
|
|
|
|
|
|
|
}# changeRelation |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub key{ |
|
184
|
0
|
|
|
0
|
1
|
|
my ($self,$value) = @_; |
|
185
|
0
|
0
|
0
|
|
|
|
return @{$self->{KEY}} unless($value && _checkArg('key',$value)); |
|
|
0
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
$self->{KEY} = $value; |
|
187
|
0
|
|
|
|
|
|
return 1; |
|
188
|
|
|
|
|
|
|
}# key |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub tableIndex{ |
|
191
|
0
|
|
|
0
|
1
|
|
my ($self,$value) = @_; |
|
192
|
0
|
0
|
0
|
|
|
|
return @{$self->{INDEX}} unless($value && _checkArg('index',$value)); |
|
|
0
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
$self->{INDEX} = $value; |
|
194
|
0
|
|
|
|
|
|
return 1; |
|
195
|
|
|
|
|
|
|
}# tableIndex |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub attribute{ |
|
198
|
0
|
|
|
0
|
1
|
|
my ($self,$value) = @_; |
|
199
|
0
|
0
|
0
|
|
|
|
return @{$self->{ATTRIBUTE}} unless($value && _checkArg('attribute',$value)); |
|
|
0
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
$self->{ATTRIBUTE} = $value; |
|
201
|
0
|
|
|
|
|
|
return 1; |
|
202
|
|
|
|
|
|
|
}# attribute |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub get_foreign_keys{ |
|
205
|
0
|
|
|
0
|
1
|
|
my ($table) = @_; |
|
206
|
|
|
|
|
|
|
|
|
207
|
0
|
0
|
|
|
|
|
unless( defined $table->{_foreign_relations} ){ |
|
208
|
0
|
|
|
|
|
|
my $tablename = $table->name(); |
|
209
|
0
|
|
|
|
|
|
my @relations = grep{$_->[1] =~ /^$tablename\./}$table->relations(); |
|
|
0
|
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
$table->{_foreign_relations} = { _getForeignKeys(@relations) }; |
|
211
|
|
|
|
|
|
|
} |
|
212
|
0
|
|
|
|
|
|
return $table->{_foreign_relations}; |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub _checkArg{ |
|
216
|
0
|
|
|
0
|
|
|
my ($type,$value) = @_; |
|
217
|
0
|
|
|
|
|
|
my $return = 0; |
|
218
|
0
|
0
|
|
|
|
|
if($value){ |
|
219
|
0
|
|
|
|
|
|
$return = 1 if($type eq 'coords' |
|
220
|
|
|
|
|
|
|
&& ref($value) eq 'ARRAY' |
|
221
|
|
|
|
|
|
|
&& scalar(@$value) == 4 |
|
222
|
0
|
0
|
0
|
|
|
|
&& !grep{/\D/}@$value); |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
$return = 1 if($type eq 'columns' |
|
225
|
|
|
|
|
|
|
&& ref($value) eq 'ARRAY' |
|
226
|
0
|
0
|
0
|
|
|
|
&& !(!grep{ref($_) eq 'HASH'}@$value)); |
|
|
|
|
0
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
|
228
|
0
|
0
|
0
|
|
|
|
$return = 1 if( $type eq 'columndetails' && ref($value) eq 'ARRAY' ); |
|
229
|
|
|
|
|
|
|
|
|
230
|
0
|
0
|
0
|
|
|
|
$return = 1 if($type eq 'name' |
|
231
|
|
|
|
|
|
|
&& ref(\$value) eq 'SCALAR'); |
|
232
|
|
|
|
|
|
|
|
|
233
|
0
|
|
|
|
|
|
$return = 1 if($type eq 'relations' |
|
234
|
|
|
|
|
|
|
&& ref($value) eq 'ARRAY' |
|
235
|
0
|
0
|
0
|
|
|
|
&& !(!grep{ref($_) eq 'ARRAY'}@$value)); |
|
|
|
|
0
|
|
|
|
|
|
236
|
|
|
|
|
|
|
|
|
237
|
0
|
|
|
|
|
|
$return = 1 if($type eq 'key' |
|
238
|
|
|
|
|
|
|
&& ref($value) eq 'ARRAY' |
|
239
|
0
|
0
|
0
|
|
|
|
&& !(!grep{ref(\$_) eq 'SCALAR'}@$value)); |
|
|
|
|
0
|
|
|
|
|
|
240
|
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
$return = 1 if($type eq 'index' |
|
242
|
|
|
|
|
|
|
&& ref($value) eq 'ARRAY' |
|
243
|
0
|
0
|
0
|
|
|
|
&& !(!grep{ref(\$_) eq 'SCALAR'}@$value)); |
|
|
|
|
0
|
|
|
|
|
|
244
|
|
|
|
|
|
|
|
|
245
|
0
|
0
|
0
|
|
|
|
$return = 1 if($type eq 'attribute' |
|
246
|
|
|
|
|
|
|
&& ref($value) eq 'HASH'); |
|
247
|
|
|
|
|
|
|
} |
|
248
|
|
|
|
|
|
|
|
|
249
|
0
|
|
|
|
|
|
return $return; |
|
250
|
|
|
|
|
|
|
}# checkArg |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
sub _getForeignKeys{ |
|
255
|
0
|
|
|
0
|
|
|
my @rels = @_; |
|
256
|
0
|
|
|
|
|
|
my %relations; |
|
257
|
0
|
|
|
|
|
|
for my $rel(@rels){ |
|
258
|
0
|
0
|
|
|
|
|
next unless $rel; |
|
259
|
0
|
|
|
|
|
|
my $start = (split(/\./,$rel->[1]))[1]; |
|
260
|
0
|
|
|
|
|
|
my ($table,$target) = split(/\./,$rel->[2]); |
|
261
|
0
|
|
|
|
|
|
push(@{$relations{$table}},[$start,$target]); |
|
|
0
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
} |
|
263
|
0
|
|
|
|
|
|
return %relations; |
|
264
|
|
|
|
|
|
|
}# getForeignKeys |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
1; |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=pod |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head1 NAME |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
FabForce::DBDesigner4::Table |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=head1 VERSION |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
version 0.33 |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head1 DBDesigner4::Table |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Each table is an object which contains information about the columns, |
|
282
|
|
|
|
|
|
|
the relations and the keys. |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
Methods of the table-objects |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=head2 name |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
# set the tablename |
|
289
|
|
|
|
|
|
|
$table->name('tablename'); |
|
290
|
|
|
|
|
|
|
# get the tablename |
|
291
|
|
|
|
|
|
|
my $name = $table->name(); |
|
292
|
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=head2 columns |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
# set the tablecolumns |
|
296
|
|
|
|
|
|
|
my @array = ({'column1' => ['int','not null']}); |
|
297
|
|
|
|
|
|
|
$table->columns(\@array); |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
# get the columns |
|
300
|
|
|
|
|
|
|
print $_,"\n" for($table->columns()); |
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
=head2 columnType |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
# get datatype of n-th column (i.e. 3rd column) |
|
305
|
|
|
|
|
|
|
my $datatype = $table->columnType(3); |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=head2 columnInfo |
|
308
|
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
# get info about n-th column (i.e. 4th column) |
|
310
|
|
|
|
|
|
|
print Dumper($table->columnInfo(4)); |
|
311
|
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
=head2 stringsToTableCols |
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
# maps column information to hash (needed for columns()) |
|
315
|
|
|
|
|
|
|
my @columns = ('col1 varchar(255) primary key', 'col2 int not null'); |
|
316
|
|
|
|
|
|
|
my @array = $table->stringsToTableCols(@columns); |
|
317
|
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
=head2 addColumn |
|
319
|
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
# add the tablecolumn |
|
321
|
|
|
|
|
|
|
my $column = ['column1','int','not null']; |
|
322
|
|
|
|
|
|
|
$table->addColumn($column); |
|
323
|
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
=head2 relations |
|
325
|
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
# set relations |
|
327
|
|
|
|
|
|
|
my @relations = ([1,'startTable.startCol','targetTable.targetCol']); |
|
328
|
|
|
|
|
|
|
$table->relations(\@relations); |
|
329
|
|
|
|
|
|
|
# get relations |
|
330
|
|
|
|
|
|
|
print $_,"\n" for($table->relations()); |
|
331
|
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
=head2 addRelation |
|
333
|
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
$table->addRelation([1,'startTable.startCol','targetTable.targetCol']); |
|
335
|
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
=head2 removeRelation |
|
337
|
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
# removes a relation (i.e. 2nd relation) |
|
339
|
|
|
|
|
|
|
$table->removeRelation(2); |
|
340
|
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
=head2 key |
|
342
|
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
# set the primary key |
|
344
|
|
|
|
|
|
|
$table->key(['prim1']); |
|
345
|
|
|
|
|
|
|
# get the primary key |
|
346
|
|
|
|
|
|
|
print "the primary key contains these columns:\n"; |
|
347
|
|
|
|
|
|
|
print $_,"\n" for($table->key()); |
|
348
|
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
=head2 attribute |
|
350
|
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
=head2 changeRelation |
|
352
|
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
=head2 coords |
|
354
|
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
=head2 new |
|
356
|
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
=head2 tableIndex |
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
=head2 column_details |
|
360
|
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
=head2 column_names |
|
362
|
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
my @names = $table->column_names |
|
364
|
|
|
|
|
|
|
print $_,"\n" for @names; |
|
365
|
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
=head2 get_foreign_keys |
|
367
|
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
my %foreign_keys = $table->get_foreign_keys; |
|
369
|
|
|
|
|
|
|
use Data::Dumper; |
|
370
|
|
|
|
|
|
|
print Dumper \%foreign_keys; |
|
371
|
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
=head1 AUTHOR |
|
373
|
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
Renee Baecker |
|
375
|
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
377
|
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
This software is Copyright (c) 2010 by Renee Baecker. |
|
379
|
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
This is free software, licensed under: |
|
381
|
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
|
383
|
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
=cut |
|
385
|
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
__END__ |