Re: [gnome-db] Sqlite database creation



Thanks for the quick response.

I found the problem. There was a mismatch between the app executable and the database names.

In my CMAKE file  :
set (EXEC_NAME "test")

and in my application.vala
conn = Gda.Connection.open_from_string ("SQLite",
            "DB_DIR=.;DB_NAME=test", null, Gda.ConnectionOptions.NONE);

It compiles correctly and creates the "test" executable.

But when I launch the app, the error is "uncaught error: file is encrypted or is not a database (gda_connection_error, 5)"

It doesn't create the database file and try to open the exec.

The workaround is to rename the EXEC_NAME or the DB_NAME.




Le ven 24 oct 2014 à 19:13, Daniel Espinosa <esodan gmail com> a écrit :
I've used:

cnn = Gda.Connection.open_from_string ("Sqlite", "DB_NAME=test.db;DB_DIR=.",null, Gda.ConnectionOptions.READ_ONLY);

and it is working for me. Using libgda 5.2 and Vala 0.22 on Ubuntu GNOME 14.04.

Could you give me some code example.

I've used this one:


using Gda;
class Application : Object {
    public Gda.Connection cnn { get; set; }
    public int run ()
    {
        cnn = Gda.Connection.open_from_string ("SQLite", "DB_NAME=test;DB_DIR=.",null, Gda.ConnectionOptions.READ_ONLY);
        return 0;
    }
    static int main (string[] args)
  {
    var app = new Application ();
    return app.run ();
  }
}

2014-10-24 9:03 GMT-05:00 Christophe Bastin <bastin chris gmail com>:
Hi everyone,

I'm having some trouble using Vala and libda 5.0 for SQLite.

In Python I have succesfully created a SQLite database with 
conn = Gda.Connection(provider = Gda.Config.get_provider("SQLite"),
                                          cnc_string = "DB_DIR=.;DB_NAME=test")
conn.open()
conn.close()

In Vala I tried different solutions:

conn = new Gda.Connection (); // fails with undefined reference to `gda_connection_new' 

or with:
conn = new Gda.Connection.open_from_string ("SQLite",
            "DB_DIR=.;DB_NAME=test", null,
            Gda.ConnectionOptions.NONE);

// fails because the database file doesn't exist.

So how can I create the SQLite file at connection startup ?

Chris

_______________________________________________
gnome-db-list mailing list
gnome-db-list gnome org
https://mail.gnome.org/mailman/listinfo/gnome-db-list




--
Trabajar, la mejor arma para tu superación
"de grano en grano, se hace la arena" (R) (en trámite, pero para los cuates: LIBRE)


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