0 | module Oracle.Internal.Lob
 1 |
 2 | import Data.ByteString
 3 | import Oracle.Error
 4 | import Oracle.FFI.Lob
 5 | import Oracle.Types.Error
 6 |
 7 | ||| Read an Oracle BLOB into a ByteString.
 8 | |||
 9 | ||| The LOB handle is released after reading.
10 | |||
11 | export
12 | readBlob : AnyPtr -> IO (Either OracleError ByteString)
13 | readBlob lob = do
14 |   size <- primIO (prim__lobSize lob)
15 |   case size < 0 of
16 |     True  => do
17 |       lasterr <- getLastError
18 |       pure (Left lasterr)
19 |     False => do
20 |       blobdata <- primIO (prim__lobRead lob 1 size)
21 |       primIO (prim__lobRelease lob)
22 |       pure (Right $ fromString blobdata)
23 |