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