
Is it possible to create a javascript User-defined function in sqlite
By: a guest on
Feb 26th, 2012 | syntax:
None | size: 0.74 KB | hits: 20 | expires: Never
//(thanks to Mirnal Kant, SQLManager)
//Version 2 -- Prevent Firefox crashing
// -- Suspect a problem with continual creation of Regex objects
var g_RegExpString = null;
var g_RegExp = null;
//functions to be created for the db
var smDbFunctions = {
// (0) = Regex Expression
// (1) = Column value to test
regexp: {
onFunctionCall: function(val) {
if (g_RegExp == null || val.getString(0) != g_RegExpString)
{
g_RegExpString = val.getString(0);
g_RegExp = new RegExp(g_RegExpString);
}
if (val.getString(1).match(g_RegExp)) return 1;
else return 0;
}
}
};
Database.createFunction("REGEXP", 2, smDbFunctions.regexp);