aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Mauger <[email protected]>2012-09-10 15:22:53 -0400
committerMichael Mauger <[email protected]>2012-09-10 15:22:53 -0400
commit04e082b0dd7d290036e2e691f65c467d8ac606c0 (patch)
tree44a5b1f5940d1da8f77777eb53160d851a93b789
parent399a361b882606ab0e67a164f8fb7af6464f3235 (diff)
* progmodes/sql.el: Version 3.1
(sql-db2-escape-newlines): New variable. (sql-escape-newlines-filter): Use it.
-rw-r--r--etc/NEWS8
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/progmodes/sql.el42
3 files changed, 43 insertions, 13 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 9f46e49b96..ef68e2e561 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -344,6 +344,14 @@ python-describe-symbol | python-eldoc-at-point
*** Accepts \r and \f as whitespace.
+** SQL Mode
+
+*** DB2 added `sql-db2-escape-newlines'
+
+If non-nil, newlines sent to the command interpreter will be escaped
+by a backslash. The default does not escape the newlines and assumes
+that the sql statement will be terminated by a semicolon.
+
** Diff mode
Faces for changes now use the same diff color scheme as in modern VCSes
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0f1b744f42..a8bf45b6f9 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
+2012-09-10 Michael R. Mauger <[email protected]>
+
+ * progmodes/sql.el: Version 3.1
+ (sql-db2-escape-newlines): New variable.
+ (sql-escape-newlines-filter): Use it.
+
2012-09-10 Juanma Barranquero <[email protected]>
* custom.el (custom-theme-load-confirm): Remove unneeded assignment.
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
index 030cc02f3f..f3ecbe3fc3 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -4,7 +4,7 @@
;; Author: Alex Schroeder <[email protected]>
;; Maintainer: Michael Mauger <[email protected]>
-;; Version: 3.0
+;; Version: 3.1
;; Keywords: comm languages processes
;; URL: http://savannah.gnu.org/projects/emacs/
@@ -218,9 +218,12 @@
;; Michael Mauger <[email protected]> -- improved product support
;; Drew Adams <[email protected]> -- Emacs 20 support
;; Harald Maier <[email protected]> -- sql-send-string
-;; Stefan Monnier <[email protected]> -- font-lock corrections; code polish
+;; Stefan Monnier <[email protected]> -- font-lock corrections;
+;; code polish
;; Paul Sleigh <[email protected]> -- MySQL keyword enhancement
;; Andrew Schein <[email protected]> -- sql-port bug
+;; Ian Bjorhovde <[email protected]> -- db2 escape newlines
+;; incorrectly enabled by default
@@ -879,6 +882,16 @@ In older versions of SQL*Plus, this was the SET SCAN OFF command."
:type 'boolean
:group 'SQL)
+(defcustom sql-db2-escape-newlines nil
+ "Non-nil if newlines should be escaped by a backslash in DB2 SQLi.
+
+When non-nil, Emacs will automatically insert a space and
+backslash prior to every newline in multi-line SQL statements as
+they are submitted to an interactive DB2 session."
+ :version "24.3"
+ :type 'boolean
+ :group 'SQL)
+
;; Customization for SQLite
(defcustom sql-sqlite-program (or (executable-find "sqlite3")
@@ -3188,20 +3201,23 @@ Placeholders are words starting with an ampersand like &this."
;; Using DB2 interactively, newlines must be escaped with " \".
;; The space before the backslash is relevant.
+
(defun sql-escape-newlines-filter (string)
"Escape newlines in STRING.
Every newline in STRING will be preceded with a space and a backslash."
- (let ((result "") (start 0) mb me)
- (while (string-match "\n" string start)
- (setq mb (match-beginning 0)
- me (match-end 0)
- result (concat result
- (substring string start mb)
- (if (and (> mb 1)
- (string-equal " \\" (substring string (- mb 2) mb)))
- "" " \\\n"))
- start me))
- (concat result (substring string start))))
+ (if (not sql-db2-escape-newlines)
+ string
+ (let ((result "") (start 0) mb me)
+ (while (string-match "\n" string start)
+ (setq mb (match-beginning 0)
+ me (match-end 0)
+ result (concat result
+ (substring string start mb)
+ (if (and (> mb 1)
+ (string-equal " \\" (substring string (- mb 2) mb)))
+ "" " \\\n"))
+ start me))
+ (concat result (substring string start)))))