Function: sql-mode
sql-mode is an autoloaded, interactive and byte-compiled function
defined in sql.el.gz.
Signature
(sql-mode)
Documentation
Major mode to edit SQL.
You can send SQL statements to the SQLi buffer using
M-x sql-send-region (sql-send-region). Such a buffer must exist before you can do this.
See sql-help on how to create SQLi buffers.
C-M-a sql-beginning-of-statement
C-M-e sql-end-of-statement
C-c C-b sql-send-buffer
C-c C-c sql-send-paragraph
C-c C-l a sql-list-all
C-c C-l t sql-list-table
C-c C-n sql-send-line-and-next
C-c C-r sql-send-region
C-c C-s sql-send-string
C-c C-z sql-show-sqli-buffer
C-c TAB sql-product-interactive
Customization: Entry to this mode runs the sql-mode-hook.
When you put a buffer in SQL mode, the buffer stores the last SQLi
buffer created as its destination in the variable sql-buffer. This
will be the buffer M-x sql-send-region (sql-send-region) sends the region to. If this
SQLi buffer is killed, M-x sql-send-region (sql-send-region) is no longer able to
determine where the strings should be sent to. You can set the
value of sql-buffer using M-x sql-set-sqli-buffer (sql-set-sqli-buffer).
For information on how to create multiple SQLi buffers, see
sql-interactive-mode.
Note that SQL doesn't have an escape character unless you specify one. If you specify backslash as escape character in SQL, you must tell Emacs. Here's how to do that in your init file:
(add-hook 'sql-mode-hook
(lambda ()
(modify-syntax-entry ?\\ "\\\\" sql-mode-syntax-table)))
Probably introduced at or before Emacs version 20.4.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/sql.el.gz
;;; SQL mode -- uses SQL interactive mode
;;;###autoload
(define-derived-mode sql-mode prog-mode "SQL"
"Major mode to edit SQL.
You can send SQL statements to the SQLi buffer using
\\[sql-send-region]. Such a buffer must exist before you can do this.
See `sql-help' on how to create SQLi buffers.
\\{sql-mode-map}
Customization: Entry to this mode runs the `sql-mode-hook'.
When you put a buffer in SQL mode, the buffer stores the last SQLi
buffer created as its destination in the variable `sql-buffer'. This
will be the buffer \\[sql-send-region] sends the region to. If this
SQLi buffer is killed, \\[sql-send-region] is no longer able to
determine where the strings should be sent to. You can set the
value of `sql-buffer' using \\[sql-set-sqli-buffer].
For information on how to create multiple SQLi buffers, see
`sql-interactive-mode'.
Note that SQL doesn't have an escape character unless you specify
one. If you specify backslash as escape character in SQL, you
must tell Emacs. Here's how to do that in your init file:
\(add-hook \\='sql-mode-hook
(lambda ()
(modify-syntax-entry ?\\\\ \"\\\\\" sql-mode-syntax-table)))"
:abbrev-table sql-mode-abbrev-table
;; (smie-setup sql-smie-grammar #'sql-smie-rules)
(setq-local comment-start "--")
;; Make each buffer in sql-mode remember the "current" SQLi buffer.
(make-local-variable 'sql-buffer)
;; Add imenu support for sql-mode. Note that imenu-generic-expression
;; is buffer-local, so we don't need a local-variable for it. SQL is
;; case-insensitive, that's why we have to set imenu-case-fold-search.
(setq imenu-generic-expression sql-imenu-generic-expression
imenu-case-fold-search t)
;; Make `sql-send-paragraph' work on paragraphs that contain indented
;; lines.
(setq-local paragraph-separate "[\f]*$")
(setq-local paragraph-start "[\n\f]")
;; Abbrevs
(setq-local abbrev-all-caps 1)
;; Contains the name of database objects
(setq-local sql-contains-names t)
(setq-local escaped-string-quote "'")
(setq-local syntax-propertize-function
(eval
'(syntax-propertize-rules
;; Handle escaped apostrophes within strings.
((if (eq sql-product 'mysql)
"\\\\'"
"''")
(0
(if (save-excursion
(nth 3 (syntax-ppss (match-beginning 0))))
(string-to-syntax ".")
(forward-char -1)
nil)))
;; Propertize rules to not have /- and -* start comments.
("\\(/-\\)" (1 "."))
("\\(-\\*\\)"
(1
(if (save-excursion
(not (ppss-comment-depth
(syntax-ppss (match-beginning 1)))))
;; If we're outside a comment, we don't let -*
;; start a comment.
(string-to-syntax ".")
;; Inside a comment, ignore it to avoid -*/ not
;; being interpreted as a comment end.
(forward-char -1)
nil))))
t))
;; Set syntax and font-face highlighting
;; Catch changes to sql-product and highlight accordingly
(sql-set-product (or sql-product 'ansi)) ; Fixes bug#13591
(add-hook 'hack-local-variables-hook #'sql-highlight-product t t))