I am trying to create a database using Genie code. However, I am facing problems with documentation, so I am asking here!
This can be considered unintuitive, because
It looks as though you have used the example in Valadoc, but not converted the type information from Vala syntax to Genie syntax. So Sqlite.Database db
would be db:Sqlite.Database
.
A working example in Genie would be:
[indent=4]
init
db:Sqlite.Database
errmsg:string
ec:int = Sqlite.Database.open("cookbook.sqlite", out db)
if ec != Sqlite.OK
stderr.printf("Can't open database: %d: %s\n", db.errcode(), db.errmsg())
Process.exit( -1 )
query:string ="""CREATE TABLE Recipes (
pkiD INTEGER PRIMARY KEY,
name TEXT,
servings TEXT,
source TEXT
)
"""
db.exec (query, null, out errmsg)
A couple of things to note:
return -1
isn't currently allowed. This may change at some point, see https://bugzilla.gnome.org/show_bug.cgi?id=707233 To work around this you can use GLib's Process.exit(), as used in the example above. This has the disadvantage that the program terminates immediately without object destruction. So if you are using final
in your classes to close the database connection, for example, the final
block will not be called. Or you can just return
, which always returns 0"""I'm a verbatim string"""
, are great for embedding SQL in Genie :-)