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">
51 <table name="Basic" order="1">
53 <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">
54 <comments>comment on id field</comments>
56 <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">
59 <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">
62 <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">
67 <index name="titleindex" type="NORMAL" fields="title" options="" />
70 <constraint name="" type="PRIMARY KEY" fields="id" reference_table="" reference_fields="" on_delete="" on_update="" match_type="" expression="" options="" deferrable="1" />
71 <constraint name="" type="UNIQUE" fields="email" reference_table="" reference_fields="" on_delete="" on_update="" match_type="" expression="" options="" deferrable="1" />
77 $obj = SQL::Translator->new(
85 lives_ok {$xml = $obj->translate($file);} "Translate (attrib_values=>1) ran";
86 ok("$xml" ne "" ,"Produced something!");
87 print "XML:\n$xml" if DEBUG;
88 # Strip sqlf header with its variable date so we diff safely
89 $xml =~ s/^([^\n]*\n){7}//m;
90 eq_or_diff $xml, $ans, "XML looks right";
97 # Thanks to Ken for the schema setup lifted from 13schema.t
102 <schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
103 <view name="foo_view" fields="name,age" order="1">
104 <sql>select name, age from person</sql>
109 $obj = SQL::Translator->new(
115 to => "XML-SQLFairy",
117 my $s = $obj->schema;
118 my $name = 'foo_view';
119 my $sql = 'select name, age from person';
120 my $fields = 'name, age';
121 my $v = $s->add_view(
128 # As we have created a Schema we give translate a dummy string so that
129 # it will run the produce.
130 lives_ok {$xml =$obj->translate("FOO");} "Translate (View) ran";
131 ok("$xml" ne "" ,"Produced something!");
132 print "XML attrib_values=>1:\n$xml" if DEBUG;
133 # Strip sqlf header with its variable date so we diff safely
134 $xml =~ s/^([^\n]*\n){7}//m;
135 eq_or_diff $xml, $ans ,"XML looks right";
141 # Thanks to Ken for the schema setup lifted from 13schema.t
146 <schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
147 <trigger name="foo_trigger" database_event="insert" on_table="foo" perform_action_when="after" order="1">
148 <action>update modified=timestamp();</action>
153 $obj = SQL::Translator->new(
159 to => "XML-SQLFairy",
161 my $s = $obj->schema;
162 my $name = 'foo_trigger';
163 my $perform_action_when = 'after';
164 my $database_event = 'insert';
165 my $on_table = 'foo';
166 my $action = 'update modified=timestamp();';
167 my $t = $s->add_trigger(
169 perform_action_when => $perform_action_when,
170 database_event => $database_event,
171 on_table => $on_table,
175 # As we have created a Schema we give translate a dummy string so that
176 # it will run the produce.
177 lives_ok {$xml =$obj->translate("FOO");} "Translate (Trigger) ran";
178 ok("$xml" ne "" ,"Produced something!");
179 print "XML attrib_values=>1:\n$xml" if DEBUG;
180 # Strip sqlf header with its variable date so we diff safely
181 $xml =~ s/^([^\n]*\n){7}//m;
182 eq_or_diff $xml, $ans ,"XML looks right";
188 # Thanks to Ken for the schema setup lifted from 13schema.t
193 <schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
194 <procedure name="foo_proc" parameters="foo,bar" owner="Nomar" order="1">
195 <sql>select foo from bar</sql>
196 <comments>Go Sox!</comments>
201 $obj = SQL::Translator->new(
207 to => "XML-SQLFairy",
209 my $s = $obj->schema;
210 my $name = 'foo_proc';
211 my $sql = 'select foo from bar';
212 my $parameters = 'foo, bar';
214 my $comments = 'Go Sox!';
215 my $p = $s->add_procedure(
218 parameters => $parameters,
220 comments => $comments,
223 # As we have created a Schema we give translate a dummy string so that
224 # it will run the produce.
225 lives_ok {$xml =$obj->translate("FOO");} "Translate (Procedure) ran";
226 ok("$xml" ne "" ,"Produced something!");
227 print "XML attrib_values=>1:\n$xml" if DEBUG;
228 # Strip sqlf header with its variable date so we diff safely
229 $xml =~ s/^([^\n]*\n){7}//m;
230 eq_or_diff $xml, $ans ,"XML looks right";