pixilang on andriod with sqlite

Pixilang programming language
Post Reply
kmatze
Posts: 47
Joined: Wed Jun 22, 2011 12:36 am

pixilang on andriod with sqlite

Post by kmatze »

hi nightradio,
is it possible to make core support in pixilang to use sqlite database?
greetings kmatze
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: pixilang on andriod with sqlite

Post by NightRadio »

Hi!
I believe you can include sqlite using dlopen() and dlcall() functions.
As for the core support - i don't think it is necessary for Pixilang :)
kmatze
Posts: 47
Joined: Wed Jun 22, 2011 12:36 am

Re: pixilang on andriod with sqlite

Post by kmatze »

hi nightradio,
NightRadio wrote:Hi!
I believe you can include sqlite using dlopen() and dlcall() functions.
As for the core support - i don't think it is necessary for Pixilang :)
I try and try but it don't go (under windows).

Thats the definition of sqlite-function:

int sqlite3_open(
const char *filename, /* Database filename (UTF-8) */
sqlite3 **ppDb /* OUT: SQLite db handle */
);

in pixilang:

SQLite = dlopen( "sqlite3.dll")
if SQLite >= 0 {
sql_open = dlsym(SQLite, "sqlite3_open", "v(pp)")
if sql_open >= 0 {
retval = dlcall( SQLite, sql_open, "test.db", "DB")
}
dlclose( SQLite )
}

The result is an windows system error.

where is the mistake? How to declare a handle?

thanks and greetings - kmatze
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: pixilang on andriod with sqlite

Post by NightRadio »

retval = dlcall( SQLite, sql_open, "test.db", "DB")
Hm... But what is "DB" in your code?
I'm not sure about sqlite, but can you provide some C/C++ source where sqlite3_open() is used?
kmatze
Posts: 47
Joined: Wed Jun 22, 2011 12:36 am

Re: pixilang on andriod with sqlite

Post by kmatze »

hi nightradio,
NightRadio wrote:
retval = dlcall( SQLite, sql_open, "test.db", "DB")
Hm... But what is "DB" in your code?
I'm not sure about sqlite, but can you provide some C/C++ source where sqlite3_open() is used?
DB should be the handle for the opend database file. DB ist used in the other calls of sqlite.

thats the declaration/definition/function in c (to call from pixilang):

Code: Select all

int sqlite3_open(
     const char *filename,   /* Database filename (UTF-8) */
     sqlite3 **ppDb              /* OUT: SQLite db handle */
);
and the usage in c:

Code: Select all

rc = sqlite3_open("test.db", &db);
the next statement is to use the open database file (handle) to execute a sql statement, here the c-function:

Code: Select all

sys   sqlite3_exec (sys db,char* s, sys p1, sys p2, sys*dberr)
where db = handle of open database file
s = callback function
p1 = callback function
p2 = parameter list for callback function
dberr = errormessage

and the uage in c:

Code: Select all

   rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
the c usage in summary thats I want to use in pixilang, but how?

Code: Select all

rc = sqlite3_open("test.db", &db);
rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
sqlite3_close(db);
//
// and the callback function
//
static int callback(void *data, int argc, char **argv, char **azColName)
thanks and greetings - kmatze
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: pixilang on andriod with sqlite

Post by NightRadio »

Ok, please try the following:

Code: Select all

SQLite = dlopen( "sqlite3.dll")
if SQLite >= 0 {
  sql_open = dlsym( SQLite, "sqlite3_open", "v(pp)" )
  if sql_open >= 0 {
    //ppDb is a pointer to pointer. In the 32bit system the pointer size is 4 bytes.
    //So we just need a four-byte container. Here is the simplest way to create such container:
    ppDb = "1234" //Four bytes (32bit pointer)
    //And then use the pointer to ppDb in the open() function:
    retval = dlcall( SQLite, sql_open, "test.db", ppDb )
  }
  dlclose( SQLite )
}
Post Reply