From: <kr_...@us...> - 2005-06-17 14:33:04
|
Update of /cvsroot/htoolkit/HSQL/MSI/Database/HSQL In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv857/Database/HSQL Modified Files: MSI.hsc Log Message: Fixed error handling Index: MSI.hsc =================================================================== RCS file: /cvsroot/htoolkit/HSQL/MSI/Database/HSQL/MSI.hsc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MSI.hsc 17 Jun 2005 14:29:24 -0000 1.2 --- MSI.hsc 17 Jun 2005 14:32:54 -0000 1.3 *************** *** 36,40 **** withCString dest $ \cdest -> alloca $ \phandle -> do ! msiOpenDatabase csource cdest phandle >>= checkResult 0 hDatabase <- peek phandle refFalse <- newMVar False --- 36,40 ---- withCString dest $ \cdest -> alloca $ \phandle -> do ! msiOpenDatabase csource cdest phandle >>= checkResult hDatabase <- peek phandle refFalse <- newMVar False *************** *** 54,59 **** disconnect :: MSIHANDLE -> IO () disconnect hDatabase = do ! msiDatabaseCommit hDatabase >>= checkResult hDatabase ! msiCloseHandle hDatabase >>= checkResult hDatabase execute :: MSIHANDLE -> String -> IO () --- 54,59 ---- disconnect :: MSIHANDLE -> IO () disconnect hDatabase = do ! msiDatabaseCommit hDatabase >>= checkResult ! msiCloseHandle hDatabase >>= checkResult execute :: MSIHANDLE -> String -> IO () *************** *** 61,68 **** withCString query $ \cquery -> alloca $ \phandle -> do ! msiDatabaseOpenView hDatabase cquery phandle >>= checkResult hDatabase hView <- peek phandle ! msiViewExecute hView 0 >>= checkResult hDatabase ! msiCloseHandle hView >>= checkResult hDatabase col_buffer_size = 1024 --- 61,68 ---- withCString query $ \cquery -> alloca $ \phandle -> do ! msiDatabaseOpenView hDatabase cquery phandle >>= checkResult hView <- peek phandle ! msiViewExecute hView 0 >>= checkResult ! msiCloseHandle hView >>= checkResult col_buffer_size = 1024 *************** *** 72,78 **** withCString query $ \cquery -> alloca $ \phandle -> do ! msiDatabaseOpenView hDatabase cquery phandle >>= checkResult hDatabase hView <- peek phandle ! msiViewExecute hView 0 >>= checkResult hDatabase fields <- getFields hView refFalse <- newMVar False --- 72,78 ---- withCString query $ \cquery -> alloca $ \phandle -> do ! msiDatabaseOpenView hDatabase cquery phandle >>= checkResult hView <- peek phandle ! msiViewExecute hView 0 >>= checkResult fields <- getFields hView refFalse <- newMVar False *************** *** 91,96 **** alloca $ \phNamesRecord -> alloca $ \phTypesRecord -> do ! msiViewGetColumnInfo hView 0 phNamesRecord >>= checkResult hView ! msiViewGetColumnInfo hView 1 phTypesRecord >>= checkResult hView hNamesRecord <- peek phNamesRecord hTypesRecord <- peek phTypesRecord --- 91,96 ---- alloca $ \phNamesRecord -> alloca $ \phTypesRecord -> do ! msiViewGetColumnInfo hView 0 phNamesRecord >>= checkResult ! msiViewGetColumnInfo hView 1 phTypesRecord >>= checkResult hNamesRecord <- peek phNamesRecord hTypesRecord <- peek phTypesRecord *************** *** 104,111 **** alloca $ \plen -> do poke plen (fromIntegral col_buffer_size) ! msiRecordGetString hNamesRecord n buffer plen >>= checkResult hNamesRecord name <- peekCString buffer poke plen (fromIntegral col_buffer_size) ! msiRecordGetString hTypesRecord n buffer plen >>= checkResult hTypesRecord typ <- peekCString buffer fieldDefs <- loop (n+1) count hNamesRecord hTypesRecord --- 104,111 ---- alloca $ \plen -> do poke plen (fromIntegral col_buffer_size) ! msiRecordGetString hNamesRecord n buffer plen >>= checkResult name <- peekCString buffer poke plen (fromIntegral col_buffer_size) ! msiRecordGetString hTypesRecord n buffer plen >>= checkResult typ <- peekCString buffer fieldDefs <- loop (n+1) count hNamesRecord hTypesRecord *************** *** 132,138 **** withCString query $ \cquery -> alloca $ \phandle -> do ! msiDatabaseOpenView hDatabase cquery phandle >>= checkResult hDatabase hView <- peek phandle ! msiViewExecute hView 0 >>= checkResult hDatabase loop hView where --- 132,138 ---- withCString query $ \cquery -> alloca $ \phandle -> do ! msiDatabaseOpenView hDatabase cquery phandle >>= checkResult hView <- peek phandle ! msiViewExecute hView 0 >>= checkResult loop hView where *************** *** 146,158 **** then do msiCloseHandle hView return [] ! else do checkResult hView res hRecord <- peek phRecord name <- allocaBytes col_buffer_size $ \buffer -> alloca $ \plen -> do poke plen (fromIntegral col_buffer_size) ! msiRecordGetString hRecord 1 buffer plen >>= checkResult hRecord len <- peek plen peekCStringLen (buffer,fromIntegral len) ! msiCloseHandle hRecord >>= checkResult hRecord names <- loop hView return (name:names) --- 146,158 ---- then do msiCloseHandle hView return [] ! else do checkResult res hRecord <- peek phRecord name <- allocaBytes col_buffer_size $ \buffer -> alloca $ \plen -> do poke plen (fromIntegral col_buffer_size) ! msiRecordGetString hRecord 1 buffer plen >>= checkResult len <- peek plen peekCStringLen (buffer,fromIntegral len) ! msiCloseHandle hRecord >>= checkResult names <- loop hView return (name:names) *************** *** 162,168 **** withCString query $ \cquery -> alloca $ \phandle -> do ! msiDatabaseOpenView hDatabase cquery phandle >>= checkResult hDatabase hView <- peek phandle ! msiViewExecute hView 0 >>= checkResult hDatabase loop hView where --- 162,168 ---- withCString query $ \cquery -> alloca $ \phandle -> do ! msiDatabaseOpenView hDatabase cquery phandle >>= checkResult hView <- peek phandle ! msiViewExecute hView 0 >>= checkResult loop hView where *************** *** 176,188 **** then do msiCloseHandle hView return [] ! else do checkResult hView res hRecord <- peek phRecord name <- allocaBytes col_buffer_size $ \buffer -> alloca $ \plen -> do poke plen (fromIntegral col_buffer_size) ! msiRecordGetString hRecord 1 buffer plen >>= checkResult hRecord len <- peek plen peekCStringLen (buffer,fromIntegral len) ! msiCloseHandle hRecord >>= checkResult hRecord columns <- loop hView return ((name, SqlText, False):columns) --- 176,188 ---- then do msiCloseHandle hView return [] ! else do checkResult res hRecord <- peek phRecord name <- allocaBytes col_buffer_size $ \buffer -> alloca $ \plen -> do poke plen (fromIntegral col_buffer_size) ! msiRecordGetString hRecord 1 buffer plen >>= checkResult len <- peek plen peekCStringLen (buffer,fromIntegral len) ! msiCloseHandle hRecord >>= checkResult columns <- loop hView return ((name, SqlText, False):columns) *************** *** 196,200 **** hRecord <- readIORef refRecord unless (hRecord == 0) $ ! (msiCloseHandle hRecord >>= checkResult hRecord) alloca $ \phRecord -> do res <- msiViewFetch hView phRecord --- 196,200 ---- hRecord <- readIORef refRecord unless (hRecord == 0) $ ! (msiCloseHandle hRecord >>= checkResult) alloca $ \phRecord -> do res <- msiViewFetch hView phRecord *************** *** 202,206 **** then do writeIORef refRecord 0 return False ! else do checkResult hView res hRecord <- peek phRecord writeIORef refRecord hRecord --- 202,206 ---- then do writeIORef refRecord 0 return False ! else do checkResult res hRecord <- peek phRecord writeIORef refRecord hRecord *************** *** 213,217 **** poke plen (fromIntegral col_buffer_size) hRecord <- readIORef refRecord ! msiRecordGetString hRecord (fromIntegral colNumber+1) buffer plen >>= checkResult hRecord len <- peek plen f sqlType buffer (fromIntegral len) --- 213,217 ---- poke plen (fromIntegral col_buffer_size) hRecord <- readIORef refRecord ! msiRecordGetString hRecord (fromIntegral colNumber+1) buffer plen >>= checkResult len <- peek plen f sqlType buffer (fromIntegral len) *************** *** 219,226 **** closeStatement :: MSIHANDLE -> IORef MSIHANDLE -> IO () closeStatement hView refRecord = do ! msiCloseHandle hView >>= checkResult 0 hRecord <- readIORef refRecord unless (hRecord == 0) $ ! (msiCloseHandle hRecord >>= checkResult 0) foreign import stdcall "MsiOpenDatabaseA" msiOpenDatabase :: CString -> CString -> Ptr MSIHANDLE -> IO Word32 --- 219,226 ---- closeStatement :: MSIHANDLE -> IORef MSIHANDLE -> IO () closeStatement hView refRecord = do ! msiCloseHandle hView >>= checkResult hRecord <- readIORef refRecord unless (hRecord == 0) $ ! (msiCloseHandle hRecord >>= checkResult) foreign import stdcall "MsiOpenDatabaseA" msiOpenDatabase :: CString -> CString -> Ptr MSIHANDLE -> IO Word32 *************** *** 237,248 **** foreign import stdcall "FormatMessageA" formatMessage :: Word32 -> Ptr () -> Word32 -> Word32 -> CString -> Word32 -> Ptr () -> IO Word32 ! checkResult :: MSIHANDLE -> Word32 -> IO () ! checkResult hDatabase err | err == 0 = return () | otherwise = do - hRecord <- msiGetLastErrorRecord msg <- allocaBytes 1024 $ \cmsg -> do formatMessage (#const FORMAT_MESSAGE_FROM_SYSTEM) nullPtr err 0 cmsg 1024 nullPtr peekCString cmsg - msiCloseHandle hRecord throwDyn (SqlError "" (fromIntegral err) msg) --- 237,246 ---- foreign import stdcall "FormatMessageA" formatMessage :: Word32 -> Ptr () -> Word32 -> Word32 -> CString -> Word32 -> Ptr () -> IO Word32 ! checkResult :: Word32 -> IO () ! checkResult err | err == 0 = return () | otherwise = do msg <- allocaBytes 1024 $ \cmsg -> do formatMessage (#const FORMAT_MESSAGE_FROM_SYSTEM) nullPtr err 0 cmsg 1024 nullPtr peekCString cmsg throwDyn (SqlError "" (fromIntegral err) msg) |