|
From: <kr_...@us...> - 2003-09-07 22:57:31
|
Update of /cvsroot/htoolkit/HSQL/ODBC
In directory sc8-pr-cvs1:/tmp/cvs-serv8597/ODBC
Modified Files:
HSQL.hsc
Log Message:
comments
Index: HSQL.hsc
===================================================================
RCS file: /cvsroot/htoolkit/HSQL/ODBC/HSQL.hsc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** HSQL.hsc 6 Sep 2003 22:44:13 -0000 1.2
--- HSQL.hsc 7 Sep 2003 22:57:25 -0000 1.3
***************
*** 198,202 ****
-----------------------------------------------------------------------------------------
! connect :: String -> String -> String -> IO Connection
connect server user authentication = withForeignPtr myEnvironment $ \hEnv -> do
(phDBC :: Ptr HDBC) <- malloc
--- 198,206 ----
-----------------------------------------------------------------------------------------
! -- | Makes a new connection to the database server.
! connect :: String -- ^ Data source name
! -> String -- ^ User identifier
! -> String -- ^ Authentication string (password)
! -> IO Connection -- ^ the returned value represents the new connection
connect server user authentication = withForeignPtr myEnvironment $ \hEnv -> do
(phDBC :: Ptr HDBC) <- malloc
***************
*** 214,218 ****
handleSqlResult (#const SQL_HANDLE_ENV) hEnv res
return (Connection {hDBC=hDBC, environment=myEnvironment})
!
disconnect :: Connection -> IO ()
disconnect (Connection {hDBC=hDBC}) = do
--- 218,223 ----
handleSqlResult (#const SQL_HANDLE_ENV) hEnv res
return (Connection {hDBC=hDBC, environment=myEnvironment})
!
! -- | Closes the connection.
disconnect :: Connection -> IO ()
disconnect (Connection {hDBC=hDBC}) = do
***************
*** 225,228 ****
--- 230,234 ----
-----------------------------------------------------------------------------------------
+ -- | Execute statement
execute :: Connection -> String -> IO ()
execute conn@(Connection {hDBC=hDBC}) query = do
***************
*** 242,245 ****
--- 248,252 ----
free pFIELD
+ -- | Executes the statement and returns a 'Statement' value which represents the result set
query :: Connection -> String -> IO Statement
query conn@(Connection {hDBC=hDBC}) query = do
***************
*** 302,305 ****
--- 309,314 ----
{-# NOINLINE fetch #-}
+ -- | '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
fetch stmt = do
***************
*** 308,312 ****
return (res /= (#const SQL_NO_DATA))
!
closeStatement :: Statement -> IO ()
closeStatement stmt = do
--- 317,323 ----
return (res /= (#const SQL_NO_DATA))
! -- | '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.
closeStatement :: Statement -> IO ()
closeStatement stmt = do
***************
*** 318,322 ****
-----------------------------------------------------------------------------------------
! inTransaction :: Connection -> (Connection -> IO a) -> IO a
inTransaction conn@(Connection {hDBC=hDBC, environment=envRef}) action = withForeignPtr envRef $ \hEnv -> do
sqlSetConnectOption hDBC (#const SQL_AUTOCOMMIT) (#const SQL_AUTOCOMMIT_OFF)
--- 329,339 ----
-----------------------------------------------------------------------------------------
! -- | 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.
! inTransaction :: Connection
! -> (Connection -> IO a) -- ^ an action
! -> IO a -- ^ the returned value is the result returned from action
inTransaction conn@(Connection {hDBC=hDBC, environment=envRef}) action = withForeignPtr envRef $ \hEnv -> do
sqlSetConnectOption hDBC (#const SQL_AUTOCOMMIT) (#const SQL_AUTOCOMMIT_OFF)
***************
*** 418,422 ****
foreign import ccall unsafe mktime :: Ptr () -> IO CTime
! getFieldValueMB :: SqlBind a => Statement -> String -> IO (Maybe a)
getFieldValueMB (Statement {hSTMT=hSTMT, fields=fields, fetchBuffer=buffer, fetchBufferSize=bufferSize}) name = do
let dataBuffer = buffer `plusPtr` (#const sizeof(SQLINTEGER))
--- 435,443 ----
foreign import ccall unsafe mktime :: Ptr () -> IO CTime
! -- | Retrieves the value of field with the specified name.
! -- The returned value is Nothing if the field value is @null@.
! getFieldValueMB :: SqlBind a => Statement
! -> String -- ^ Field name
! -> IO (Maybe a) -- ^ Field value or Nothing
getFieldValueMB (Statement {hSTMT=hSTMT, fields=fields, fetchBuffer=buffer, fetchBufferSize=bufferSize}) name = do
let dataBuffer = buffer `plusPtr` (#const sizeof(SQLINTEGER))
***************
*** 467,471 ****
SqlLongVarBinary _ -> (#const SQL_C_BINARY)
! getFieldValue :: SqlBind a => Statement -> String -> IO a
getFieldValue stmt name = do
mb_v <- getFieldValueMB stmt name
--- 488,496 ----
SqlLongVarBinary _ -> (#const SQL_C_BINARY)
! -- | Retrieves the value of field with the specified name.
! -- If the field value is @null@ then the function will throw 'SqlFetchNull' exception.
! getFieldValue :: SqlBind a => Statement
! -> String -- ^ Field name
! -> IO a -- ^ Field value
getFieldValue stmt name = do
mb_v <- getFieldValueMB stmt name
***************
*** 474,487 ****
Just a -> return a
! getFieldValue' :: SqlBind a => Statement -> String -> a -> IO a
getFieldValue' stmt name def = do
mb_v <- getFieldValueMB stmt name
return (case mb_v of { Nothing -> def; Just a -> a })
!
! getFieldValueType :: Statement -> String -> (SqlType, Bool)
getFieldValueType stmt name = (sqlType, nullable)
where
(sqlType,nullable,colNumber) = findFieldInfo name (fields stmt) 1
getFieldsTypes :: Statement -> [(String, SqlType, Bool)]
getFieldsTypes = fields
--- 499,521 ----
Just a -> return 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 -- ^ Field name
! -> a -- ^ Default field value
! -> IO a -- ^ Field value
getFieldValue' stmt name def = do
mb_v <- getFieldValueMB stmt name
return (case mb_v of { Nothing -> def; Just a -> a })
!
! -- | Returns the type and the @nullable@ flag for field with specified name
! getFieldValueType :: Statement
! -> String -- ^ Field name
! -> (SqlType, Bool) -- ^ Field type and @nullable@
getFieldValueType stmt name = (sqlType, nullable)
where
(sqlType,nullable,colNumber) = findFieldInfo name (fields stmt) 1
+ -- | Returns the list of fields with their types and @nullable@ flags
getFieldsTypes :: Statement -> [(String, SqlType, Bool)]
getFieldsTypes = fields
***************
*** 497,510 ****
-----------------------------------------------------------------------------------------
! forEachRow :: (Statement -> s -> IO s) -> Statement -> s -> IO s
forEachRow f stmt s = do
success <- fetch stmt
if success then f stmt s >>= forEachRow f stmt else closeStatement stmt >> return s
!
forEachRow' :: (Statement -> IO ()) -> Statement -> IO ()
forEachRow' f stmt = do
success <- fetch stmt
if success then f stmt >> forEachRow' f stmt else closeStatement stmt
!
collectRows :: (Statement -> IO a) -> Statement -> IO [a]
collectRows f stmt = loop
--- 531,554 ----
-----------------------------------------------------------------------------------------
! -- | The 'forEachRow' function iterates through the result set in 'Statement' and
! -- executes the given action for each row in the set. After processing the last row
! -- the statement is automatically closed.
! forEachRow :: (Statement -> s -> IO s) -- ^ an action
! -> Statement -- ^ the statement
! -> s -- ^ initial state
! -> IO s -- ^ final state
forEachRow f stmt s = do
success <- fetch stmt
if success then f stmt s >>= forEachRow f stmt else closeStatement stmt >> return s
!
! -- | The 'forEachRow\'' function is analogous to 'forEachRow' but doesn't provide state.
forEachRow' :: (Statement -> IO ()) -> Statement -> IO ()
forEachRow' f stmt = do
success <- fetch stmt
if success then f stmt >> forEachRow' f stmt else closeStatement stmt
!
! -- | 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.
collectRows :: (Statement -> IO a) -> Statement -> IO [a]
collectRows f stmt = loop
|