[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] Return from executed SQL block sometimes generates a backtrace
From: |
Sebastien Vauban |
Subject: |
[O] Return from executed SQL block sometimes generates a backtrace |
Date: |
Fri, 07 Sep 2012 15:41:15 +0200 |
User-agent: |
Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.2 (windows-nt) |
Hello,
Code blocks which return (almost) nothing aren't correctly handled by Babel.
When they really don't return anything, "error" displayed in the echo area;
when they return the empty string, a backtrace is generated.
* Examples
#+PROPERTY: engine msosql
#+PROPERTY: cmdline -S server -U user -P password -d database -n -w 234
#+PROPERTY: results output
#+PROPERTY: exports both
** Block with no return
#+begin_src sql :tangle no :eval yes
ALTER TABLE tableindb
ADD rol1 smalldatetime NULL
#+end_src
- does not add any "results" block
- echoes "progn: Beginning of buffer" in the echo area
** Block with empty string returned
#+begin_src sql :tangle no :eval yes
ALTER TABLE tableindb
ADD rol22 smalldatetime NULL
PRINT ''
#+end_src
#+results:
- adds the above "results" block
- but generates an error:
#+begin_example
Debugger entered--Lisp error: (args-out-of-range 0 1)
buffer-substring(1 0)
(progn (insert (orgtbl-to-generic table params)) (goto-char (point-min))
(while (re-search-forward org-table-hline-regexp nil t) (org-table-align))
(buffer-substring 1 (buffer-size)))
(unwind-protect (progn (insert (orgtbl-to-generic table params)) (goto-char
(point-min)) (while (re-search-forward org-table-hline-regexp nil t)
(org-table-align)) (buffer-substring 1 (buffer-size))) (and (buffer-name
temp-buffer) (kill-buffer temp-buffer)))
(save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert
(orgtbl-to-generic table params)) (goto-char (point-min)) (while
(re-search-forward org-table-hline-regexp nil t) (org-table-align))
(buffer-substring 1 (buffer-size))) (and (buffer-name temp-buffer) (kill-buffer
temp-buffer))))
(with-current-buffer temp-buffer (unwind-protect (progn (insert
(orgtbl-to-generic table params)) (goto-char (point-min)) (while
(re-search-forward org-table-hline-regexp nil t) (org-table-align))
(buffer-substring 1 (buffer-size))) (and (buffer-name temp-buffer) (kill-buffer
temp-buffer))))
(let ((temp-buffer (generate-new-buffer " *temp*"))) (with-current-buffer
temp-buffer (unwind-protect (progn (insert (orgtbl-to-generic table params))
(goto-char (point-min)) (while (re-search-forward org-table-hline-regexp nil t)
(org-table-align)) (buffer-substring 1 (buffer-size))) (and (buffer-name
temp-buffer) (kill-buffer temp-buffer)))))
(with-temp-buffer (insert (orgtbl-to-generic table params)) (goto-char
(point-min)) (while (re-search-forward org-table-hline-regexp nil t)
(org-table-align)) (buffer-substring 1 (buffer-size)))
(let* ((params2 (list :remove-newlines t :tstart nil :tend nil :hline "|---"
:sep " | " :lstart "| " :lend " |")) (params (org-combine-plists params2
params))) (with-temp-buffer (insert (orgtbl-to-generic table params))
(goto-char (point-min)) (while (re-search-forward org-table-hline-regexp nil t)
(org-table-align)) (buffer-substring 1 (buffer-size))))
orgtbl-to-orgtbl((nil) (:fmt (lambda (cell) (format "%s" cell))))
(concat (orgtbl-to-orgtbl (if (or (eq (quote hline) (car result)) (and (listp
(car result)) (listp (cdr (car result))))) result (list result)) (quote (:fmt
(lambda (cell) (format "%s" cell))))) "\n")
(insert (concat (orgtbl-to-orgtbl (if (or (eq (quote hline) (car result))
(and (listp (car result)) (listp (cdr ...)))) result (list result)) (quote
(:fmt (lambda (cell) (format "%s" cell))))) "\n"))
(cond ((null result)) ((member "list" result-params) (insert (org-babel-trim
(org-list-to-generic (cons (quote unordered) (mapcar (lambda ... ...) (if ...
result ...))) (quote (:splicep nil :istart "- " :iend "\n")))) "\n")) ((funcall
proper-list-p result) (goto-char beg) (insert (concat (orgtbl-to-orgtbl (if (or
(eq ... ...) (and ... ...)) result (list result)) (quote (:fmt (lambda ...
...)))) "\n")) (goto-char beg) (when (org-at-table-p) (org-table-align))) ((and
(listp result) (not (funcall proper-list-p result))) (insert (format "%s\n"
result))) ((member "file" result-params) (when inlinep (goto-char inlinep))
(insert result)) (t (goto-char beg) (insert result)))
(let ((wrap (lambda (start finish) (goto-char end) (insert (concat finish
"\n")) (goto-char beg) (insert (concat start "\n")) (goto-char end) (goto-char
(point-at-eol)) (setq end (point-marker)))) (proper-list-p (lambda (it) (and
(listp it) (null (cdr (last it))))))) (cond ((null result)) ((member "list"
result-params) (insert (org-babel-trim (org-list-to-generic (cons (quote
unordered) (mapcar ... ...)) (quote (:splicep nil :istart "- " :iend "\n"))))
"\n")) ((funcall proper-list-p result) (goto-char beg) (insert (concat
(orgtbl-to-orgtbl (if (or ... ...) result (list result)) (quote (:fmt ...)))
"\n")) (goto-char beg) (when (org-at-table-p) (org-table-align))) ((and (listp
result) (not (funcall proper-list-p result))) (insert (format "%s\n" result)))
((member "file" result-params) (when inlinep (goto-char inlinep)) (insert
result)) (t (goto-char beg) (insert result))) (when (funcall proper-list-p
result) (goto-char (org-table-end))) (setq end (point-marker)) (cond ((assoc
:wrap (nth 2 info)) (let ((name (or (cdr ...) "RESULTS"))) (funcall wrap
(concat "#+BEGIN_" name) (concat "#+END_" name)))) ((member "html"
result-params) (funcall wrap "#+BEGIN_HTML" "#+END_HTML")) ((member "latex"
result-params) (funcall wrap "#+BEGIN_LaTeX" "#+END_LaTeX")) ((member "code"
result-params) (funcall wrap (format "#+BEGIN_SRC %s%s" (or lang "none")
results-switches) "#+END_SRC")) ((member "org" result-params) (funcall wrap
"#+BEGIN_ORG" "#+END_ORG")) ((member "raw" result-params) (goto-char beg) (if
(org-at-table-p) (org-cycle))) ((member "wrap" result-params) (funcall wrap
":RESULTS:" ":END:")) ((and (not (funcall proper-list-p result)) (not (member
"file" result-params))) (org-babel-examplize-region beg end results-switches)
(setq end (point)))))
(let* ((inlinep (save-excursion (when (or
(org-babel-get-inline-src-block-matches) (org-babel-get-lob-one-liner-matches))
(goto-char (match-end 0)) (insert (if (listp result) "\n" " ")) (point))))
(existing-result (unless inlinep (org-babel-where-is-src-block-result t info
hash indent))) (results-switches (cdr (assoc :results_switches (nth 2 info))))
beg end) (when (and (stringp result) (not inlinep) (> (length result) 0) (not
(or (string-equal (substring result -1) "\n") (string-equal (substring result
-1) "")))) (setq result (concat result "\n"))) (if (not existing-result) (setq
beg (or inlinep (point))) (goto-char existing-result) (save-excursion
(re-search-forward "#" nil t) (setq indent (- (current-column) 1)))
(forward-line 1) (setq beg (point)) (cond ((member "replace" result-params)
(delete-region (point) (org-babel-result-end))) ((member "append"
result-params) (goto-char (org-babel-result-end)) (setq beg (point-marker)))
((member "prepend" result-params)))) (setq results-switches (if
results-switches (concat " " results-switches) "")) (let ((wrap (lambda (start
finish) (goto-char end) (insert (concat finish "\n")) (goto-char beg) (insert
(concat start "\n")) (goto-char end) (goto-char (point-at-eol)) (setq end
(point-marker)))) (proper-list-p (lambda (it) (and (listp it) (null (cdr
...)))))) (cond ((null result)) ((member "list" result-params) (insert
(org-babel-trim (org-list-to-generic (cons ... ...) (quote ...))) "\n"))
((funcall proper-list-p result) (goto-char beg) (insert (concat
(orgtbl-to-orgtbl (if ... result ...) (quote ...)) "\n")) (goto-char beg) (when
(org-at-table-p) (org-table-align))) ((and (listp result) (not (funcall
proper-list-p result))) (insert (format "%s\n" result))) ((member "file"
result-params) (when inlinep (goto-char inlinep)) (insert result)) (t
(goto-char beg) (insert result))) (when (funcall proper-list-p result)
(goto-char (org-table-end))) (setq end (point-marker)) (cond ((assoc :wrap (nth
2 info)) (let ((name (or ... "RESULTS"))) (funcall wrap (concat "#+BEGIN_"
name) (concat "#+END_" name)))) ((member "html" result-params) (funcall wrap
"#+BEGIN_HTML" "#+END_HTML")) ((member "latex" result-params) (funcall wrap
"#+BEGIN_LaTeX" "#+END_LaTeX")) ((member "code" result-params) (funcall wrap
(format "#+BEGIN_SRC %s%s" (or lang "none") results-switches) "#+END_SRC"))
((member "org" result-params) (funcall wrap "#+BEGIN_ORG" "#+END_ORG"))
((member "raw" result-params) (goto-char beg) (if (org-at-table-p)
(org-cycle))) ((member "wrap" result-params) (funcall wrap ":RESULTS:"
":END:")) ((and (not (funcall proper-list-p result)) (not (member "file"
result-params))) (org-babel-examplize-region beg end results-switches) (setq
end (point))))) (when (and (not inlinep) (numberp indent) indent (> indent 0)
(not (and (listp result) (member "append" result-params)))) (indent-rigidly beg
end indent)))
(save-excursion (let* ((inlinep (save-excursion (when (or
(org-babel-get-inline-src-block-matches) (org-babel-get-lob-one-liner-matches))
(goto-char (match-end 0)) (insert (if ... "\n" " ")) (point))))
(existing-result (unless inlinep (org-babel-where-is-src-block-result t info
hash indent))) (results-switches (cdr (assoc :results_switches (nth 2 info))))
beg end) (when (and (stringp result) (not inlinep) (> (length result) 0) (not
(or (string-equal (substring result -1) "\n") (string-equal (substring result
-1) "")))) (setq result (concat result "\n"))) (if (not existing-result) (setq
beg (or inlinep (point))) (goto-char existing-result) (save-excursion
(re-search-forward "#" nil t) (setq indent (- (current-column) 1)))
(forward-line 1) (setq beg (point)) (cond ((member "replace" result-params)
(delete-region (point) (org-babel-result-end))) ((member "append"
result-params) (goto-char (org-babel-result-end)) (setq beg (point-marker)))
((member "prepend" result-params)))) (setq results-switches (if
results-switches (concat " " results-switches) "")) (let ((wrap (lambda (start
finish) (goto-char end) (insert (concat finish "\n")) (goto-char beg) (insert
(concat start "\n")) (goto-char end) (goto-char (point-at-eol)) (setq end
(point-marker)))) (proper-list-p (lambda (it) (and (listp it) (null ...)))))
(cond ((null result)) ((member "list" result-params) (insert (org-babel-trim
(org-list-to-generic ... ...)) "\n")) ((funcall proper-list-p result)
(goto-char beg) (insert (concat (orgtbl-to-orgtbl ... ...) "\n")) (goto-char
beg) (when (org-at-table-p) (org-table-align))) ((and (listp result) (not
(funcall proper-list-p result))) (insert (format "%s\n" result))) ((member
"file" result-params) (when inlinep (goto-char inlinep)) (insert result)) (t
(goto-char beg) (insert result))) (when (funcall proper-list-p result)
(goto-char (org-table-end))) (setq end (point-marker)) (cond ((assoc :wrap (nth
2 info)) (let ((name ...)) (funcall wrap (concat "#+BEGIN_" name) (concat
"#+END_" name)))) ((member "html" result-params) (funcall wrap "#+BEGIN_HTML"
"#+END_HTML")) ((member "latex" result-params) (funcall wrap "#+BEGIN_LaTeX"
"#+END_LaTeX")) ((member "code" result-params) (funcall wrap (format
"#+BEGIN_SRC %s%s" (or lang "none") results-switches) "#+END_SRC")) ((member
"org" result-params) (funcall wrap "#+BEGIN_ORG" "#+END_ORG")) ((member "raw"
result-params) (goto-char beg) (if (org-at-table-p) (org-cycle))) ((member
"wrap" result-params) (funcall wrap ":RESULTS:" ":END:")) ((and (not (funcall
proper-list-p result)) (not (member "file" result-params)))
(org-babel-examplize-region beg end results-switches) (setq end (point)))))
(when (and (not inlinep) (numberp indent) indent (> indent 0) (not (and (listp
result) (member "append" result-params)))) (indent-rigidly beg end indent))))
(if (and result-params (member "silent" result-params)) (progn (message
(replace-regexp-in-string "%" "%%" (format "%S" result))) result)
(save-excursion (let* ((inlinep (save-excursion (when (or ... ...) (goto-char
...) (insert ...) (point)))) (existing-result (unless inlinep
(org-babel-where-is-src-block-result t info hash indent))) (results-switches
(cdr (assoc :results_switches (nth 2 info)))) beg end) (when (and (stringp
result) (not inlinep) (> (length result) 0) (not (or (string-equal ... "\n")
(string-equal ... "")))) (setq result (concat result "\n"))) (if (not
existing-result) (setq beg (or inlinep (point))) (goto-char existing-result)
(save-excursion (re-search-forward "#" nil t) (setq indent (- (current-column)
1))) (forward-line 1) (setq beg (point)) (cond ((member "replace"
result-params) (delete-region (point) (org-babel-result-end))) ((member
"append" result-params) (goto-char (org-babel-result-end)) (setq beg
(point-marker))) ((member "prepend" result-params)))) (setq results-switches
(if results-switches (concat " " results-switches) "")) (let ((wrap (lambda
(start finish) (goto-char end) (insert ...) (goto-char beg) (insert ...)
(goto-char end) (goto-char ...) (setq end ...))) (proper-list-p (lambda (it)
(and ... ...)))) (cond ((null result)) ((member "list" result-params) (insert
(org-babel-trim ...) "\n")) ((funcall proper-list-p result) (goto-char beg)
(insert (concat ... "\n")) (goto-char beg) (when (org-at-table-p)
(org-table-align))) ((and (listp result) (not ...)) (insert (format "%s\n"
result))) ((member "file" result-params) (when inlinep (goto-char inlinep))
(insert result)) (t (goto-char beg) (insert result))) (when (funcall
proper-list-p result) (goto-char (org-table-end))) (setq end (point-marker))
(cond ((assoc :wrap (nth 2 info)) (let (...) (funcall wrap ... ...))) ((member
"html" result-params) (funcall wrap "#+BEGIN_HTML" "#+END_HTML")) ((member
"latex" result-params) (funcall wrap "#+BEGIN_LaTeX" "#+END_LaTeX")) ((member
"code" result-params) (funcall wrap (format "#+BEGIN_SRC %s%s" ...
results-switches) "#+END_SRC")) ((member "org" result-params) (funcall wrap
"#+BEGIN_ORG" "#+END_ORG")) ((member "raw" result-params) (goto-char beg) (if
(org-at-table-p) (org-cycle))) ((member "wrap" result-params) (funcall wrap
":RESULTS:" ":END:")) ((and (not ...) (not ...)) (org-babel-examplize-region
beg end results-switches) (setq end (point))))) (when (and (not inlinep)
(numberp indent) indent (> indent 0) (not (and (listp result) (member "append"
result-params)))) (indent-rigidly beg end indent)))) (if (null result) (if
(member "value" result-params) (message "Code block returned no value.")
(message "Code block produced no output.")) (message "Code block evaluation
complete.")))
(save-restriction (widen) (if (stringp result) (progn (setq result
(org-no-properties result)) (when (member "file" result-params) (setq result
(org-babel-result-to-file result (when (assoc :file-desc ...) (or ...
result)))))) (unless (listp result) (setq result (format "%S" result)))) (if
(and result-params (member "silent" result-params)) (progn (message
(replace-regexp-in-string "%" "%%" (format "%S" result))) result)
(save-excursion (let* ((inlinep (save-excursion (when ... ... ... ...)))
(existing-result (unless inlinep (org-babel-where-is-src-block-result t info
hash indent))) (results-switches (cdr (assoc :results_switches ...))) beg end)
(when (and (stringp result) (not inlinep) (> (length result) 0) (not (or ...
...))) (setq result (concat result "\n"))) (if (not existing-result) (setq beg
(or inlinep (point))) (goto-char existing-result) (save-excursion
(re-search-forward "#" nil t) (setq indent (- ... 1))) (forward-line 1) (setq
beg (point)) (cond ((member "replace" result-params) (delete-region ... ...))
((member "append" result-params) (goto-char ...) (setq beg ...)) ((member
"prepend" result-params)))) (setq results-switches (if results-switches (concat
" " results-switches) "")) (let ((wrap (lambda ... ... ... ... ... ... ...
...)) (proper-list-p (lambda ... ...))) (cond ((null result)) ((member "list"
result-params) (insert ... "\n")) ((funcall proper-list-p result) (goto-char
beg) (insert ...) (goto-char beg) (when ... ...)) ((and ... ...) (insert ...))
((member "file" result-params) (when inlinep ...) (insert result)) (t
(goto-char beg) (insert result))) (when (funcall proper-list-p result)
(goto-char (org-table-end))) (setq end (point-marker)) (cond ((assoc :wrap ...)
(let ... ...)) ((member "html" result-params) (funcall wrap "#+BEGIN_HTML"
"#+END_HTML")) ((member "latex" result-params) (funcall wrap "#+BEGIN_LaTeX"
"#+END_LaTeX")) ((member "code" result-params) (funcall wrap ... "#+END_SRC"))
((member "org" result-params) (funcall wrap "#+BEGIN_ORG" "#+END_ORG"))
((member "raw" result-params) (goto-char beg) (if ... ...)) ((member "wrap"
result-params) (funcall wrap ":RESULTS:" ":END:")) ((and ... ...)
(org-babel-examplize-region beg end results-switches) (setq end ...)))) (when
(and (not inlinep) (numberp indent) indent (> indent 0) (not (and ... ...)))
(indent-rigidly beg end indent)))) (if (null result) (if (member "value"
result-params) (message "Code block returned no value.") (message "Code block
produced no output.")) (message "Code block evaluation complete."))))
org-babel-insert-result((nil) ("output" "replace") ("sql" "ALTER TABLE
tableindb\nADD rol22 smalldatetime NULL\n\nPRINT ''" ((:comments . "yes")
(:shebang . "") (:cache . "no") (:padline . "") (:noweb . "yes") (:tangle .
"no") (:exports . "both") (:results . "replace output") (:session . "none")
(:hlines . "no") (:padnewline . "yes") (:engine . "msosql") (:cmdline . "-S
cauchy -U sa -P LpmdlP -d pfi-dev -n -w 234") (:eval . "yes") (:result-type .
output) (:result-params "output" "replace") (:rowname-names) (:colname-names))
"" nil 0) nil 0 "sql")
(if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion
(goto-char (org-babel-where-is-src-block-result nil info)) (end-of-line 1)
(forward-char 1) (setq result (org-babel-read-result)) (message
(replace-regexp-in-string "%" "%%" (format "%S" result))) result) (message
"executing %s code block%s..." (capitalize lang) (if (nth 4 info) (format "
(%s)" (nth 4 info)) "")) (setq result ((lambda (result) (if (and (eq (cdr ...)
(quote value)) (or (member "vector" result-params) (member "table"
result-params)) (not (listp result))) (list (list result)) result)) (funcall
cmd body params))) (when (cdr (assoc :file params)) (when result
(with-temp-file (cdr (assoc :file params)) (insert (org-babel-format-result
result (cdr (assoc :sep ...)))))) (setq result (cdr (assoc :file params))))
(org-babel-insert-result result result-params info new-hash indent lang)
(run-hooks (quote org-babel-after-execute-hook)) result)
(let ((call-process-region (lambda (&rest args) (apply (quote
org-babel-tramp-handle-call-process-region) args)))) (let ((lang-check (lambda
(f) (let ((f ...)) (when (fboundp f) f))))) (setq cmd (or (funcall lang-check
lang) (funcall lang-check (symbol-name (cdr (assoc lang org-src-lang-modes))))
(error "No org-babel-execute function for %s!" lang)))) (if (and (not arg)
new-hash (equal new-hash old-hash)) (save-excursion (goto-char
(org-babel-where-is-src-block-result nil info)) (end-of-line 1) (forward-char
1) (setq result (org-babel-read-result)) (message (replace-regexp-in-string "%"
"%%" (format "%S" result))) result) (message "executing %s code block%s..."
(capitalize lang) (if (nth 4 info) (format " (%s)" (nth 4 info)) "")) (setq
result ((lambda (result) (if (and (eq ... ...) (or ... ...) (not ...)) (list
(list result)) result)) (funcall cmd body params))) (when (cdr (assoc :file
params)) (when result (with-temp-file (cdr (assoc :file params)) (insert
(org-babel-format-result result (cdr ...))))) (setq result (cdr (assoc :file
params)))) (org-babel-insert-result result result-params info new-hash indent
lang) (run-hooks (quote org-babel-after-execute-hook)) result))
(unwind-protect (let ((call-process-region (lambda (&rest args) (apply (quote
org-babel-tramp-handle-call-process-region) args)))) (let ((lang-check (lambda
(f) (let (...) (when ... f))))) (setq cmd (or (funcall lang-check lang)
(funcall lang-check (symbol-name (cdr ...))) (error "No org-babel-execute
function for %s!" lang)))) (if (and (not arg) new-hash (equal new-hash
old-hash)) (save-excursion (goto-char (org-babel-where-is-src-block-result nil
info)) (end-of-line 1) (forward-char 1) (setq result (org-babel-read-result))
(message (replace-regexp-in-string "%" "%%" (format "%S" result))) result)
(message "executing %s code block%s..." (capitalize lang) (if (nth 4 info)
(format " (%s)" (nth 4 info)) "")) (setq result ((lambda (result) (if (and ...
... ...) (list ...) result)) (funcall cmd body params))) (when (cdr (assoc
:file params)) (when result (with-temp-file (cdr (assoc :file params)) (insert
(org-babel-format-result result ...)))) (setq result (cdr (assoc :file
params)))) (org-babel-insert-result result result-params info new-hash indent
lang) (run-hooks (quote org-babel-after-execute-hook)) result)) (setq
call-process-region (quote org-babel-call-process-region-original)))
(let* ((lang (nth 0 info)) (params (if params (org-babel-process-params
(org-babel-merge-params (nth 2 info) params)) (nth 2 info))) (cache\? (and (not
arg) (cdr (assoc :cache params)) (string= "yes" (cdr (assoc :cache params)))))
(result-params (cdr (assoc :result-params params))) (new-hash (when cache\?
(org-babel-sha1-hash info))) (old-hash (when cache\?
(org-babel-current-result-hash))) (body (setf (nth 1 info) (if
(org-babel-noweb-p params :eval) (org-babel-expand-noweb-references info) (nth
1 info)))) (dir (cdr (assoc :dir params))) (default-directory (or (and dir
(file-name-as-directory (expand-file-name dir))) default-directory))
(org-babel-call-process-region-original (if (boundp (quote
org-babel-call-process-region-original)) org-babel-call-process-region-original
(symbol-function (quote call-process-region)))) (indent (car (last info)))
result cmd) (unwind-protect (let ((call-process-region (lambda (&rest args)
(apply (quote org-babel-tramp-handle-call-process-region) args)))) (let
((lang-check (lambda (f) (let ... ...)))) (setq cmd (or (funcall lang-check
lang) (funcall lang-check (symbol-name ...)) (error "No org-babel-execute
function for %s!" lang)))) (if (and (not arg) new-hash (equal new-hash
old-hash)) (save-excursion (goto-char (org-babel-where-is-src-block-result nil
info)) (end-of-line 1) (forward-char 1) (setq result (org-babel-read-result))
(message (replace-regexp-in-string "%" "%%" (format "%S" result))) result)
(message "executing %s code block%s..." (capitalize lang) (if (nth 4 info)
(format " (%s)" (nth 4 info)) "")) (setq result ((lambda (result) (if ... ...
result)) (funcall cmd body params))) (when (cdr (assoc :file params)) (when
result (with-temp-file (cdr ...) (insert ...))) (setq result (cdr (assoc :file
params)))) (org-babel-insert-result result result-params info new-hash indent
lang) (run-hooks (quote org-babel-after-execute-hook)) result)) (setq
call-process-region (quote org-babel-call-process-region-original))))
(progn (let* ((lang (nth 0 info)) (params (if params
(org-babel-process-params (org-babel-merge-params (nth 2 info) params)) (nth 2
info))) (cache\? (and (not arg) (cdr (assoc :cache params)) (string= "yes" (cdr
(assoc :cache params))))) (result-params (cdr (assoc :result-params params)))
(new-hash (when cache\? (org-babel-sha1-hash info))) (old-hash (when cache\?
(org-babel-current-result-hash))) (body (setf (nth 1 info) (if
(org-babel-noweb-p params :eval) (org-babel-expand-noweb-references info) (nth
1 info)))) (dir (cdr (assoc :dir params))) (default-directory (or (and dir
(file-name-as-directory (expand-file-name dir))) default-directory))
(org-babel-call-process-region-original (if (boundp (quote
org-babel-call-process-region-original)) org-babel-call-process-region-original
(symbol-function (quote call-process-region)))) (indent (car (last info)))
result cmd) (unwind-protect (let ((call-process-region (lambda (&rest args)
(apply ... args)))) (let ((lang-check (lambda ... ...))) (setq cmd (or (funcall
lang-check lang) (funcall lang-check ...) (error "No org-babel-execute function
for %s!" lang)))) (if (and (not arg) new-hash (equal new-hash old-hash))
(save-excursion (goto-char (org-babel-where-is-src-block-result nil info))
(end-of-line 1) (forward-char 1) (setq result (org-babel-read-result)) (message
(replace-regexp-in-string "%" "%%" ...)) result) (message "executing %s code
block%s..." (capitalize lang) (if (nth 4 info) (format " (%s)" ...) "")) (setq
result ((lambda ... ...) (funcall cmd body params))) (when (cdr (assoc :file
params)) (when result (with-temp-file ... ...)) (setq result (cdr ...)))
(org-babel-insert-result result result-params info new-hash indent lang)
(run-hooks (quote org-babel-after-execute-hook)) result)) (setq
call-process-region (quote org-babel-call-process-region-original)))))
(if (org-babel-confirm-evaluate (let ((i info)) (setf (nth 2 i)
(org-babel-merge-params (nth 2 info) params)) i)) (progn (let* ((lang (nth 0
info)) (params (if params (org-babel-process-params (org-babel-merge-params ...
params)) (nth 2 info))) (cache\? (and (not arg) (cdr (assoc :cache params))
(string= "yes" (cdr ...)))) (result-params (cdr (assoc :result-params params)))
(new-hash (when cache\? (org-babel-sha1-hash info))) (old-hash (when cache\?
(org-babel-current-result-hash))) (body (setf (nth 1 info) (if
(org-babel-noweb-p params :eval) (org-babel-expand-noweb-references info) (nth
1 info)))) (dir (cdr (assoc :dir params))) (default-directory (or (and dir
(file-name-as-directory ...)) default-directory))
(org-babel-call-process-region-original (if (boundp (quote
org-babel-call-process-region-original)) org-babel-call-process-region-original
(symbol-function (quote call-process-region)))) (indent (car (last info)))
result cmd) (unwind-protect (let ((call-process-region (lambda ... ...))) (let
((lang-check ...)) (setq cmd (or ... ... ...))) (if (and (not arg) new-hash
(equal new-hash old-hash)) (save-excursion (goto-char ...) (end-of-line 1)
(forward-char 1) (setq result ...) (message ...) result) (message "executing %s
code block%s..." (capitalize lang) (if ... ... "")) (setq result (... ...))
(when (cdr ...) (when result ...) (setq result ...)) (org-babel-insert-result
result result-params info new-hash indent lang) (run-hooks (quote
org-babel-after-execute-hook)) result)) (setq call-process-region (quote
org-babel-call-process-region-original))))))
(when (org-babel-confirm-evaluate (let ((i info)) (setf (nth 2 i)
(org-babel-merge-params (nth 2 info) params)) i)) (let* ((lang (nth 0 info))
(params (if params (org-babel-process-params (org-babel-merge-params (nth 2
info) params)) (nth 2 info))) (cache\? (and (not arg) (cdr (assoc :cache
params)) (string= "yes" (cdr (assoc :cache params))))) (result-params (cdr
(assoc :result-params params))) (new-hash (when cache\? (org-babel-sha1-hash
info))) (old-hash (when cache\? (org-babel-current-result-hash))) (body (setf
(nth 1 info) (if (org-babel-noweb-p params :eval)
(org-babel-expand-noweb-references info) (nth 1 info)))) (dir (cdr (assoc :dir
params))) (default-directory (or (and dir (file-name-as-directory
(expand-file-name dir))) default-directory))
(org-babel-call-process-region-original (if (boundp (quote
org-babel-call-process-region-original)) org-babel-call-process-region-original
(symbol-function (quote call-process-region)))) (indent (car (last info)))
result cmd) (unwind-protect (let ((call-process-region (lambda (&rest args)
(apply ... args)))) (let ((lang-check (lambda ... ...))) (setq cmd (or (funcall
lang-check lang) (funcall lang-check ...) (error "No org-babel-execute function
for %s!" lang)))) (if (and (not arg) new-hash (equal new-hash old-hash))
(save-excursion (goto-char (org-babel-where-is-src-block-result nil info))
(end-of-line 1) (forward-char 1) (setq result (org-babel-read-result)) (message
(replace-regexp-in-string "%" "%%" ...)) result) (message "executing %s code
block%s..." (capitalize lang) (if (nth 4 info) (format " (%s)" ...) "")) (setq
result ((lambda ... ...) (funcall cmd body params))) (when (cdr (assoc :file
params)) (when result (with-temp-file ... ...)) (setq result (cdr ...)))
(org-babel-insert-result result result-params info new-hash indent lang)
(run-hooks (quote org-babel-after-execute-hook)) result)) (setq
call-process-region (quote org-babel-call-process-region-original)))))
(let ((info (or info (org-babel-get-src-block-info)))) (when
(org-babel-confirm-evaluate (let ((i info)) (setf (nth 2 i)
(org-babel-merge-params (nth 2 info) params)) i)) (let* ((lang (nth 0 info))
(params (if params (org-babel-process-params (org-babel-merge-params ...
params)) (nth 2 info))) (cache\? (and (not arg) (cdr (assoc :cache params))
(string= "yes" (cdr ...)))) (result-params (cdr (assoc :result-params params)))
(new-hash (when cache\? (org-babel-sha1-hash info))) (old-hash (when cache\?
(org-babel-current-result-hash))) (body (setf (nth 1 info) (if
(org-babel-noweb-p params :eval) (org-babel-expand-noweb-references info) (nth
1 info)))) (dir (cdr (assoc :dir params))) (default-directory (or (and dir
(file-name-as-directory ...)) default-directory))
(org-babel-call-process-region-original (if (boundp (quote
org-babel-call-process-region-original)) org-babel-call-process-region-original
(symbol-function (quote call-process-region)))) (indent (car (last info)))
result cmd) (unwind-protect (let ((call-process-region (lambda ... ...))) (let
((lang-check ...)) (setq cmd (or ... ... ...))) (if (and (not arg) new-hash
(equal new-hash old-hash)) (save-excursion (goto-char ...) (end-of-line 1)
(forward-char 1) (setq result ...) (message ...) result) (message "executing %s
code block%s..." (capitalize lang) (if ... ... "")) (setq result (... ...))
(when (cdr ...) (when result ...) (setq result ...)) (org-babel-insert-result
result result-params info new-hash indent lang) (run-hooks (quote
org-babel-after-execute-hook)) result)) (setq call-process-region (quote
org-babel-call-process-region-original))))))
org-babel-execute-src-block(nil ("sql" "ALTER TABLE tableindb\nADD rol22
smalldatetime NULL\n\nPRINT ''" ((:comments . "yes") (:shebang . "") (:cache .
"no") (:padline . "") (:noweb . "yes") (:tangle . "no") (:exports . "both")
(:results . "replace output") (:session . "none") (:hlines . "no") (:padnewline
. "yes") (:engine . "msosql") (:cmdline . "-S cauchy -U sa -P LpmdlP -d pfi-dev
-n -w 234") (:eval . "yes") (:result-type . output) (:result-params "output"
"replace") (:rowname-names) (:colname-names)) "" nil 0))
(progn (org-babel-eval-wipe-error-buffer) (org-babel-execute-src-block
current-prefix-arg info) t)
(if info (progn (org-babel-eval-wipe-error-buffer)
(org-babel-execute-src-block current-prefix-arg info) t) nil)
(let ((info (org-babel-get-src-block-info))) (if info (progn
(org-babel-eval-wipe-error-buffer) (org-babel-execute-src-block
current-prefix-arg info) t) nil))
org-babel-execute-src-block-maybe()
(or (org-babel-execute-src-block-maybe) (org-babel-lob-execute-maybe))
org-babel-execute-maybe()
call-interactively(org-babel-execute-maybe nil nil)
#+end_example
** Block with non-empty string returned
#+begin_src sql :tangle no :eval yes
ALTER TABLE tableindb
ADD rol333 smalldatetime NULL
PRINT 'OK'
#+end_src
#+results:
| OK |
... does work OK.
Best regards,
Seb
--
Sebastien Vauban
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [O] Return from executed SQL block sometimes generates a backtrace,
Sebastien Vauban <=