Your message dated Sun, 27 Apr 2008 14:40:28 +0200
with message-id <[EMAIL PROTECTED]>
and subject line Bug#468436: libghc6-hsql-sqlite3-dev: Fails to read non-text 
fields
has caused the Debian Bug report #468436,
regarding libghc6-hsql-sqlite3-dev: Fails to read non-text fields
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [EMAIL PROTECTED]
immediately.)


-- 
468436: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=468436
Debian Bug Tracking System
Contact [EMAIL PROTECTED] with problems
--- Begin Message ---
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.



--- End Message ---
--- Begin Message ---
Hi Austin,

Sorry for the late response. I have relayed your bug report to Krasimir
(the developer of hsql-sqlite3) and he gave the following response:

> The SQLite database is textual by design. All fields are text fields
> even if they were declared as Integer. For example you can insert
> string in a column that is supposed to be textual. For that reason
> HSQL reports all columns as textual and they should be read as textual
> as well. The API even doesn't provide an easy way to read the column
> type.
> 
> Best regards,
>   Krasimir

This is why the SQLite backend will always return Strings and not the
the type of the value before it was stored in the database. You can work
around this by doing the conversion yourself with the read function:

> 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 (read v :: Int)) s 

As this is not bug I am closing the bug report.

Greetings Arjan 

Attachment: signature.asc
Description: Dit berichtdeel is digitaal ondertekend


--- End Message ---

Reply via email to