DdlUtils
  1. DdlUtils
  2. DDLUTILS-275

platform.readModelFromDatabase(name) is not working if one of the table names contains underscore.

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Blocker Blocker
    • Resolution: Unresolved
    • Affects Version/s: 1.1
    • Fix Version/s: None
    • Component/s: Core - MySql
    • Labels:
    • Environment:
      Ubuntu 10.02, 64 bit, JDK 1.6.0_20, probably all others as well.

      Description

      org.apache.ddlutils.platform.JdbcModelReader
      lines 859, 900, 1007

      pkData = metaData.getPrimaryKeys(metaData.escapeForSearch(tableName));
      fkData = metaData.getForeignKeys(metaData.escapeForSearch(tableName));
      indexData = metaData.getIndices(metaData.escapeForSearch(tableName), false, false);

      should be replaced to:

      pkData = metaData.getPrimaryKeys(tableName);
      fkData = metaData.getForeignKeys(tableName);
      indexData = metaData.getIndices(tableName, false, false);

      According to MySQL 5 documentation "show create table" accepts table name, not table name pattern.
      http://dev.mysql.com/doc/refman/5.0/en/show-create-table.html

      If any of the table names contain underline this line bombs:
      Database db = platform.readModelFromDatabase( "test" );

        Activity

        Hide
        Charith Haputhanthree added a comment -

        Hi ,
        I have tried the fix with a Oracle Data Base and its not working.
        Have this been highlighted earlier and has a fix now ?
        Kind Regards
        Charith

        Show
        Charith Haputhanthree added a comment - Hi , I have tried the fix with a Oracle Data Base and its not working. Have this been highlighted earlier and has a fix now ? Kind Regards Charith
        Hide
        Sergio Cruz added a comment -

        Run the same test as posted and now runs smooth. Thanks Masker

        Show
        Sergio Cruz added a comment - Run the same test as posted and now runs smooth. Thanks Masker
        Hide
        Masker71 added a comment -

        Here is fixed JdbcModelReader attached

        Show
        Masker71 added a comment - Here is fixed JdbcModelReader attached
        Hide
        Sergio Cruz added a comment -

        Hi Masker.
        Of course I tested before but I think I didn't explain myself correctly.

        Here it goes:

        I have checked out from Subversion both revisions: trunk and tag 1.0

        I have created the bin distros via "ant bin-archive" for both revisions just to get the complete packages with all the nedded dependencies.

        I have created a mysql db called test_db:

        DROP DATABASE IF EXISTS test_db;
        CREATE DATABASE test_db;
        USE test_db;
        CREATE TABLE `test_table` (`col_bit` TINYINT(1));

        I use the same ant script to dump the ddl with this task.

        <target name="database-dump" description="DDL Dump">
        <taskdef name="databaseToDdl" classname="org.apache.ddlutils.task.DatabaseToDdlTask">
        <classpath refid="runtime-classpath"/>
        </taskdef>
        <echo message="jdbc:mysql://$

        {mysql.host.name}:${mysql.host.port}/${mysql.database.name}}"/>
        <databaseToDdl modelName="MyModel">
        <database url="jdbc:mysql://${mysql.host.name}

        :$

        {mysql.host.port}

        /$

        {mysql.database.name}

        "
        driverClassName="com.mysql.jdbc.Driver"
        username="$

        {mysql.user.name}

        "
        password="$

        {mysql.user.password}

        "/>
        <writeSchemaToFile outputFile="$

        {ddlutils.struct.file.name}

        "/>
        <writeDataToFile outputFile="$

        {ddlutils.data.file.name}

        "/>
        </databaseToDdl>
        </target>

        After executing that script on both revisions I get the following output

        Tag V-1.0
        =========
        ~/tmp/apache-ddlutils/v-1.0 $ ant -propertyfile build.properties database-dump
        Buildfile: /home/scmoral/tmp/apache-ddlutils/v-1.0/build.xml

        database-dump:
        [echo] jdbc:mysql://localhost:3306/test_db
        [databaseToDdl] Written schema to /home/scmoral/tmp/apache-ddlutils/v-1.0/struct.xml
        [databaseToDdl] Written data XML to file/home/scmoral/tmp/apache-ddlutils/v-1.0/data.xml

        BUILD SUCCESSFUL
        Total time: 2 seconds

        The ddl file generated was as follows:

        <?xml version="1.0"?>
        <!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database">
        <database name="MyModel">
        <table name="test_table">
        <column name="col_bit" primaryKey="false" required="false" type="BIT" autoIncrement="false"/>
        </table>
        </database>

        TRUNK
        =======
        ~/tmp/apache-ddlutils/v-1.1 $ ant -propertyfile build.properties database-dump
        Buildfile: /home/scmoral/tmp/apache-ddlutils/v-1.1/build.xml

        database-dump:
        [echo] jdbc:mysql://localhost:3306/test_db

        BUILD FAILED
        /home/scmoral/tmp/apache-ddlutils/v-1.1/build.xml:23: Could not read the schema from the specified database: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test_db.test_table' doesn't exist

        Total time: 1 second

        The same version of mysql jdbc driver was used for both tests (mysql-connector-java-5.1.18.jar)

        Hope that helps.

        Show
        Sergio Cruz added a comment - Hi Masker. Of course I tested before but I think I didn't explain myself correctly. Here it goes: I have checked out from Subversion both revisions: trunk and tag 1.0 http://svn.apache.org/repos/asf/db/ddlutils/trunk/ http://svn.apache.org/repos/asf/db/ddlutils/tags/1.0/ I have created the bin distros via "ant bin-archive" for both revisions just to get the complete packages with all the nedded dependencies. I have created a mysql db called test_db: DROP DATABASE IF EXISTS test_db; CREATE DATABASE test_db; USE test_db; CREATE TABLE `test_table` (`col_bit` TINYINT(1)); I use the same ant script to dump the ddl with this task. <target name="database-dump" description="DDL Dump"> <taskdef name="databaseToDdl" classname="org.apache.ddlutils.task.DatabaseToDdlTask"> <classpath refid="runtime-classpath"/> </taskdef> <echo message="jdbc:mysql://$ {mysql.host.name}:${mysql.host.port}/${mysql.database.name}}"/> <databaseToDdl modelName="MyModel"> <database url="jdbc:mysql://${mysql.host.name} :$ {mysql.host.port} /$ {mysql.database.name} " driverClassName="com.mysql.jdbc.Driver" username="$ {mysql.user.name} " password="$ {mysql.user.password} "/> <writeSchemaToFile outputFile="$ {ddlutils.struct.file.name} "/> <writeDataToFile outputFile="$ {ddlutils.data.file.name} "/> </databaseToDdl> </target> After executing that script on both revisions I get the following output Tag V-1.0 ========= ~/tmp/apache-ddlutils/v-1.0 $ ant -propertyfile build.properties database-dump Buildfile: /home/scmoral/tmp/apache-ddlutils/v-1.0/build.xml database-dump: [echo] jdbc:mysql://localhost:3306/test_db [databaseToDdl] Written schema to /home/scmoral/tmp/apache-ddlutils/v-1.0/struct.xml [databaseToDdl] Written data XML to file/home/scmoral/tmp/apache-ddlutils/v-1.0/data.xml BUILD SUCCESSFUL Total time: 2 seconds The ddl file generated was as follows: <?xml version="1.0"?> <!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database"> <database name="MyModel"> <table name="test_table"> <column name="col_bit" primaryKey="false" required="false" type="BIT" autoIncrement="false"/> </table> </database> TRUNK ======= ~/tmp/apache-ddlutils/v-1.1 $ ant -propertyfile build.properties database-dump Buildfile: /home/scmoral/tmp/apache-ddlutils/v-1.1/build.xml database-dump: [echo] jdbc:mysql://localhost:3306/test_db BUILD FAILED /home/scmoral/tmp/apache-ddlutils/v-1.1/build.xml:23: Could not read the schema from the specified database: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test_db.test_table' doesn't exist Total time: 1 second The same version of mysql jdbc driver was used for both tests (mysql-connector-java-5.1.18.jar) Hope that helps.
        Hide
        Masker71 added a comment -

        Hi Sergio,

        Maybe you will test it as well before saying it's working? Because it doesn't.

        Show
        Masker71 added a comment - Hi Sergio, Maybe you will test it as well before saying it's working? Because it doesn't.
        Hide
        Sergio Cruz added a comment -

        Hi.

        As far as I could check, the code in Subversion tag 1.0 allows underscores in table names. At least for MySQL...

        Show
        Sergio Cruz added a comment - Hi. As far as I could check, the code in Subversion tag 1.0 allows underscores in table names. At least for MySQL...
        Hide
        Masker71 added a comment -

        Perhaps that function metaData.escapeForSearch(String) changed...

        Show
        Masker71 added a comment - Perhaps that function metaData.escapeForSearch(String) changed...
        Hide
        Aleksey Izmailov added a comment -

        Is it a regression? I would be surprised if that bug was there for long time. If so, which version does not have this problem?

        Show
        Aleksey Izmailov added a comment - Is it a regression? I would be surprised if that bug was there for long time. If so, which version does not have this problem?

          People

          • Assignee:
            Thomas Dudziak
            Reporter:
            Masker71
          • Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:

              Development