install_rewriter.sql 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software Foundation,
  11. 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
  12. CREATE DATABASE IF NOT EXISTS query_rewrite;
  13. CREATE TABLE IF NOT EXISTS query_rewrite.rewrite_rules (
  14. id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  15. pattern VARCHAR(10000) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  16. pattern_database VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_bin,
  17. replacement VARCHAR(10000) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  18. enabled ENUM('YES', 'NO') CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
  19. DEFAULT 'YES',
  20. message VARCHAR(1000) CHARACTER SET utf8 COLLATE utf8_bin,
  21. pattern_digest VARCHAR(32),
  22. normalized_pattern VARCHAR(100)
  23. ) DEFAULT CHARSET = utf8 ENGINE = INNODB;
  24. INSTALL PLUGIN rewriter SONAME 'rewriter.dll';
  25. CREATE FUNCTION load_rewrite_rules RETURNS STRING
  26. SONAME 'rewriter.dll';
  27. DELIMITER //
  28. CREATE PROCEDURE query_rewrite.flush_rewrite_rules()
  29. BEGIN
  30. DECLARE message_text VARCHAR(100);
  31. COMMIT;
  32. SELECT load_rewrite_rules() INTO message_text;
  33. RESET QUERY CACHE;
  34. IF NOT message_text IS NULL THEN
  35. SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = message_text;
  36. END IF;
  37. END //
  38. DELIMITER ;
  39. RESET QUERY CACHE;