x550j / trimpath

Automatically exported from code.google.com/p/trimpath
0 stars 0 forks source link

here is an RLIKE (regular expression LIKE) implementation - a little crude #3

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Your forum won't let me post, so I'm posting this here, hopefully it will
be googled. BTW, this effectively does LIKE as well...

I add this line of code:

/*CEM*/js = js.replace(/RLIKE(.*)\((.*)\,(.*)\)/g, "(new
RegExp($2)).exec($3) != null");

to this block of code around like 344 in my query.js (1.0.38):

        NodeType.rawSql.prototype.toJs = function(flags) { 
            var js = this.sql;
            js = js.replace(/ AND /g, " && ");
            js = js.replace(/ OR /g, " || ");
            js = js.replace(/ = /g, " == ");
            js = js.replace(/ IS NULL/g, " == null");
            js = js.replace(/ IS NOT NULL/g, " != null");
            js = js.replace(/ NOT /g, " ! ");
            return js;
        }

The syntax would kinda be like this (from your playsite/demosite/example page:)

SELECT Customer.id, Customer.acctBalance
FROM Customer
WHERE RLIKE('0.*0',Customer.acctBalance)
ORDER BY Customer.id

Query Result:
id: 10, acctBalance: 1000,
id: 20, acctBalance: 2000,
id: 30, acctBalance: 3000, 

Limits: can't have commas or () in your regexp...

Original issue reported on code.google.com by carlemueller on 27 Jun 2007 at 8:34