package SQL::Translator::Producer::XML::SQLFairy;
# -------------------------------------------------------------------
-# $Id: SQLFairy.pm,v 1.13 2004-07-08 19:34:29 grommit Exp $
+# $Id: SQLFairy.pm,v 1.14 2004-07-08 20:37:26 grommit Exp $
# -------------------------------------------------------------------
# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
# darren chamberlain <darren@cpan.org>,
=head1 ARGS
-Doesn't take any extra arguments.
+=over 4
+
+=item add_prefix
+
+Set to true to use the default namespace prefix of 'sqlf', instead of using
+the default namespace for
+C<http://sqlfairy.sourceforge.net/sqlfairy.xml namespace>
+
+e.g.
+
+ <!-- add_prefix=0 -->
+ <field name="foo" />
+
+ <!-- add_prefix=1 -->
+ <sqlf:field name="foo" />
+
+=item prefix
+
+Set to the namespace prefix you want to use for the
+C<http://sqlfairy.sourceforge.net/sqlfairy.xml namespace>
+
+e.g.
+
+ <!-- prefix='foo' -->
+ <foo:field name="foo" />
+
+=back
=head1 LEGACY FORMAT
use strict;
use vars qw[ $VERSION @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.13 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/;
use Exporter;
use base qw(Exporter);
my $translator = shift;
my $schema = $translator->schema;
$PArgs = $translator->producer_args;
+ my $newlines = defined $PArgs->{newlines} ? $PArgs->{newlines} : 1;
+ my $indent = defined $PArgs->{indent} ? $PArgs->{indent} : 2;
my $io = IO::Scalar->new;
+
+ my $prefix = "";
+ $prefix = $Name if $PArgs->{add_prefix};
+ $prefix = $PArgs->{prefix} if $PArgs->{prefix};
my $xml = XML::Writer->new(
OUTPUT => $io,
NAMESPACES => 1,
- PREFIX_MAP => { $Namespace => $Name },
- DATA_MODE => 1,
- DATA_INDENT => 2,
+ PREFIX_MAP => { $Namespace => $prefix },
+ DATA_MODE => $newlines,
+ DATA_INDENT => $indent,
);
$xml->xmlDecl('UTF-8');
my ($obj,$ans,$xml);
$ans = <<EOXML;
-<sqlf:schema name="" database="" xmlns:sqlf="http://sqlfairy.sourceforge.net/sqlfairy.xml">
- <sqlf:table name="Basic" order="1">
- <sqlf:fields>
- <sqlf: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">
- <sqlf:comments>comment on id field</sqlf:comments>
- </sqlf:field>
- <sqlf: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">
- <sqlf:comments></sqlf:comments>
- </sqlf:field>
- <sqlf: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">
- <sqlf:comments></sqlf:comments>
- </sqlf:field>
- <sqlf: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">
- <sqlf:comments></sqlf:comments>
- </sqlf:field>
- </sqlf:fields>
- <sqlf:indices>
- <sqlf:index name="titleindex" type="NORMAL" fields="title" options="" />
- </sqlf:indices>
- <sqlf:constraints>
- <sqlf:constraint name="" type="PRIMARY KEY" fields="id" reference_table="" reference_fields="" on_delete="" on_update="" match_type="" expression="" options="" deferrable="1" />
- <sqlf:constraint name="" type="UNIQUE" fields="email" reference_table="" reference_fields="" on_delete="" on_update="" match_type="" expression="" options="" deferrable="1" />
- </sqlf:constraints>
- </sqlf:table>
-</sqlf:schema>
+<schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
+ <table name="Basic" order="1">
+ <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">
+ <comments>comment on id field</comments>
+ </field>
+ <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">
+ <comments></comments>
+ </field>
+ <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">
+ <comments></comments>
+ </field>
+ <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">
+ <comments></comments>
+ </field>
+ </fields>
+ <indices>
+ <index name="titleindex" type="NORMAL" fields="title" options="" />
+ </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" />
+ </constraints>
+ </table>
+</schema>
EOXML
$obj = SQL::Translator->new(
my ($obj,$ans,$xml);
$ans = <<EOXML;
-<sqlf:schema name="" database="" xmlns:sqlf="http://sqlfairy.sourceforge.net/sqlfairy.xml">
- <sqlf:view name="foo_view" fields="name,age" order="1">
- <sqlf:sql>select name, age from person</sqlf:sql>
- </sqlf:view>
-</sqlf:schema>
+<schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
+ <view name="foo_view" fields="name,age" order="1">
+ <sql>select name, age from person</sql>
+ </view>
+</schema>
EOXML
$obj = SQL::Translator->new(
my ($obj,$ans,$xml);
$ans = <<EOXML;
-<sqlf:schema name="" database="" xmlns:sqlf="http://sqlfairy.sourceforge.net/sqlfairy.xml">
- <sqlf:trigger name="foo_trigger" database_event="insert" on_table="foo" perform_action_when="after" order="1">
- <sqlf:action>update modified=timestamp();</sqlf:action>
- </sqlf:trigger>
-</sqlf:schema>
+<schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
+ <trigger name="foo_trigger" database_event="insert" on_table="foo" perform_action_when="after" order="1">
+ <action>update modified=timestamp();</action>
+ </trigger>
+</schema>
EOXML
$obj = SQL::Translator->new(
my ($obj,$ans,$xml);
$ans = <<EOXML;
-<sqlf:schema name="" database="" xmlns:sqlf="http://sqlfairy.sourceforge.net/sqlfairy.xml">
- <sqlf:procedure name="foo_proc" parameters="foo,bar" owner="Nomar" order="1">
- <sqlf:sql>select foo from bar</sqlf:sql>
- <sqlf:comments>Go Sox!</sqlf:comments>
- </sqlf:procedure>
-</sqlf:schema>
+<schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
+ <procedure name="foo_proc" parameters="foo,bar" owner="Nomar" order="1">
+ <sql>select foo from bar</sql>
+ <comments>Go Sox!</comments>
+ </procedure>
+</schema>
EOXML
$obj = SQL::Translator->new(