squeather-0.2.0.0: Use databases with the version 3 series of the SQLite C library

Safe HaskellSafe
LanguageHaskell2010

Squeather.Internal

Synopsis

Documentation

data C'sqlite3 Source #

SQLite3 database handle

data C'sqlite3_stmt Source #

SQLite3 statement handle

data C'void Source #

Void

data Database Source #

Database handle. To create a database handle, use open. After creating and using the handle, be sure to clean it up using close as this is not done automatically. Consider using bracket to make allocation and cleanup exception-safe.

Constructors

Database 

Fields

Instances
Eq Database Source # 
Instance details

Defined in Squeather.Internal

Ord Database Source # 
Instance details

Defined in Squeather.Internal

Show Database Source # 
Instance details

Defined in Squeather.Internal

data Statement Source #

Statement handle. To create a statement handle, use prepare. After creating and using a Statement, be sure to clean it up using finalize as this is not done automatically. Consider using bracket to make allocation and cleanup exception-safe.

Constructors

Statement 

Fields

data SqueatherErrorFlag Source #

Errors produced by the Squeather library (as opposed to being caused directly by the underlying SQLite3 C library.)

Constructors

ParameterNotFound

Named parameter for SQL statement not found

ExecFailed

The exec function found an error string

IntConversion

Failed to convert an Int to a CInt or vice-versa because the values were out of range.

UnknownColumnType CInt

sqlite3_column_type returned a type Squeather didn't identify.

UnknownSqliteError CInt

SQLite returned an error code that is uknown to Squeather.

IncompleteBackup

A backup was started, but it did not finish running.

Bug

These failures should never happen and indicate a bug in Squeather.

ColumnNameNull Int

The call to sqlite3_column_name returned a null pointer.

data Error Source #

Exceptions. Squeather indicates all errors (even those arising from possible bugs) by throwing exceptions of this type.

Constructors

Error 

Fields

Instances
Eq Error Source # 
Instance details

Defined in Squeather.Internal

Methods

(==) :: Error -> Error -> Bool #

(/=) :: Error -> Error -> Bool #

Ord Error Source # 
Instance details

Defined in Squeather.Internal

Methods

compare :: Error -> Error -> Ordering #

(<) :: Error -> Error -> Bool #

(<=) :: Error -> Error -> Bool #

(>) :: Error -> Error -> Bool #

(>=) :: Error -> Error -> Bool #

max :: Error -> Error -> Error #

min :: Error -> Error -> Error #

Show Error Source # 
Instance details

Defined in Squeather.Internal

Methods

showsPrec :: Int -> Error -> ShowS #

show :: Error -> String #

showList :: [Error] -> ShowS #

Exception Error Source # 
Instance details

Defined in Squeather.Internal

sqlite3_open_v2 Source #

Arguments

:: Ptr CChar

Database filename, UTF-8

