[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MirageOS-devel] problem with sqlite constraints and orm

Problem demonstrated below: violating a unique constraint in sqlite3 seems to leave things in an inconsistent state.

Also, tangentially, I discovered this while trying to maintain my own id on a table because my app is serving json objects over a rest api, and I need some sort of unique id for clients to be able to send updates to existing objects. If there were a way to have the autogenerated sql __id__ column be a record field, that would be extremely useful.


$ cat db.ml
type item = {
 id: int;
} with orm (
 unique: item<id>

let db_name = "test.db"

$ cat init_db.ml
open Db

let _ =
 let db = item_init Db.db_name in
 let item = {
  id = 1;
 } in
 item_save db item

$ ./init_db.native
$ ./init_db.native
Fatal error: exception Sqlite3.Error("CONSTRAINT")

$ sqlite3 test.db
sqlite> select * from item;
__id__   Âid    Â
---------- Â----------
1 Â Â Â Â Â 1 Â Â Â Â
2 Â Â Â Â Â Â Â Â Â Â
sqlite> delete from item;
Error: no such function: SYNC_CACHE_item

MirageOS-devel mailing list



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.