Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for HDBC >= 2.2.7.0. #4

Merged
merged 1 commit into from

2 participants

@khibino

.HDBC's new versions no longer converts column names to lower case.

I reported this before in haskelldb-users mailing list.
(http://sourceforge.net/mailarchive/forum.php?thread_name=CABPxb2kq1Bgr6%2BBkYHhDQCZPofLQWYET3Y7YDwxj8xk0DjoJ6A%40mail.gmail.com&forum_name=haskelldb-users)

@m4dc4p
Owner

Looks good. Thanks!

@m4dc4p m4dc4p merged commit 795c591 into m4dc4p:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 12, 2012
  1. Fix for HDBC >= 2.2.7.0. HDBC's new versions no longer converts colum…

    Kei Hibino authored
    …n names to lower case.
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 3 deletions.
  1. +11 −3 driver-hdbc/Database/HaskellDB/HDBC.hs
View
14 driver-hdbc/Database/HaskellDB/HDBC.hs
@@ -161,6 +161,9 @@ hdbcTransaction conn action =
type HDBCRow = Map String HDBC.SqlValue
+normalizeField :: String -> String
+normalizeField = map toLower
+
-- | Primitive query
hdbcPrimQuery :: (GetRec er vr, IConnection conn) =>
conn -- ^ Database connection.
@@ -172,8 +175,13 @@ hdbcPrimQuery conn sql scheme rel =
do
stmt <- handleSqlError $ HDBC.prepare conn sql
handleSqlError $ HDBC.execute stmt []
- rows <- HDBC.fetchAllRowsMap stmt
- mapM (getRec hdbcGetInstances rel scheme) rows
+ rows <- fetchNormalizedAllRowsAL stmt
+ mapM (getRec hdbcGetInstances rel scheme) $ map Map.fromList rows
+ where fetchNormalizedAllRowsAL sth =
+ do
+ names <- map normalizeField `fmap` getColumnNames sth
+ rows <- fetchAllRows sth
+ return $ map (zip names) rows
-- | Primitive execute
hdbcPrimExecute :: (IConnection conn) => conn -- ^ Database connection.
@@ -203,6 +211,6 @@ hdbcGetInstances =
-- hdbcGetValue :: Data.Convertible.Base.Convertible SqlValue a
-- => HDBCRow -> String -> IO (Maybe a)
-hdbcGetValue m f = case Map.lookup (map toLower f) m of
+hdbcGetValue m f = case Map.lookup (normalizeField f) m of
Nothing -> fail $ "No such field " ++ f
Just x -> return $ HDBC.fromSql x
Something went wrong with that request. Please try again.