From: <kr_...@us...> - 2004-11-01 09:55:51
|
Update of /cvsroot/htoolkit/HSQL/src/HSQL In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14257 Modified Files: ODBC.hsc Log Message: Limited support for batch queries. Now we can safely execute queries like: insert into T(..) values (..); select @@identity Index: ODBC.hsc =================================================================== RCS file: /cvsroot/htoolkit/HSQL/src/HSQL/ODBC.hsc,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** ODBC.hsc 28 Feb 2004 20:09:50 -0000 1.10 --- ODBC.hsc 1 Nov 2004 09:55:41 -0000 1.11 *************** *** 74,77 **** --- 74,78 ---- foreign import #{CALLCONV} "HsODBC.h SQLTables" sqlTables :: HSTMT -> CString -> SQLSMALLINT -> CString -> SQLSMALLINT -> CString -> SQLSMALLINT -> CString -> SQLSMALLINT -> IO SQLRETURN foreign import #{CALLCONV} "HsODBC.h SQLColumns" sqlColumns :: HSTMT -> CString -> SQLSMALLINT -> CString -> SQLSMALLINT -> CString -> SQLSMALLINT -> CString -> SQLSMALLINT -> IO SQLRETURN + foreign import #{CALLCONV} "HsODBC.h SQLMoreResults" sqlMoreResults :: HSTMT -> IO SQLRETURN ----------------------------------------------------------------------------------------- *************** *** 187,191 **** withStatement :: Connection -> HDBC -> (HSTMT -> IO SQLRETURN) -> IO Statement withStatement connection hDBC f = ! allocaBytes (#const sizeof(FIELD)) $ \pFIELD -> do res <- sqlAllocStmt hDBC ((#ptr FIELD, hSTMT) pFIELD) handleSqlResult (#const SQL_HANDLE_DBC) hDBC res --- 188,192 ---- withStatement :: Connection -> HDBC -> (HSTMT -> IO SQLRETURN) -> IO Statement withStatement connection hDBC f = ! allocaBytes (#const sizeof(FIELD)) $ \pFIELD -> do res <- sqlAllocStmt hDBC ((#ptr FIELD, hSTMT) pFIELD) handleSqlResult (#const SQL_HANDLE_DBC) hDBC res *************** *** 193,199 **** let handleResult res = handleSqlResult (#const SQL_HANDLE_STMT) hSTMT res f hSTMT >>= handleResult ! sqlNumResultCols hSTMT ((#ptr FIELD, fieldsCount) pFIELD) >>= handleResult ! count <- (#peek FIELD, fieldsCount) pFIELD ! fields <- getFieldDefs hSTMT pFIELD 1 count buffer <- mallocBytes (fromIntegral stmtBufferSize) refFalse <- newMVar False --- 194,198 ---- let handleResult res = handleSqlResult (#const SQL_HANDLE_STMT) hSTMT res f hSTMT >>= handleResult ! fields <- moveToFirstResult hSTMT pFIELD buffer <- mallocBytes (fromIntegral stmtBufferSize) refFalse <- newMVar False *************** *** 208,211 **** --- 207,224 ---- return statement where + moveToFirstResult :: HSTMT -> Ptr a -> IO [FieldDef] + moveToFirstResult hSTMT pFIELD = do + res <- sqlNumResultCols hSTMT ((#ptr FIELD, fieldsCount) pFIELD) + handleSqlResult (#const SQL_HANDLE_STMT) hSTMT res + count <- (#peek FIELD, fieldsCount) pFIELD + if count == 0 + then do + res <- sqlMoreResults hSTMT + if res == (#const SQL_SUCCESS) + then moveToFirstResult hSTMT pFIELD + else return [] + else + getFieldDefs hSTMT pFIELD 1 count + getFieldDefs :: HSTMT -> Ptr a -> SQLUSMALLINT -> SQLUSMALLINT -> IO [FieldDef] getFieldDefs hSTMT pFIELD n count |