hdbc / hdbc-sqlite3

Sqlite v3 driver for HDBC
BSD 3-Clause "New" or "Revised" License
21 stars 6 forks source link

describeTable return incorrect result #4

Closed daapp closed 13 years ago

daapp commented 13 years ago

describeTable function return incorrect result (SqlUnknownT for all fields) because it can't decode SqlByteString type. Here is patch:


---
Database/HDBC/Sqlite3/Connection.hs |   17 +++++++++++------
1 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/Database/HDBC/Sqlite3/Connection.hs b/Database/HDBC/Sqlite/Connection.hs
index 8f95b24..5d1c066 100644
--- a/Database/HDBC/Sqlite3/Connection.hs
+++ b/Database/HDBC/Sqlite3/Connection.hs
@@ -38,6 +38,7 @@ import Foreign.Ptr
 import Control.Concurrent.MVar
 import qualified Data.ByteString as B
 import qualified Data.ByteString.UTF8 as BUTF8
+import qualified Data.Char

 {- | Connect to an Sqlite version 3 database.  The only parameter needed is
 the filename of the database to connect to.
@@ -119,13 +120,17 @@ fdescribeTable o mchildren name =  do
      nullable _ = Nothing

      typeId SqlNull                     = SqlUnknownT "Any"
-     typeId (SqlString ('i':'n':'t':_)) = SqlIntegerT
-     typeId (SqlString "text")          = SqlVarCharT
-     typeId (SqlString "real")          = SqlRealT
-     typeId (SqlString "blob")          = SqlVarBinaryT
-     typeId (SqlString "")              = SqlUnknownT "Any"
-     typeId (SqlString other)           = SqlUnknownT other
+     typeId (SqlString t)               = typeId' t
+     typeId (SqlByteString t)           = typeId' $ BUTF8.toString t
      typeId _                           = SqlUnknownT "Unknown"
+     
+     typeId' t = case map Data.Char.toLower t of
+       ('i':'n':'t':_) -> SqlIntegerT
+       "text"          -> SqlVarCharT
+       "real"          -> SqlRealT
+       "blob"          -> SqlVarBinaryT
+       ""              -> SqlUnknownT "Any"
+       other           -> SqlUnknownT other

 fsetbusy o ms = withRawSqlite3 o $ \ppdb ->
-- 
1.7.2.5
jgoerzen commented 13 years ago

Thanks. Applied andpushed.