package SQL::Translator::Producer::XML::SQLFairy;
# -------------------------------------------------------------------
-# $Id: SQLFairy.pm,v 1.18 2004-08-19 20:41:32 grommit Exp $
+# $Id: SQLFairy.pm,v 1.19 2004-11-05 16:37:00 grommit Exp $
# -------------------------------------------------------------------
# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
# darren chamberlain <darren@cpan.org>,
Child objects, such as a tables fields, get mapped to child tags wrapped in a
set of container tags using the plural of their contained classes name.
-L<SQL::Translator::Schema::Field>'s extra attribute (a hash of arbitary data) is
+An objects's extra attribute (a hash of arbitary data) is
mapped to a tag called extra, with the hash of data as attributes, sorted into
alphabetical order.
use strict;
use vars qw[ $VERSION @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.18 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.19 $ =~ /(\d+)\.(\d+)/;
use Exporter;
use base qw(Exporter);
$xml->xmlDecl('UTF-8');
$xml->comment(header_comment('', ''));
xml_obj($xml, $schema,
- tag => "schema", methods => [qw/name database/], end_tag => 0 );
+ tag => "schema", methods => [qw/name database extra/], end_tag => 0 );
#
# Table
debug "Table:",$table->name;
xml_obj($xml, $table,
tag => "table",
- methods => [qw/name order/],
+ methods => [qw/name order extra/],
end_tag => 0
);
xml_obj_children( $xml, $table,
tag => 'index',
collection_tag => "indices",
- methods => [qw/name type fields options/],
+ methods => [qw/name type fields options extra/],
);
#
methods => [qw/
name type fields reference_table reference_fields
on_delete on_update match_type expression options deferrable
+ extra
/],
);
#
xml_obj_children( $xml, $schema,
tag => 'view',
- methods => [qw/name sql fields order/],
+ methods => [qw/name sql fields order extra/],
);
#
xml_obj_children( $xml, $schema,
tag => 'trigger',
methods => [qw/name database_event action on_table perform_action_when
- fields order/],
+ fields order extra/],
);
#
#
xml_obj_children( $xml, $schema,
tag => 'procedure',
- methods => [qw/name sql parameters owner comments order/],
+ methods => [qw/name sql parameters owner comments order extra/],
);
$xml->endTag([ $Namespace => 'schema' ]);
$ans = <<EOXML;
<schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
+ <extra />
<tables>
<table name="Basic" order="1">
+ <extra />
<fields>
<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">
<extra />
</field>
</fields>
<indices>
- <index name="titleindex" type="NORMAL" fields="title" options="" />
+ <index name="titleindex" type="NORMAL" fields="title" options="">
+ <extra />
+ </index>
</indices>
<constraints>
- <constraint name="" type="PRIMARY KEY" fields="id" reference_table="" reference_fields="" on_delete="" on_update="" match_type="" expression="" options="" deferrable="1" />
- <constraint name="" type="UNIQUE" fields="email" reference_table="" reference_fields="" on_delete="" on_update="" match_type="" expression="" options="" deferrable="1" />
+ <constraint name="" type="PRIMARY KEY" fields="id" reference_table="" reference_fields="" on_delete="" on_update="" match_type="" expression="" options="" deferrable="1">
+ <extra />
+ </constraint>
+ <constraint name="" type="UNIQUE" fields="email" reference_table="" reference_fields="" on_delete="" on_update="" match_type="" expression="" options="" deferrable="1">
+ <extra />
+ </constraint>
</constraints>
</table>
</tables>
$ans = <<EOXML;
<schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
+ <extra />
<tables></tables>
<views>
<view name="foo_view" fields="name,age" order="1">
<sql>select name, age from person</sql>
+ <extra hello="world" />
</view>
</views>
<triggers></triggers>
name => $name,
sql => $sql,
fields => $fields,
+ extra => { hello => "world" },
schema => $s,
) or die $s->error;
$ans = <<EOXML;
<schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
+ <extra />
<tables></tables>
<views></views>
<triggers>
<trigger name="foo_trigger" database_event="insert" on_table="foo" perform_action_when="after" order="1">
<action>update modified=timestamp();</action>
+ <extra hello="world" />
</trigger>
</triggers>
<procedures></procedures>
database_event => $database_event,
on_table => $on_table,
action => $action,
+ extra => { hello => "world" },
) or die $s->error;
# As we have created a Schema we give translate a dummy string so that
$ans = <<EOXML;
<schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
+ <extra />
<tables></tables>
<views></views>
<triggers></triggers>
<procedure name="foo_proc" parameters="foo,bar" owner="Nomar" order="1">
<sql>select foo from bar</sql>
<comments>Go Sox!</comments>
+ <extra hello="world" />
</procedure>
</procedures>
</schema>
parameters => $parameters,
owner => $owner,
comments => $comments,
+ extra => { hello => "world" },
) or die $s->error;
# As we have created a Schema we give translate a dummy string so that
$ans = <<EOXML;
<schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
+ <extra />
<tables>
<table name="Basic" order="2">
+ <extra />
<fields>
<field name="foo" data_type="integer" size="10" is_nullable="1" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="5">
<extra ZEROFILL="1" />