From 9709ba12969179c811b42609e03cc1fc0f33b7f2 Mon Sep 17 00:00:00 2001 From: Kei Hibino Date: Wed, 25 Sep 2013 22:20:46 +0900 Subject: [PATCH] Flip arguments of runQuery. --- relational-query-HDBC/src/Database/HDBC/Record/Query.hs | 8 ++++---- relational-query-HDBC/src/Database/HDBC/Schema/IBMDB2.hs | 6 +++--- .../src/Database/HDBC/Schema/PostgreSQL.hs | 7 +++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/relational-query-HDBC/src/Database/HDBC/Record/Query.hs b/relational-query-HDBC/src/Database/HDBC/Record/Query.hs index 2c923f5a..2628de80 100644 --- a/relational-query-HDBC/src/Database/HDBC/Record/Query.hs +++ b/relational-query-HDBC/src/Database/HDBC/Record/Query.hs @@ -127,15 +127,15 @@ runPreparedQuery' ps = runStatement' . bind ps -- | Prepare SQL, bind parameters, execute statement and lazily fetch all records. runQuery :: (IConnection conn, ToSql SqlValue p, FromSql SqlValue a) => conn -- ^ Database connection - -> p -- ^ Parameter type -> Query p a -- ^ Query to get record type 'a' requires parameter 'p' + -> p -- ^ Parameter type -> IO [a] -- ^ Action to get records -runQuery conn p = (>>= \ps -> runPreparedQuery ps p) . prepare conn +runQuery conn q p = prepare conn q >>= (`runPreparedQuery` p) -- | Strict version of 'runQuery'. runQuery' :: (IConnection conn, ToSql SqlValue p, FromSql SqlValue a) => conn -- ^ Database connection - -> p -- ^ Parameter type -> Query p a -- ^ Query to get record type 'a' requires parameter 'p' + -> p -- ^ Parameter type -> IO [a] -- ^ Action to get records -runQuery' conn p = (>>= \ps -> runPreparedQuery' ps p) . prepare conn +runQuery' conn q p = prepare conn q >>= (`runPreparedQuery'` p) diff --git a/relational-query-HDBC/src/Database/HDBC/Schema/IBMDB2.hs b/relational-query-HDBC/src/Database/HDBC/Schema/IBMDB2.hs index 1ea4a005..4ba91b78 100644 --- a/relational-query-HDBC/src/Database/HDBC/Schema/IBMDB2.hs +++ b/relational-query-HDBC/src/Database/HDBC/Schema/IBMDB2.hs @@ -64,7 +64,7 @@ getPrimaryKey' :: IConnection conn getPrimaryKey' conn scm' tbl' = do let tbl = map toUpper tbl' scm = map toUpper scm' - primCols <- runQuery' conn (scm, tbl) primaryKeyQuerySQL + primCols <- runQuery' conn primaryKeyQuerySQL (scm, tbl) let primaryKeyCols = normalizeColumn `fmap` primCols putLog $ "getPrimaryKey: primary key = " ++ show primaryKeyCols @@ -79,8 +79,8 @@ getFields' :: IConnection conn getFields' tmap conn scm' tbl' = do let tbl = map toUpper tbl' scm = map toUpper scm' - - cols <- runQuery' conn (scm, tbl) columnsQuerySQL + + cols <- runQuery' conn columnsQuerySQL (scm, tbl) case cols of [] -> compileErrorIO $ "getFields: No columns found: schema = " ++ scm ++ ", table = " ++ tbl diff --git a/relational-query-HDBC/src/Database/HDBC/Schema/PostgreSQL.hs b/relational-query-HDBC/src/Database/HDBC/Schema/PostgreSQL.hs index b4fae2fe..ced77399 100644 --- a/relational-query-HDBC/src/Database/HDBC/Schema/PostgreSQL.hs +++ b/relational-query-HDBC/src/Database/HDBC/Schema/PostgreSQL.hs @@ -65,13 +65,13 @@ getPrimaryKey' :: IConnection conn getPrimaryKey' conn scm' tbl' = do let scm = map toLower scm' tbl = map toLower tbl' - mayKeyLen <- runQuery' conn (scm, tbl) primaryKeyLengthQuerySQL + mayKeyLen <- runQuery' conn primaryKeyLengthQuerySQL (scm, tbl) case mayKeyLen of [] -> do putLog $ "getPrimaryKey: Primary key not found." return [] [keyLen] -> do - primCols <- runQuery' conn (scm, tbl) (primaryKeyQuerySQL keyLen) + primCols <- runQuery' conn (primaryKeyQuerySQL keyLen) (scm, tbl) let primaryKeyCols = normalizeColumn `fmap` primCols putLog $ "getPrimaryKey: primary key = " ++ show primaryKeyCols return primaryKeyCols @@ -88,7 +88,7 @@ getFields' :: IConnection conn getFields' tmap conn scm' tbl' = do let scm = map toLower scm' tbl = map toLower tbl' - cols <- runQuery' conn (scm, tbl) columnQuerySQL + cols <- runQuery' conn columnQuerySQL (scm, tbl) case cols of [] -> compileErrorIO $ "getFields: No columns found: schema = " ++ scm ++ ", table = " ++ tbl @@ -111,4 +111,3 @@ driverPostgreSQL :: IConnection conn => Driver conn driverPostgreSQL = emptyDriver { getFieldsWithMap = getFields' } { getPrimaryKey = getPrimaryKey' } -