Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

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  |  views: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //(thanks to Mirnal Kant, SQLManager)
  2. //Version 2 -- Prevent Firefox crashing
  3. //          -- Suspect a problem with continual creation of Regex objects
  4.  
  5. var g_RegExpString = null;
  6. var g_RegExp = null;
  7.  
  8. //functions to be created for the db
  9. var smDbFunctions = {
  10.   // (0) = Regex Expression
  11.   // (1) = Column value to test
  12.     regexp: {
  13.         onFunctionCall: function(val) {
  14.             if (g_RegExp == null || val.getString(0) != g_RegExpString)
  15.             {
  16.                 g_RegExpString = val.getString(0);
  17.                 g_RegExp = new RegExp(g_RegExpString);
  18.             }
  19.             if (val.getString(1).match(g_RegExp)) return 1;
  20.             else return 0;
  21.         }
  22.     }
  23. };
  24.        
  25. Database.createFunction("REGEXP", 2, smDbFunctions.regexp);