HDBC-1.1.3: Haskell Database ConnectivityContentsIndex
Database.HDBC.Statement
Synopsis
data Statement = Statement {
execute :: ([SqlValue] -> IO Integer)
executeMany :: ([[SqlValue]] -> IO ())
finish :: (IO ())
fetchRow :: (IO (Maybe [SqlValue]))
getColumnNames :: (IO [String])
originalQuery :: String
describeResult :: (IO [(String, SqlColDesc)])
}
data SqlError = SqlError {
seState :: String
seNativeError :: Int
seErrorMsg :: String
}
class Show a => SqlType a where
toSql :: a -> SqlValue
fromSql :: SqlValue -> a
nToSql :: Integral a => a -> SqlValue
iToSql :: Int -> SqlValue
data SqlValue
= SqlString String
| SqlByteString ByteString
| SqlWord32 Word32
| SqlWord64 Word64
| SqlInt32 Int32
| SqlInt64 Int64
| SqlInteger Integer
| SqlChar Char
| SqlBool Bool
| SqlDouble Double
| SqlRational Rational
| SqlEpochTime Integer
| SqlTimeDiff Integer
| SqlNull
Documentation
data Statement
Constructors
Statement
execute :: ([SqlValue] -> IO Integer)

Execute the prepared statement, passing in the given positional parameters (that should take the place of the question marks in the call to prepare).

For non-SELECT queries, the return value is the number of rows modified, if known. If no rows were modified, you get 0. If the value is unknown, you get -1. All current HDBC drivers support this function and should never return -1.

For SELECT queries, you will always get 0.

This function should automatically call finish() to finish the previous execution, if necessary.

executeMany :: ([[SqlValue]] -> IO ())

Execute the query with many rows. The return value is the return value from the final row as if you had called execute on it.

Due to optimizations that are possible due to different databases and driver designs, this can often be significantly faster than using execute multiple times since queries need to be compiled only once.

This is most useful for non-SELECT statements.

finish :: (IO ())Abort a query in progress -- usually not needed.
fetchRow :: (IO (Maybe [SqlValue]))Fetches one row from the DB. Returns Nothing if there are no more rows. Will automatically call finish when the last row is read.
getColumnNames :: (IO [String])

Returns a list of the column names in the result. For maximum portability, you should not assume that information is available until after an execute function has been run.

Information is returned here directly as returned by the underlying database layer. Note that different databases have different rules about capitalization of return values and about representation of names of columns that are not simple columns. For this reason, it is suggested that you treat this information for display purposes only. Failing that, you should convert to lower (or upper) case, and use AS clauses for anything other than simple columns.

A simple getColumnNames implementation could simply apply map fst to the return value of describeResult.

originalQuery :: StringThe original query that this Statement was prepared with.
describeResult :: (IO [(String, SqlColDesc)])

Obtain information about the columns in the result set. Must be run only after execute. The String in the result set is the column name.

You should expect this to be returned in the same manner as a result from fetchAllRows'.

All results should be converted to lowercase for you before you see them.

Please see caveats under getColumnNames for information on the column name field here.

data SqlError

The main HDBC exception object. As much information as possible is passed from the database through to the application through this object.

Errors generated in the Haskell layer will have seNativeError set to -1.

Constructors
SqlError
seState :: String
seNativeError :: Int
seErrorMsg :: String
show/hide Instances
class Show a => SqlType a where

Conversions to and from SqlValues and standard Haskell types.

Conversions are powerful; for instance, you can call fromSql on a SqlInt32 and get a String or a Double out of it. This class attempts to Do The Right Thing whenever possible, and will raise an error when asked to do something incorrect. In particular, when converting to any type except a Maybe, SqlNull as the input will cause an error to be raised.

Here are some notes about conversion:

  • Fractions of a second are not preserved on time values

See also nToSql, iToSql.

Methods
toSql :: a -> SqlValue
fromSql :: SqlValue -> a
show/hide Instances
nToSql :: Integral a => a -> SqlValue
Converts any Integral type to a SqlValue by using toInteger.
iToSql :: Int -> SqlValue
Convenience function for using numeric literals in your program.
data SqlValue

The main type for expressing Haskell values to SQL databases.

This type is used to marshall Haskell data to and from database APIs. HDBC driver interfaces will do their best to use the most accurate and efficient way to send a particular value to the database server.

Values read back from the server are put in the most appropriate SqlValue type. fromSql can then be used to convert them into whatever type is needed locally in Haskell.

Most people will use toSql and fromSql instead of manipulating SqlValues directly.

The default representation of time values is an integer number of seconds. Databases such as PostgreSQL with builtin timestamp types can will see automatic conversion between these Haskell types to local types. Other databases can just use an int or a string.

This behavior also exists for other types. For instance, many databases don't have a Rational type, so they'll just use Haskell's show function and store a Rational as a string.

Two SqlValues are considered to be equal if one of these hold (first one that is true holds; if none are true, they are not equal): * Both are NULL * Both represent the same type and the encapsulated values are equal * The values of each, when converted to a string, are equal.

Constructors
SqlString String
SqlByteString ByteString
SqlWord32 Word32
SqlWord64 Word64
SqlInt32 Int32
SqlInt64 Int64
SqlInteger Integer
SqlChar Char
SqlBool Bool
SqlDouble Double
SqlRational Rational
SqlEpochTime IntegerRepresentation of ClockTime or CalendarTime
SqlTimeDiff IntegerRepresentation of TimeDiff
SqlNullNULL in SQL or Nothing in Haskell
show/hide Instances
Produced by Haddock version 0.8