You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by Mike Pearce <mi...@studioelectrica.com> on 2003/07/08 11:24:46 UTC

HSQLDB primary key generation

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


Re: HSQLDB primary key generation

Posted by Daniel Rall <dl...@finemaltcoding.com>.
Anyone look into Mike's suggestion yet?

"Mike Pearce" <mi...@studioelectrica.com> writes:

> 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
> 

-- 

Daniel Rall

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