Use of string utility functions.

This commit is contained in:
Kei Hibino 2013-09-02 16:10:10 +09:00
parent a56d0c4e52
commit e70a84a3d5
2 changed files with 5 additions and 4 deletions

View File

@ -35,6 +35,7 @@ import qualified Data.Text as T
import Database.Relational.Query.Expr.Unsafe (Expr(Expr), showExpr)
import Database.Relational.Query.Internal.String (paren)
import qualified Language.SQL.Keyword as SQL
import qualified Language.SQL.Keyword.ConcatString as SQLs
@ -120,4 +121,4 @@ fromJust = unsafeCastExpr
-- | AND operator for 'Expr'.
exprAnd :: Expr p Bool -> Expr p Bool -> Expr p Bool
exprAnd a b = Expr $ '(' : SQLs.defineBinOp SQL.AND (showExpr a) (showExpr b) ++ [')']
exprAnd a b = Expr . paren $ SQLs.defineBinOp SQL.AND (showExpr a) (showExpr b)

View File

@ -63,7 +63,7 @@ import Database.Relational.Query.Table
import qualified Database.Relational.Query.Table as Table
import Database.Relational.Query.Internal.String
(showUnwordsSQL, showWordSQL, showUnwords)
(showUnwordsSQL, showWordSQL, showUnwords, paren)
import Language.SQL.Keyword (Keyword(..), unwordsSQL)
import qualified Language.SQL.Keyword as SQL
import qualified Language.SQL.Keyword.ConcatString as SQLs
@ -146,8 +146,8 @@ toSQLs :: SubQuery
-> (String, String) -- ^ subquery SQL and top-level SQL
toSQLs = d where
d (Table u) = (Table.name' u, fromTableToSql u)
d (SubQuery { sql' = q }) = ('(' : q ++ [')'], q)
d (Bin op l r) = ('(' : q ++ [')'], q) where
d (SubQuery { sql' = q }) = (paren q, q)
d (Bin op l r) = (paren q, q) where
q = unwords [unitSQL l, SQL.wordShow $ keywordBinOp op, unitSQL r]
-- | SQL string for nested-qeury.