Portability | non-portable |
---|---|
Stability | experimental |
Maintainer | oleg@pobox.com, alistair@abayley.org |
Wrappers for ODBC FFI functions, plus buffer marshaling.
- data HandleObj = HandleObj
- type Handle = Ptr HandleObj
- data EnvObj = EnvObj
- type EnvHandle = Ptr EnvObj
- data ConnObj = ConnObj
- type ConnHandle = Ptr ConnObj
- data StmtObj = StmtObj
- type StmtHandle = Ptr StmtObj
- type WindowHandle = Ptr ()
- data Buffer = Buffer
- type BufferFPtr = ForeignPtr Buffer
- type SizeFPtr = ForeignPtr SqlLen
- data BindBuffer = BindBuffer {}
- type SqlInteger = Int32
- type SqlUInteger = Word32
- type SqlSmallInt = Int16
- type SqlUSmallInt = Word16
- type SqlLen = Int32
- type SqlULen = Word32
- type SqlReturn = SqlSmallInt
- type SqlHandleType = SqlSmallInt
- type SqlDataType = SqlSmallInt
- type SqlCDataType = SqlSmallInt
- type SqlParamDirection = SqlSmallInt
- sqlDriverNoPrompt :: SqlUSmallInt
- sqlNullTermedString :: SqlInteger
- sqlNullData :: SqlLen
- sqlTransCommit :: SqlSmallInt
- sqlTransRollback :: SqlSmallInt
- sqlAutoCommitOff :: SqlInteger
- sqlAutoCommitOn :: SqlInteger
- data OdbcException = OdbcException Int String String [OdbcException]
- catchOdbc :: IO a -> (OdbcException -> IO a) -> IO a
- throwOdbc :: OdbcException -> a
- type MyCString = CString
- type MyCStringLen = CStringLen
- getDiagRec :: SqlReturn -> SqlHandleType -> Handle -> SqlSmallInt -> IO [OdbcException]
- checkError :: SqlReturn -> SqlHandleType -> Handle -> IO ()
- allocHdl :: Storable a => Handle -> SqlHandleType -> IO a
- allocEnv :: IO EnvHandle
- allocConn :: EnvHandle -> IO ConnHandle
- allocStmt :: ConnHandle -> IO StmtHandle
- freeHelper :: SqlHandleType -> Handle -> IO ()
- freeEnv :: EnvHandle -> IO ()
- freeConn :: ConnHandle -> IO ()
- freeStmt :: StmtHandle -> IO ()
- int2Ptr :: SqlInteger -> Ptr ()
- setOdbcVer :: EnvHandle -> IO ()
- connect :: ConnHandle -> String -> IO String
- disconnect :: ConnHandle -> IO ()
- prepareStmt :: StmtHandle -> String -> IO ()
- executeStmt :: StmtHandle -> IO ()
- closeCursor :: StmtHandle -> IO ()
- rowCount :: StmtHandle -> IO Int
- fetch :: StmtHandle -> IO Bool
- moreResults :: StmtHandle -> IO Bool
- commit :: ConnHandle -> IO ()
- rollback :: ConnHandle -> IO ()
- setAutoCommitOn :: ConnHandle -> IO ()
- setAutoCommitOff :: ConnHandle -> IO ()
- setTxnIsolation :: ConnHandle -> SqlInteger -> IO ()
- getMaybeFromBuffer :: Storable a => Ptr SqlLen -> Ptr a -> (Ptr a -> SqlLen -> IO b) -> IO (Maybe b)
- getDataStorable :: Storable a => StmtHandle -> Int -> SqlDataType -> Int -> (a -> b) -> IO (Maybe b)
- getDataUtcTime :: StmtHandle -> Int -> IO (Maybe UTCTime)
- getDataCStringLen :: StmtHandle -> Int -> IO (Maybe CStringLen)
- getDataUTF8String :: StmtHandle -> Int -> IO (Maybe String)
- getDataCString :: StmtHandle -> Int -> IO (Maybe String)
- peekSmallInt :: Ptr a -> Int -> IO SqlSmallInt
- peekUSmallInt :: Ptr a -> Int -> IO SqlUSmallInt
- peekUInteger :: Ptr a -> Int -> IO SqlUInteger
- readUtcTimeFromMemory :: Ptr Word8 -> IO UTCTime
- bindColumnBuffer :: StmtHandle -> Int -> SqlDataType -> SqlLen -> IO BindBuffer
- createEmptyBuffer :: SqlLen -> IO BindBuffer
- testForNull :: BindBuffer -> (Ptr Buffer -> SqlLen -> IO a) -> IO (Maybe a)
- getStorableFromBuffer :: Storable a => BindBuffer -> IO (Maybe a)
- getCAStringFromBuffer :: BindBuffer -> IO (Maybe String)
- getCWStringFromBuffer :: BindBuffer -> IO (Maybe String)
- getUTF8StringFromBuffer :: BindBuffer -> IO (Maybe String)
- getUtcTimeFromBuffer :: BindBuffer -> IO (Maybe UTCTime)
- createBufferForStorable :: Storable a => Maybe a -> IO BindBuffer
- createBufferHelper :: Storable a => a -> SqlLen -> IO BindBuffer
- wrapSizedBuffer :: Ptr a -> SqlLen -> IO BindBuffer
- bindParam :: StmtHandle -> Int -> SqlParamDirection -> SqlCDataType -> SqlDataType -> SqlULen -> SqlSmallInt -> BindBuffer -> IO ()
- bindNull :: StmtHandle -> Int -> SqlParamDirection -> SqlCDataType -> SqlDataType -> IO BindBuffer
- bindParamCStringLen :: StmtHandle -> Int -> SqlParamDirection -> Maybe CStringLen -> IO BindBuffer
- bindEncodedString :: StmtHandle -> Int -> SqlParamDirection -> Maybe String -> (String -> ((Ptr a, Int) -> IO BindBuffer) -> IO BindBuffer) -> IO BindBuffer
- bindParamUTF8String :: StmtHandle -> Int -> SqlParamDirection -> Maybe String -> IO BindBuffer
- bindParamCAString :: StmtHandle -> Int -> SqlParamDirection -> Maybe String -> IO BindBuffer
- bindParamCWString :: StmtHandle -> Int -> SqlParamDirection -> Maybe String -> IO BindBuffer
- pokeSmallInt :: Ptr a -> Int -> SqlSmallInt -> IO ()
- pokeUSmallInt :: Ptr a -> Int -> SqlUSmallInt -> IO ()
- pokeUInteger :: Ptr a -> Int -> SqlUInteger -> IO ()
- writeUTCTimeToMemory :: Ptr Word8 -> UTCTime -> IO ()
- makeUtcTimeBuffer :: UTCTime -> IO BindBuffer
- makeUtcTimeStringBuffer :: UTCTime -> IO BindBuffer
- bindParamUtcTime :: StmtHandle -> Int -> SqlParamDirection -> Maybe UTCTime -> IO BindBuffer
- sizeOfMaybe :: forall a. Storable a => Maybe a -> Int
- newtype OutParam a = OutParam a
- newtype InOutParam a = InOutParam a
- class OdbcBindBuffer a where
- bindColBuffer :: StmtHandle -> Int -> Int -> a -> IO BindBuffer
- getFromBuffer :: BindBuffer -> IO a
- getData :: StmtHandle -> Int -> IO a
- class OdbcBindParam a where
- bindParamBuffer :: StmtHandle -> Int -> a -> IO BindBuffer
- sqlAllocHandle :: SqlHandleType -> Handle -> Ptr Handle -> IO SqlReturn
- sqlFreeHandle :: SqlSmallInt -> Handle -> IO SqlReturn
- sqlGetDiagRec :: SqlHandleType -> Handle -> SqlSmallInt -> MyCString -> Ptr SqlInteger -> MyCString -> SqlSmallInt -> Ptr SqlSmallInt -> IO SqlReturn
- sqlDriverConnect :: ConnHandle -> WindowHandle -> MyCString -> SqlSmallInt -> MyCString -> SqlSmallInt -> Ptr SqlSmallInt -> SqlUSmallInt -> IO SqlReturn
- sqlDisconnect :: ConnHandle -> IO SqlReturn
- sqlSetEnvAttr :: EnvHandle -> SqlInteger -> Ptr () -> SqlInteger -> IO SqlReturn
- sqlSetConnectAttr :: ConnHandle -> SqlInteger -> Ptr () -> SqlInteger -> IO SqlReturn
- sqlPrepare :: StmtHandle -> MyCString -> SqlInteger -> IO SqlReturn
- sqlExecute :: StmtHandle -> IO SqlReturn
- sqlCloseCursor :: StmtHandle -> IO SqlReturn
- sqlRowCount :: StmtHandle -> Ptr SqlLen -> IO SqlReturn
- sqlGetData :: StmtHandle -> SqlUSmallInt -> SqlDataType -> Ptr Buffer -> SqlLen -> Ptr SqlLen -> IO SqlReturn
- sqlBindCol :: StmtHandle -> SqlUSmallInt -> SqlDataType -> Ptr Buffer -> SqlLen -> Ptr SqlLen -> IO SqlReturn
- sqlFetch :: StmtHandle -> IO SqlReturn
- sqlBindParameter :: StmtHandle -> SqlUSmallInt -> SqlParamDirection -> SqlCDataType -> SqlDataType -> SqlULen -> SqlSmallInt -> Ptr Buffer -> SqlLen -> Ptr SqlLen -> IO SqlReturn
- sqlMoreResults :: StmtHandle -> IO SqlReturn
- sqlEndTran :: SqlSmallInt -> Handle -> SqlSmallInt -> IO SqlReturn
Documentation
type ConnHandle = Ptr ConnObjSource
type StmtHandle = Ptr StmtObjSource
type WindowHandle = Ptr ()Source
type BufferFPtr = ForeignPtr BufferSource
type SizeFPtr = ForeignPtr SqlLenSource
data BindBuffer Source
type SqlInteger = Int32Source
type SqlUInteger = Word32Source
type SqlSmallInt = Int16Source
type SqlUSmallInt = Word16Source
type SqlReturn = SqlSmallIntSource
type SqlHandleType = SqlSmallIntSource
type SqlDataType = SqlSmallIntSource
type SqlCDataType = SqlSmallIntSource
data OdbcException Source
throwOdbc :: OdbcException -> aSource
type MyCStringLen = CStringLenSource
getDiagRec :: SqlReturn -> SqlHandleType -> Handle -> SqlSmallInt -> IO [OdbcException]Source
checkError :: SqlReturn -> SqlHandleType -> Handle -> IO ()Source
allocConn :: EnvHandle -> IO ConnHandleSource
freeHelper :: SqlHandleType -> Handle -> IO ()Source
freeConn :: ConnHandle -> IO ()Source
freeStmt :: StmtHandle -> IO ()Source
int2Ptr :: SqlInteger -> Ptr ()Source
setOdbcVer :: EnvHandle -> IO ()Source
disconnect :: ConnHandle -> IO ()Source
prepareStmt :: StmtHandle -> String -> IO ()Source
executeStmt :: StmtHandle -> IO ()Source
closeCursor :: StmtHandle -> IO ()Source
rowCount :: StmtHandle -> IO IntSource
moreResults :: StmtHandle -> IO BoolSource
commit :: ConnHandle -> IO ()Source
rollback :: ConnHandle -> IO ()Source
setAutoCommitOn :: ConnHandle -> IO ()Source
setAutoCommitOff :: ConnHandle -> IO ()Source
setTxnIsolation :: ConnHandle -> SqlInteger -> IO ()Source
getMaybeFromBuffer :: Storable a => Ptr SqlLen -> Ptr a -> (Ptr a -> SqlLen -> IO b) -> IO (Maybe b)Source
getDataStorable :: Storable a => StmtHandle -> Int -> SqlDataType -> Int -> (a -> b) -> IO (Maybe b)Source
getDataUtcTime :: StmtHandle -> Int -> IO (Maybe UTCTime)Source
getDataCStringLen :: StmtHandle -> Int -> IO (Maybe CStringLen)Source
getDataUTF8String :: StmtHandle -> Int -> IO (Maybe String)Source
getDataCString :: StmtHandle -> Int -> IO (Maybe String)Source
peekSmallInt :: Ptr a -> Int -> IO SqlSmallIntSource
peekUSmallInt :: Ptr a -> Int -> IO SqlUSmallIntSource
peekUInteger :: Ptr a -> Int -> IO SqlUIntegerSource
bindColumnBuffer :: StmtHandle -> Int -> SqlDataType -> SqlLen -> IO BindBufferSource
testForNull :: BindBuffer -> (Ptr Buffer -> SqlLen -> IO a) -> IO (Maybe a)Source
getStorableFromBuffer :: Storable a => BindBuffer -> IO (Maybe a)Source
createBufferForStorable :: Storable a => Maybe a -> IO BindBufferSource
createBufferHelper :: Storable a => a -> SqlLen -> IO BindBufferSource
wrapSizedBuffer :: Ptr a -> SqlLen -> IO BindBufferSource
bindParam :: StmtHandle -> Int -> SqlParamDirection -> SqlCDataType -> SqlDataType -> SqlULen -> SqlSmallInt -> BindBuffer -> IO ()Source
bindNull :: StmtHandle -> Int -> SqlParamDirection -> SqlCDataType -> SqlDataType -> IO BindBufferSource
bindParamCStringLen :: StmtHandle -> Int -> SqlParamDirection -> Maybe CStringLen -> IO BindBufferSource
bindEncodedString :: StmtHandle -> Int -> SqlParamDirection -> Maybe String -> (String -> ((Ptr a, Int) -> IO BindBuffer) -> IO BindBuffer) -> IO BindBufferSource
bindParamUTF8String :: StmtHandle -> Int -> SqlParamDirection -> Maybe String -> IO BindBufferSource
bindParamCAString :: StmtHandle -> Int -> SqlParamDirection -> Maybe String -> IO BindBufferSource
bindParamCWString :: StmtHandle -> Int -> SqlParamDirection -> Maybe String -> IO BindBufferSource
pokeSmallInt :: Ptr a -> Int -> SqlSmallInt -> IO ()Source
pokeUSmallInt :: Ptr a -> Int -> SqlUSmallInt -> IO ()Source
pokeUInteger :: Ptr a -> Int -> SqlUInteger -> IO ()Source
bindParamUtcTime :: StmtHandle -> Int -> SqlParamDirection -> Maybe UTCTime -> IO BindBufferSource
sizeOfMaybe :: forall a. Storable a => Maybe a -> IntSource
newtype InOutParam a Source
class OdbcBindBuffer a whereSource
:: StmtHandle | stmt handle |
-> Int | column position (1-indexed) |
-> Int | size of result buffer (ignored when it can be inferred from type of a) |
-> a | dummy value of the appropriate type (just to ensure we get the right class instance) |
-> IO BindBuffer | returns a |
getFromBuffer :: BindBuffer -> IO aSource
getData :: StmtHandle -> Int -> IO aSource
class OdbcBindParam a whereSource
:: StmtHandle | stmt handle |
-> Int | parameter position (1-indexed) |
-> a | value to write to buffer |
-> IO BindBuffer | returns a |
sqlAllocHandle :: SqlHandleType -> Handle -> Ptr Handle -> IO SqlReturnSource
sqlFreeHandle :: SqlSmallInt -> Handle -> IO SqlReturnSource
:: SqlHandleType | enum: which handle type is the next parameter? |
-> Handle | generic handle ptr |
-> SqlSmallInt | row (or message) number |
-> MyCString | OUT: state |
-> Ptr SqlInteger | OUT: error number |
-> MyCString | OUT: error message |
-> SqlSmallInt | IN: message buffer size |
-> Ptr SqlSmallInt | OUT: message length |
-> IO SqlReturn |
:: ConnHandle | |
-> WindowHandle | just pass nullPtr |
-> MyCString | connection string |
-> SqlSmallInt | connection string size |
-> MyCString | OUT: buffer for normalised connection string |
-> SqlSmallInt | buffer size |
-> Ptr SqlSmallInt | OUT: length of returned string |
-> SqlUSmallInt | enum: should driver prompt user for missing info? |
-> IO SqlReturn |
:: EnvHandle | Env Handle |
-> SqlInteger | Attribute (enumeration) |
-> Ptr () | value (cast to void*) |
-> SqlInteger | ? - set to 0 |
-> IO SqlReturn |
:: ConnHandle | Connection Handle |
-> SqlInteger | Attribute (enumeration) |
-> Ptr () | value (cast to void*) |
-> SqlInteger | ? - set to 0 |
-> IO SqlReturn |
sqlPrepare :: StmtHandle -> MyCString -> SqlInteger -> IO SqlReturnSource
sqlRowCount :: StmtHandle -> Ptr SqlLen -> IO SqlReturnSource
:: StmtHandle | |
-> SqlUSmallInt | column position, 1-indexed |
-> SqlDataType | SQL data type: string, int, long, date, etc |
-> Ptr Buffer | output buffer |
-> SqlLen | output buffer size |
-> Ptr SqlLen | output data size, or -1 (SQL_NULL_DATA) for null |
-> IO SqlReturn |
:: StmtHandle | |
-> SqlUSmallInt | column position, 1-indexed |
-> SqlDataType | SQL data type: string, int, long, date, etc |
-> Ptr Buffer | output buffer |
-> SqlLen | output buffer size |
-> Ptr SqlLen | output data size, or -1 (SQL_NULL_DATA) for null |
-> IO SqlReturn |
sqlFetch :: StmtHandle -> IO SqlReturnSource
:: StmtHandle | |
-> SqlUSmallInt | position, 1-indexed |
-> SqlParamDirection | direction: IN, OUT |
-> SqlCDataType | C data type: char, int, long, float, etc |
-> SqlDataType | SQL data type: string, int, long, date, etc |
-> SqlULen | col size (precision) |
-> SqlSmallInt | decimal digits (scale) |
-> Ptr Buffer | input+output buffer |
-> SqlLen | buffer size |
-> Ptr SqlLen | input+output data size, or -1 (SQL_NULL_DATA) for null |
-> IO SqlReturn |
sqlEndTran :: SqlSmallInt -> Handle -> SqlSmallInt -> IO SqlReturnSource