Skip to content

Commit

Permalink
Merge pull request #8 from snakamura/truncated
Browse files Browse the repository at this point in the history
Get the whole value using mysql_stmt_fetch_column if it was truncated.
  • Loading branch information
bos committed Dec 13, 2011
2 parents 5bc9298 + 97487e3 commit 9696a73
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Database/HDBC/MySQL/Connection.hsc
Expand Up @@ -567,10 +567,19 @@ fetchRow mysql__ stmt__ results =
rv <- mysql_stmt_fetch stmt_
case rv of
0 -> row
#{const MYSQL_DATA_TRUNCATED} -> row
#{const MYSQL_DATA_TRUNCATED} -> liftM Just $ mapM (uncurry $ fill stmt_) $ zip [0..] results
#{const MYSQL_NO_DATA} -> finalizeForeignPtr stmt__ >> return Nothing
_ -> statementError stmt_
where row = mapM cellValue results >>= \cells -> return $ Just cells
where row = liftM Just $ mapM cellValue results
fill stmt_ column bind = do
err <- peek $ bindError bind
if err == 1 then do len <- peek $ bindLength bind
bracket (mallocBytes $ fromIntegral len) free $ \buffer_ ->
do let tempBind = bind { bindBuffer = buffer_, bindBufferLength = len }
rv <- with tempBind $ \bind_ -> mysql_stmt_fetch_column stmt_ bind_ column 0
when (rv /= 0) (statementError stmt_)
cellValue tempBind
else cellValue bind

-- Produces a single SqlValue cell value given the binding, handling
-- nulls appropriately.
Expand Down Expand Up @@ -859,6 +868,9 @@ foreign import ccall unsafe mysql_fetch_field
foreign import ccall unsafe mysql_stmt_fetch
:: Ptr MYSQL_STMT -> IO CInt

foreign import ccall unsafe mysql_stmt_fetch_column
:: Ptr MYSQL_STMT -> Ptr MYSQL_BIND -> CUInt -> CULong -> IO CInt

foreign import ccall unsafe mysql_stmt_close
:: Ptr MYSQL_STMT -> IO ()

Expand Down

0 comments on commit 9696a73

Please sign in to comment.