diff options
| author | Michael R. Mauger | 2019-04-20 20:13:56 -0400 |
|---|---|---|
| committer | Michael R. Mauger | 2019-04-21 00:05:42 -0400 |
| commit | 23d8cfb9ce950f12b80314a9840a637177178e29 (patch) | |
| tree | 8f2d9b233d40b50d199ddb3265e1d70d46e69181 | |
| parent | 21db386ac0df26f0b1a549e0bd4f83c5bbce6361 (diff) | |
| download | emacs-23d8cfb9ce950f12b80314a9840a637177178e29.tar.gz emacs-23d8cfb9ce950f12b80314a9840a637177178e29.zip | |
* lisp/progmodes.sql.el
(sql-product-alist): Corrected :terminator defns.
(sql-debug-send): New variable.
(sql-send-string): Use it and correct buffer context.
(sql-send-magic-terminator): Use `sql-input-sender'.
(sql-placeholders-filter): Bug#11481 Don't recursively replace placeholders
* test/lisp/progmodes/sql-tests.el
(sql-test-placeholder-filter): Test placeholder functionality.
| -rw-r--r-- | lisp/progmodes/sql.el | 42 | ||||
| -rw-r--r-- | test/lisp/progmodes/sql-tests.el | 34 |
2 files changed, 57 insertions, 19 deletions
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el index 4ab174d92b9..fa9354e012e 100644 --- a/lisp/progmodes/sql.el +++ b/lisp/progmodes/sql.el | |||
| @@ -223,6 +223,7 @@ | |||
| 223 | ;; Simen Heggestøyl <simenheg@gmail.com> -- Postgres database completion | 223 | ;; Simen Heggestøyl <simenheg@gmail.com> -- Postgres database completion |
| 224 | ;; Robert Cochran <robert-emacs@cochranmail.com> -- MariaDB support | 224 | ;; Robert Cochran <robert-emacs@cochranmail.com> -- MariaDB support |
| 225 | ;; Alex Harsanyi <alexharsanyi@gmail.com> -- sql-indent package and support | 225 | ;; Alex Harsanyi <alexharsanyi@gmail.com> -- sql-indent package and support |
| 226 | ;; Roy Mathew <rmathew8@gmail.com> -- bug in `sql-send-string' | ||
| 226 | ;; | 227 | ;; |
| 227 | 228 | ||
| 228 | 229 | ||
| @@ -477,7 +478,7 @@ file. Since that is a plaintext file, this could be dangerous." | |||
| 477 | :prompt-cont-regexp "^\\(?:[ ][ ][1-9]\\|[ ][1-9][0-9]\\|[1-9][0-9]\\{2\\}\\)[ ]\\{2\\}" | 478 | :prompt-cont-regexp "^\\(?:[ ][ ][1-9]\\|[ ][1-9][0-9]\\|[1-9][0-9]\\{2\\}\\)[ ]\\{2\\}" |
| 478 | :statement sql-oracle-statement-starters | 479 | :statement sql-oracle-statement-starters |
| 479 | :syntax-alist ((?$ . "_") (?# . "_")) | 480 | :syntax-alist ((?$ . "_") (?# . "_")) |
| 480 | :terminator ("\\(^/\\|;\\)$" . "/") | 481 | :terminator ("\\(^/\\|;\\)" . "/") |
| 481 | :input-filter sql-placeholders-filter) | 482 | :input-filter sql-placeholders-filter) |
| 482 | 483 | ||
| 483 | (postgres | 484 | (postgres |
| @@ -495,7 +496,7 @@ file. Since that is a plaintext file, this could be dangerous." | |||
| 495 | :prompt-length 5 | 496 | :prompt-length 5 |
| 496 | :prompt-cont-regexp "^[[:alnum:]_]*[-(][#>] " | 497 | :prompt-cont-regexp "^[[:alnum:]_]*[-(][#>] " |
| 497 | :input-filter sql-remove-tabs-filter | 498 | :input-filter sql-remove-tabs-filter |
| 498 | :terminator ("\\(^\\s-*\\\\g$\\|;\\)" . "\\g")) | 499 | :terminator ("\\(^\\s-*\\\\g\\|;\\)" . "\\g")) |
| 499 | 500 | ||
| 500 | (solid | 501 | (solid |
| 501 | :name "Solid" | 502 | :name "Solid" |
| @@ -520,8 +521,7 @@ file. Since that is a plaintext file, this could be dangerous." | |||
| 520 | :completion-object sql-sqlite-completion-object | 521 | :completion-object sql-sqlite-completion-object |
| 521 | :prompt-regexp "^sqlite> " | 522 | :prompt-regexp "^sqlite> " |
| 522 | :prompt-length 8 | 523 | :prompt-length 8 |
| 523 | :prompt-cont-regexp "^ \\.\\.\\.> " | 524 | :prompt-cont-regexp "^ \\.\\.\\.> ") |
| 524 | :terminator ";") | ||
| 525 | 525 | ||
| 526 | (sybase | 526 | (sybase |
| 527 | :name "Sybase" | 527 | :name "Sybase" |
| @@ -3640,12 +3640,16 @@ Inserts SELECT or commas if appropriate." | |||
| 3640 | Placeholders are words starting with an ampersand like &this." | 3640 | Placeholders are words starting with an ampersand like &this." |
| 3641 | 3641 | ||
| 3642 | (when sql-oracle-scan-on | 3642 | (when sql-oracle-scan-on |
| 3643 | (while (string-match "&?&\\(\\(?:\\sw\\|\\s_\\)+\\)[.]?" string) | 3643 | (let ((start 0) |
| 3644 | (setq string (replace-match | 3644 | (replacement "")) |
| 3645 | (read-from-minibuffer | 3645 | (while (string-match "&?&\\(\\(?:\\sw\\|\\s_\\)+\\)[.]?" string start) |
| 3646 | (format "Enter value for %s: " (match-string 1 string)) | 3646 | (setq replacement (read-from-minibuffer |
| 3647 | nil nil nil 'sql-placeholder-history) | 3647 | (format "Enter value for %s: " |
| 3648 | t t string)))) | 3648 | (propertize (match-string 1 string) |
| 3649 | 'face 'font-lock-variable-name-face)) | ||
| 3650 | nil nil nil 'sql-placeholder-history) | ||
| 3651 | string (replace-match replacement t t string) | ||
| 3652 | start (+ (match-beginning 1) (length replacement)))))) | ||
| 3649 | string) | 3653 | string) |
| 3650 | 3654 | ||
| 3651 | ;; Using DB2 interactively, newlines must be escaped with " \". | 3655 | ;; Using DB2 interactively, newlines must be escaped with " \". |
| @@ -3794,6 +3798,8 @@ to avoid deleting non-prompt output." | |||
| 3794 | oline) | 3798 | oline) |
| 3795 | 3799 | ||
| 3796 | ;;; Sending the region to the SQLi buffer. | 3800 | ;;; Sending the region to the SQLi buffer. |
| 3801 | (defvar sql-debug-send nil | ||
| 3802 | "Display text sent to SQL process pragmatically.") | ||
| 3797 | 3803 | ||
| 3798 | (defun sql-send-string (str) | 3804 | (defun sql-send-string (str) |
| 3799 | "Send the string STR to the SQL process." | 3805 | "Send the string STR to the SQL process." |
| @@ -3807,12 +3813,14 @@ to avoid deleting non-prompt output." | |||
| 3807 | (save-excursion | 3813 | (save-excursion |
| 3808 | ;; Set product context | 3814 | ;; Set product context |
| 3809 | (with-current-buffer sql-buffer | 3815 | (with-current-buffer sql-buffer |
| 3816 | (when sql-debug-send | ||
| 3817 | (message ">>SQL> %S" s)) | ||
| 3818 | |||
| 3810 | ;; Send the string (trim the trailing whitespace) | 3819 | ;; Send the string (trim the trailing whitespace) |
| 3811 | (sql-input-sender (get-buffer-process sql-buffer) s) | 3820 | (sql-input-sender (get-buffer-process (current-buffer)) s) |
| 3812 | 3821 | ||
| 3813 | ;; Send a command terminator if we must | 3822 | ;; Send a command terminator if we must |
| 3814 | (when sql-send-terminator | 3823 | (sql-send-magic-terminator sql-buffer s sql-send-terminator) |
| 3815 | (sql-send-magic-terminator sql-buffer s sql-send-terminator)) | ||
| 3816 | 3824 | ||
| 3817 | (when sql-pop-to-buffer-after-send-region | 3825 | (when sql-pop-to-buffer-after-send-region |
| 3818 | (message "Sent string to buffer %s" sql-buffer)))) | 3826 | (message "Sent string to buffer %s" sql-buffer)))) |
| @@ -3874,12 +3882,8 @@ to avoid deleting non-prompt output." | |||
| 3874 | 3882 | ||
| 3875 | ;; Check to see if the pattern is present in the str already sent | 3883 | ;; Check to see if the pattern is present in the str already sent |
| 3876 | (unless (and pat term | 3884 | (unless (and pat term |
| 3877 | (string-match (concat pat "\\'") str)) | 3885 | (string-match-p (concat pat "\\'") str)) |
| 3878 | (comint-simple-send (get-buffer-process buf) term) | 3886 | (sql-input-sender (get-buffer-process buf) term)))) |
| 3879 | (setq sql-output-newline-count | ||
| 3880 | (if sql-output-newline-count | ||
| 3881 | (1+ sql-output-newline-count) | ||
| 3882 | 1))))) | ||
| 3883 | 3887 | ||
| 3884 | (defun sql-remove-tabs-filter (str) | 3888 | (defun sql-remove-tabs-filter (str) |
| 3885 | "Replace tab characters with spaces." | 3889 | "Replace tab characters with spaces." |
diff --git a/test/lisp/progmodes/sql-tests.el b/test/lisp/progmodes/sql-tests.el index 7a11f762eb0..5ac34907c2d 100644 --- a/test/lisp/progmodes/sql-tests.el +++ b/test/lisp/progmodes/sql-tests.el | |||
| @@ -270,5 +270,39 @@ Perform ACTION and validate results" | |||
| 270 | (sql-test-product-feature-harness | 270 | (sql-test-product-feature-harness |
| 271 | (should-not (sql-get-product-feature 'd :Z)))) | 271 | (should-not (sql-get-product-feature 'd :Z)))) |
| 272 | 272 | ||
| 273 | ;;; SQL Oracle SCAN/DEFINE | ||
| 274 | (ert-deftest sql-tests-placeholder-filter () | ||
| 275 | "Test that placeholder relacement is as expected." | ||
| 276 | (let ((syntab (syntax-table)) | ||
| 277 | (sql-oracle-scan-on t) | ||
| 278 | (placeholder-value "")) | ||
| 279 | (set-syntax-table sql-mode-syntax-table) | ||
| 280 | |||
| 281 | (cl-letf | ||
| 282 | (((symbol-function 'read-from-minibuffer) | ||
| 283 | (lambda (&rest _) placeholder-value))) | ||
| 284 | |||
| 285 | (setq placeholder-value "XX") | ||
| 286 | (should (equal | ||
| 287 | (sql-placeholders-filter "select '&x' from dual;") | ||
| 288 | "select 'XX' from dual;")) | ||
| 289 | |||
| 290 | (setq placeholder-value "&Y") | ||
| 291 | (should (equal | ||
| 292 | (sql-placeholders-filter "select '&x' from dual;") | ||
| 293 | "select '&Y' from dual;")) | ||
| 294 | (should (equal | ||
| 295 | (sql-placeholders-filter "select '&x' from dual;") | ||
| 296 | "select '&Y' from dual;")) | ||
| 297 | (should (equal | ||
| 298 | (sql-placeholders-filter "select '&x.' from dual;") | ||
| 299 | "select '&Y' from dual;")) | ||
| 300 | (should (equal | ||
| 301 | (sql-placeholders-filter "select '&x.y' from dual;") | ||
| 302 | "select '&Yy' from dual;"))) | ||
| 303 | |||
| 304 | (set-syntax-table syntab))) | ||
| 305 | |||
| 306 | |||
| 273 | (provide 'sql-tests) | 307 | (provide 'sql-tests) |
| 274 | ;;; sql-tests.el ends here | 308 | ;;; sql-tests.el ends here |