DdlUtils
  1. DdlUtils
  2. DDLUTILS-178

ModelException thrown when reading columns with "special" names

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.0 RC2
    • Fix Version/s: 1.1
    • Component/s: Core - PostgreSql
    • Labels:
      None
    • Environment:
      PostgreSQL 8.2 on Ubuntu 7.04. Java 6.

      Description

      Trying to execute the method "readModelFromDatabase" a ModelException is thrown. The database has only one table with a field named "year". If this field is renamed by another name it works ok. The field "year" appears in the pgAdmin tool with quotes. This must be the reason why DDLutils throws the ModelException.

      This is the exception thrown:

      org.apache.ddlutils.model.ModelException: The index ad_sequence_no_key in table ad_sequence_no references the undefined column "year"
      at org.apache.ddlutils.model.Database.initialize(Database.java:393)
      at org.apache.ddlutils.platform.JdbcModelReader.getDatabase(JdbcModelReader.java:484)
      at org.apache.ddlutils.platform.JdbcModelReader.getDatabase(JdbcModelReader.java:432)
      at org.apache.ddlutils.platform.PlatformImplBase.readModelFromDatabase(PlatformImplBase.java:1884)
      at org.apache.ddlutils.platform.PlatformImplBase.readModelFromDatabase(PlatformImplBase.java:1869)
      at org.openbravo.ddl.Test.main(Test.java:52)

      The database was previously populated with the following XML::

      <?xml version="1.0"?>
      <!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database">
      <database name="openbravo-tests">
      <table name="ad_sequence_no">
      <column name="ad_sequence_id" primaryKey="false" required="true" type="NUMERIC" size="10" autoIncrement="false"/>
      <column name="year" primaryKey="false" required="true" type="VARCHAR" size="4" default="0000" autoIncrement="false"/>
      <column name="ad_client_id" primaryKey="false" required="true" type="NUMERIC" size="10" autoIncrement="false"/>
      <unique name="ad_sequence_no_key">
      <unique-column name="ad_sequence_id"/>
      <unique-column name="year"/>
      </unique>
      </table>
      </database>

      And in the pgAdmin tool, the table definition is:

      – Table: ad_sequence_no

      – DROP TABLE ad_sequence_no;

      CREATE TABLE ad_sequence_no
      (
      ad_sequence_id numeric(10) NOT NULL,
      "year" varchar(4) NOT NULL DEFAULT '0000'::character varying,
      ad_client_id numeric(10) NOT NULL
      )
      WITHOUT OIDS;
      ALTER TABLE ad_sequence_no OWNER TO tad;

      – Index: ad_sequence_no_key

      – DROP INDEX ad_sequence_no_key;

      CREATE UNIQUE INDEX ad_sequence_no_key
      ON ad_sequence_no
      USING btree
      (ad_sequence_id, "year");

        Activity

        Hide
        sunil added a comment -

        Dear Thomas Dudziak

        Can u send me the ddutils-1.1.jar
        please its urgent for me
        b'coz i have same problem while configuring symmetricDS2.0.x version
        in postgresql 8.0 and 8.2 primary key shows index as ("first column",second)
        means column name in ("")
        and throws the same exception

        waiting for ur reply

        Show
        sunil added a comment - Dear Thomas Dudziak Can u send me the ddutils-1.1.jar please its urgent for me b'coz i have same problem while configuring symmetricDS2.0.x version in postgresql 8.0 and 8.2 primary key shows index as ("first column",second) means column name in ("") and throws the same exception waiting for ur reply
        Thomas Dudziak made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Cannot Reproduce [ 5 ]
        Hide
        Thomas Dudziak added a comment -

        This seems to be a bug in the JDBC driver. It works fine for me without the patch using DdlUtils 1.1 (though the model reading logic hasn't changed in 1.1) and PostgreSQL 8.2 using the JDBC driver 8.2-506.jdbc3, both with and without delimited identifier mode.

        Show
        Thomas Dudziak added a comment - This seems to be a bug in the JDBC driver. It works fine for me without the patch using DdlUtils 1.1 (though the model reading logic hasn't changed in 1.1) and PostgreSQL 8.2 using the JDBC driver 8.2-506.jdbc3, both with and without delimited identifier mode.
        Thomas Dudziak made changes -
        Fix Version/s 1.1 [ 12311984 ]
        Adrián Romero made changes -
        Field Original Value New Value
        Attachment remove-quotes.patch [ 12361000 ]
        Hide
        Adrián Romero added a comment -

        This is a quick and dirty patch that fixes the problem for PostgreSQL

        Show
        Adrián Romero added a comment - This is a quick and dirty patch that fixes the problem for PostgreSQL
        Hide
        Adrián Romero added a comment -

        Yes. This is the sample source code:

        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName("org.postgresql.Driver");
        ds.setUrl("jdbc:postgresql://localhost:5432/openbravo230");
        ds.setUsername("tad");
        ds.setPassword("tad");

        try

        { Platform platform = PlatformFactory.createNewPlatformInstance(ds); platform.setDelimitedIdentifierModeOn(true); Database db = platform.readModelFromDatabase("openbravo230"); Writer sw = new OutputStreamWriter(new FileOutputStream(new File("/home/adrian/openbravo230.xml"))); new DatabaseIO().write(db, sw); sw.close(); }

        catch (Exception e)

        { e.printStackTrace(); }
        Show
        Adrián Romero added a comment - Yes. This is the sample source code: BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("org.postgresql.Driver"); ds.setUrl("jdbc:postgresql://localhost:5432/openbravo230"); ds.setUsername("tad"); ds.setPassword("tad"); try { Platform platform = PlatformFactory.createNewPlatformInstance(ds); platform.setDelimitedIdentifierModeOn(true); Database db = platform.readModelFromDatabase("openbravo230"); Writer sw = new OutputStreamWriter(new FileOutputStream(new File("/home/adrian/openbravo230.xml"))); new DatabaseIO().write(db, sw); sw.close(); } catch (Exception e) { e.printStackTrace(); }
        Hide
        Thomas Dudziak added a comment -

        Did you run this with delimited identifier mode turned on ?

        Show
        Thomas Dudziak added a comment - Did you run this with delimited identifier mode turned on ?
        Adrián Romero created issue -

          People

          • Assignee:
            Thomas Dudziak
            Reporter:
            Adrián Romero
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development