Function: sql-interactive-mode

sql-interactive-mode is an interactive and byte-compiled function defined in sql.el.gz.

Signature

(sql-interactive-mode)

Documentation

Major mode to use a SQL interpreter interactively.

Do not call this function by yourself. The environment must be initialized by an entry function specific for the SQL interpreter. See sql-help for a list of available entry functions.

M-x comint-send-input (comint-send-input) after the end of the process' output sends the text from the end of process to the end of the current line. M-x comint-send-input (comint-send-input) before end of process output copies the current line minus the prompt to the end of the buffer and sends it. M-x comint-copy-old-input (comint-copy-old-input) just copies the current line. Use M-x sql-accumulate-and-indent (sql-accumulate-and-indent) to enter multi-line statements.

If you want to make multiple SQL buffers, rename the *SQL* buffer using C-x x r (rename-buffer) or C-x x u (rename-uniquely) and start a new process. See sql-help for a list of available entry functions. The last buffer created by such an entry function is the current SQLi buffer. SQL buffers will send strings to the SQLi buffer current at the time of their creation. See sql-mode for details.

Sample session using two connections:

1. Create first SQLi buffer by calling an entry function.
2. Rename buffer "*SQL*" to "*Connection 1*".
3. Create a SQL buffer "test1.sql".
4. Create second SQLi buffer by calling an entry function.
5. Rename buffer "*SQL*" to "*Connection 2*".
6. Create a SQL buffer "test2.sql".

Now M-x sql-send-region (sql-send-region) in buffer "test1.sql" will send the region to buffer "*Connection 1*", M-x sql-send-region (sql-send-region) in buffer "test2.sql" will send the region to buffer "*Connection 2*".

If you accidentally suspend your process, use M-x comint-continue-subjob (comint-continue-subjob) to continue it. On some operating systems, this will not work because the signals are not supported.

; sql-magic-semicolon
<delete> delete-forward-char
<kp-delete> delete-forward-char
<mouse-2> comint-insert-input
C-<down> comint-next-input
C-<up> comint-previous-input
C-M-l comint-show-output
C-c . comint-insert-previous-argument
C-c C-\ comint-quit-subjob
C-c C-a comint-bol-or-process-mark
C-c C-c comint-interrupt-subjob
C-c C-d comint-send-eof
C-c C-e comint-show-maximum-output
C-c C-l comint-dynamic-list-input-ring
C-c C-l a sql-list-all
C-c C-l t sql-list-table
C-c C-n comint-next-prompt
C-c C-o comint-delete-output
C-c C-p comint-previous-prompt
C-c C-r comint-show-output
C-c C-s comint-write-output
C-c C-u comint-kill-input
C-c C-w backward-kill-word
C-c C-w sql-copy-column
C-c C-x comint-get-next-from-history
C-c C-z comint-stop-subjob
C-c M-o comint-clear-buffer
C-c M-r comint-previous-matching-input-from-input
C-c M-s comint-next-matching-input-from-input
C-c RET comint-copy-old-input
C-c SPC comint-accumulate
C-d comint-delchar-or-maybe-eof
C-j sql-accumulate-and-indent
C-x <up> comint-complete-input-ring
M-n comint-next-input
M-p comint-previous-input
M-r comint-history-isearch-backward-regexp
RET comint-send-input
Customization: Entry to this mode runs the hooks on comint-mode-hook and sql-interactive-mode-hook (in that order). Before each input, the hooks on comint-input-filter-functions are run. After each SQL interpreter output, the hooks on comint-output-filter-functions are run.

Variable sql-input-ring-file-name controls the initialization of the input ring history.

Variables comint-output-filter-functions, a hook, and comint-scroll-to-bottom-on-input and comint-scroll-to-bottom-on-output control whether input and output cause the window to scroll to the end of the buffer.

If you want to make SQL buffers limited in length, add the function comint-truncate-buffer to comint-output-filter-functions.

Here is an example for your init file. It keeps the SQLi buffer a certain length.