-> Ptr (Ptr C'sqlite3)

OUT: SQLite db handle

-> CInt

Flags

-> Ptr CChar

VFS module to use

-> IO CInt 

readUtf8 :: Ptr CChar -> IO Text Source #

Reads a UTF-8 text.

writeUtf8 :: Text -> (Ptr CChar -> IO a) -> IO a Source #

Writes a UTF-8 text for foreign function use.

writeUtf8Len :: Text -> ((Ptr CChar, Int) -> IO a) -> IO a Source #

Like writeUtf8 but instead returns a CStringLen.

checkError Source #

Arguments

:: Database 
-> Text

Context

-> CInt 
-> IO () 

Checks SQLite return code. Throws an exception if the code is an error. Otherwise, returns successfully. Do not use this function if checking the return code from a function such as sqlite3_step; instead, use checkStepError.

checkStepError Source #

Arguments

:: Database 
-> Text

Context

-> CInt 
-> IO StepResult 

Like checkError but for use when using sqlite3_step.

open Source #

Arguments

:: Text

Database filename

-> IO Database 

Opens a new Database. The openFlags are used.

openWithFlags Source #

Arguments

:: OpenFlags 
-> Text

Database filename

-> IO Database 

Opens a new Database, with settings specified with openFlags.

sqlite3_prepare_v2 Source #

Arguments

:: Ptr C'sqlite3

Database handle

-> Ptr CChar

SQL Statement, UTF-8

-> CInt

Length of SQL statement in bytes

-> Ptr (Ptr C'sqlite3_stmt)

OUT Statement handle

-> Ptr (Ptr CChar)

OUT unused portion of input statement

-> IO CInt 

prepare Source #

Arguments

:: Database

Database handle

-> Text

SQL Statement, UTF-8

-> IO Statement 

Prepares a statement. The corresponding C SQLite function allows you to pass in a multi-statement SQL text, and retrieve the unused portion for later use. Squeather does not allow this. Squeather will prepare only the first statement.

sqlite3_bind_parameter_index Source #

Arguments

:: Ptr C'sqlite3_stmt

Statement

-> Ptr CChar

Parameter name

-> IO CInt

The index of the parameter. Returns 0 if no matching parameter is found.

getParameterIndex Source #

Arguments

:: Statement 
-> Text

Look up the parameter with this name.

-> IO CInt 

Gets the index of the parameter that has the given name. Throws an Error with ParameterNotFound if the given parameter name does not exist for this statement.

sqlite3_bind_blob Source #

Arguments

:: Ptr C'sqlite3_stmt 
-> CInt

Index

-> Ptr a

Blob

-> CInt

Length

-> FunPtr (Ptr a -> IO ())

Callback to dispose of the blob. Use SQLITE_STATIC if the blob is in static, unmanaged space and does not need to be freed. Use SQLITE_TRANSIENT to have SQLite make its own private copy of the data immediately.

-> IO CInt 

bindBlob Source #

Arguments

:: Statement 
-> Text

Parameter name

-> ByteString

Blob

-> IO () 

bindDouble Source #

Arguments

:: Statement 
-> Text

Parameter name

-> Double 
-> IO () 

bindInt64 Source #

Arguments

:: Statement 
-> Text

Parameter name

-> Int64 
-> IO () 

bindNull Source #

Arguments

:: Statement 
-> Text

Parameter name

-> IO () 

sqlite3_bind_text Source #

Arguments

:: Ptr C'sqlite3_stmt 
-> CInt

Index

-> Ptr CChar

UTF-8 text

-> CInt

Length

-> FunPtr (Ptr a -> IO ())

Callback to dispose of the string. Use SQLITE_STATIC if the string is in static, unmanaged space and does not need to be freed. Use SQLITE_TRANSIENT to have SQLite make its own private copy of the data immediately.

-> IO CInt 

bindText Source #

Arguments

:: Statement 
-> Text

Parameter name

-> Text

Text to bind

-> IO () 

bindSqlData Source #

Arguments

:: Statement 
-> Text

Parameter name

-> SQLData 
-> IO () 

Binds a parameter with given SQL data to the given Statement.

step :: Statement -> IO StepResult Source #

Evaluate a prepared statement. Returns Row if the Statement has returned a row of data. In that case, use column or columns to get individual columns or all columns, respectively. Returns Done if there is no data to retrieve. In that case, step should not be called again without first calling reset.

sqlite3_column_count :: Ptr C'sqlite3_stmt -> IO CInt Source #

The number of columns returned by the prepared statement. Can be zero. However, just because this routine returns a positive number does not mean that data will be returned. A SELECT statement will always return a postive column count, but a particular query might return no rows.

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

column Source #

Arguments

:: Statement 
-> Int

Index

-> IO SQLData 

Retrieves a column with a given index from the Statement. Assumes that step was already called and that it returned Row.

columnCount :: Statement -> IO Int Source #

The number of columns that a given Statement will return. Works regardless of whether step has been applied or not; however, just because this returns a positive value does not mean that step will ever actually return a Row.

columns :: Statement -> IO [SQLData] Source #

Return all available columns, in order, from a Statement on which step returned Row. You should already have applied step.

allRows :: Statement -> IO [[SQLData]] Source #

Retrieves all remaining rows from a Statement. Applies step for you for as many times as needed.

bindParams :: Statement -> [(Text, SQLData)] -> IO () Source #

Bind multiple named parameters to a Statement.

execute Source #

Arguments

:: Database 
-> Text

SQL text

-> IO [[SQLData]]

All SQL data from the query.

Execute a query without any parameters. Executes only one query - there is no need to terminate it with a semicolon, although you can. If you use a semicolon-separated list of queries, only the first query will be run. There is no way to use SQL parameters; for that you will need executeNamed.

executeNamed Source #

Arguments

:: Database 
-> Text

SQL text

-> [(Text, SQLData)]

Pairs, where each Text is a named parameter and each SQLData is the corresponding data to bind to that parameter. This page describes the different parameter syntax that is allowed. Squeather makes no effort to support the plain ? syntax. Note that the leading mark (?, :, @, or $) is part of the parameter name and must appear as part of the Text.

-> IO [[SQLData]]

All SQL data from the query.

Execute a query with named parameters. Executes only one query - there is no need to terminate it with a semicolon, although you can. If you use a semicolon-separated list of queries, only the first query will be run.

executeNamedWithColumns Source #

Arguments

:: Database 
-> Text

SQL text

-> [(Text, SQLData)]

Pairs, where each Text is a named parameter and each SQLData is the corresponding data to bind to that parameter. This page describes the different parameter syntax that is allowed. Squeather makes no effort to support the plain ? syntax. Note that the leading mark (?, :, @, or $) is part of the parameter name and must appear as part of the Text.

-> IO ([Text], [[SQLData]])

The column names, and all SQL data from the query.

Like executeNamed but also returns the names of the columns in addition to the SQL results.

reset :: Statement -> IO () Source #

Resets a Statement so it may be re-executed. Does not clear bindings. In SQLite, sqlite3_reset returns an error code if the most recent step statement returned an error. reset does not do this. It does not check the error code returned by sqlite3_reset.

clearBindings :: Statement -> IO () Source #

Clears all bindings on the Statement.

finalize :: Statement -> IO () Source #

Finalize a statement. Frees up resources the statement used. Any use of the statement after finalization can result in undefined and undesirable behavior. In the SQLite library, this returns an error code if the most recent evaluation of the statement failed. This function does not replicate that behavior; it does not check the return result of sqlite3_finalize. (In general such behvaior is not necessary; if the previous action caused a failure, it should already have thrown an exception.)

close :: Database -> IO () Source #

Closes and cleans up a database handle.

type ExecCallback a Source #

Arguments

 = Ptr a

The fourth argument of sqlite3_exec is passed through here.

-> CInt

The number of columns in the result

-> Ptr (Ptr CChar)

An array of pointers to strings obtained as if from sqlite3_column_text

-> Ptr (Ptr CChar)

An array of pointers to strings where each entry represents the name of the corresponding result column as obtained from sqlite3_column_name

-> IO CInt

The function should return zero if successful. If it returns non-zero, then SQLITE_ABORT will be thrown without involking the callback again and without running any more SQL statements.

The type of the callback from sqlite3_exec. This callback is invoked for every row of data.

sqlite3_exec Source #

Arguments

:: Ptr C'sqlite3 
-> Ptr CChar

SQL

-> FunPtr (ExecCallback a)

Callback. Pass nullFunPtr if you do not with to use a callback.

-> Ptr a

Passed to callback for every row

-> Ptr (Ptr CChar)

If there is a failure, the error message is written here. If there is no failure, nullPtr is written here.

-> IO CInt 

exec Source #

Arguments

:: Database 
-> Text

SQL to be evaluated. Multiple, semicolon-separated statements will be executed.

-> IO () 

Evaluate one or more SQL statements. There is no way to obtain the results; for that you will need execute or executeNamed. There is no way to use SQL parameters; for that you will need executeNamed.

lastInsertRowId :: Database -> IO Int64 Source #

Get the rowid of the most recent successful INSERT.

intToCInt Source #

Arguments

:: Text

Context. For error messages only.

-> Text

Database filename. For error messages only.

-> Int 
-> IO CInt 

Convert from an Int to a CInt. Makes sure the conversion fits in the space allotted. Throws an exception if it doesn't fit.

intFromCInt Source #

Arguments

:: Text

Context. For error messages only.

-> Text

Database filename. For error messages only.

-> CInt 
-> IO Int 

Convert from an CInt to a Int. Makes sure the conversion fits in the space allotted. Throws an exception if it doesn't fit.

sqliteVersion :: String Source #

Returns a string which is the version number for SQLite used to build this library. SQLite is embedded into the library, so the only way to change the SQLite version is to recompile the library.

openFlags :: OpenFlags Source #

Default settings for OpenFlags, where the writeMode is ReadWrite Create, fullMutex is True, and all other flags are set to False.

sqlite3_backup_init Source #

Arguments

:: Ptr C'sqlite3

Destination database handle

-> Ptr CChar

Destination database name - main for the main database, temp for the temporary database, or the name specified after the AS keyword in an ATTACH statement for an attached database.

-> Ptr C'sqlite3

Source database handle

-> Ptr CChar

Source database name

-> IO (Ptr C'sqlite3_backup)

Returns pointer to backup object

sqlite3_backup_step Source #

Arguments

:: Ptr C'sqlite3_backup 
-> CInt

Number of pages. If negative, copy all remaining source pages.

-> IO CInt

Returns error code

sqlite3_backup_remaining Source #

Arguments

:: Ptr C'sqlite3_backup 
-> IO CInt

Returns number of pages remaining to be backed up

data Source Source #

Backup source

Constructors

Source 

Fields

  • sourceConnection :: Database
     
  • sourceName :: Text

    The name for the source database. Use main for the main database, temp for the temporary database, or the name specified after the AS keyword in an ATTACH statement for an attached database.

Instances
Eq Source Source # 
Instance details

Defined in Squeather.Internal

Methods

(==) :: Source -> Source -> Bool #

(/=) :: Source -> Source -> Bool #

Ord Source Source # 
Instance details

Defined in Squeather.Internal

Show Source Source # 
Instance details

Defined in Squeather.Internal

data Destination Source #

Backup destination

Constructors

Destination 

Fields

  • destConnection :: Database
     
  • destName :: Text

    The name for the destination database. Use main for the main database, temp for the temporary database, or the name specified after the AS keyword in an ATTACH statement for an attached database.

backup :: Source -> Destination -> IO () Source #

Use the SQLite backup API to copy the content of one database to another. Can be used to safely copy databases while they are in use, or to copy in-memory databases to or from persistent files.

changes :: Database -> IO Int Source #

Count the number of rows modified by the most recent INSERT, UPDATE, or DELETE statement.

columnName Source #

Arguments

:: Statement 
-> Int

Index. The leftmost column is 0.

-> IO Text 

Gets the name of a column. The name is the value of the AS clause if it exists, or is an undefined string otherwise.

columnNames :: Statement -> IO [Text] Source #

Gets all column names, in order.