| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Database.ODBC.Internal
Description
ODBC database API.
WARNING: This API is meant as a base for more high-level APIs, such as the one provided in Database.ODBC.SQLServer. The commands here are all vulerable to SQL injection attacks. See https://en.wikipedia.org/wiki/SQL_injection for more information.
Don't use this module if you don't know what you're doing.
- connect :: MonadIO m => Text -> m Connection
- close :: MonadIO m => Connection -> m ()
- withConnection :: MonadUnliftIO m => Text -> (Connection -> m a) -> m a
- data Connection
- exec :: MonadIO m => Connection -> Text -> m ()
- query :: MonadIO m => Connection -> Text -> m [[Value]]
- data Value
- newtype Binary = Binary {}
- stream :: (MonadIO m, MonadUnliftIO m) => Connection -> Text -> (state -> [Value] -> m (Step state)) -> state -> m state
- data Step a
- data ODBCException
Connect/disconnect
Arguments
| :: MonadIO m | |
| => Text | An ODBC connection string. |
| -> m Connection | A connection to the database. You should call |
Connect using the given connection string.
Arguments
| :: MonadIO m | |
| => Connection | A connection to the database. |
| -> m () |
Close the connection. Further use of the Connection will throw
an exception. Double closes also throw an exception to avoid
architectural mistakes.
Arguments
| :: MonadUnliftIO m | |
| => Text | An ODBC connection string. |
| -> (Connection -> m a) | Program that uses the ODBC connection. |
| -> m a |
data Connection Source #
Connection to a database. Use of this connection is thread-safe. When garbage collected, the connection will be closed if not done already.
Executing queries
Arguments
| :: MonadIO m | |
| => Connection | A connection to the database. |
| -> Text | SQL statement. |
| -> m () |
Execute a statement on the database.
Arguments
| :: MonadIO m | |
| => Connection | A connection to the database. |
| -> Text | SQL query. |
| -> m [[Value]] | A strict list of rows. This list is not lazy, so if you are retrieving a large data set, be aware that all of it will be loaded into memory. |
Query and return a list of rows.
A value used for input/output with the database.
Constructors
| TextValue !Text | A Unicode text value. |
| ByteStringValue !ByteString | A vector of bytes. It might be binary, or a string, but we
don't know the encoding. Use |
| BinaryValue !Binary | Only a vector of bytes. Intended for binary data, not for ASCII text. |
| BoolValue !Bool | A simple boolean. |
| DoubleValue !Double | Floating point values that fit in a |
| FloatValue !Float | Floating point values that fit in a |
| IntValue !Int | Integer values that fit in an |
| ByteValue !Word8 | Values that fit in one byte. |
| DayValue !Day | Date (year, month, day) values. |
| TimeOfDayValue !TimeOfDay | Time of day (hh, mm, ss + fractional) values. |
| LocalTimeValue !LocalTime | Local date and time. |
| NullValue | SQL null value. |
A simple newtype wrapper around the ByteString type to use when
you want to mean the binary type of SQL, and render to binary
literals e.g. 0xFFEF01.
The ByteString type is already mapped to the non-Unicode text
type.
Constructors
| Binary | |
Fields | |
Streaming results
Arguments
| :: (MonadIO m, MonadUnliftIO m) | |
| => Connection | A connection to the database. |
| -> Text | SQL query. |
| -> (state -> [Value] -> m (Step state)) | A stepping function that gets as input the current |
| -> state | A state that you can use for the computation. Strictly evaluated each iteration. |
| -> m state | Final result, produced by the stepper function. |
Stream results like a fold with the option to stop at any time.
A step in the streaming process for the stream function.
Exceptions
data ODBCException Source #
A database exception. Any of the functions in this library may throw this exception type.
Constructors
| UnsuccessfulReturnCode !String !Int16 !String | An ODBC operation failed with the given return code. |
| AllocationReturnedNull !String | Allocating an ODBC resource failed. |
| UnknownDataType !String !Int16 | An unsupported/unknown data type was returned from the ODBC driver. |
| DatabaseIsClosed !String | You tried to use the database connection after it was closed. |
| DatabaseAlreadyClosed | You attempted to |
| NoTotalInformation !Int | No total length information for column. |
| DataRetrievalError !String | There was a general error retrieving data. String will contain the reason why. |
Instances