(add-hook 'sql-interactive-mode-hook
    (lambda ()
        (setq comint-output-filter-functions #'comint-truncate-buffer)))

Here is another example. It will always put point back to the statement you entered, right above the output it created.

(setq comint-output-filter-functions
       (lambda (STR) (comint-show-output)))

Probably introduced at or before Emacs version 20.4.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/sql.el.gz
(define-derived-mode sql-interactive-mode comint-mode "SQLi[?]"
  "Major mode to use a SQL interpreter interactively.

Do not call this function by yourself.  The environment must be
initialized by an entry function specific for the SQL interpreter.
See `sql-help' for a list of available entry functions.

\\[comint-send-input] after the end of the process' output sends the
text from the end of process to the end of the current line.
\\[comint-send-input] before end of process output copies the current
line minus the prompt to the end of the buffer and sends it.
\\[comint-copy-old-input] just copies the current line.
Use \\[sql-accumulate-and-indent] to enter multi-line statements.

If you want to make multiple SQL buffers, rename the `*SQL*' buffer
using \\[rename-buffer] or \\[rename-uniquely] and start a new process.
See `sql-help' for a list of available entry functions.  The last buffer
created by such an entry function is the current SQLi buffer.  SQL
buffers will send strings to the SQLi buffer current at the time of
their creation.  See `sql-mode' for details.

Sample session using two connections:

1. Create first SQLi buffer by calling an entry function.
2. Rename buffer \"*SQL*\" to \"*Connection 1*\".
3. Create a SQL buffer \"test1.sql\".
4. Create second SQLi buffer by calling an entry function.
5. Rename buffer \"*SQL*\" to \"*Connection 2*\".
6. Create a SQL buffer \"test2.sql\".

Now \\[sql-send-region] in buffer \"test1.sql\" will send the region to
buffer \"*Connection 1*\", \\[sql-send-region] in buffer \"test2.sql\"
will send the region to buffer \"*Connection 2*\".

If you accidentally suspend your process, use \\[comint-continue-subjob]
to continue it.  On some operating systems, this will not work because
the signals are not supported.

\\{sql-interactive-mode-map}
Customization: Entry to this mode runs the hooks on `comint-mode-hook'
and `sql-interactive-mode-hook' (in that order).  Before each input, the
hooks on `comint-input-filter-functions' are run.  After each SQL
interpreter output, the hooks on `comint-output-filter-functions' are
run.

Variable `sql-input-ring-file-name' controls the initialization of the
input ring history.

Variables `comint-output-filter-functions', a hook, and
`comint-scroll-to-bottom-on-input' and
`comint-scroll-to-bottom-on-output' control whether input and output
cause the window to scroll to the end of the buffer.

If you want to make SQL buffers limited in length, add the function
`comint-truncate-buffer' to `comint-output-filter-functions'.

Here is an example for your init file.  It keeps the SQLi buffer a
certain length.

\(add-hook \\='sql-interactive-mode-hook
    (lambda ()
        (setq comint-output-filter-functions #\\='comint-truncate-buffer)))

Here is another example.  It will always put point back to the statement
you entered, right above the output it created.

\(setq comint-output-filter-functions
       (lambda (STR) (comint-show-output)))"
  :syntax-table sql-mode-syntax-table
  ;; FIXME: The doc above uses `setq' on `comint-output-filter-functions',
  ;; whereas hooks should be manipulated with things like `add/remove-hook'.
  :after-hook (sql--adjust-interactive-setup)

  ;; Get the `sql-product' for this interactive session.
  (setq-local sql-product (or sql-interactive-product
                           sql-product))

  ;; Setup the mode.
  (setq mode-name
        (concat "SQLi[" (or (sql-get-product-feature sql-product :name)
                            (symbol-name sql-product)) "]"))

  ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try
  ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column
  ;; will have just one quote.  Therefore syntactic highlighting is
  ;; disabled for interactive buffers.  No imenu support.
  (sql-product-font-lock t nil)

  ;; Enable commenting and uncommenting of the region.
  (setq-local comment-start "--")
  ;; Abbreviation table init and case-insensitive.  It is not activated
  ;; by default.
  (setq local-abbrev-table sql-mode-abbrev-table)
  (setq abbrev-all-caps 1)
  ;; Exiting the process will call sql-stop.
  (let ((proc (get-buffer-process (current-buffer))))
    (when proc (set-process-sentinel proc #'sql-stop)))
  ;; Save the connection and login params
  (setq-local sql-user       sql-user)
  (setq-local sql-database   sql-database)
  (setq-local sql-server     sql-server)
  (setq-local sql-port       sql-port)
  (setq-local sql-connection sql-connection)
  (setq-default sql-connection nil)
  ;; Contains the name of database objects
  (setq-local sql-contains-names t)
  ;; Keep track of existing object names
  (setq-local sql-completion-object nil)
  (setq-local sql-completion-column nil)
  ;; Create a useful name for renaming this buffer later.
  (setq-local sql-alternate-buffer-name
              (sql-make-alternate-buffer-name))
  ;; User stuff.  Initialize before the hook.
  (setq-local sql-prompt-regexp
              (or (sql-get-product-feature sql-product :prompt-regexp) "^"))
  (setq-local sql-prompt-length
              (sql-get-product-feature sql-product :prompt-length))
  (setq-local sql-prompt-cont-regexp
              (sql-get-product-feature sql-product :prompt-cont-regexp))
  (make-local-variable 'sql-output-newline-count)
  (make-local-variable 'sql-preoutput-hold)
  (add-hook 'comint-preoutput-filter-functions
            #'sql-interactive-remove-continuation-prompt nil t)
  (make-local-variable 'sql-input-ring-separator)
  (make-local-variable 'sql-input-ring-file-name))