HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Moduledirect-sqlite-2.3.29Haskell2010

Database.SQLite3

Contents
  1. Connection management
  2. Simple query execution
  3. Statement management
  4. Parameter and column information
  5. Binding values to a prepared statement
  6. Reading the result row
  7. Result statistics
  8. Create custom SQL functions
  9. Extract function arguments
  10. Set the result of a function
  11. Create custom collations
  12. Interrupting a long-running query
  13. Incremental blob I/O
  14. Online Backup API
  15. Types
  16. Results and errors
  17. Special integers
Synopsis

Connection management

Simple query execution

valueexecPrint :: Database -> Text -> IO ()

Like exec, but print result rows to System.IO.stdout.

This is mainly for convenience when experimenting in GHCi. The output format may change in the future.

Statement management

Parameter and column information

Binding values to a prepared statement

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]
valuebind :: Statement -> [SQLData] -> IO ()

Convenience function for binding values to all parameters. This will fail if the list has the wrong number of parameters.

valuebindNamed :: Statement -> [(Text, 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)]

Reading the result row

https://www.sqlite.org/c3ref/column_blob.html

Warning: column and columns will throw a DecodeError if any TEXT datum contains invalid UTF-8.

Result statistics

Create custom SQL functions

valuecreateFunction
  1. :: Database
  2. -> Text

    Name of the function.

  3. -> Maybe ArgCount

    Number of arguments. Nothing means that the function accepts any number of arguments.

  4. -> Bool

    Is the function deterministic?

  5. -> (FuncContext -> FuncArgs -> IO ())

    Implementation of the function.

  6. -> IO ()

https://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.

Extract function arguments

Set the result of a function

Create custom collations

Interrupting a long-running query

valueinterrupt :: Database -> IO ()

https://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.

valueinterruptibly :: Database -> IO a -> IO a

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.

Incremental blob I/O

Online Backup API

Types

newtypenewtype Database
#
Instances2Eq, Show
  • Eq DatabaseDefined in direct-sqlite-2.3.29 · Database.SQLite3.Direct
  • Show DatabaseDefined in direct-sqlite-2.3.29 · Database.SQLite3.Direct
newtypenewtype Statement
#
Instances2Eq, Show
  • Eq StatementDefined in direct-sqlite-2.3.29 · Database.SQLite3.Direct
  • Show StatementDefined in direct-sqlite-2.3.29 · Database.SQLite3.Direct
datadata SQLData
#
Instances4Eq, Show, Generic, Rep
datadata SQLOpenFlag
Instances2Eq, Show
datadata SQLError

Exception thrown when SQLite3 reports an error.

direct-sqlite may throw other types of exceptions if you misuse the API.

Constructors

Instances5Eq, Show, Generic, Exception, Rep
newtypenewtype FuncContext

The context in which a custom SQL function is executed.

Instances2Eq, Show
  • Eq FuncContextDefined in direct-sqlite-2.3.29 · Database.SQLite3.Direct
  • Show FuncContextDefined in direct-sqlite-2.3.29 · Database.SQLite3.Direct
datadata Blob

The type of blob handles used for incremental blob I/O

Instances2Eq, Show
  • Eq BlobDefined in direct-sqlite-2.3.29 · Database.SQLite3.Direct
  • Show BlobDefined in direct-sqlite-2.3.29 · Database.SQLite3.Direct
datadata Backup

A handle for an online backup process.

Instances2Eq, Show
  • Eq BackupDefined in direct-sqlite-2.3.29 · Database.SQLite3.Direct
  • Show BackupDefined in direct-sqlite-2.3.29 · Database.SQLite3.Direct

Results and errors

datadata Error

Constructors

Instances5Eq, Show, Generic, FFIType, Rep

Special integers

newtypenewtype ParamIndex

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 https://www.sqlite.org/lang_expr.html#varparam for the syntax of parameter placeholders, and how parameter indices are assigned.

Constructors

Instances9Bounded, Enum, Eq, Integral, Num, Ord, …
  • Bounded ParamIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types

    Limit min/max bounds to fit into SQLite's native parameter ranges.

  • Enum ParamIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Eq ParamIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Integral ParamIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Num ParamIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Ord ParamIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Real ParamIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Show ParamIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types

    This just shows the underlying integer, without the data constructor.

  • FFIType ParamIndex CParamIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
newtypenewtype ColumnIndex

Index of a column in a result set. Column indices start from 0.

Constructors

Instances9Bounded, Enum, Eq, Integral, Num, Ord, …
  • Bounded ColumnIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types

    Limit min/max bounds to fit into SQLite's native parameter ranges.

  • Enum ColumnIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Eq ColumnIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Integral ColumnIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Num ColumnIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Ord ColumnIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Real ColumnIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Show ColumnIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types

    This just shows the underlying integer, without the data constructor.

  • FFIType ColumnIndex CColumnIndexDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
newtypenewtype ArgCount

Number of arguments of a user defined SQL function.

Constructors

Instances9Bounded, Enum, Eq, Integral, Num, Ord, …
  • Bounded ArgCountDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Enum ArgCountDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Eq ArgCountDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Integral ArgCountDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Num ArgCountDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Ord ArgCountDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Real ArgCountDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types
  • Show ArgCountDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types

    This just shows the underlying integer, without the data constructor.

  • FFIType ArgCount CArgCountDefined in direct-sqlite-2.3.29 · Database.SQLite3.Bindings.Types