-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Low-level binding to SQLite3. Includes UTF8 and BLOB support. -- -- This package is not very different from the other SQLite3 bindings out -- there, but it fixes a few deficiencies I was finding. As compared to -- bindings-sqlite3, it is slightly higher-level, in that it supports -- marshalling of data values to and from the database. In particular, it -- supports strings encoded as UTF8, and BLOBs represented as -- ByteStrings. -- -- Release history: -- --
-- >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 -- | 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 CError instance Show CError instance Eq CColumnType instance Show CColumnType instance FFIType ColumnType CColumnType instance FFIType Error CError instance FFIType ColumnIndex CColumnIndex instance FFIType ParamIndex CParamIndex 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_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 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: -- --
-- autocommit <- getAutoCommit conn -- when (not autocommit) $ -- exec conn "ROLLBACK" --getAutoCommit :: Database -> IO Bool 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: -- --
-- >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 instance Eq Database instance Show Database instance Eq Statement instance Show Statement instance Eq StepResult instance Show StepResult instance Eq Utf8 instance Ord Utf8 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 () 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 () 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://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 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 data StepResult Row :: StepResult Done :: StepResult 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 instance Typeable SQLData instance Typeable SQLError instance Eq SQLData instance Show SQLData instance Exception SQLError instance Show SQLError