4 # Before `make install' is performed this script should be runnable with
5 # `make test'. After `make install' it should work as `perl test.pl'
12 use Test::SQL::Translator qw(maybe_plan);
16 BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; }
17 use constant DEBUG => (exists $opt{d} ? 1 : 0);
18 use constant TRACE => (exists $opt{t} ? 1 : 0);
22 my $file = "$Bin/data/mysql/sqlfxml-producer-basic.sql";
24 local $SIG{__WARN__} = sub {
26 unless $_[0] =~ m!XML/Writer!;
30 #=============================================================================
36 'SQL::Translator::Producer::XML::SQLFairy');
39 use Test::Differences;
41 use SQL::Translator::Producer::XML::SQLFairy;
50 <schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
53 <table name="Basic" order="1">
56 <field name="id" data_type="integer" size="10" is_nullable="0" is_auto_increment="1" is_primary_key="1" is_foreign_key="0" order="1">
58 <comments>comment on id field</comments>
60 <field name="title" data_type="varchar" size="100" is_nullable="0" default_value="hello" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="2">
64 <field name="description" data_type="text" size="65535" is_nullable="1" default_value="" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="3">
68 <field name="email" data_type="varchar" size="255" is_nullable="1" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="4">
74 <index name="titleindex" type="NORMAL" fields="title" options="">
79 <constraint name="" type="PRIMARY KEY" fields="id" reference_table="" reference_fields="" on_delete="" on_update="" match_type="" expression="" options="" deferrable="1">
82 <constraint name="" type="UNIQUE" fields="email" reference_table="" reference_fields="" on_delete="" on_update="" match_type="" expression="" options="" deferrable="1">
91 <procedures></procedures>
95 $obj = SQL::Translator->new(
101 to => "XML-SQLFairy",
103 $xml = $obj->translate($file) or die $obj->error;
104 ok("$xml" ne "" ,"Produced something!");
105 print "XML:\n$xml" if DEBUG;
106 # Strip sqlf header with its variable date so we diff safely
107 $xml =~ s/^([^\n]*\n){7}//m;
108 eq_or_diff $xml, $ans, "XML looks right";
115 # Thanks to Ken for the schema setup lifted from 13schema.t
120 <schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
124 <view name="foo_view" fields="name,age" order="1">
125 <sql>select name, age from person</sql>
126 <extra hello="world" />
129 <triggers></triggers>
130 <procedures></procedures>
134 $obj = SQL::Translator->new(
140 to => "XML-SQLFairy",
142 my $s = $obj->schema;
143 my $name = 'foo_view';
144 my $sql = 'select name, age from person';
145 my $fields = 'name, age';
146 my $v = $s->add_view(
150 extra => { hello => "world" },
154 # As we have created a Schema we give translate a dummy string so that
155 # it will run the produce.
156 lives_ok {$xml =$obj->translate("FOO");} "Translate (View) ran";
157 ok("$xml" ne "" ,"Produced something!");
158 print "XML attrib_values=>1:\n$xml" if DEBUG;
159 # Strip sqlf header with its variable date so we diff safely
160 $xml =~ s/^([^\n]*\n){7}//m;
161 eq_or_diff $xml, $ans ,"XML looks right";
167 # Thanks to Ken for the schema setup lifted from 13schema.t
172 <schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
175 <table name="Basic" order="1">
179 <constraints></constraints>
180 <comments></comments>
185 <trigger name="foo_trigger" database_events="insert" on_table="Basic" perform_action_when="after" order="1">
186 <action>update modified=timestamp();</action>
187 <extra hello="world" />
190 <procedures></procedures>
194 $obj = SQL::Translator->new(
200 to => "XML-SQLFairy",
202 my $s = $obj->schema;
203 my $name = 'foo_trigger';
204 my $perform_action_when = 'after';
205 my $database_event = 'insert';
206 my $action = 'update modified=timestamp();';
207 my $table = $s->add_table( name => "Basic" ) or die $s->error;
208 my $t = $s->add_trigger(
210 perform_action_when => $perform_action_when,
211 database_events => [$database_event],
214 extra => { hello => "world" },
217 # As we have created a Schema we give translate a dummy string so that
218 # it will run the produce.
219 lives_ok {$xml =$obj->translate("FOO");} "Translate (Trigger) ran";
220 ok("$xml" ne "" ,"Produced something!");
221 print "XML attrib_values=>1:\n$xml" if DEBUG;
222 # Strip sqlf header with its variable date so we diff safely
223 $xml =~ s/^([^\n]*\n){7}//m;
224 eq_or_diff $xml, $ans ,"XML looks right";
230 # Thanks to Ken for the schema setup lifted from 13schema.t
235 <schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
239 <triggers></triggers>
241 <procedure name="foo_proc" parameters="foo,bar" owner="Nomar" order="1">
242 <sql>select foo from bar</sql>
243 <comments>Go Sox!</comments>
244 <extra hello="world" />
250 $obj = SQL::Translator->new(
256 to => "XML-SQLFairy",
258 my $s = $obj->schema;
259 my $name = 'foo_proc';
260 my $sql = 'select foo from bar';
261 my $parameters = 'foo, bar';
263 my $comments = 'Go Sox!';
264 my $p = $s->add_procedure(
267 parameters => $parameters,
269 comments => $comments,
270 extra => { hello => "world" },
273 # As we have created a Schema we give translate a dummy string so that
274 # it will run the produce.
275 lives_ok {$xml =$obj->translate("FOO");} "Translate (Procedure) ran";
276 ok("$xml" ne "" ,"Produced something!");
277 print "XML attrib_values=>1:\n$xml" if DEBUG;
278 # Strip sqlf header with its variable date so we diff safely
279 $xml =~ s/^([^\n]*\n){7}//m;
280 eq_or_diff $xml, $ans ,"XML looks right";
290 <schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
293 <table name="Basic" order="1">
296 <field name="foo" data_type="integer" size="10" is_nullable="1" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="1">
297 <extra ZEROFILL="1" />
298 <comments></comments>
300 <field name="bar" data_type="numeric" size="10,2" is_nullable="1" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="2">
302 <comments></comments>
304 <field name="baz" data_type="decimal" size="8,3" is_nullable="1" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="3">
306 <comments></comments>
310 <constraints></constraints>
311 <comments></comments>
315 <triggers></triggers>
316 <procedures></procedures>
320 $obj = SQL::Translator->new(
326 to => "XML-SQLFairy",
328 my $s = $obj->schema;
329 my $t = $s->add_table( name => "Basic" ) or die $s->error;
330 my $f = $t->add_field(
332 data_type => "integer",
335 $f->extra(ZEROFILL => "1");
339 data_type => "numeric",
344 data_type => "decimal",
349 # As we have created a Schema we give translate a dummy string so that
350 # it will run the produce.
351 lives_ok {$xml =$obj->translate("FOO");} "Translate (Field.extra) ran";
352 ok("$xml" ne "" ,"Produced something!");
353 print "XML:\n$xml" if DEBUG;
354 # Strip sqlf header with its variable date so we diff safely
355 $xml =~ s/^([^\n]*\n){7}//m;
356 eq_or_diff $xml, $ans ,"XML looks right";