Hi All,

I have been playing around with loadable extensions and am calling some C code 
to do batch processing from database triggers like so:

SQL:

CREATE TRIGGER mytrigger AFTER UPDATE OF myfield ON mytable
BEGIN
    [do some stuff]
    INSERT INTO batch_table (id) SELECT ... [ids of rows which need processing];
    SELECT myfunc(); /* Do batch processing */
END

C extension:

static sqlite3 *_db;

static int odl_recalc_deco_cb(void *unused, int argc, char **argv, char 
**azColName)
{
    [batch functionality]
    return 0;
}

static void myfunc(sqlite3_context *context, int argc, sqlite3_value **arg)
{
    sqlite3_exec(_db, "SELECT id FROM batch_table;DELETE FROM batch_table", 
myfunc_cb, NULL, NULL);
}

int sqlite3_extension_init(sqlite3 *db, char **pzErrMsg, const 
sqlite3_api_routines *pApi)
{
    SQLITE_EXTENSION_INIT2(pApi)
    _db = db;
    sqlite3_create_function(db, "myfunc", 2, SQLITE_ANY, 0, myfunc, 0, 0);
    return 0;
}

Is there anything wrong with doing the above?  The fact that the a sqlite3* is 
not provided to automatically to the custom function (myfunc) makes me think I 
should not be doing anything like this. However, it does work.

Thanks, Si.



       
---------------------------------
Get the name you always wanted with the new y7mail email address.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to