Hi, all!

i wanted to share a bit:

This evening i've made good progress on sqlite3 bindings for v8. It
only binds about 15 functions at the moment, but this effort has shown
that it'll be relatively little work to port over the SpiderMonkey/
SpiderApe sqlite3 bindings to v8.

Here's an example: (working JS code):

{{{
var my = {db:0,stmt:0};
my.db = sqlite3_open("my.db");
print('typeof db =',typeof my.db); // print(my.db) segfaults!
print('SQLITE_BUSY ==',SQLITE_BUSY); // all SQLITE_xxx macros are
bound
my.stmt = sqlite3_prepare( my.db, "create table if not exists t
(a,b,c)");
print('typeof stmt ==',typeof my.stmt,', errmsg =',sqlite3_errmsg
(my.db));
var rc = sqlite3_step( my.stmt );
print("step() rc ==",rc);
rc = sqlite3_finalize( my.stmt );
my.stmt = 0;
print("finalize() rc ==",rc);
if(1)
{
    my.stmt = sqlite3_prepare( my.db, "insert into t(a,b,c) values
(?,?,?)" );
    var now = (new Date()).toString();
    for( var i = 0; i < 5; ++i )
    {
        sqlite3_bind( my.stmt, 1, 42 + i );
        sqlite3_bind( my.stmt, 2, 24.42 * i );
        //sqlite3_bind_text( my.stmt, 3, now+": #"+i, 10 );
        sqlite3_bind_text( my.stmt, 3, now+": #"+i );
        sqlite3_step( my.stmt );
        sqlite3_reset( my.stmt );
    }
    sqlite3_finalize( my.stmt );
}
sqlite3_close( my.db );
}}}

The output looks a bit like:

{{{
step...@jareth:~/src/google/v8/samples$ ./my s.js
typeof db = object
SQLITE_BUSY == 5
typeof stmt == object , errmsg = not an error
step() rc == 101
finalize() rc == 0
v8-sqlite3.cc:82 : Closing sqlite3 handle @0x91a6b38
}}}

(Interestingly, the real (typeof my.db) is v8::External, which is-not-
a Object, and i'm curious if that's a bug in v8?)

If anyone's interested in getting the code, send me a mail off-list
and i'll send you a link to the code once it's usable. (In case the
list filters out my email addy, it's here: 
http://wanderinghorse.net/home/stephan/)

Because i'm basically porting over older (SpiderMonkey-based) code, i
expect the final result will look something like the existing
SpiderMonkey bindings:

http://spiderape.sourceforge.net/plugins/sqlite/

Happy hacking!

--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to