[Vala] sqlite needs more love



I'm writting a Vala application that interacts with an SQLite database,
and i have found some problems with it. (i'll upload a working example
to the wiki when everything works well).

Here's the snippet:
------------------------------------
using GLib;
using Sqlite;

public class Foo.Bar
{
        public static int select_callback(pointer data, int n_columns, string[] values, string[] column_names)
        {
                stdout.printf(" ncolumns: %d\n", n_columns);
                stdout.printf(" values: %s = %s\n", values[0], values[1]);
                stdout.printf(" colnames: %x\n", column_names);
                return 0; // continue
        }

        public static void main(string[] args)
        {
                Database db;
                Database.open("test.db", out db);
                // init
                //db.exec("create table hello (name VARCHAR(100), surname VARCHAR(100))");
                //db.exec("insert into hello (name, surname) values ('foo','bar')");
                db.exec("select * from hello", (Sqlite.Callback)select_callback);
                db = null;
        }
}
----------------------------------------

The program shows:

$ ./hello 
 ncolumns: 2
 values: name = surname
 colnames: 0

This is not ok, coz "colnames" is a NULL pointer and values argument has
the contents of the colnames column.

So...the arguments are not shifted...but i don't know where they are :)

The another thing is that there'r lot of enums missing (i will provide
an update for the .vapi file asap). these values refer to the step() and
exec() methods which returns an integer value defined in the sqlite3.h file.

#define SQLITE_OK           0   /* Successful result */
/* beginning-of-error-codes */
#define SQLITE_ERROR        1   /* SQL error or missing database */
#define SQLITE_INTERNAL     2   /* NOT USED. Internal logic error in SQLite */
...

Another thing is that I was unable to setup a reference to a delegate
callback when assigning the second argument for exec()

Which is the right way?

  Sqlite.Callback cb = ref select_callback;
  Sqlite.Callback cb = out select_callback;
  ...

The compiler actually allows too many ways to write Vala code, but not much
of these ways are compilable by gcc. I think that all these kind of things
(weak, out, ref, delegate, ...) should be defined in a more strict way to
avoid segmentation faults, gcc warnings and so.

Thanks!

  --pancake



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