db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Pearce" <m...@studioelectrica.com>
Subject HSQLDB primary key generation
Date Tue, 08 Jul 2003 09:24:46 GMT
Hello.

I am using Torque with OJB and came across a bug when generating a SQL
script for HSQL.  If the schema xml file has a column tag with both
primaryKey and autoIncrement attributes, it generates incorrect HSQL create
table syntax.  The latest version (and probably other versions) of HSQL does
not appear to allow having a column specified as "IDENTITY" and setting that
same column as "PRIMARY KEY".  According to the HSQL documentation, identity
columns are "automatically primary key columns."

NOT CORRECT:
CREATE TABLE Product
(
    id integer IDENTITY,
    name VARCHAR (30),
    price DOUBLE,
    stock integer,
    PRIMARY KEY(id)
);


CORRECT:
CREATE TABLE Product
(
    id integer IDENTITY,
    name VARCHAR (30),
    price DOUBLE,
    stock integer
);


I modified the primarykey.vm to work when both of these attributes are
specified:

/sql/base/hypersonic/primarykey.vm
----------------------------------------------------------------------------
-------
#if ($table.hasPrimaryKey())
#set ( $hasAutoIncrement = "false" )
#foreach ($col in $table.Columns)
#if ( $col.isAutoIncrement() )
#set ( $hasAutoIncrement = "true" )
#end
#end
#if ( $hasAutoIncrement == "false" )
PRIMARY KEY($table.printPrimaryKey()),
#end
#end

-mike


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message