Safe Haskell | None |
---|
- module Database.SQLite3.Bindings.Types
- c_sqlite3_open :: CString -> Ptr (Ptr CDatabase) -> IO CError
- c_sqlite3_close :: Ptr CDatabase -> IO CError
- c_sqlite3_errmsg :: Ptr CDatabase -> IO CString
- c_sqlite3_interrupt :: Ptr CDatabase -> IO ()
- c_sqlite3_trace :: Ptr CDatabase -> FunPtr (CTraceCallback a) -> Ptr a -> IO (Ptr ())
- type CTraceCallback a = Ptr a -> CString -> IO ()
- mkCTraceCallback :: CTraceCallback a -> IO (FunPtr (CTraceCallback a))
- c_sqlite3_get_autocommit :: Ptr CDatabase -> IO CInt
- c_sqlite3_exec :: Ptr CDatabase -> CString -> FunPtr (CExecCallback a) -> Ptr a -> Ptr CString -> IO CError
- type CExecCallback a = Ptr a -> CColumnCount -> Ptr CString -> Ptr CString -> IO CInt
- mkCExecCallback :: CExecCallback a -> IO (FunPtr (CExecCallback a))
- c_sqlite3_prepare_v2 :: Ptr CDatabase -> CString -> CNumBytes -> Ptr (Ptr CStatement) -> Ptr CString -> IO CError
- c_sqlite3_db_handle :: Ptr CStatement -> IO (Ptr CDatabase)
- c_sqlite3_step :: Ptr CStatement -> IO CError
- c_sqlite3_reset :: Ptr CStatement -> IO CError
- c_sqlite3_finalize :: Ptr CStatement -> IO CError
- c_sqlite3_clear_bindings :: Ptr CStatement -> IO CError
- c_sqlite3_sql :: Ptr CStatement -> IO CString
- c_sqlite3_bind_parameter_count :: Ptr CStatement -> IO CParamIndex
- c_sqlite3_bind_parameter_name :: Ptr CStatement -> CParamIndex -> IO CString
- c_sqlite3_bind_parameter_index :: Ptr CStatement -> CString -> IO CParamIndex
- c_sqlite3_column_count :: Ptr CStatement -> IO CColumnCount
- c_sqlite3_column_name :: Ptr CStatement -> CColumnIndex -> IO CString
- c_sqlite3_bind_blob :: Ptr CStatement -> CParamIndex -> Ptr a -> CNumBytes -> Ptr CDestructor -> IO CError
- c_sqlite3_bind_text :: Ptr CStatement -> CParamIndex -> CString -> CNumBytes -> Ptr CDestructor -> IO CError
- c_sqlite3_bind_double :: Ptr CStatement -> CParamIndex -> Double -> IO CError
- c_sqlite3_bind_int64 :: Ptr CStatement -> CParamIndex -> Int64 -> IO CError
- c_sqlite3_bind_null :: Ptr CStatement -> CParamIndex -> IO CError
- c_sqlite3_column_type :: Ptr CStatement -> CColumnIndex -> IO CColumnType
- c_sqlite3_column_bytes :: Ptr CStatement -> CColumnIndex -> IO CNumBytes
- c_sqlite3_column_blob :: Ptr CStatement -> CColumnIndex -> IO (Ptr a)
- c_sqlite3_column_int64 :: Ptr CStatement -> CColumnIndex -> IO Int64
- c_sqlite3_column_double :: Ptr CStatement -> CColumnIndex -> IO Double
- c_sqlite3_column_text :: Ptr CStatement -> CColumnIndex -> IO CString
- c_sqlite3_last_insert_rowid :: Ptr CDatabase -> IO Int64
- c_sqlite3_changes :: Ptr CDatabase -> IO CInt
- c_sqlite3_total_changes :: Ptr CDatabase -> IO CInt
- c_sqlite3_free :: Ptr a -> IO ()
Documentation
Connection management
c_sqlite3_open :: CString -> Ptr (Ptr CDatabase) -> IO CErrorSource
http://www.sqlite.org/c3ref/open.html
This sets the 'Ptr CDatabase'
even on failure.
type CTraceCallback aSource
mkCTraceCallback :: CTraceCallback a -> IO (FunPtr (CTraceCallback a))Source
Simple query execution
type CExecCallback aSource
= Ptr a | |
-> CColumnCount | Number of columns, which is the number of elements in the following arrays. |
-> Ptr CString | Array of column values, as returned by
|
-> Ptr CString | Array of column names |
-> IO CInt | If the callback returns non-zero, then
|
mkCExecCallback :: CExecCallback a -> IO (FunPtr (CExecCallback a))Source
A couple important things to know about callbacks from Haskell code:
- If the callback throws an exception, apparently, the whole program is terminated.
- Remember to call
freeHaskellFunPtr
when you are done with the wrapper, to avoid leaking memory.
Statement management
:: Ptr CDatabase | |
-> CString | SQL statement, UTF-8 encoded |
-> CNumBytes | Maximum length of the SQL statement, in bytes. If this is negative, then the SQL statement is treated as a NUL-terminated string. |
-> Ptr (Ptr CStatement) | OUT: Statement handle. This must not be null. |
-> Ptr CString | OUT: Pointer to unused portion of zSql |
-> IO CError |
http://www.sqlite.org/c3ref/prepare.html
If the query contains no SQL statements, this returns SQLITE_OK
and sets
the
to null.
Ptr
CStatement
c_sqlite3_db_handle :: Ptr CStatement -> IO (Ptr CDatabase)Source
c_sqlite3_reset :: Ptr CStatement -> IO CErrorSource
http://www.sqlite.org/c3ref/reset.html
Warning: If the most recent c_sqlite3_step
call failed,
this will return the corresponding error code.
c_sqlite3_finalize :: Ptr CStatement -> IO CErrorSource
http://www.sqlite.org/c3ref/finalize.html
Warning: If the most recent c_sqlite3_step
call failed,
this will return the corresponding error code.
c_sqlite3_clear_bindings :: Ptr CStatement -> IO CErrorSource
http://www.sqlite.org/c3ref/clear_bindings.html
A look at the source reveals that this function always returns SQLITE_OK
.
Parameter and column information
c_sqlite3_bind_parameter_count :: Ptr CStatement -> IO CParamIndexSource
http://www.sqlite.org/c3ref/bind_parameter_count.html
This returns the index of the largest (rightmost) parameter, which is not
necessarily the number of parameters. If numbered parameters like ?5
are used, there may be gaps in the list.
Binding Values To Prepared Statements
:: Ptr CStatement | |
-> CParamIndex | Index of the SQL parameter to be set |
-> Ptr a | Value to bind to the parameter. Warning: If this pointer is |
-> CNumBytes | Length, in bytes. This must not be negative. |
-> Ptr CDestructor | |
-> IO CError |
:: Ptr CStatement | |
-> CParamIndex | |
-> CString | Warning: If this pointer is |
-> CNumBytes | Length, in bytes. If this is negative, the value is treated as a NUL-terminated string. |
-> Ptr CDestructor | |
-> IO CError |
c_sqlite3_bind_double :: Ptr CStatement -> CParamIndex -> Double -> IO CErrorSource
c_sqlite3_bind_int64 :: Ptr CStatement -> CParamIndex -> Int64 -> IO CErrorSource
Result Values From A Query
c_sqlite3_column_blob :: Ptr CStatement -> CColumnIndex -> IO (Ptr a)Source