-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Database access from Haskell. -- -- Simple library for database access from Haskell. @package hsql @version 1.8.2 module DB.HSQL.Type -- | Variety of common data types used in databases. data SqlType SqlInteger :: SqlType SqlBigInt :: SqlType SqlSmallInt :: SqlType SqlTinyInt :: SqlType SqlMedInt :: SqlType SqlDecimal :: Int -> Int -> SqlType typeSize :: SqlType -> Int typeDecimals :: SqlType -> Int SqlNumeric :: Int -> Int -> SqlType typeSize :: SqlType -> Int typeDecimals :: SqlType -> Int SqlReal :: SqlType SqlDouble :: SqlType SqlFloat :: SqlType SqlMoney :: SqlType SqlChar :: Int -> SqlType typeSize :: SqlType -> Int SqlVarChar :: Int -> SqlType typeSize :: SqlType -> Int SqlLongVarChar :: Int -> SqlType typeSize :: SqlType -> Int SqlText :: SqlType SqlWChar :: Int -> SqlType typeSize :: SqlType -> Int SqlWVarChar :: Int -> SqlType typeSize :: SqlType -> Int SqlWLongVarChar :: Int -> SqlType typeSize :: SqlType -> Int SqlDate :: SqlType SqlTime :: SqlType SqlTimeTZ :: SqlType SqlAbsTime :: SqlType SqlRelTime :: SqlType SqlTimeInterval :: SqlType SqlAbsTimeInterval :: SqlType SqlTimeStamp :: SqlType SqlDateTime :: SqlType SqlDateTimeTZ :: SqlType SqlYear :: SqlType SqlBit :: SqlType SqlENUM :: SqlType SqlPoint :: SqlType SqlLSeg :: SqlType SqlPath :: SqlType SqlBox :: SqlType SqlPolygon :: SqlType SqlLine :: SqlType SqlCircle :: SqlType SqlINetAddr :: SqlType SqlCIDRAddr :: SqlType SqlMacAddr :: SqlType SqlBinary :: Int -> SqlType typeSize :: SqlType -> Int SqlVarBinary :: Int -> SqlType typeSize :: SqlType -> Int SqlLongVarBinary :: Int -> SqlType typeSize :: SqlType -> Int SqlSET :: SqlType SqlBLOB :: SqlType -- | HSQL returns SqlUnknown for all columns for which it cannot -- determine the right type. The backendTypeCode here is the -- internal type code returned from the backend library SqlUnknown :: Int -> SqlType typeCode :: SqlType -> Int instance Eq SqlType instance Ord SqlType instance Show SqlType instance Read SqlType -- | SqlError type for a variety of DB specific error conditions, -- with appropriate Show, Typeable, and Exception -- instances. module DB.HSQL.Error data SqlError -- | generic error condition, with further specification SqlError :: String -> Int -> String -> SqlError seState :: SqlError -> String seNativeError :: SqlError -> Int seErrorMsg :: SqlError -> String -- | no more data was available SqlNoMoreData :: SqlError -- | requested handle is invalid SqlInvalidHandle :: SqlError -- | connection is blocked by running transaction SqlStillExecuting :: SqlError -- | more data is needed, e.g. additional connection specs SqlNeedMoreData :: SqlError -- | requested field can't be converted to requested type SqlBadTypeCast :: String -> SqlType -> SqlError seFieldName :: SqlError -> String seFieldType :: SqlError -> SqlType -- | requested field returns NULL SqlFetchNull :: String -> SqlError seFieldName :: SqlError -> String -- | requested field isn't known SqlUnknownField :: String -> SqlError seFieldName :: SqlError -> String -- | requested operation isn't supported SqlUnsupportedOperation :: SqlError -- | referenced handle is already closed SqlClosedHandle :: SqlError instance Typeable SqlError instance Eq SqlError instance Ord SqlError instance Exception SqlError instance Show SqlError -- | Basic type class & type definitions for DB interfacing. module Database.HSQL.Types -- | An SQL Query. type SQL = String -- | A table ID. type TableId = String -- | A Connection type represents a connection to a database, -- through which you can operate on the it. In order to create the -- connection you need to use the connect function from the -- module for your prefered backend. data Connection Connection :: IO () -> (SQL -> IO ()) -> (SQL -> IO Statement) -> IO [TableId] -> (TableId -> IO [ColDef]) -> IO () -> IO () -> IO () -> MVar Bool -> Connection -- | disconnect action connDisconnect :: Connection -> IO () -- | query execution action (without return value) connExecute :: Connection -> SQL -> IO () -- | query action with return value connQuery :: Connection -> SQL -> IO Statement -- | retrieval of the names of the tables in reach connTables :: Connection -> IO [TableId] -- | retrieval of the field defs of a table connDescribe :: Connection -> TableId -> IO [ColDef] -- | begin of a transaction connBeginTransaction :: Connection -> IO () -- | commit of a pending transaction connCommitTransaction :: Connection -> IO () -- | rollback of a pending transaction connRollbackTransaction :: Connection -> IO () -- | closing state of the connection connClosed :: Connection -> MVar Bool -- | A table column ID. type ColId = String -- | Whether fields of a table col may be NULL. type Nullability = Bool -- | Description of the properties of a table column. type ColDef = (ColId, SqlType, Nullability) -- | A DB generic field extraction function, specifiable by field -- definition, receiving the content code and its length. type FieldReader t = ColDef -> CString -> Int -> IO t -- | An extraction of a field of type to be specified by requester, from a -- row index with source ColDef, applying an appropriate -- FieldReader. type FieldReading = forall t. Int -> ColDef -> FieldReader t -> IO t -- | The Statement type represents a result from the execution of -- given SQL query. data Statement Statement :: Connection -> IO () -> IO Bool -> FieldReading -> [ColDef] -> MVar Bool -> Statement -- | DB connection the statement depends on stmtConn :: Statement -> Connection -- | close action stmtClose :: Statement -> IO () -- | incrementation of the row pointer and indication whether this is still -- in range of available rows stmtFetch :: Statement -> IO Bool -- | a FieldReading function applicable for each row stmtGetCol :: Statement -> FieldReading -- | field descriptors for each result table column stmtFields :: Statement -> [ColDef] -- | check whether the statement is closed stmtClosed :: Statement -> MVar Bool -- | Equivalent to Show and Read adapted to SQL expressions. class SqlBind a where fromSqlCStringLen (name, sqlType, _) cstr cstrLen | cstr == nullPtr = throw (SqlFetchNull name) | otherwise = do { str <- peekCStringLen (cstr, cstrLen); case fromSqlValue sqlType str of { Nothing -> throw (SqlBadTypeCast name sqlType) Just v -> return v } } toSqlValue :: SqlBind a => a -> SQL fromSqlValue :: SqlBind a => SqlType -> SQL -> Maybe a fromSqlCStringLen :: SqlBind a => ColDef -> CString -> Int -> IO a -- | Variety of common data types used in databases. data SqlType SqlInteger :: SqlType SqlBigInt :: SqlType SqlSmallInt :: SqlType SqlTinyInt :: SqlType SqlMedInt :: SqlType SqlDecimal :: Int -> Int -> SqlType typeSize :: SqlType -> Int typeDecimals :: SqlType -> Int SqlNumeric :: Int -> Int -> SqlType typeSize :: SqlType -> Int typeDecimals :: SqlType -> Int SqlReal :: SqlType SqlDouble :: SqlType SqlFloat :: SqlType SqlMoney :: SqlType SqlChar :: Int -> SqlType typeSize :: SqlType -> Int SqlVarChar :: Int -> SqlType typeSize :: SqlType -> Int SqlLongVarChar :: Int -> SqlType typeSize :: SqlType -> Int SqlText :: SqlType SqlWChar :: Int -> SqlType typeSize :: SqlType -> Int SqlWVarChar :: Int -> SqlType typeSize :: SqlType -> Int SqlWLongVarChar :: Int -> SqlType typeSize :: SqlType -> Int SqlDate :: SqlType SqlTime :: SqlType SqlTimeTZ :: SqlType SqlAbsTime :: SqlType SqlRelTime :: SqlType SqlTimeInterval :: SqlType SqlAbsTimeInterval :: SqlType SqlTimeStamp :: SqlType SqlDateTime :: SqlType SqlDateTimeTZ :: SqlType SqlYear :: SqlType SqlBit :: SqlType SqlENUM :: SqlType SqlPoint :: SqlType SqlLSeg :: SqlType SqlPath :: SqlType SqlBox :: SqlType SqlPolygon :: SqlType SqlLine :: SqlType SqlCircle :: SqlType SqlINetAddr :: SqlType SqlCIDRAddr :: SqlType SqlMacAddr :: SqlType SqlBinary :: Int -> SqlType typeSize :: SqlType -> Int SqlVarBinary :: Int -> SqlType typeSize :: SqlType -> Int SqlLongVarBinary :: Int -> SqlType typeSize :: SqlType -> Int SqlSET :: SqlType SqlBLOB :: SqlType -- | HSQL returns SqlUnknown for all columns for which it cannot -- determine the right type. The backendTypeCode here is the -- internal type code returned from the backend library SqlUnknown :: Int -> SqlType typeCode :: SqlType -> Int data SqlError -- | generic error condition, with further specification SqlError :: String -> Int -> String -> SqlError seState :: SqlError -> String seNativeError :: SqlError -> Int seErrorMsg :: SqlError -> String -- | no more data was available SqlNoMoreData :: SqlError -- | requested handle is invalid SqlInvalidHandle :: SqlError -- | connection is blocked by running transaction SqlStillExecuting :: SqlError -- | more data is needed, e.g. additional connection specs SqlNeedMoreData :: SqlError -- | requested field can't be converted to requested type SqlBadTypeCast :: String -> SqlType -> SqlError seFieldName :: SqlError -> String seFieldType :: SqlError -> SqlType -- | requested field returns NULL SqlFetchNull :: String -> SqlError seFieldName :: SqlError -> String -- | requested field isn't known SqlUnknownField :: String -> SqlError seFieldName :: SqlError -> String -- | requested operation isn't supported SqlUnsupportedOperation :: SqlError -- | referenced handle is already closed SqlClosedHandle :: SqlError -- | SqlBind instances for String, Bool and -- Maybe. module DB.HSQL.Type.Diverse instance SqlBind a => SqlBind (Maybe a) instance SqlBind Bool instance SqlBind String -- | Geometric 2D types, equipped with SqlBind instances. module DB.HSQL.Type.Geometric -- | A 2D point. data Point Point :: Double -> Double -> Point pointX :: Point -> Double pointY :: Point -> Double -- | A 2D straight line. data Line Line :: Point -> Point -> Line lineBegin :: Line -> Point lineEnd :: Line -> Point -- | A 2D path, either open, or closed (looping). data Path -- | An open path OpenPath :: [Point] -> Path pathPoints :: Path -> [Point] -- | A looping path ClosedPath :: [Point] -> Path pathPoints :: Path -> [Point] -- | A 2D rectangle. data Box Box :: Double -> Double -> Double -> Double -> Box boxX1 :: Box -> Double boxY1 :: Box -> Double boxX2 :: Box -> Double boxY2 :: Box -> Double -- | A 2D polygon (without holes). data Polygon Polygon :: [Point] -> Polygon polygonPoints :: Polygon -> [Point] -- | A 2D circle data Circle Circle :: Point -> Double -> Circle circleCenter :: Circle -> Point circleRadius :: Circle -> Double instance Eq Point instance Ord Point instance Show Point instance Read Point instance Eq Line instance Show Line instance Read Line instance Eq Path instance Show Path instance Read Path instance Eq Box instance Show Box instance Read Box instance Eq Polygon instance Show Polygon instance Read Polygon instance Eq Circle instance Show Circle instance Read Circle instance SqlBind Circle instance SqlBind Polygon instance SqlBind Box instance SqlBind Path instance SqlBind Line instance SqlBind Point -- | SqlBind instance for ClockTime. module DB.HSQL.Type.Time instance SqlBind ClockTime -- | Network addresses, equipped with SqlBind instances. module DB.HSQL.Type.NetAddress -- | An IP4 address with netmask in CIDR notation. data INetAddr INetAddr :: Int -> Int -> Int -> Int -> Int -> INetAddr ip4Octet1 :: INetAddr -> Int ip4Octet2 :: INetAddr -> Int ip4Octet3 :: INetAddr -> Int ip4Octet4 :: INetAddr -> Int cidrMaskBits :: INetAddr -> Int -- | A MAC network address. data MacAddr MacAddr :: Int -> Int -> Int -> Int -> Int -> Int -> MacAddr macOctet1 :: MacAddr -> Int macOctet2 :: MacAddr -> Int macOctet3 :: MacAddr -> Int macOctet4 :: MacAddr -> Int macOctet5 :: MacAddr -> Int macOctet6 :: MacAddr -> Int instance Eq INetAddr instance Ord INetAddr instance Show INetAddr instance Read INetAddr instance Eq MacAddr instance Ord MacAddr instance Show MacAddr instance Read MacAddr instance SqlBind MacAddr instance SqlBind INetAddr -- | SqlBind instances for Int, Int64, Integer, -- Double, and Float. module DB.HSQL.Type.Numeric instance SqlBind Float instance SqlBind Double instance SqlBind Integer instance SqlBind Int64 instance SqlBind Int -- | Management of handles and exception handling. module DB.HSQL.Core -- | if closed, no action. closeHandle :: MVar Bool -> IO () -> IO () -- | if closed, throws SqlClosedHandle exception. checkHandle :: MVar Bool -> IO a -> IO a -- | Casts, if possible, an Exception to an SqlError. sqlExceptions :: Exception x => x -> Maybe SqlError -- | Deprecated: Use catch instead. catchSql :: IO a -> (SqlError -> IO a) -> IO a -- | Deprecated: Use handle instead. handleSql :: (SqlError -> IO a) -> IO a -> IO a module Database.HSQL -- | A Connection type represents a connection to a database, -- through which you can operate on the it. In order to create the -- connection you need to use the connect function from the -- module for your prefered backend. data Connection -- | Closes the connection. Performing disconnect on a connection -- that has already been closed has no effect. All other operations on a -- closed connection will fail. disconnect :: Connection -> IO () -- | List all tables in the database. tables :: Connection -> IO [TableId] -- | Description of the properties of a table column. type ColDef = (ColId, SqlType, Nullability) -- | List all columns in a table along with their types and -- nullable flags describe :: Connection -> TableId -> IO [ColDef] -- | An SQL Query. type SQL = String -- | Submits a command to the database. execute :: Connection -> SQL -> IO () -- | The Statement type represents a result from the execution of -- given SQL query. data Statement -- | Executes a query and returns a result set query :: Connection -> SQL -> IO Statement -- | closeStatement stops processing associated with a specific -- statement, closes any open cursors associated with the statement, -- discards pending results, and frees all resources associated with the -- statement. Performing closeStatement on a statement that has -- already been closed has no effect. All other operations on a closed -- statement will fail. closeStatement :: Statement -> IO () -- | fetch fetches the next rowset of data from the result set. The -- values from columns can be retrieved with getFieldValue -- function. fetch :: Statement -> IO Bool -- | Equivalent to Show and Read adapted to SQL expressions. class SqlBind a where fromSqlCStringLen (name, sqlType, _) cstr cstrLen | cstr == nullPtr = throw (SqlFetchNull name) | otherwise = do { str <- peekCStringLen (cstr, cstrLen); case fromSqlValue sqlType str of { Nothing -> throw (SqlBadTypeCast name sqlType) Just v -> return v } } fromSqlCStringLen :: SqlBind a => ColDef -> CString -> Int -> IO a -- | Retrieves the value of field with the specified name. getFieldValue :: SqlBind a => Statement -> String -> IO a getFieldValueMB :: SqlBind a => Statement -> String -> IO (Maybe a) -- | Retrieves the value of field with the specified name. If the field -- value is null then the function will return the default -- value. getFieldValue' :: SqlBind a => Statement -> String -> a -> IO a -- | Returns the type and the nullable flag for field with -- specified name getFieldValueType :: Statement -> String -> (SqlType, Bool) -- | Returns the list of fields with their types and nullable -- flags getFieldsTypes :: Statement -> [(String, SqlType, Bool)] -- | The inTransaction function executes the specified action in -- transaction mode. If the action completes successfully then the -- transaction will be commited. If the action completes with an -- exception then the transaction will be rolled back and the exception -- will be throw again. A transaction is to catch ANY exception, so -- SomeException is adequate. inTransaction :: Connection -> (Connection -> IO a) -> IO a -- | The forEachRow function iterates through the result set in -- Statement and executes the given action for each row in the -- set. The function closes the Statement after the last row -- processing or if the given action raises an exception. forEachRow :: (Statement -> s -> IO s) -> Statement -> s -> IO s -- | The 'forEachRow\'' function is analogous to forEachRow but -- doesn't provide state. The function closes the Statement after -- the last row processing or if the given action raises an exception. forEachRow' :: (Statement -> IO ()) -> Statement -> IO () -- | The collectRows function iterates through the result set in -- Statement and executes the given action for each row in the -- set. The values returned from action are collected and returned as -- list. The function closes the Statement after the last row -- processing or if the given action raises an exception. collectRows :: (Statement -> IO a) -> Statement -> IO [a] data SqlError -- | generic error condition, with further specification SqlError :: String -> Int -> String -> SqlError seState :: SqlError -> String seNativeError :: SqlError -> Int seErrorMsg :: SqlError -> String -- | no more data was available SqlNoMoreData :: SqlError -- | requested handle is invalid SqlInvalidHandle :: SqlError -- | connection is blocked by running transaction SqlStillExecuting :: SqlError -- | more data is needed, e.g. additional connection specs SqlNeedMoreData :: SqlError -- | requested field can't be converted to requested type SqlBadTypeCast :: String -> SqlType -> SqlError seFieldName :: SqlError -> String seFieldType :: SqlError -> SqlType -- | requested field returns NULL SqlFetchNull :: String -> SqlError seFieldName :: SqlError -> String -- | requested field isn't known SqlUnknownField :: String -> SqlError seFieldName :: SqlError -> String -- | requested operation isn't supported SqlUnsupportedOperation :: SqlError -- | referenced handle is already closed SqlClosedHandle :: SqlError -- | Deprecated: Use catch instead. catchSql :: IO a -> (SqlError -> IO a) -> IO a -- | Deprecated: Use handle instead. handleSql :: (SqlError -> IO a) -> IO a -> IO a -- | Casts, if possible, an Exception to an SqlError. sqlExceptions :: Exception x => x -> Maybe SqlError -- | A 2D point. data Point Point :: Double -> Double -> Point pointX :: Point -> Double pointY :: Point -> Double -- | A 2D straight line. data Line Line :: Point -> Point -> Line lineBegin :: Line -> Point lineEnd :: Line -> Point -- | A 2D path, either open, or closed (looping). data Path -- | An open path OpenPath :: [Point] -> Path pathPoints :: Path -> [Point] -- | A looping path ClosedPath :: [Point] -> Path pathPoints :: Path -> [Point] -- | A 2D rectangle. data Box Box :: Double -> Double -> Double -> Double -> Box boxX1 :: Box -> Double boxY1 :: Box -> Double boxX2 :: Box -> Double boxY2 :: Box -> Double -- | A 2D circle data Circle Circle :: Point -> Double -> Circle circleCenter :: Circle -> Point circleRadius :: Circle -> Double -- | A 2D polygon (without holes). data Polygon Polygon :: [Point] -> Polygon polygonPoints :: Polygon -> [Point] -- | An IP4 address with netmask in CIDR notation. data INetAddr INetAddr :: Int -> Int -> Int -> Int -> Int -> INetAddr ip4Octet1 :: INetAddr -> Int ip4Octet2 :: INetAddr -> Int ip4Octet3 :: INetAddr -> Int ip4Octet4 :: INetAddr -> Int cidrMaskBits :: INetAddr -> Int -- | A MAC network address. data MacAddr MacAddr :: Int -> Int -> Int -> Int -> Int -> Int -> MacAddr macOctet1 :: MacAddr -> Int macOctet2 :: MacAddr -> Int macOctet3 :: MacAddr -> Int macOctet4 :: MacAddr -> Int macOctet5 :: MacAddr -> Int macOctet6 :: MacAddr -> Int -- | Variety of common data types used in databases. data SqlType SqlInteger :: SqlType SqlBigInt :: SqlType SqlSmallInt :: SqlType SqlTinyInt :: SqlType SqlMedInt :: SqlType SqlDecimal :: Int -> Int -> SqlType typeSize :: SqlType -> Int typeDecimals :: SqlType -> Int SqlNumeric :: Int -> Int -> SqlType typeSize :: SqlType -> Int typeDecimals :: SqlType -> Int SqlReal :: SqlType SqlDouble :: SqlType SqlFloat :: SqlType SqlMoney :: SqlType SqlChar :: Int -> SqlType typeSize :: SqlType -> Int SqlVarChar :: Int -> SqlType typeSize :: SqlType -> Int SqlLongVarChar :: Int -> SqlType typeSize :: SqlType -> Int SqlText :: SqlType SqlWChar :: Int -> SqlType typeSize :: SqlType -> Int SqlWVarChar :: Int -> SqlType typeSize :: SqlType -> Int SqlWLongVarChar :: Int -> SqlType typeSize :: SqlType -> Int SqlDate :: SqlType SqlTime :: SqlType SqlTimeTZ :: SqlType SqlAbsTime :: SqlType SqlRelTime :: SqlType SqlTimeInterval :: SqlType SqlAbsTimeInterval :: SqlType SqlTimeStamp :: SqlType SqlDateTime :: SqlType SqlDateTimeTZ :: SqlType SqlYear :: SqlType SqlBit :: SqlType SqlENUM :: SqlType SqlPoint :: SqlType SqlLSeg :: SqlType SqlPath :: SqlType SqlBox :: SqlType SqlPolygon :: SqlType SqlLine :: SqlType SqlCircle :: SqlType SqlINetAddr :: SqlType SqlCIDRAddr :: SqlType SqlMacAddr :: SqlType SqlBinary :: Int -> SqlType typeSize :: SqlType -> Int SqlVarBinary :: Int -> SqlType typeSize :: SqlType -> Int SqlLongVarBinary :: Int -> SqlType typeSize :: SqlType -> Int SqlSET :: SqlType SqlBLOB :: SqlType -- | HSQL returns SqlUnknown for all columns for which it cannot -- determine the right type. The backendTypeCode here is the -- internal type code returned from the backend library SqlUnknown :: Int -> SqlType typeCode :: SqlType -> Int