[Vala] fix sqlite example
- From: Alexey Lubimov <avl l14 ru>
- To: vala-list gnome org
- Subject: [Vala] fix sqlite example
- Date: Sat, 09 Aug 2008 00:15:03 +0400
Sqlite sample source from http://live.gnome.org/Vala/SqliteSample
contains some bugs.
Fixed example attached.
using GLib;
using Sqlite;
public class SqliteSample : GLib.Object {
[NoArrayLength ()]
public static int callback (void* data, int n_columns, string[] values, string[] column_names) {
for (int i = 0; i < n_columns; i++) {
stdout.printf ("%s = %s\n", column_names[i], values[i]);
}
stdout.printf ("\n");
return 0;
}
public static int main (string[] args) {
Database db;
int rc;
if (args.length != 3) {
stderr.printf ("Usage: %s DATABASE SQL-STATEMENT\n", args[0]);
return 1;
}
if (!FileUtils.test (args[1], FileTest.IS_REGULAR))
{
stderr.printf ("Database %s not exist or is directory\n",args[1]);
return 1;
}
rc = Database.open(args[1], out db);
if (rc != Sqlite.OK) {
stderr.printf ("Can't open database: %d,%s\n", rc,db.errmsg());
return 1;
}
rc = db.exec(args[2], (Sqlite.Callback) callback, null);
if (rc != Sqlite.OK) {
stderr.printf ("SQL error: %d,%s\n", rc,db.errmsg());
return 1;
}
return 0;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]