Package: libghc6-hsql-sqlite3-dev Version: 1.7-1 Severity: important The sqllite driver ignores field type information, reporting all fields as SqlText fields. This was workable in HSQL 1.6, but conflicts with changes in HSQL 1.7, resulting in SQL type cast exceptions when trying to read fields as Int's or Int64's.
The bug occurs when calling getFieldValue on an INTEGER field and expecting getFieldValue to yield an Int. For example, > import Database.HSQL.SQLite3 > import System.IO (IOMode(ReadWriteMode)) > > main = test `catchSql` (error . show) > > test = do > c <- connect "test.db" ReadWriteMode > execute c "create table Foo (x INTEGER)" > execute c "insert into Foo values (42)" > s <- query c "select x from Foo" > forEachRow' (\s -> do > v <- getFieldValue s "x" > print (v :: Int)) s In HSQL 1.6, getFieldValue would call getFieldValueMB, which would parse an Int field by first invoking fromNonNullSqlCStringLen in the SqlBind instance for Int. Because the sqlite driver always reported SqlText for sqlType, this would return Nothing, so getFieldValueMB would convert the field to a Haskell String and fall back to fromSqlValue in SqlBind. For SqlText-typed fields, this would simply use the read function. Thus, ultimately, you would get the integral value of the field. In HSQL 1.7, the implementation of getFieldValue no longer falls back to fromSqlValue if fromSqlCStringLen fails. (Indeed, fromSqlCStringLen now fails with an exception instead of by returning Nothing.) Thus, when fromSqlCStringLen in the SqlBind Int instance is passed the SqlText-typed field, it fails with a SQL type cast exception. There are a few potential ways to fix this bug. Probably the ideal way is to fix the sqlite driver to return the correct field types (which are already available in the results of the pragma call). Alternatively, the old behavior of getFieldValue could be restored, but this would probably be difficult in light of the changes to fromSqlCStringLen and isn't ideal anyways. Better would be to make fromSqlCStringLen and fromSqlValue behave equivalently in instances that provide fromSqlCStringLen, since the intent seems to be that fromSqlCStringLen is merely an optimization of fromSqlValue. -- System Information: Debian Release: lenny/sid APT prefers unstable APT policy: (500, 'unstable'), (500, 'testing') Architecture: i386 (i686) Kernel: Linux 2.6.21-awakening Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/bash -- Austin Clements MIT/'06/CSAIL [EMAIL PROTECTED] http://web.mit.edu/~amdragon/ Somewhere in the dream we call reality you will find me, searching for the reality we call dreams. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]