sqlite-regex-replace-ext icon indicating copy to clipboard operation
sqlite-regex-replace-ext copied to clipboard

Doesn't Work

Open rothkj1022 opened this issue 8 years ago • 2 comments

Was able to compile and load extension to sqlite db, but the regex_replace() function just doesn't work. Seems to always return the second parameter.

Perhaps providing some usage examples and/or instructions would help.

rothkj1022 avatar Jun 23 '17 21:06 rothkj1022

sqlite> .load glib_replace.so
sqlite> select regex_replace("world", "hello, world!", "C");
hello, C!

gwenn avatar Jun 29 '17 18:06 gwenn

I too would like to see some examples. And a description. I've been using this function for a while with this module and never looked very closely. But it looks like its arguments are in a different order from Oracle and MySQL. mysql has args of expression (the field name), pat (the regex), replacement. But this one is pattern, expression, replacement. From the source code:

    const UChar *zPattern = sqlite3_value_text16(argv[0]);
    const UChar *zString = sqlite3_value_text16(argv[1]);
    const UChar *zReplacement = sqlite3_value_text16(argv[2]);
sqlite> CREATE TABLE test(name CHAR);
sqlite> INSERT INTO test VALUES ("alphabetical");
sqlite> SELECT * FROM test ;
alphabetical
sqlite> SELECT name,regex_replace("p.*i",name,"junk")  FROM test;
alphabetical|aljunkcal
And more:
sqlite> INSERT INTO test VALUES ("anti-alphabetical");
sqlite> SELECT 
              name,
               REGEX_REPLACE("p.*i",name,"junk"),
               REGEX_REPLACE("^a.*?i",name,"betterjunk") 
           FROM test;

alphabetical|aljunkcal|betterjunkcal
anti-alphabetical|anti-aljunkcal|betterjunk-alphabetical

gsker avatar Feb 06 '21 00:02 gsker