From: <kr_...@us...> - 2005-06-17 14:29:33
|
Update of /cvsroot/htoolkit/HSQL/MSI/Database/HSQL In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31030/Database/HSQL Modified Files: MSI.hsc Log Message: Implementation for tables and describe functions Index: MSI.hsc =================================================================== RCS file: /cvsroot/htoolkit/HSQL/MSI/Database/HSQL/MSI.hsc,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MSI.hsc 14 Jun 2005 14:16:31 -0000 1.1 --- MSI.hsc 17 Jun 2005 14:29:24 -0000 1.2 *************** *** 43,48 **** , connExecute = execute hDatabase , connQuery = query connection hDatabase ! , connTables = tables connection hDatabase ! , connDescribe = describe connection hDatabase , connBeginTransaction = beginTransaction hDatabase , connCommitTransaction = commitTransaction hDatabase --- 43,48 ---- , connExecute = execute hDatabase , connQuery = query connection hDatabase ! , connTables = tables hDatabase ! , connDescribe = describe hDatabase , connBeginTransaction = beginTransaction hDatabase , connCommitTransaction = commitTransaction hDatabase *************** *** 66,69 **** --- 66,71 ---- msiCloseHandle hView >>= checkResult hDatabase + col_buffer_size = 1024 + query :: Connection -> MSIHANDLE -> String -> IO Statement query connection hDatabase query = *************** *** 99,108 **** | n > count = return [] | otherwise = ! allocaBytes 1024 $ \buffer -> ! alloca $ \plen -> do ! poke plen 1024 msiRecordGetString hNamesRecord n buffer plen >>= checkResult hNamesRecord name <- peekCString buffer ! poke plen 1024 msiRecordGetString hTypesRecord n buffer plen >>= checkResult hTypesRecord typ <- peekCString buffer --- 101,110 ---- | n > count = return [] | otherwise = ! allocaBytes col_buffer_size $ \buffer -> ! 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 *************** *** 126,135 **** 0 -> SqlBLOB ! tables :: Connection -> MSIHANDLE -> IO [String] ! tables connection hDatabase = undefined - describe :: Connection -> MSIHANDLE -> String -> IO [FieldDef] - describe connection hDatabase tableName = undefined - beginTransaction hDatabase = throwDyn SqlUnsupportedOperation commitTransaction hDatabase = throwDyn SqlUnsupportedOperation --- 128,191 ---- 0 -> SqlBLOB ! tables :: MSIHANDLE -> IO [String] ! tables hDatabase = ! withCString query $ \cquery -> ! alloca $ \phandle -> do ! msiDatabaseOpenView hDatabase cquery phandle >>= checkResult hDatabase ! hView <- peek phandle ! msiViewExecute hView 0 >>= checkResult hDatabase ! loop hView ! where ! query = "select Name from _Tables" ! ! loop :: MSIHANDLE -> IO [String] ! loop hView = do ! alloca $ \phRecord -> do ! res <- msiViewFetch hView phRecord ! if res == 259 ! 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) ! ! describe :: MSIHANDLE -> String -> IO [FieldDef] ! describe hDatabase tableName = ! withCString query $ \cquery -> ! alloca $ \phandle -> do ! msiDatabaseOpenView hDatabase cquery phandle >>= checkResult hDatabase ! hView <- peek phandle ! msiViewExecute hView 0 >>= checkResult hDatabase ! loop hView ! where ! query = "select Name from _Columns where `Table`="++toSqlValue tableName ! ! loop :: MSIHANDLE -> IO [FieldDef] ! loop hView = do ! alloca $ \phRecord -> do ! res <- msiViewFetch hView phRecord ! if res == 259 ! 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) beginTransaction hDatabase = throwDyn SqlUnsupportedOperation commitTransaction hDatabase = throwDyn SqlUnsupportedOperation *************** *** 153,159 **** getColValue :: IORef MSIHANDLE -> Int -> FieldDef -> (SqlType -> CString -> Int -> IO (Maybe a)) -> IO (Maybe a) getColValue refRecord colNumber (name,sqlType,nullable) f = ! allocaBytes 1024 $ \buffer -> ! alloca $ \plen -> do ! poke plen 1024 hRecord <- readIORef refRecord msiRecordGetString hRecord (fromIntegral colNumber+1) buffer plen >>= checkResult hRecord --- 209,215 ---- getColValue :: IORef MSIHANDLE -> Int -> FieldDef -> (SqlType -> CString -> Int -> IO (Maybe a)) -> IO (Maybe a) getColValue refRecord colNumber (name,sqlType,nullable) f = ! allocaBytes col_buffer_size $ \buffer -> ! alloca $ \plen -> do ! poke plen (fromIntegral col_buffer_size) hRecord <- readIORef refRecord msiRecordGetString hRecord (fromIntegral colNumber+1) buffer plen >>= checkResult hRecord |