Have you looked at the HAppS.DBMS.IxSet? It gives you a type safe way
to query indexed collections.
-Alex-
Isto Aho wrote:
Hi,
I'd like to store small matrices into a db. Number of rows and columns
may vary in a way not
known in advance. One might use a relation (matrixId, col, row, value)
or something like that
but if it is possible to put a matrix in one command into db, some
queries will be easier.
E.g., one relation can store several matrices and it would be easy to
query, how many
matrices are stored currently. With that above four tuple you can find
out the number of unique
matrixId's, too, but it is not as easy as with matrices.
Anyhow, now I'm not sure if I should stick with HSQL any more... Earlier
comments on this
thread made me think that maybe it would be a better idea to try to
learn enough HDBC.
This would be used in a server application. Is HAppS applicable here?
e.g. after some tweaking the following works with HSQL:
addRows = do
dbh <- connect server database user_id passwd
intoDB dbh ([555,111, 50, 1000]::[Int])
([21.0,22.0,23.0,24.0]::[Double])
intoDB dbh ([556,111, 50, 1000]::[Int])
([21.0,22.0,23.0,24.0]::[Double])
intoDB dbh ([]::[Int]) ([]::[Double])
where
intoDB dbh i_lst d_lst =
catchSql (do
let cmd = "INSERT INTO trial (intList, dList)
VALUES (" ++
toSqlValue i_lst ++ "," ++ toSqlValue
d_lst ++ ")"
execute dbh cmd
)
(\e -> putStrLn $ "Problem: " ++ show e)
Similarly, queries can handle matrices and I like that it is now
possible to select those columns or rows from the stored matrix that
are needed. E.g.
retrieveRecords2 :: Connection -> IO [[Double]]
retrieveRecords2 c = do
-- query c "select dList[1:2] from trial" >>= collectRows getRow
query c "select dList from trial" >>= collectRows getRow
where
getRow :: Statement -> IO [Double]
getRow stmt = do
lst <- getFieldValue stmt "dList"
return lst
readTable2 = do
dbh <- connect server database user_id passwd
values <- retrieveRecords2 dbh
putStrLn $ "dLists are : " ++ (show values)
br,
Isto
2007/8/1, Alex Jacobson <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>>:
Out of curiosity, can I ask what you are actually trying to do?
I am asking because I am trying to make HAppS a reasonable replacement
for all contexts in which you would otherwise use an external relational
database except those in which an external SQL database is a specific
requirement.
-Alex-
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe