Skip to content
This repository has been archived by the owner on Jan 21, 2023. It is now read-only.

Commit

Permalink
Bug correction
Browse files Browse the repository at this point in the history
  • Loading branch information
l-monnier committed Feb 13, 2015
1 parent a12ebaf commit 35b7c0c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 23 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Hedsql
Hedsql is a EDSL (Embedded Domain-Specific Language) written in Haskell for SQL.

It allows to create SQL statements in a compact, modular and flexible way.
The output are strings, meaning that it can be used with in any database
access library such as HDBC or [x]-simple, etc.
Outputs are strings. It means that Hedsql can be used with in any database
access library such as HDBC, [x]-simple, etc.

Please see the GitHub Wiki for a quick start and examples.
Take a look at the GitHub Wiki for a quick start and examples.
8 changes: 4 additions & 4 deletions src/Database/Hedsql/Common/Constructor/DataManipulation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ import Database.Hedsql.Common.DataStructure
-- | Create a column/value pair to be used in an UPDATE statement.
assign ::
(
ToCols a [Column c]
, ToSqlValues b [SqlValue c]
ToCols a [Column c]
, ToColRefs b [ColRef c]
)
=> a -- ^ Column or name of the column.
-> b -- ^ Value for this column.
-> b -- ^ Value for this column. It can also be an expression.
-> Assignment c
assign a val = Assignment (toCol a) (ValueExpr $ value val)
assign a val = Assignment (toCol a) (expr val)

-- | Create a DELETE FROM statement.
deleteFrom ::
Expand Down
6 changes: 3 additions & 3 deletions src/Database/Hedsql/Common/DataStructure/Select.hs
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ data Where a =

-- | SQL Condition.
data Condition a =
FuncCond (FuncBool a)
| And [Condition a]
| Or [Condition a]
FuncCond (FuncBool a)
| And [Condition a]
| Or [Condition a]
deriving (Show)

-- | GROUP BY clause.
Expand Down
20 changes: 14 additions & 6 deletions src/Database/Hedsql/Common/DataStructure/Update.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ Data structure of the UPDATE statement.
-}
module Database.Hedsql.Common.DataStructure.Update where

--------------------------------------------------------------------------------
-- IMPORTS
--------------------------------------------------------------------------------

import Database.Hedsql.Common.DataStructure.Select

import Control.Lens

-- | UPDATE query.
data Update a = Update
{ _updateTable :: Table a
, _updateAssignments :: [Assignment a]
, _updateWherePart :: Maybe (Where a)
} deriving (Show)
--------------------------------------------------------------------------------
-- PUBLIC
--------------------------------------------------------------------------------

{-|
A value assigned to a column (used in the SET clause of an UPDATE statement).
Expand All @@ -32,6 +33,13 @@ data Assignment a = Assignment
, _assignmentVal :: Expression a
} deriving (Show)

-- | UPDATE query.
data Update a = Update
{ _updateTable :: Table a
, _updateAssignments :: [Assignment a]
, _updateWherePart :: Maybe (Where a)
} deriving (Show)

-- Make the lenses.
makeLenses ''Assignment
makeLenses ''Update
20 changes: 13 additions & 7 deletions src/Database/Hedsql/Common/Parser/Queries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ parseUpdateFunc parser update =
, Just $ parser^.quoteElem $ update^.updateTable.tableName
, Just " SET "
, Just $ intercalate ", " $ map (parser^.parseAssgnmt) assignments
, fmap (parser^.parseWhere) (update^.updateWherePart)
, fmap (\x -> " " ++ (parser^.parseWhere) x) (update^.updateWherePart)
]
where
assignments = update^.updateAssignments
Expand Down Expand Up @@ -634,12 +634,18 @@ parseWhereFunc parser (Where condition) =
parseJoinClauseFunc :: QueryParser a -> JoinClause a -> String
parseJoinClauseFunc parser jClause =
case jClause of
JoinClauseOn predicate -> "ON " ++ (parser^.parseCondition) predicate
JoinClauseUsing cols -> concat
[ "USING ("
, intercalate ", " $ map (parser^.parseCol) cols
, ")"
]
JoinClauseOn predicate ->
let cond = (parser^.parseCondition) predicate
in "ON " ++
case predicate of
FuncCond _ -> cond
_ -> "(" ++ cond ++ ")"
JoinClauseUsing cols ->
concat
[ "USING ("
, intercalate ", " $ map (parser^.parseCol) cols
, ")"
]

-- | Parser a join on a column.
parseJoinTColFunc :: JoinTypeCol a -> String
Expand Down

0 comments on commit 35b7c0c

Please sign in to comment.