On Mar 2, 4:27 pm, Stephan Beal <[email protected]> wrote:
> On Mar 2, 12:50 pm, Slide <[email protected]> wrote:
>
> > This is great!
>
> :)

It works!

i finally got my scoping issue worked out (i had to use Persistent::New
(...) instead of Persistent(...)), which means i was able to add
sqlite3_create_function() and the supporting API. The bindings are now
more or less feature complete, with 58 (or so) bound functions. The
only notable things you can't do from JS code are:

- Custom collators (no plans to implement that, since i don't use
them)
- SQL authorizer functions (again, no plans)
- The UTF16 API isn't yet bound. That'll be easy to do once i find the
v8::String::Utf16Value class(???). (This assumes that sqlite3 and v8
use the same internal byte order UTF16 strings...)

The newest source and a link to the source repo are on the code's home
page:

http://wanderinghorse.net/computing/javascript/v8/

Here's a demo of using custom functions:

    print("sqlite3_create_function() test...");
    function my_cb( sqcx, data, values )
    {
        print( "my_cb()!!! argc =",arguments.length, ", values.length
=",values.length);
        for( var i = 0; i < values.length; ++i )
        {
            print( "sqlite3_value_text(value #"+i+") =",sqlite3_value_text
(values[i]));
        }
        sqlite3_result_value( sqcx, values[0] );
        return SQLITE_OK;
    }

    var rc = sqlite3_create_function( my.db, "myfunc", -1,
SQLITE_UTF8, {msg:"hi, callback"}, my_cb );
    print("create_function() rc=",rc);
    rc = sqlite3_select_int(my.db,"select myfunc(7,11,13)");
    print("myfunc() rc=",rc,', errmsg=',sqlite3_errmsg(my.db));


The output:

sqlite3_create_function() test...
create_function() rc= 0
my_cb()!!! argc = 3 , values.length = 3
sqlite3_value_text(value #0) = 7
sqlite3_value_text(value #1) = 11
sqlite3_value_text(value #2) = 13
myfunc() rc= 7 , errmsg= not an error


As always: comments, criticism, suggestions, etc., are always happily
received.

And i'll say this because someone mentioned it to me off-list earlier:
the code is BSD-licensed simply because i took the easy route and
adopted v8's license for it. If someone needs a copy under a different
license, that's not a problem (i honestly don't care what you do with
your copy, including how you choose to re-license it).

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

Reply via email to