db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Malte Stien <ma...@stien.de>
Subject Errors in generated SQL-script: Statements mixed up
Date Mon, 05 May 2003 05:37:25 GMT
Hi,

I am pretty sure there is something wrong in the way that Torque generates the 
sql-script xxx-schema.sql. It appearantly generates SQL code that is not 
valid by mixing up the sequence of some statements. The result is, that some 
constraints are not setup properly in the database. There is something really 
weird going on. It looks like a bug to me.

Maybe someone likes to have a look at that.
Thanks,
Malte.

The following appears on the screen if I insert the sql statements to the 
database.
=======================================================================
[malte@melbourne:Dori.C014]$ ant -f build-torque.xml insert-sql
Buildfile: build-torque.xml

insert-sql:

[torque-sql-exec] Executing file: /src/sql/dori-schema.sql
...
[torque-sql-exec] Failed to execute: ALTER TABLE Project ALTER TABLE Task ADD 
CONSTRAINT Task_FK_1 FOREIGN KEY (ProjectElementID) REFERENCES ProjectElement 
(ProjectElementID)
[torque-sql-exec] java.sql.SQLException: ERROR:  parser: parse error at or 
near "TABLE"
[torque-sql-exec] Failed to execute: ADD CONSTRAINT Project_FK_3 FOREIGN KEY 
(ProjectTypeID) REFERENCES ProjectType (ProjectSpecifierID)
[torque-sql-exec] java.sql.SQLException: ERROR:  parser: parse error at or 
near "ADD"

=======================================================================

The errors are fully understandable if you look at the following segment of 
/src/sql/dori-schema.sql that has been generated by Torque.
=======================================================================
----------------------------------------------------------------------
-- PRC_PET_Association
----------------------------------------------------------------------

ALTER TABLE Project
    ADD CONSTRAINT Project_FK_1 FOREIGN KEY (ProjectElementID)
    REFERENCES ProjectElement (ProjectElementID)
;
ALTER TABLE Project
    ADD CONSTRAINT Project_FK_2 FOREIGN KEY (ProjectSpecifierID)
    REFERENCES ProjectSpecifier (ProjectSpecifierID)
;
ALTER TABLE Project
----------------------------------------------------------------------

ALTER TABLE Task
    ADD CONSTRAINT Task_FK_1 FOREIGN KEY (ProjectElementID)
    REFERENCES ProjectElement (ProjectElementID)
;
ALTER TABLE Task
    ADD CONSTRAINT Task_FK_2 FOREIGN KEY (ParentTaskID)
    REFERENCES Task (ProjectElementID)
;

----------------------------------------------------------------------
-- Task
    ADD CONSTRAINT Project_FK_3 FOREIGN KEY (ProjectTypeID)
    REFERENCES ProjectType (ProjectSpecifierID)
;
=======================================================================

For someone who is interested in the XML-schema, that I have used, here it is 
(partially). Hopefully, I selected the crucial part since I do not know where 
the error originates from.
=======================================================================
<database
  name="dori"
  defaultIdMethod="idbroker"
  defaultJavaNamingMethod="nochange">

<!-- *** Project *** -->
  <table name="Project" description="">
    <column
      name="ProjectSpecifierID"
      required="true"
      type="INTEGER"
      description=""/>
    ...
    <column
      name="ProjectTypeID"
      required="true"
      type="INTEGER"
      description=""/>
    <!-- ModelRelationShip R9 -->
    <foreign-key foreignTable="ProjectElement">
      <reference
        local="ProjectElementID"
        foreign="ProjectElementID"/>
    </foreign-key>
    <foreign-key foreignTable="ProjectSpecifier">
    <!-- ModelRelationShip R28 -->
      <reference
        local="ProjectSpecifierID"
        foreign="ProjectSpecifierID"/>
    </foreign-key>
    <foreign-key foreignTable="ProjectType">
    <!-- ModelRelationShip R12 -->
      <reference
        local="ProjectTypeID"
        foreign="ProjectSpecifierID"/>
    </foreign-key>
    <unique name="Project_ProjectSpecifier_Uniqueness">
        <unique-column name="ProjectSpecifierID"/>
    </unique>
  </table>

<!-- *** Task *** -->
  <table name="Task" description="">
    <column
      name="ProjectElementID"
      required="true"
      primaryKey="true"
      type="INTEGER"
      description=""/>
    <column
      name="TaskName"
      required="true"
      primaryKey="false"
      type="VARCHAR"
      size="1024"
      description="Name of the Task"/>
    <column
      name="ParentTaskID"
      required="false"
      primaryKey="false"
      type="INTEGER"
      description=""/>
    ...
    <foreign-key foreignTable="ProjectElement">
    <!-- ModelRelationShip R9 -->
      <reference
        local="ProjectElementID"
        foreign="ProjectElementID"/>
    </foreign-key>
    <foreign-key foreignTable="Task">
    <!-- ModelRelationShip R21 -->
      <reference
        local="ParentTaskID"
        foreign="ProjectElementID"/>
    </foreign-key>
  </table>
<!-- ********************** ProjectElement ********************** -->
  <table name="ProjectElement" description="">
    <column
      name="ProjectElementID"
      required="true"
      primaryKey="true"
      type="INTEGER"
      description="ID of the ProjectElement"/>
    <column
      name="ProjectElementTypeID"
      required="true"
      type="INTEGER"
      description="Foreign Key Project ID"/>
    <column
      name="ProjectID"
      required="false"
      type="INTEGER"
      description="Foreign Key Project ID"/>
      <!-- required must be true, is just false because otherwise circular 
dependency project/element project -->
    <foreign-key foreignTable="Project">
    <!-- ModelRelationShip R11 -->
      <reference
        local="ProjectID"
        foreign="ProjectSpecifierID"/>
    </foreign-key>
    <foreign-key foreignTable="ProjectElementType">
    <!-- ModelRelationShip R6 -->
      <reference
        local="ProjectElementTypeID"
        foreign="ProjectElementTypeID"/>
    </foreign-key>
  </table>
</database>


Mime
View raw message