From: R. E. B. <re...@cs...> - 2009-11-15 09:56:53
|
Justin Bailey said: > On Sat, Nov 14, 2009 at 1:35 PM, R. Emre Başar <re...@cs...> > wrote: > > Thanks. I managed to get it to some level. I defined a table like: > > > > $(mkDBDirectTableWithName "LastInsertId" "Server" [("LAST_INSERT_ID()", [t|Int|])]) > > > > Nice work! Unfortunately you are right - you have to give a table > name. If the table name is irrelevant (i.e., it doesn't affect > LAST_INSERT_ID), try using information_schema.schema_catalog_name. > That's a SQL-standard table that always has one row. It's useful for a > "fake" query like this. > Unfortunately, the table name is relevant. If there is no table name, you can have an action which always produces the value of the last insert, if you use it with a table name you get the value of the last insert for a table. (this also changes the type from Int to Maybe Int since the table might not have any insertions but that's another story) It looks that the only solution is to create a last insert table for each table that I will insert. > If you are feeling adventerous, the darcs version of haskelldb has the > "func" and "literal" query operators which would let you build this > query fairly easily: > > lastInsertID = func "last_insert_id()" > > or > > lastInsertID = constant (literal "last_insert_id()") > > but it is has undergone some major changes in syntax. The underlying > Record system was shifted over to HList and the library is still very > much in flux. In any case you can find it at > > http://code.haskell.org/haskelldb > I will take a look at it. Since I have a deadline for that project, I cannot be too adventureous, but I will test the new version. Thanks. -- R. Emre Başar İstanbul Bilgi University Department of Computer Science |