-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Low-level binding to SQLite3. Includes UTF8 and BLOB support. -- @package direct-sqlite @version 2.3.16 module Database.SQLite3.Bindings.Types -- | http://www.sqlite.org/c3ref/sqlite3.html -- -- CDatabase = sqlite3 data CDatabase -- | http://www.sqlite.org/c3ref/stmt.html -- -- CStatement = sqlite3_stmt data CStatement -- | http://www.sqlite.org/c3ref/value.html -- -- CValue = sqlite3_value data CValue -- | http://www.sqlite.org/c3ref/context.html -- -- CContext = sqlite3_context data CContext -- | https://www.sqlite.org/c3ref/blob.html -- -- CBlob = sqlite3_blob data CBlob -- | https://www.sqlite.org/c3ref/backup.html -- -- CBackup = sqlite3_backup data CBackup -- | http://www.sqlite.org/c3ref/c_abort.html newtype CError CError :: CInt -> CError -- | Note that this is a partial function. If the error code is invalid, or -- perhaps introduced in a newer version of SQLite but this library has -- not been updated to support it, the result is undefined. -- -- To be clear, if decodeError fails, it is undefined -- behavior, not an exception you can handle. -- -- Therefore, do not use direct-sqlite with a different version of SQLite -- than the one bundled (currently, 3.7.13). If you do, ensure that -- decodeError and decodeColumnType are still exhaustive. decodeError :: CError -> Error encodeError :: Error -> CError data Error -- | Successful result ErrorOK :: Error -- | SQL error or missing database ErrorError :: Error -- | Internal logic error in SQLite ErrorInternal :: Error -- | Access permission denied ErrorPermission :: Error -- | Callback routine requested an abort ErrorAbort :: Error -- | The database file is locked ErrorBusy :: Error -- | A table in the database is locked ErrorLocked :: Error -- | A malloc() failed ErrorNoMemory :: Error -- | Attempt to write a readonly database ErrorReadOnly :: Error -- | Operation terminated by sqlite3_interrupt() ErrorInterrupt :: Error -- | Some kind of disk I/O error occurred ErrorIO :: Error -- | The database disk image is malformed ErrorCorrupt :: Error -- | Unknown opcode in sqlite3_file_control() ErrorNotFound :: Error -- | Insertion failed because database is full ErrorFull :: Error -- | Unable to open the database file ErrorCan'tOpen :: Error -- | Database lock protocol error ErrorProtocol :: Error -- | Database is empty ErrorEmpty :: Error -- | The database schema changed ErrorSchema :: Error -- | String or BLOB exceeds size limit ErrorTooBig :: Error -- | Abort due to constraint violation ErrorConstraint :: Error -- | Data type mismatch ErrorMismatch :: Error -- | Library used incorrectly ErrorMisuse :: Error -- | Uses OS features not supported on host ErrorNoLargeFileSupport :: Error -- | Authorization denied ErrorAuthorization :: Error -- | Auxiliary database format error ErrorFormat :: Error -- | 2nd parameter to sqlite3_bind out of range ErrorRange :: Error -- | File opened that is not a database file ErrorNotADatabase :: Error -- | sqlite3_step() has another row ready ErrorRow :: Error -- | sqlite3_step() has finished executing ErrorDone :: Error -- | http://www.sqlite.org/c3ref/c_blob.html newtype CColumnType CColumnType :: CInt -> CColumnType -- | Note that this is a partial function. See decodeError for more -- information. decodeColumnType :: CColumnType -> ColumnType encodeColumnType :: ColumnType -> CColumnType data ColumnType IntegerColumn :: ColumnType FloatColumn :: ColumnType TextColumn :: ColumnType BlobColumn :: ColumnType NullColumn :: ColumnType -- | Index of a parameter in a parameterized query. Parameter indices start -- from 1. -- -- When a query is prepared, SQLite allocates an array indexed -- from 1 to the highest parameter index. For example: -- --
--   >Right stmt <- prepare conn "SELECT ?1, ?5, ?3, ?"
--   >bindParameterCount stmt
--   ParamIndex 6
--   
-- -- This will allocate an array indexed from 1 to 6 (? takes the -- highest preceding index plus one). The array is initialized with null -- values. When you bind a parameter with bindSQLData, it assigns -- a new value to one of these indices. -- -- See http://www.sqlite.org/lang_expr.html#varparam for the -- syntax of parameter placeholders, and how parameter indices are -- assigned. newtype ParamIndex ParamIndex :: Int -> ParamIndex -- | Index of a column in a result set. Column indices start from 0. newtype ColumnIndex ColumnIndex :: Int -> ColumnIndex -- | Number of columns in a result set. type ColumnCount = ColumnIndex newtype CParamIndex CParamIndex :: CInt -> CParamIndex newtype CColumnIndex CColumnIndex :: CInt -> CColumnIndex type CColumnCount = CColumnIndex newtype CNumBytes CNumBytes :: CInt -> CNumBytes -- | http://www.sqlite.org/c3ref/c_static.html -- -- Ptr CDestructor = sqlite3_destructor_type data CDestructor -- | Tells SQLite3 to make its own private copy of the data c_SQLITE_TRANSIENT :: Ptr CDestructor c_SQLITE_UTF8 :: CInt -- | Number of arguments of a user defined SQL function. newtype ArgCount ArgCount :: Int -> ArgCount -- | Index of an argument to a custom function. Indices start from 0. type ArgIndex = ArgCount newtype CArgCount CArgCount :: CInt -> CArgCount -- | Tells SQLite3 that the defined custom SQL function is deterministic. c_SQLITE_DETERMINISTIC :: CInt -- | The Database.SQLite3 and Database.SQLite3.Direct modules -- use higher-level representations of some types than those used in the -- FFI signatures (Database.SQLite3.Bindings). This typeclass -- helps with the conversions. class FFIType public ffi | public -> ffi, ffi -> public toFFI :: FFIType public ffi => public -> ffi fromFFI :: FFIType public ffi => ffi -> public instance Eq Error instance Show Error instance Eq ColumnType instance Show ColumnType instance Eq ParamIndex instance Ord ParamIndex instance Enum ParamIndex instance Num ParamIndex instance Real ParamIndex instance Integral ParamIndex instance Eq ColumnIndex instance Ord ColumnIndex instance Enum ColumnIndex instance Num ColumnIndex instance Real ColumnIndex instance Integral ColumnIndex instance Eq CParamIndex instance Ord CParamIndex instance Enum CParamIndex instance Num CParamIndex instance Real CParamIndex instance Integral CParamIndex instance Eq CColumnIndex instance Ord CColumnIndex instance Enum CColumnIndex instance Num CColumnIndex instance Real CColumnIndex instance Integral CColumnIndex instance Eq CNumBytes instance Ord CNumBytes instance Show CNumBytes instance Enum CNumBytes instance Num CNumBytes instance Real CNumBytes instance Integral CNumBytes instance Eq ArgCount instance Ord ArgCount instance Enum ArgCount instance Num ArgCount instance Real ArgCount instance Integral ArgCount instance Eq CArgCount instance Ord CArgCount instance Enum CArgCount instance Num CArgCount instance Real CArgCount instance Integral CArgCount instance Eq CError instance Show CError instance Eq CColumnType instance Show CColumnType instance FFIType ArgCount CArgCount instance FFIType ColumnType CColumnType instance FFIType Error CError instance FFIType ColumnIndex CColumnIndex instance FFIType ParamIndex CParamIndex instance Bounded CArgCount instance Show CArgCount instance Bounded ArgCount instance Show ArgCount instance Show CColumnIndex instance Show CParamIndex instance Bounded ColumnIndex instance Show ColumnIndex instance Bounded ParamIndex instance Show ParamIndex module Database.SQLite3.Bindings -- | http://www.sqlite.org/c3ref/open.html -- -- This sets the 'Ptr CDatabase' even on failure. c_sqlite3_open :: CString -> Ptr (Ptr CDatabase) -> IO CError -- | http://www.sqlite.org/c3ref/close.html c_sqlite3_close :: Ptr CDatabase -> IO CError -- | http://www.sqlite.org/c3ref/errcode.html c_sqlite3_errcode :: Ptr CDatabase -> IO CError -- | http://www.sqlite.org/c3ref/errcode.html c_sqlite3_errmsg :: Ptr CDatabase -> IO CString -- | http://www.sqlite.org/c3ref/interrupt.html c_sqlite3_interrupt :: Ptr CDatabase -> IO () -- | http://www.sqlite.org/c3ref/profile.html 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)) -- | http://www.sqlite.org/c3ref/get_autocommit.html c_sqlite3_get_autocommit :: Ptr CDatabase -> IO CInt -- | https://www.sqlite.org/c3ref/enable_shared_cache.html c_sqlite3_enable_shared_cache :: CInt -> IO CError 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 -- | A couple important things to know about callbacks from Haskell code: -- -- mkCExecCallback :: CExecCallback a -> IO (FunPtr (CExecCallback a)) -- | 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_prepare_v2 :: Ptr CDatabase -> CString -> CNumBytes -> Ptr (Ptr CStatement) -> Ptr CString -> IO CError -- | http://www.sqlite.org/c3ref/db_handle.html c_sqlite3_db_handle :: Ptr CStatement -> IO (Ptr CDatabase) -- | http://www.sqlite.org/c3ref/step.html c_sqlite3_step :: Ptr CStatement -> IO CError -- | 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_reset :: Ptr CStatement -> IO CError -- | 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_finalize :: Ptr CStatement -> IO CError -- | http://www.sqlite.org/c3ref/clear_bindings.html -- -- A look at the source reveals that this function always returns -- SQLITE_OK. c_sqlite3_clear_bindings :: Ptr CStatement -> IO CError -- | http://www.sqlite.org/c3ref/sql.html c_sqlite3_sql :: Ptr CStatement -> IO CString -- | 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. c_sqlite3_bind_parameter_count :: Ptr CStatement -> IO CParamIndex -- | http://www.sqlite.org/c3ref/bind_parameter_name.html c_sqlite3_bind_parameter_name :: Ptr CStatement -> CParamIndex -> IO CString -- | http://www.sqlite.org/c3ref/bind_parameter_index.html c_sqlite3_bind_parameter_index :: Ptr CStatement -> CString -> IO CParamIndex -- | http://www.sqlite.org/c3ref/column_count.html c_sqlite3_column_count :: Ptr CStatement -> IO CColumnCount -- | http://www.sqlite.org/c3ref/column_name.html 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_zeroblob :: Ptr CStatement -> CParamIndex -> CInt -> 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 -- | http://www.sqlite.org/c3ref/last_insert_rowid.html c_sqlite3_last_insert_rowid :: Ptr CDatabase -> IO Int64 -- | http://www.sqlite.org/c3ref/changes.html c_sqlite3_changes :: Ptr CDatabase -> IO CInt -- | http://www.sqlite.org/c3ref/total_changes.html c_sqlite3_total_changes :: Ptr CDatabase -> IO CInt -- | http://sqlite.org/c3ref/create_function.html c_sqlite3_create_function_v2 :: Ptr CDatabase -> CString -> CArgCount -> CInt -> Ptr a -> FunPtr CFunc -> FunPtr CFunc -> FunPtr CFuncFinal -> FunPtr (CFuncDestroy a) -> IO CError type CFunc = Ptr CContext -> CArgCount -> Ptr (Ptr CValue) -> IO () type CFuncFinal = Ptr CContext -> IO () type CFuncDestroy a = Ptr a -> IO () mkCFunc :: CFunc -> IO (FunPtr CFunc) mkCFuncFinal :: CFuncFinal -> IO (FunPtr CFuncFinal) mkCFuncDestroy :: CFuncDestroy a -> IO (FunPtr (CFuncDestroy a)) -- | http://www.sqlite.org/c3ref/user_data.html c_sqlite3_user_data :: Ptr CContext -> IO (Ptr a) -- | http://www.sqlite.org/c3ref/context_db_handle.html c_sqlite3_context_db_handle :: Ptr CContext -> IO (Ptr CDatabase) -- | http://www.sqlite.org/c3ref/aggregate_context.html c_sqlite3_aggregate_context :: Ptr CContext -> CNumBytes -> IO (Ptr a) c_sqlite3_value_type :: Ptr CValue -> IO CColumnType c_sqlite3_value_bytes :: Ptr CValue -> IO CNumBytes c_sqlite3_value_blob :: Ptr CValue -> IO (Ptr a) c_sqlite3_value_text :: Ptr CValue -> IO CString c_sqlite3_value_int64 :: Ptr CValue -> IO Int64 c_sqlite3_value_double :: Ptr CValue -> IO Double c_sqlite3_result_null :: Ptr CContext -> IO () c_sqlite3_result_blob :: Ptr CContext -> Ptr a -> CNumBytes -> Ptr CDestructor -> IO () c_sqlite3_result_zeroblob :: Ptr CContext -> CNumBytes -> IO () c_sqlite3_result_text :: Ptr CContext -> CString -> CNumBytes -> Ptr CDestructor -> IO () c_sqlite3_result_int64 :: Ptr CContext -> Int64 -> IO () c_sqlite3_result_double :: Ptr CContext -> Double -> IO () c_sqlite3_result_value :: Ptr CContext -> Ptr CValue -> IO () c_sqlite3_result_error :: Ptr CContext -> CString -> CNumBytes -> IO () -- | http://www.sqlite.org/c3ref/create_collation.html c_sqlite3_create_collation_v2 :: Ptr CDatabase -> CString -> CInt -> Ptr a -> FunPtr (CCompare a) -> FunPtr (CFuncDestroy a) -> IO CError type CCompare a = Ptr a -> CNumBytes -> CString -> CNumBytes -> CString -> IO CInt mkCCompare :: CCompare a -> IO (FunPtr (CCompare a)) -- | http://sqlite.org/c3ref/free.html c_sqlite3_free :: Ptr a -> IO () -- | http://sqlite.org/c3ref/enable_load_extension.html c_sqlite3_enable_load_extension :: Ptr CDatabase -> Bool -> IO CError -- | https://www.sqlite.org/c3ref/wal_hook.html c_sqlite3_wal_hook :: Ptr CDatabase -> FunPtr CWalHook -> Ptr a -> IO (Ptr ()) type CWalHook = Ptr () -> Ptr CDatabase -> CString -> CInt -> IO CError mkCWalHook :: CWalHook -> IO (FunPtr CWalHook) -- | https://www.sqlite.org/c3ref/blob_open.html c_sqlite3_blob_open :: Ptr CDatabase -> CString -> CString -> CString -> Int64 -> CInt -> Ptr (Ptr CBlob) -> IO CError -- | https://www.sqlite.org/c3ref/blob_close.html c_sqlite3_blob_close :: Ptr CBlob -> IO CError -- | https://www.sqlite.org/c3ref/blob_reopen.html c_sqlite3_blob_reopen :: Ptr CBlob -> Int64 -> IO CError -- | https://www.sqlite.org/c3ref/blob_bytes.html c_sqlite3_blob_bytes :: Ptr CBlob -> IO CInt -- | https://www.sqlite.org/c3ref/blob_read.html c_sqlite3_blob_read :: Ptr CBlob -> Ptr a -> CInt -> CInt -> IO CError -- | https://www.sqlite.org/c3ref/blob_write.html c_sqlite3_blob_write :: Ptr CBlob -> Ptr a -> CInt -> CInt -> IO CError c_sqlite3_backup_init :: Ptr CDatabase -> CString -> Ptr CDatabase -> CString -> IO (Ptr CBackup) c_sqlite3_backup_finish :: Ptr CBackup -> IO CError c_sqlite3_backup_step :: Ptr CBackup -> CInt -> IO CError c_sqlite3_backup_remaining :: Ptr CBackup -> IO CInt c_sqlite3_backup_pagecount :: Ptr CBackup -> IO CInt -- | This API is a slightly lower-level version of Database.SQLite3. -- Namely: -- -- module Database.SQLite3.Direct -- | http://www.sqlite.org/c3ref/open.html open :: Utf8 -> IO (Either (Error, Utf8) Database) -- | http://www.sqlite.org/c3ref/close.html close :: Database -> IO (Either Error ()) -- | http://www.sqlite.org/c3ref/errcode.html errcode :: Database -> IO Error -- | http://www.sqlite.org/c3ref/errcode.html errmsg :: Database -> IO Utf8 -- | http://www.sqlite.org/c3ref/profile.html -- -- Enable/disable tracing of SQL execution. Tracing can be disabled by -- setting Nothing as the logger callback. -- -- Warning: If the logger callback throws an exception, your whole -- program will crash. Enable only for debugging! setTrace :: Database -> Maybe (Utf8 -> IO ()) -> IO () -- | http://www.sqlite.org/c3ref/get_autocommit.html -- -- Return True if the connection is in autocommit mode, or -- False if a transaction started with BEGIN is still -- active. -- -- Be warned that some errors roll back the transaction automatically, -- and that ROLLBACK will throw an error if no transaction is -- active. Use getAutoCommit to avoid such an error: -- --
--   autocommit <- getAutoCommit conn
--   when (not autocommit) $
--       exec conn "ROLLBACK"
--   
getAutoCommit :: Database -> IO Bool -- | https://www.sqlite.org/c3ref/enable_shared_cache.html -- -- Enable or disable shared cache for all future connections. setSharedCacheEnabled :: Bool -> IO (Either Error ()) exec :: Database -> Utf8 -> IO (Either (Error, Utf8) ()) -- | Like exec, but invoke the callback for each result row. -- -- If the callback throws an exception, it will be rethrown by -- execWithCallback. execWithCallback :: Database -> Utf8 -> ExecCallback -> IO (Either (Error, Utf8) ()) type ExecCallback = ColumnCount -> [Utf8] -> [Maybe Utf8] -> IO () -- | http://www.sqlite.org/c3ref/prepare.html -- -- If the query contains no SQL statements, this returns Right -- Nothing. prepare :: Database -> Utf8 -> IO (Either Error (Maybe Statement)) -- | http://www.sqlite.org/c3ref/db_handle.html getStatementDatabase :: Statement -> IO Database -- | http://www.sqlite.org/c3ref/step.html step :: Statement -> IO (Either Error StepResult) -- | http://www.sqlite.org/c3ref/reset.html -- -- Warning: -- -- reset :: Statement -> IO (Either Error ()) -- | http://www.sqlite.org/c3ref/finalize.html -- -- Warning: If the most recent step call failed, this will -- return the corresponding error. finalize :: Statement -> IO (Either Error ()) -- | http://www.sqlite.org/c3ref/clear_bindings.html -- -- Set all parameters in the prepared statement to null. clearBindings :: Statement -> IO () -- | http://www.sqlite.org/c3ref/sql.html -- -- Return a copy of the original SQL text used to compile the statement. statementSql :: Statement -> IO (Maybe Utf8) -- | http://www.sqlite.org/c3ref/bind_parameter_count.html -- -- This returns the index of the largest (rightmost) parameter. Note that -- this is not necessarily the number of parameters. If numbered -- parameters like ?5 are used, there may be gaps in the list. -- -- See ParamIndex for more information. bindParameterCount :: Statement -> IO ParamIndex -- | http://www.sqlite.org/c3ref/bind_parameter_name.html bindParameterName :: Statement -> ParamIndex -> IO (Maybe Utf8) -- | http://www.sqlite.org/c3ref/bind_parameter_index.html bindParameterIndex :: Statement -> Utf8 -> IO (Maybe ParamIndex) -- | http://www.sqlite.org/c3ref/column_count.html columnCount :: Statement -> IO ColumnCount -- | http://www.sqlite.org/c3ref/column_name.html columnName :: Statement -> ColumnIndex -> IO (Maybe Utf8) bindInt64 :: Statement -> ParamIndex -> Int64 -> IO (Either Error ()) bindDouble :: Statement -> ParamIndex -> Double -> IO (Either Error ()) bindText :: Statement -> ParamIndex -> Utf8 -> IO (Either Error ()) bindBlob :: Statement -> ParamIndex -> ByteString -> IO (Either Error ()) bindZeroBlob :: Statement -> ParamIndex -> Int -> IO (Either Error ()) bindNull :: Statement -> ParamIndex -> IO (Either Error ()) columnType :: Statement -> ColumnIndex -> IO ColumnType columnInt64 :: Statement -> ColumnIndex -> IO Int64 columnDouble :: Statement -> ColumnIndex -> IO Double columnText :: Statement -> ColumnIndex -> IO Utf8 columnBlob :: Statement -> ColumnIndex -> IO ByteString -- | http://www.sqlite.org/c3ref/enable_load_extension.html -- -- Enable or disable extension loading. setLoadExtensionEnabled :: Database -> Bool -> IO (Either Error ()) -- | http://www.sqlite.org/c3ref/last_insert_rowid.html lastInsertRowId :: Database -> IO Int64 -- | http://www.sqlite.org/c3ref/changes.html -- -- Return the number of rows that were changed, inserted, or deleted by -- the most recent INSERT, DELETE, or UPDATE -- statement. changes :: Database -> IO Int -- | http://www.sqlite.org/c3ref/total_changes.html -- -- Return the total number of row changes caused by INSERT, -- DELETE, or UPDATE statements since the -- Database was opened. totalChanges :: Database -> IO Int -- | http://sqlite.org/c3ref/create_function.html -- -- Create a custom SQL function or redefine the behavior of an existing -- function. createFunction :: Database -> Utf8 -> Maybe ArgCount -> Bool -> (FuncContext -> FuncArgs -> IO ()) -> IO (Either Error ()) -- | Like createFunction except that it creates an aggregate -- function. createAggregate :: Database -> Utf8 -> Maybe ArgCount -> a -> (FuncContext -> FuncArgs -> a -> IO a) -> (FuncContext -> a -> IO ()) -> IO (Either Error ()) -- | Delete an SQL function (scalar or aggregate). deleteFunction :: Database -> Utf8 -> Maybe ArgCount -> IO (Either Error ()) funcArgCount :: FuncArgs -> ArgCount funcArgType :: FuncArgs -> ArgIndex -> IO ColumnType funcArgInt64 :: FuncArgs -> ArgIndex -> IO Int64 funcArgDouble :: FuncArgs -> ArgIndex -> IO Double funcArgText :: FuncArgs -> ArgIndex -> IO Utf8 funcArgBlob :: FuncArgs -> ArgIndex -> IO ByteString funcResultInt64 :: FuncContext -> Int64 -> IO () funcResultDouble :: FuncContext -> Double -> IO () funcResultText :: FuncContext -> Utf8 -> IO () funcResultBlob :: FuncContext -> ByteString -> IO () funcResultZeroBlob :: FuncContext -> Int -> IO () funcResultNull :: FuncContext -> IO () -- | https://www.sqlite.org/c3ref/context_db_handle.html getFuncContextDatabase :: FuncContext -> IO Database -- | http://www.sqlite.org/c3ref/create_collation.html createCollation :: Database -> Utf8 -> (Utf8 -> Utf8 -> Ordering) -> IO (Either Error ()) -- | Delete a collation. deleteCollation :: Database -> Utf8 -> IO (Either Error ()) -- | http://www.sqlite.org/c3ref/interrupt.html -- -- Cause any pending operation on the Database handle to stop at -- its earliest opportunity. This simply sets a flag and returns -- immediately. It does not wait for the pending operation to finish. -- -- You'll need to compile with -threaded for this to do any -- good. Without -threaded, FFI calls block the whole RTS, -- meaning interrupt would never run at the same time as -- step. interrupt :: Database -> IO () -- | https://www.sqlite.org/c3ref/blob_open.html -- -- Open a blob for incremental I/O. blobOpen :: Database -> Utf8 -> Utf8 -> Utf8 -> Int64 -> Bool -> IO (Either Error Blob) -- | https://www.sqlite.org/c3ref/blob_close.html blobClose :: Blob -> IO (Either Error ()) -- | https://www.sqlite.org/c3ref/blob_reopen.html blobReopen :: Blob -> Int64 -> IO (Either Error ()) -- | https://www.sqlite.org/c3ref/blob_bytes.html blobBytes :: Blob -> IO Int -- | https://www.sqlite.org/c3ref/blob_read.html blobRead :: Blob -> Int -> Int -> IO (Either Error ByteString) blobReadBuf :: Blob -> Ptr a -> Int -> Int -> IO (Either Error ()) -- | https://www.sqlite.org/c3ref/blob_write.html blobWrite :: Blob -> ByteString -> Int -> IO (Either Error ()) backupInit :: Database -> Utf8 -> Database -> Utf8 -> IO (Either Error Backup) backupFinish :: Backup -> IO (Either Error ()) backupStep :: Backup -> Int -> IO (Either Error BackupStepResult) backupRemaining :: Backup -> IO Int backupPagecount :: Backup -> IO Int newtype Database Database :: (Ptr CDatabase) -> Database newtype Statement Statement :: (Ptr CStatement) -> Statement data ColumnType IntegerColumn :: ColumnType FloatColumn :: ColumnType TextColumn :: ColumnType BlobColumn :: ColumnType NullColumn :: ColumnType -- | The context in which a custom SQL function is executed. newtype FuncContext FuncContext :: (Ptr CContext) -> FuncContext -- | The arguments of a custom SQL function. data FuncArgs FuncArgs :: CArgCount -> (Ptr (Ptr CValue)) -> FuncArgs -- | The type of blob handles used for incremental blob I/O data Blob Blob :: Database -> (Ptr CBlob) -> Blob -- | A handle for an online backup process. data Backup Backup :: Database -> (Ptr CBackup) -> Backup data StepResult Row :: StepResult Done :: StepResult data BackupStepResult -- | There are still more pages to be copied. BackupOK :: BackupStepResult -- | All pages were successfully copied. BackupDone :: BackupStepResult data Error -- | Successful result ErrorOK :: Error -- | SQL error or missing database ErrorError :: Error -- | Internal logic error in SQLite ErrorInternal :: Error -- | Access permission denied ErrorPermission :: Error -- | Callback routine requested an abort ErrorAbort :: Error -- | The database file is locked ErrorBusy :: Error -- | A table in the database is locked ErrorLocked :: Error -- | A malloc() failed ErrorNoMemory :: Error -- | Attempt to write a readonly database ErrorReadOnly :: Error -- | Operation terminated by sqlite3_interrupt() ErrorInterrupt :: Error -- | Some kind of disk I/O error occurred ErrorIO :: Error -- | The database disk image is malformed ErrorCorrupt :: Error -- | Unknown opcode in sqlite3_file_control() ErrorNotFound :: Error -- | Insertion failed because database is full ErrorFull :: Error -- | Unable to open the database file ErrorCan'tOpen :: Error -- | Database lock protocol error ErrorProtocol :: Error -- | Database is empty ErrorEmpty :: Error -- | The database schema changed ErrorSchema :: Error -- | String or BLOB exceeds size limit ErrorTooBig :: Error -- | Abort due to constraint violation ErrorConstraint :: Error -- | Data type mismatch ErrorMismatch :: Error -- | Library used incorrectly ErrorMisuse :: Error -- | Uses OS features not supported on host ErrorNoLargeFileSupport :: Error -- | Authorization denied ErrorAuthorization :: Error -- | Auxiliary database format error ErrorFormat :: Error -- | 2nd parameter to sqlite3_bind out of range ErrorRange :: Error -- | File opened that is not a database file ErrorNotADatabase :: Error -- | sqlite3_step() has another row ready ErrorRow :: Error -- | sqlite3_step() has finished executing ErrorDone :: Error -- | A ByteString containing UTF8-encoded text with no NUL -- characters. newtype Utf8 Utf8 :: ByteString -> Utf8 -- | Index of a parameter in a parameterized query. Parameter indices start -- from 1. -- -- When a query is prepared, SQLite allocates an array indexed -- from 1 to the highest parameter index. For example: -- --
--   >Right stmt <- prepare conn "SELECT ?1, ?5, ?3, ?"
--   >bindParameterCount stmt
--   ParamIndex 6
--   
-- -- This will allocate an array indexed from 1 to 6 (? takes the -- highest preceding index plus one). The array is initialized with null -- values. When you bind a parameter with bindSQLData, it assigns -- a new value to one of these indices. -- -- See http://www.sqlite.org/lang_expr.html#varparam for the -- syntax of parameter placeholders, and how parameter indices are -- assigned. newtype ParamIndex ParamIndex :: Int -> ParamIndex -- | Index of a column in a result set. Column indices start from 0. newtype ColumnIndex ColumnIndex :: Int -> ColumnIndex -- | Number of columns in a result set. type ColumnCount = ColumnIndex -- | Number of arguments of a user defined SQL function. newtype ArgCount ArgCount :: Int -> ArgCount -- | Index of an argument to a custom function. Indices start from 0. type ArgIndex = ArgCount instance Eq Database instance Show Database instance Eq Statement instance Show Statement instance Eq StepResult instance Show StepResult instance Eq BackupStepResult instance Show BackupStepResult instance Eq Utf8 instance Ord Utf8 instance Eq FuncContext instance Show FuncContext instance Eq Blob instance Show Blob instance Eq Backup instance Show Backup instance Monoid Utf8 instance IsString Utf8 instance Show Utf8 module Database.SQLite3 -- | http://www.sqlite.org/c3ref/open.html open :: Text -> IO Database -- | http://www.sqlite.org/c3ref/close.html close :: Database -> IO () -- | Execute zero or more SQL statements delimited by semicolons. exec :: Database -> Text -> IO () -- | Like exec, but print result rows to stdout. -- -- This is mainly for convenience when experimenting in GHCi. The output -- format may change in the future. execPrint :: Database -> Text -> IO () -- | Like exec, but invoke the callback for each result row. execWithCallback :: Database -> Text -> ExecCallback -> IO () type ExecCallback = ColumnCount -> [Text] -> [Maybe Text] -> IO () -- | http://www.sqlite.org/c3ref/prepare.html -- -- Unlike exec, prepare only executes the first statement, -- and ignores subsequent statements. -- -- If the query string contains no SQL statements, this fails. prepare :: Database -> Text -> IO Statement -- | http://www.sqlite.org/c3ref/prepare.html -- -- It can help to avoid redundant Utf8 to Text conversion if you already -- have Utf8 -- -- If the query string contains no SQL statements, this fails. prepareUtf8 :: Database -> Utf8 -> IO Statement -- | http://www.sqlite.org/c3ref/step.html step :: Statement -> IO StepResult -- | http://www.sqlite.org/c3ref/reset.html -- -- Note that in the C API, sqlite3_reset returns an error code -- if the most recent sqlite3_step indicated an error. We do not -- replicate that behavior here. reset never throws an exception. reset :: Statement -> IO () -- | http://www.sqlite.org/c3ref/finalize.html -- -- Like reset, finalize never throws an exception. finalize :: Statement -> IO () -- | http://www.sqlite.org/c3ref/clear_bindings.html -- -- Set all parameters in the prepared statement to null. clearBindings :: Statement -> IO () -- | http://www.sqlite.org/c3ref/bind_parameter_count.html -- -- This returns the index of the largest (rightmost) parameter. Note that -- this is not necessarily the number of parameters. If numbered -- parameters like ?5 are used, there may be gaps in the list. -- -- See ParamIndex for more information. bindParameterCount :: Statement -> IO ParamIndex -- | http://www.sqlite.org/c3ref/bind_parameter_name.html -- -- Return the N-th SQL parameter name. -- -- Named parameters are returned as-is. E.g. ":v" is returned as Just -- ":v". Unnamed parameters, however, are converted to -- Nothing. -- -- Note that the parameter index starts at 1, not 0. bindParameterName :: Statement -> ParamIndex -> IO (Maybe Text) -- | http://www.sqlite.org/c3ref/column_count.html columnCount :: Statement -> IO ColumnCount -- | http://www.sqlite.org/c3ref/column_name.html -- -- Return the name of a result column. If the column index is out of -- range, return Nothing. columnName :: Statement -> ColumnIndex -> IO (Maybe Text) -- | If the index is not between 1 and bindParameterCount inclusive, -- this fails with ErrorRange. Otherwise, it succeeds, even if the -- query skips this index by using numbered parameters. -- -- Example: -- --
--   > stmt <- prepare conn "SELECT ?1, ?3, ?5"
--   > bindSQLData stmt 1 (SQLInteger 1)
--   > bindSQLData stmt 2 (SQLInteger 2)
--   > bindSQLData stmt 6 (SQLInteger 6)
--   *** Exception: SQLite3 returned ErrorRange while attempting to perform bind int64.
--   > step stmt >> columns stmt
--   [SQLInteger 1,SQLNull,SQLNull]
--   
bindSQLData :: Statement -> ParamIndex -> SQLData -> IO () -- | Convenience function for binding values to all parameters. This will -- fail if the list has the wrong number of parameters. bind :: Statement -> [SQLData] -> IO () -- | Convenience function for binding named values to all parameters. This -- will fail if the list has the wrong number of parameters or if -- an unknown name is used. -- -- Example: -- --
--   stmt <- prepare conn "SELECT :foo + :bar"
--   bindNamed stmt [(":foo", SQLInteger 1), (":bar", SQLInteger 2)]
--   
bindNamed :: Statement -> [(Text, SQLData)] -> IO () bindInt :: Statement -> ParamIndex -> Int -> IO () bindInt64 :: Statement -> ParamIndex -> Int64 -> IO () bindDouble :: Statement -> ParamIndex -> Double -> IO () bindText :: Statement -> ParamIndex -> Text -> IO () bindBlob :: Statement -> ParamIndex -> ByteString -> IO () bindZeroBlob :: Statement -> ParamIndex -> Int -> IO () bindNull :: Statement -> ParamIndex -> IO () column :: Statement -> ColumnIndex -> IO SQLData columns :: Statement -> IO [SQLData] -- | This avoids extra API calls using the list of column types. If passed -- types do not correspond to the actual types, the values will be -- converted according to the rules at -- http://www.sqlite.org/c3ref/column_blob.html. If the list -- contains more items that number of columns, the result is undefined. typedColumns :: Statement -> [Maybe ColumnType] -> IO [SQLData] columnType :: Statement -> ColumnIndex -> IO ColumnType columnInt64 :: Statement -> ColumnIndex -> IO Int64 columnDouble :: Statement -> ColumnIndex -> IO Double -- | This will throw a DecodeError if the datum contains invalid -- UTF-8. If this behavior is undesirable, you can use columnText -- from Database.SQLite3.Direct, which does not perform conversion -- to Text. columnText :: Statement -> ColumnIndex -> IO Text columnBlob :: Statement -> ColumnIndex -> IO ByteString -- | http://www.sqlite.org/c3ref/last_insert_rowid.html lastInsertRowId :: Database -> IO Int64 -- | http://www.sqlite.org/c3ref/changes.html -- -- Return the number of rows that were changed, inserted, or deleted by -- the most recent INSERT, DELETE, or UPDATE -- statement. changes :: Database -> IO Int -- | http://sqlite.org/c3ref/create_function.html -- -- Create a custom SQL function or redefine the behavior of an existing -- function. If the function is deterministic, i.e. if it always returns -- the same result given the same input, you can set the boolean flag to -- let sqlite perform additional optimizations. createFunction :: Database -> Text -> Maybe ArgCount -> Bool -> (FuncContext -> FuncArgs -> IO ()) -> IO () -- | Like createFunction except that it creates an aggregate -- function. createAggregate :: Database -> Text -> Maybe ArgCount -> a -> (FuncContext -> FuncArgs -> a -> IO a) -> (FuncContext -> a -> IO ()) -> IO () -- | Delete an SQL function (scalar or aggregate). deleteFunction :: Database -> Text -> Maybe ArgCount -> IO () funcArgCount :: FuncArgs -> ArgCount funcArgType :: FuncArgs -> ArgIndex -> IO ColumnType funcArgInt64 :: FuncArgs -> ArgIndex -> IO Int64 funcArgDouble :: FuncArgs -> ArgIndex -> IO Double funcArgText :: FuncArgs -> ArgIndex -> IO Text funcArgBlob :: FuncArgs -> ArgIndex -> IO ByteString funcResultSQLData :: FuncContext -> SQLData -> IO () funcResultInt64 :: FuncContext -> Int64 -> IO () funcResultDouble :: FuncContext -> Double -> IO () funcResultText :: FuncContext -> Text -> IO () funcResultBlob :: FuncContext -> ByteString -> IO () funcResultZeroBlob :: FuncContext -> Int -> IO () funcResultNull :: FuncContext -> IO () -- | https://www.sqlite.org/c3ref/context_db_handle.html getFuncContextDatabase :: FuncContext -> IO Database -- | http://www.sqlite.org/c3ref/create_collation.html createCollation :: Database -> Text -> (Text -> Text -> Ordering) -> IO () -- | Delete a collation. deleteCollation :: Database -> Text -> IO () -- | http://www.sqlite.org/c3ref/interrupt.html -- -- Cause any pending operation on the Database handle to stop at -- its earliest opportunity. This simply sets a flag and returns -- immediately. It does not wait for the pending operation to finish. -- -- You'll need to compile with -threaded for this to do any -- good. Without -threaded, FFI calls block the whole RTS, -- meaning interrupt would never run at the same time as -- step. interrupt :: Database -> IO () -- | Make it possible to interrupt the given database operation with an -- asynchronous exception. This only works if the program is compiled -- with base >= 4.3 and -threaded. -- -- It works by running the callback in a forked thread. If interrupted, -- it uses interrupt to try to stop the operation. interruptibly :: Database -> IO a -> IO a -- | https://www.sqlite.org/c3ref/blob_open.html -- -- Open a blob for incremental I/O. blobOpen :: Database -> Text -> Text -> Text -> Int64 -> Bool -> IO Blob -- | https://www.sqlite.org/c3ref/blob_close.html blobClose :: Blob -> IO () -- | https://www.sqlite.org/c3ref/blob_reopen.html blobReopen :: Blob -> Int64 -> IO () -- | https://www.sqlite.org/c3ref/blob_bytes.html blobBytes :: Blob -> IO Int -- | https://www.sqlite.org/c3ref/blob_read.html blobRead :: Blob -> Int -> Int -> IO ByteString blobReadBuf :: Blob -> Ptr a -> Int -> Int -> IO () -- | https://www.sqlite.org/c3ref/blob_write.html blobWrite :: Blob -> ByteString -> Int -> IO () backupInit :: Database -> Text -> Database -> Text -> IO Backup backupFinish :: Backup -> IO (()) backupStep :: Backup -> Int -> IO BackupStepResult backupRemaining :: Backup -> IO Int backupPagecount :: Backup -> IO Int data Database data Statement data SQLData SQLInteger :: !Int64 -> SQLData SQLFloat :: !Double -> SQLData SQLText :: !Text -> SQLData SQLBlob :: !ByteString -> SQLData SQLNull :: SQLData -- | Exception thrown when SQLite3 reports an error. -- -- direct-sqlite may throw other types of exceptions if you misuse the -- API. data SQLError SQLError :: !Error -> Text -> Text -> SQLError -- | Error code returned by API call sqlError :: SQLError -> !Error -- | Text describing the error sqlErrorDetails :: SQLError -> Text -- | Indicates what action produced this error, e.g. exec "SELECT * -- FROM foo" sqlErrorContext :: SQLError -> Text data ColumnType IntegerColumn :: ColumnType FloatColumn :: ColumnType TextColumn :: ColumnType BlobColumn :: ColumnType NullColumn :: ColumnType -- | The context in which a custom SQL function is executed. data FuncContext -- | The arguments of a custom SQL function. data FuncArgs -- | The type of blob handles used for incremental blob I/O data Blob -- | A handle for an online backup process. data Backup data StepResult Row :: StepResult Done :: StepResult data BackupStepResult -- | There are still more pages to be copied. BackupOK :: BackupStepResult -- | All pages were successfully copied. BackupDone :: BackupStepResult data Error -- | Successful result ErrorOK :: Error -- | SQL error or missing database ErrorError :: Error -- | Internal logic error in SQLite ErrorInternal :: Error -- | Access permission denied ErrorPermission :: Error -- | Callback routine requested an abort ErrorAbort :: Error -- | The database file is locked ErrorBusy :: Error -- | A table in the database is locked ErrorLocked :: Error -- | A malloc() failed ErrorNoMemory :: Error -- | Attempt to write a readonly database ErrorReadOnly :: Error -- | Operation terminated by sqlite3_interrupt() ErrorInterrupt :: Error -- | Some kind of disk I/O error occurred ErrorIO :: Error -- | The database disk image is malformed ErrorCorrupt :: Error -- | Unknown opcode in sqlite3_file_control() ErrorNotFound :: Error -- | Insertion failed because database is full ErrorFull :: Error -- | Unable to open the database file ErrorCan'tOpen :: Error -- | Database lock protocol error ErrorProtocol :: Error -- | Database is empty ErrorEmpty :: Error -- | The database schema changed ErrorSchema :: Error -- | String or BLOB exceeds size limit ErrorTooBig :: Error -- | Abort due to constraint violation ErrorConstraint :: Error -- | Data type mismatch ErrorMismatch :: Error -- | Library used incorrectly ErrorMisuse :: Error -- | Uses OS features not supported on host ErrorNoLargeFileSupport :: Error -- | Authorization denied ErrorAuthorization :: Error -- | Auxiliary database format error ErrorFormat :: Error -- | 2nd parameter to sqlite3_bind out of range ErrorRange :: Error -- | File opened that is not a database file ErrorNotADatabase :: Error -- | sqlite3_step() has another row ready ErrorRow :: Error -- | sqlite3_step() has finished executing ErrorDone :: Error -- | Index of a parameter in a parameterized query. Parameter indices start -- from 1. -- -- When a query is prepared, SQLite allocates an array indexed -- from 1 to the highest parameter index. For example: -- --
--   >Right stmt <- prepare conn "SELECT ?1, ?5, ?3, ?"
--   >bindParameterCount stmt
--   ParamIndex 6
--   
-- -- This will allocate an array indexed from 1 to 6 (? takes the -- highest preceding index plus one). The array is initialized with null -- values. When you bind a parameter with bindSQLData, it assigns -- a new value to one of these indices. -- -- See http://www.sqlite.org/lang_expr.html#varparam for the -- syntax of parameter placeholders, and how parameter indices are -- assigned. newtype ParamIndex ParamIndex :: Int -> ParamIndex -- | Index of a column in a result set. Column indices start from 0. newtype ColumnIndex ColumnIndex :: Int -> ColumnIndex -- | Number of columns in a result set. type ColumnCount = ColumnIndex -- | Number of arguments of a user defined SQL function. newtype ArgCount ArgCount :: Int -> ArgCount -- | Index of an argument to a custom function. Indices start from 0. type ArgIndex = ArgCount instance Typeable SQLData instance Typeable SQLError instance Eq SQLData instance Show SQLData instance Eq SQLError instance Exception SQLError instance Show SQLError