Advertisement
Guest User

Is it possible to create a javascript User-defined function in sqlite

a guest
Feb 26th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  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);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement