Add REGEXP SQLite UDF

SQLite automatically uses this function for the "foo REGEX '/[a-z]+/'" syntax
This commit is contained in:
Dan Stillman 2008-06-25 22:22:52 +00:00
parent 9f441140f6
commit 08279f3ff2

View file

@ -957,22 +957,31 @@ Zotero.DBConnection.prototype._getDBConnection = function () {
observerService.addObserver(this, "xpcom-shutdown", false);
observerService = null;
// User-defined functions
// TODO: move somewhere else?
// Levenshtein distance UDF
//
// Implements mozIStorageFunction
// TODO: move somewhere else
var lev = {
ZU: new Zotero.Utilities,
onFunctionCall: function (arg) {
var a = arg.getUTF8String(0);
var b = arg.getUTF8String(1);
return this.ZU.levenshtein(a, b);
}
};
this._connection.createFunction('levenshtein', 2, lev);
// Regexp UDF
var rx = {
onFunctionCall: function (arg) {
var re = new RegExp(arg.getUTF8String(0));
var str = arg.getUTF8String(1);
return re.test(str);
}
};
this._connection.createFunction('regexp', 2, rx);
return this._connection;
}