Subject: | SQL::Translator comments out part of create table command for PostgreSQL |
Date: | Wed, 15 Aug 2007 05:59:02 +0000 |
To: | bug-SQL-Translator [...] rt.cpan.org |
From: | "Jim Dread" <jimdread [...] hotmail.com> |
Part of create table command is commented with Pg producer
----------------------------------------------------------
Hello SQLFairy developers. Today I started to use your excellent tool,
but unfortunately had a few problems. One problem was that using the
PostgreSQL producer, the SQL that came out had part of the create
table command commented out. I was able to fix this with a dirty hack
oops I mean "patch" which is below after the test data and results.
I don't really know why this went wrong, maybe some flag or switch I
haven't set.
I don't guarantee the patch is useful to you, since I just did the
simplest thing I could see to make it work for me and didn't test all
possibilities. But I can't think of any reason why an extra linefeed
in front of "CREATE TABLE" would hurt anything. Feel free to use it if
you want to.
Thanks for a great tool.
Jim
Follows:
0. Version information
1. XML for test database
2. Command to run to produce output
3. Output of broken producer
4. Output of patched producer
5. Patch for producer
========================================================================
0. Version information
SQL::Translator is up to date (0.08).
This is perl, v5.8.8 built for i486-linux-gnu-thread-multi
Linux asp 2.6.22 #2 Tue Jul 10 14:04:42 EST 2007 i686 GNU/Linux
-----------------------------8<-----------------------------------------
1. SQLFairy XML for a simple database table
-----------------------------8<-----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<schema name="" database=""
xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
<extra />
<tables>
<table name="control" order="1">
<extra />
<fields>
<field name="id" data_type="int" size="11" is_nullable="0"
is_auto_increment="1" is_primary_key="1" is_foreign_key="0" order="1">
<extra />
<comments></comments>
</field>
<field name="name" data_type="varchar" size="255" is_nullable="0"
is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="2">
<extra />
<comments></comments>
</field>
</fields>
<indices>
</indices>
<constraints>
<constraint name="control-id" type="PRIMARY KEY" fields="id"
reference_table="" reference_fields="" on_delete="" on_update=""
match_type="" expression="" options="" deferrable="1">
<extra />
</constraint>
<constraint name="control-name" type="UNIQUE" fields="name"
reference_table="" reference_fields="" on_delete="" on_update=""
match_type="" expression="" options="" deferrable="1">
<extra />
</constraint>
</constraints>
<comments></comments>
</table>
</tables>
<views></views>
<triggers></triggers>
<procedures></procedures>
</schema>
-----------------------------8<-----------------------------------------
2. Command to run to produce output.
sqlt -f XML-SQLFairy -t PostgreSQL bugschema.xml
-----------------------------8<-----------------------------------------
3. Output of broken producer. Note that the first line of the create
table command is commented out. That turns good SQL into syntax
errors.
-----------------------------8<-----------------------------------------
--
-- Table: control
--CREATE TABLE "control" (
"id" serial NOT NULL,
"name" character varying(255) NOT NULL,
Constraint "control-id" PRIMARY KEY ("id"),
Constraint "control-name" UNIQUE ("name")
);
-----------------------------8<-----------------------------------------
4. Output of patched producer. Looks better to me.
-----------------------------8<-----------------------------------------
--
-- Table: control
--
CREATE TABLE "control" (
"id" serial NOT NULL,
"name" character varying(255) NOT NULL,
Constraint "control-id" PRIMARY KEY ("id"),
Constraint "control-name" UNIQUE ("name")
);
-----------------------------8<-----------------------------------------
5. Patch for SQL::Translator::Producer::PostgreSQL.pm
-----------------------------8<-----------------------------------------
--- PostgreSQL.pm 2007-08-15 05:50:56.000000000 +0000
+++ PostgreSQL.pm-orig 2007-08-15 05:50:41.000000000 +0000
@@ -379,7 +379,7 @@
$create_statement = join("\n", @comments);
$create_statement .= qq[DROP TABLE $qt$table_name_ur$qt CASCADE;\n]
if $add_drop_table;
- $create_statement .= qq[\nCREATE TABLE $qt$table_name_ur$qt (\n].
+ $create_statement .= qq[CREATE TABLE $qt$table_name_ur$qt (\n].
join( ",\n", map { " $_" } @field_defs,
@constraint_defs ).
"\n);"
;
-----------------------------8<-----------------------------------------
Show quoted text
_________________________________________________________________
Puzzles, trivia teasers, word scrambles and more. Play for your chance to
win! http://club.live.com/home.aspx?icid=CLUB_hotmailtextlink