direct-sqlite-2.3.7: Low-level binding to SQLite3. Includes UTF8 and BLOB support.

Safe HaskellNone

Database.SQLite3.Bindings

Contents

Synopsis

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.

c_sqlite3_traceSource

Arguments

:: Ptr CDatabase 
-> FunPtr (CTraceCallback a)

Optional callback function called for each row

-> Ptr a

Context passed to the callback

-> IO (Ptr ())

Returns context pointer from previously registered trace

type CTraceCallback aSource

Arguments

 = Ptr a 
-> CString

UTF-8 rendering of the SQL statement text as the statement first begins executing

-> IO () 

Simple query execution

c_sqlite3_execSource

Arguments

:: Ptr CDatabase 
-> CString

SQL statement, UTF-8 encoded

-> FunPtr (CExecCallback a)

Optional callback function called for each row

-> Ptr a

Context passed to the callback

-> Ptr CString

OUT: Error message string

-> IO CError 

type CExecCallback aSource

Arguments

 = 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 c_sqlite3_column_text. Null values are represented as null pointers.

-> Ptr CString

Array of column names

-> IO CInt

If the callback returns non-zero, then c_sqlite3_exec returns SQLITE_ABORT (ErrorAbort).

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

c_sqlite3_prepare_v2Source

Arguments

:: 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 Ptr CStatement to null.

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

c_sqlite3_bind_blobSource

Arguments

:: Ptr CStatement 
-> CParamIndex

Index of the SQL parameter to be set

-> Ptr a

Value to bind to the parameter.

Warning: If this pointer is NULL, this will bind a null value, rather than an empty blob.

-> CNumBytes

Length, in bytes. This must not be negative.

-> Ptr CDestructor 
-> IO CError 

c_sqlite3_bind_textSource

Arguments

:: Ptr CStatement 
-> CParamIndex 
-> CString

Warning: If this pointer is NULL, this will bind a null value, rather than an empty text.

-> CNumBytes

Length, in bytes. If this is negative, the value is treated as a NUL-terminated string.

-> Ptr CDestructor 
-> IO CError 

Result Values From A Query

Result statistics

Miscellaneous