commit 08279f3ff25831ae9eff28d703e328733c0cf755
parent 9f441140f6eca252006e77441c0383d882547722
Author: Dan Stillman <dstillman@zotero.org>
Date: Wed, 25 Jun 2008 22:22:52 +0000
Add REGEXP SQLite UDF
SQLite automatically uses this function for the "foo REGEX '/[a-z]+/'" syntax
Diffstat:
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js
@@ -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;
}