Function: sql-redirect-value

sql-redirect-value is a byte-compiled function defined in sql.el.gz.

Signature

(sql-redirect-value SQLBUF COMMAND &optional REGEXP REGEXP-GROUPS)

Documentation

Execute the SQL command and return part of result.

SQLBUF must be an active SQL interactive buffer. COMMAND should be a string of commands accepted by the SQLi program. From the output, the REGEXP is repeatedly matched and the list of REGEXP-GROUPS submatches is returned. This behaves much like M-x comint-redirect-results-list-from-process (comint-redirect-results-list-from-process) but instead of returning a single submatch it returns a list of each submatch for each match.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/sql.el.gz
(defun sql-redirect-value (sqlbuf command &optional regexp regexp-groups)
  "Execute the SQL command and return part of result.

SQLBUF must be an active SQL interactive buffer.  COMMAND should
be a string of commands accepted by the SQLi program.  From the
output, the REGEXP is repeatedly matched and the list of
REGEXP-GROUPS submatches is returned.  This behaves much like
\\[comint-redirect-results-list-from-process] but instead of
returning a single submatch it returns a list of each submatch
for each match."

  (let ((outbuf " *SQL-Redirect-values*")
        (results nil))
    (sql-redirect sqlbuf command outbuf nil)
    (with-current-buffer outbuf
      (while (re-search-forward (or regexp "^.+$") nil t)
	(push
         (cond
          ;; no groups-return all of them
          ((null regexp-groups)
           (let ((i (/ (length (match-data)) 2))
                 (r nil))
             (while (> i 0)
               (setq i (1- i))
               (push (match-string i) r))
             r))
          ;; one group specified
          ((numberp regexp-groups)
           (match-string regexp-groups))
          ;; list of numbers; return the specified matches only
          ((consp regexp-groups)
           (mapcar (lambda (c)
                       (cond
                        ((numberp c) (match-string c))
                        ((stringp c) (match-substitute-replacement c))
                        (t (error "sql-redirect-value: Unknown REGEXP-GROUPS value - %s" c))))
                   regexp-groups))
          ;; String is specified; return replacement string
          ((stringp regexp-groups)
           (match-substitute-replacement regexp-groups))
          (t
           (error "sql-redirect-value: Unknown REGEXP-GROUPS value - %s"
                  regexp-groups)))
         results)))

    (when sql-debug-redirect
      (message ">>SQL> = %S" (reverse results)))

    (nreverse results)))