Hello,

I'm trying to add support for SQLiteJDBC to SQuirreL SQL Client and I
came across some odd behavior.  If I declare a table with a single
integer column, select from it (no records - just an emtpy ResultSet)
and look at the ResultSet's MetaData, the column type is returned as
zero (java.sql.Types.NULL).  However when I insert a record into it,
and do another select, the column type is reported to be integer
(java.sql.Types.INTEGER).  Shouldn't the column type be consistent
regardless of whether or not the table has data?  My test below yields
the following output:

getColumnType: 0
getColumnName: integer
getColumnType: 4
getColumnName: integer


TestSQLite.java:


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;

public class TestSQLite
{

        public static void main(String[] args) throws Exception
        {
                Class.forName("org.sqlite.JDBC");
                Connection conn = DriverManager.getConnection("jdbc:sqlite:/tmp/
test.dbf");
                Statement stat = conn.createStatement();
                stat.executeUpdate("drop table if exists test");
                stat.executeUpdate("create table test (myid integer)");
                stat.close();

                printColumnTypeAndName(conn);

                PreparedStatement prep = conn.prepareStatement("insert into test
values (?)");
                prep.setInt(1, 1);
                prep.executeUpdate();

                printColumnTypeAndName(conn);

                conn.close();
        }

        private static void printColumnTypeAndName(Connection conn) throws
Exception
        {
                Statement stat = conn.createStatement();
                ResultSet rs = stat.executeQuery("select * from test");
                ResultSetMetaData md = rs.getMetaData();
                System.out.println("getColumnType: " + md.getColumnType(1));
                System.out.println("getColumnName: " + md.getColumnTypeName(1));
                rs.close();
        }
}
--~--~---------~--~----~------------~-------~--~----~
Mailing List: http://groups.google.com/group/sqlitejdbc?hl=en
To unsubscribe, send email to [EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---

Reply via email to