mbeckler <[EMAIL PROTECTED]> wrote:
>         DatabaseMetaData meta = conn.getMetaData();
>         rs = meta.getColumns("test.db", null, "people", null);
>
>         while (rs.next()) {
>             String columnName = rs.getString(4);
>             int sqlType = rs.getInt(5);
>             System.out.println("type of col " + columnName + " = " +
>  sqlType);
>         }

A simple solution is to switch to using getString("TYPE_NAME"), which
returns whatever name you gave the type when you called CREATE TABLE.
Supporting getInt("DATA_TYPE") is a little more complicated, as SQLite
doesn't actually assign data types to columns. One option would be
parsing the TYPE_NAME (see below), but I'm not too happy about this. I
would prefer to measure the affine type of the column, but this can
only be done by opening up a select statement on the table. Hmm.

Perhaps I will offer a patch to SQLite to add the affine type to
pragma table_info, that would make it easy.

For more details on SQLite datatypes: http://sqlite.org/datatype3.html

d.

diff -rN -u old-sqlitejdbc/src/org/sqlite/MetaData.java
new-sqlitejdbc/src/org/sqlite/MetaData.java
--- old-sqlitejdbc/src/org/sqlite/MetaData.java 2008-04-05
11:02:24.000000000 +1100
+++ new-sqlitejdbc/src/org/sqlite/MetaData.java 2008-04-05
11:02:24.000000000 +1100
@@ -340,7 +340,7 @@
             + "null as TABLE_SCHEM, "
             + "'" + escape(tbl) + "' as TABLE_NAME, "
             + "cn as COLUMN_NAME, "
-            + "-1 as DATA_TYPE, "
+            + "ct as DATA_TYPE, "
             + "tn as TYPE_NAME, "
             + "2000000000 as COLUMN_SIZE, "
             + "2000000000 as BUFFER_LENGTH, "
@@ -372,14 +372,25 @@
             String colNotNull = rs.getString(4);

             int colNullable = 2;
-            if (colType == null) colType = "TEXT";
             if (colNotNull != null) colNullable = colNotNull.equals("0") ? 1:0;
             if (colFound) sql += " union all ";
             colFound = true;

+            colType = colType == null ? "TEXT" : colType.toUpperCase();
+            int colJavaType = -1;
+            if (colType == "INT" || colType == "INTEGER")
+                colJavaType = Types.INTEGER;
+            else if (colType == "TEXT")
+                colJavaType = Types.VARCHAR;
+            else if (colType == "FLOAT")
+                colJavaType = Types.FLOAT;
+            else
+                colJavaType = Types.VARCHAR;
+
             sql += "select "
                 + i + " as ordpos, "
                 + colNullable + " as colnullable, '"
+                + colJavaType + "' as ct, '"
                 + escape(colName) + "' as cn, '"
                 + escape(colType) + "' as tn";

--~--~---------~--~----~------------~-------~--~----~
Mailing List: http://groups.google.com/group/sqlitejdbc?hl=en
To unsubscribe, send email to [EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---

Reply via email to