| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package FabForce::DBDesigner4; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Parse/Analyse XML-Files created by DBDesigner 4 (FabForce) |
|
4
|
|
|
|
|
|
|
|
|
5
|
11
|
|
|
11
|
|
261730
|
use strict; |
|
|
11
|
|
|
|
|
34
|
|
|
|
11
|
|
|
|
|
398
|
|
|
6
|
11
|
|
|
11
|
|
56
|
use warnings; |
|
|
11
|
|
|
|
|
20
|
|
|
|
11
|
|
|
|
|
301
|
|
|
7
|
11
|
|
|
11
|
|
54
|
use Carp; |
|
|
11
|
|
|
|
|
23
|
|
|
|
11
|
|
|
|
|
601
|
|
|
8
|
11
|
|
|
11
|
|
6213
|
use FabForce::DBDesigner4::XML; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use FabForce::DBDesigner4::SQL; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.33'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new{ |
|
14
|
|
|
|
|
|
|
my ($class,%args) = @_; |
|
15
|
|
|
|
|
|
|
croak "only one filetype" if(defined $args{sql} and defined $args{xml}); |
|
16
|
|
|
|
|
|
|
my $self = {}; |
|
17
|
|
|
|
|
|
|
bless $self,$class; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$self->{sql} = $args{sql} if(defined $args{sql}); |
|
20
|
|
|
|
|
|
|
$self->{xml} = $args{xml} if(defined $args{xml}); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
return $self; |
|
23
|
|
|
|
|
|
|
}# new |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub parsefile{ |
|
26
|
|
|
|
|
|
|
my ($self,%args) = @_; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$self->{xml} = $args{xml} if(defined $args{xml}); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
if( defined $self->{xml} ) { |
|
31
|
|
|
|
|
|
|
my $xml = FabForce::DBDesigner4::XML->new; |
|
32
|
|
|
|
|
|
|
$self->{structure} = $xml->parsefile( $self->{xml} ); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
else{ |
|
35
|
|
|
|
|
|
|
croak "No valid filetype defined!" |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
}# parsefile |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub writeSQL{ |
|
40
|
|
|
|
|
|
|
my ($self,$filename,$args) = @_; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $sql = FabForce::DBDesigner4::SQL->new(); |
|
43
|
|
|
|
|
|
|
my $struct = delete $args->{structure}; |
|
44
|
|
|
|
|
|
|
$args->{type} ||= 'other'; |
|
45
|
|
|
|
|
|
|
my $structForFile = $struct || $self->{structure} || ''; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$sql->writeSQL($structForFile, $filename, $args); |
|
48
|
|
|
|
|
|
|
}# writeSQL |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub getTables{ |
|
51
|
|
|
|
|
|
|
my ($self) = @_; |
|
52
|
|
|
|
|
|
|
return @{$self->{structure}}; |
|
53
|
|
|
|
|
|
|
}# getTables |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub getSQL{ |
|
56
|
|
|
|
|
|
|
my ($self,$args) = @_; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $sql = FabForce::DBDesigner4::SQL->new(); |
|
59
|
|
|
|
|
|
|
$args->{type} ||= 'other'; |
|
60
|
|
|
|
|
|
|
my @creates = $sql->getSQL($self->{structure},$args); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
return @creates; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=pod |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 NAME |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
FabForce::DBDesigner4 - Parse/Analyse XML-Files created by DBDesigner 4 (FabForce) |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 VERSION |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
version 0.33 |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
use FabForce::DBDesigner4; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $designer = FabForce::DBDesigner4->new(); |
|
84
|
|
|
|
|
|
|
$designer->parsefile(xml => 'KESS.xml'); |
|
85
|
|
|
|
|
|
|
$designer->writeSQL('text_sql.sql',{ type => 'mysql' }); |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
FabForce::DBDesigner4 is a module to analyse xml-files created |
|
90
|
|
|
|
|
|
|
by the Database-Design tool DBDesigner (Version 4) from |
|
91
|
|
|
|
|
|
|
FabForce (http://www.fabforce.net). |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
B: As of version 0.2 you can not parse sql files any longer. You just |
|
94
|
|
|
|
|
|
|
can parse xml files created by DBDesigner. And you can't create XML files! |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 METHODS |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 new |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# create a new instance |
|
101
|
|
|
|
|
|
|
my $designer = FabForce::DBDesigner4->new(); |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 parsefile |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
parse the input file (XML - FabForce format ) |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# parse a xml-file |
|
108
|
|
|
|
|
|
|
$designer->parsefile(xml => 'KESS.xml'); |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 writeSQL |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
print the structure into a sql-file |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$designer->writeSQL('foo.sql'); |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# print "drop table statements" |
|
117
|
|
|
|
|
|
|
$designer->writeSQL( 'foo.sql', { drop_tables => 1 } ); |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 getTables |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
returns an array of table-objects |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my @tables = $designer->getTables(); |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 getSQL |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
returns an array of CREATE statements. One element for each table. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my @creates = $designer->getSQL(); |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# get "drop table" statements in extra elements |
|
132
|
|
|
|
|
|
|
my @creates = $designer->getSQL({ drop_table => 1 }); |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 DBDesigner4::Table |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Each table is an object which contains information about the columns, |
|
137
|
|
|
|
|
|
|
the relations and the keys. |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Methods of the table-objects |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 name |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# set the tablename |
|
144
|
|
|
|
|
|
|
$table->name('tablename'); |
|
145
|
|
|
|
|
|
|
# get the tablename |
|
146
|
|
|
|
|
|
|
my $name = $table->name(); |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 columns |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# set the tablecolumns |
|
151
|
|
|
|
|
|
|
my @array = ({'column1' => ['int','not null']}); |
|
152
|
|
|
|
|
|
|
$table->columns(\@array); |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# get the columns |
|
155
|
|
|
|
|
|
|
print $_,"\n" for($table->columns()); |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 columnType |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# get datatype of n-th column (i.e. 3rd column) |
|
160
|
|
|
|
|
|
|
my $datatype = $table->columnType(3); |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 columnInfo |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# get info about n-th column (i.e. 4th column) |
|
165
|
|
|
|
|
|
|
print Dumper($table->columnInfo(4)); |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 stringsToTableCols |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# maps column information to hash (needed for columns()) |
|
170
|
|
|
|
|
|
|
my @columns = ('col1 varchar(255) primary key', 'col2 int not null'); |
|
171
|
|
|
|
|
|
|
my @array = $table->stringsToTableCols(@columns); |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 addColumn |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# add the tablecolumn |
|
176
|
|
|
|
|
|
|
my $column = ['column1','int','not null']; |
|
177
|
|
|
|
|
|
|
$table->addColumn($column); |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 relations |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# set relations |
|
182
|
|
|
|
|
|
|
my @relations = ([1,'startTable.startCol','targetTable.targetCol']); |
|
183
|
|
|
|
|
|
|
$table->relations(\@relations); |
|
184
|
|
|
|
|
|
|
# get relations |
|
185
|
|
|
|
|
|
|
print $_,"\n" for($table->relations()); |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 addRelation |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
$table->addRelation([1,'startTable.startCol','targetTable.targetCol']); |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 removeRelation |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# removes a relation (i.e. 2nd relation) |
|
194
|
|
|
|
|
|
|
$table->removeRelation(2); |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 key |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
# set the primary key |
|
199
|
|
|
|
|
|
|
$table->key(['prim1']); |
|
200
|
|
|
|
|
|
|
# get the primary key |
|
201
|
|
|
|
|
|
|
print "the primary key contains these columns:\n"; |
|
202
|
|
|
|
|
|
|
print $_,"\n" for($table->key()); |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 column_details |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
This module requires XML::Twig |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 BUGS and COMMENTS |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
This module is still in development so feel free to contact me and send me |
|
213
|
|
|
|
|
|
|
bugreports or comments on this module. |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
XML::Twig and IO::File |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 AUTHOR |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Renee Baecker |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
This software is Copyright (c) 2010 by Renee Baecker. |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This is free software, licensed under: |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=cut |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
__END__ |