db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Piet Blok" <pbh...@wanadoo.nl>
Subject ClientDriver ResultSetMetaData.isAutoIncrement(column) always returns false
Date Wed, 24 May 2006 08:05:27 GMT
Hi,

When porting from EmbeddedDriver to ClientDriver I encountered the following 
problem:

The ClientDriver seems to always return false from 
ResultSetMetaData.isAutoIncrement(int column).

If you agree that this is a bug I will file a JIRA issue.

Derby version 10.1.2.1 (See full sysinfo at the bottom).

The following code demonstrates the problem:

=====================================================================
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.derby.jdbc.ClientDriver;
import org.apache.derby.jdbc.EmbeddedDriver;

public class TestAutoIncrement {
    private static final String URL_EMBEDDED = 
"jdbc:derby:EmbeddedTestBase;";

    private static final String URL_CLIENT = 
"jdbc:derby://localhost:1527/ClientTestBase;";

    public TestAutoIncrement() {
        super();
    }

    public static void main(String[] args) throws SQLException {
        System.out.println(new ClientDriver().getClass().getName()
                + " registered");
        System.out.println(new EmbeddedDriver().getClass().getName()
                + " registered");
        new TestAutoIncrement().test();
    }

    private void test() throws SQLException {
        if (test(URL_EMBEDDED) != test(URL_CLIENT)) {
            System.out.println("Embedded and client driver behave 
differently for isAutoIncrement().");
        } else {
            System.out.println("Embedded and client driver behave the same 
for isAutoIncrement().");
        }
    }

    private boolean test(String url) throws SQLException {
        boolean ai = false;
        Connection connection = DriverManager.getConnection(url
                + "create=true;");
        Statement statement = connection.createStatement();
        statement
                .execute("CREATE TABLE TEST_TABEL ("
                        + "ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY 
(START WITH 1, INCREMENT BY 1),"
                        + "VALUE INTEGER NOT NULL, PRIMARY KEY (ID))");
        statement.execute("INSERT INTO TEST_TABEL (VALUE) VALUES(1)");
        ResultSet resultSet = statement
                .executeQuery("SELECT * FROM TEST_TABEL");
        ResultSetMetaData meta = resultSet.getMetaData();
        ai = meta.isAutoIncrement(1);
        System.out.println("For " + url + " " + meta.getColumnName(1)
                + " isAutoIncrement: " + ai);
        connection.close();
        try {
            DriverManager.getConnection(url + "shutdown=true;");
        } catch (SQLException e) {
            System.out.println(e.getMessage());
        }
        return ai;
    }

}

=====================================================================
Output from the abvove program:

org.apache.derby.jdbc.ClientDriver registered
org.apache.derby.jdbc.EmbeddedDriver registered
For jdbc:derby:EmbeddedTestBase; ID isAutoIncrement: true
Database 'EmbeddedTestBase' shutdown.
For jdbc:derby://localhost:1527/ClientTestBase; ID isAutoIncrement: false
DERBY SQL error: SQLCODE: -1, SQLSTATE: 08006, SQLERRMC: Database 
'ClientTestBase' shutdown.
Embedded and client driver behave differently for isAutoIncrement().

=====================================================================
------------------ Java Information ------------------
Java Version:    1.5.0_06
Java Vendor:     Sun Microsystems Inc.
Java home:       C:\Program Files\Java\jre1.5.0_06
Java classpath: 
.;C:\PROGRA~1\JMF21~1.1E\lib\sound.jar;C:\PROGRA~1\JMF21~1.1E\lib\jmf.jar;C:\PROGRA~1\JMF21~1.1E\lib;C:\WINDOWS\java\classes;C:\WorkSpace\PB

3.0\bin;C:\WorkSpace\Filipe\bin;C:\Documents and Settings\Piet\My 
Documents\Resources\Jars\ImgrRdr130.jar;C:\Documents and Settings\Piet\My 
Documents\Resources\Jars\lucene-1.4.1.jar;C:\Documents and Settings\Piet\My 
Documents\Resources\Jars\Multivalent20040415.jar;C:\Workspace\Stick\bin;
OS name:         Windows XP
OS architecture: x86
OS version:      5.1
Java user name:  Piet
Java user home:  C:\Documents and Settings\Piet
Java user dir:   C:\StickFolder
java.specification.name: Java Platform API Specification
java.specification.version: 1.5
--------- Derby Information --------
JRE - JDBC: J2SE 5.0 - JDBC 3.0
[/org/apache/derby/info/DBMS.properties] 10.1.2.1 - (330608)
[/org/apache/derby/info/tools.properties] 10.1.2.1 - (330608)
[/org/apache/derby/info/net.properties] 10.1.2.1 - (330608)
[/org/apache/derby/info/dnc.properties] 10.1.2.1 - (330608)
------------------------------------------------------
----------------- Locale Information -----------------
Current Locale :  [Nederlands/Nederland [nl_NL]]
Found support for locale: [de_DE]
  version: 10.1.2.1 - (330608)
Found support for locale: [es]
  version: 10.1.2.1 - (330608)
Found support for locale: [fr]
  version: 10.1.2.1 - (330608)
Found support for locale: [it]
  version: 10.1.2.1 - (330608)
Found support for locale: [ja_JP]
  version: 10.1.2.1 - (330608)
Found support for locale: [ko_KR]
  version: 10.1.2.1 - (330608)
Found support for locale: [pt_BR]
  version: 10.1.2.1 - (330608)
Found support for locale: [zh_CN]
  version: 10.1.2.1 - (330608)
Found support for locale: [zh_TW]
  version: 10.1.2.1 - (330608)
------------------------------------------------------

Kind regards,

Piet Blok



Mime
View raw message