Skip to content

Commit

Permalink
deallocate binds once execute has finished.
Browse files Browse the repository at this point in the history
  • Loading branch information
waterson committed Apr 17, 2010
1 parent 4d71d45 commit 8d112ea
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Database/HDBC/MySQL/Connection.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,9 @@ execute :: ForeignPtr MYSQL -> ForeignPtr MYSQL_STMT -> [Types.SqlValue] -> IO I
execute mysql__ stmt__ params =
withForeignPtr mysql__ $ \_ ->
withForeignPtr stmt__ $ \stmt_ -> do
bindParams stmt_ params
binds <- bindParams stmt_ params
rv <- mysql_stmt_execute stmt_
freeBinds binds
when (rv /= 0) (statementError stmt_)
nrows <- mysql_stmt_affected_rows stmt_

Expand All @@ -329,7 +330,7 @@ execute mysql__ stmt__ params =
return $ fromIntegral (if nrows == (-1 :: CULLong) then 0 else nrows)

-- Binds placeholder parameters to values.
bindParams :: Ptr MYSQL_STMT -> [Types.SqlValue] -> IO ()
bindParams :: Ptr MYSQL_STMT -> [Types.SqlValue] -> IO [MYSQL_BIND]
bindParams stmt_ params = do
param_count <- mysql_stmt_param_count stmt_
let nparams = fromIntegral param_count
Expand All @@ -346,6 +347,8 @@ bindParams stmt_ params = do
rv <- mysql_stmt_bind_param stmt_ bind_
when (rv /= 0) (statementError stmt_)

return binds

-- Given a SqlValue, return a MYSQL_BIND structure that we can use to
-- pass its value.
bindOfSqlValue :: Types.SqlValue -> IO MYSQL_BIND
Expand Down

0 comments on commit 8d112ea

Please sign in to comment.