changeset 24267:f40837b25999

Changed version to 1.2.1. (sql-pop-to-buffer-after-send-region): Improved documentation. (sql-mysql-program): Added MySQL support. (sql-prompt-length): Made prompt-length configurable. (sql-mode-syntax-table): Made apostrophe (') be a string delimiter. (sql-help): Added MySQL support, changed documentation. (sql-send-region): A message is displayed if something is sent. (sql-mode): Added buffer-local comment-start. (sql-interactive-mode): Use sql-prompt-length to set left-margin. (sql-interactive-mode): Added buffer-local comment-start. (sql-oracle): Set sql-prompt-length. (sql-sybase): Set sql-prompt-length. (sql-mysql): Added MySQL support. (sql-ingres): Set sql-prompt-length. (sql-ms): Set sql-prompt-length. (sql-postgres): Set sql-prompt-length.
author Richard M. Stallman <rms@gnu.org>
date Sat, 06 Feb 1999 05:09:31 +0000
parents 894911d2c01d
children 17b13a968841
files lisp/progmodes/sql.el
diffstat 1 files changed, 94 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/progmodes/sql.el	Sat Feb 06 05:00:54 1999 +0000
+++ b/lisp/progmodes/sql.el	Sat Feb 06 05:09:31 1999 +0000
@@ -1,10 +1,10 @@
 ;;; sql.el --- specialized comint.el for SQL interpreters
 
-;; Copyright (C) 1998  Free Software Foundation, Inc.
+;; Copyright (C) 1998, 1999  Free Software Foundation, Inc.
 
 ;; Author: Alex Schroeder <a.schroeder@bsiag.ch>
 ;; Maintainer: Alex Schroeder <a.schroeder@bsiag.ch>
-;; Version: 1.1.6
+;; Version: 1.2.1
 ;; Keywords: processes SQL
 
 ;; This file is part of GNU Emacs.
@@ -99,6 +99,7 @@
 ;; <ibalaban@dalet.com>
 ;; Yair Friedman <yfriedma@JohnBryce.Co.Il>
 ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de>
+;; nino <nino@inform.dk>
 
 
 ;;; Code:
@@ -146,7 +147,9 @@
 
 After a call to `sql-send-region' or `sql-send-buffer',
 the window is split and the SQLi buffer is shown.  If this
-variable is not nil, that buffer's window will be selected."
+variable is not nil, that buffer's window will be selected
+by calling `pop-to-buffer'.  If this variable is nil, that
+buffer is shown using `display-buffer'."
   :type 'string
   :group 'SQL)
 
@@ -177,6 +180,17 @@
   :type 'file
   :group 'SQL)
 
+;; Customisation for MySql
+
+(defcustom sql-mysql-program "mysql"
+  "*Command to start mysql by TcX.
+
+Starts `sql-interactive-mode' after doing some setup.
+
+The program can also specify a TCP connection.  See `make-comint'."
+  :type 'file
+  :group 'SQL)
+
 ;; Customisation for SyBase
 
 (defcustom sql-sybase-program "isql"
@@ -255,6 +269,11 @@
 
 You can change `comint-prompt-regexp' on `sql-interactive-mode-hook'.")
 
+(defvar sql-prompt-length 0
+  "Prompt used to set `left-margin' in `sql-interactive-mode'.
+
+You can change it on `sql-interactive-mode-hook'.")
+
 ;; Keymap for sql-interactive-mode, based on comint-mode-map.
 
 (if (not (string-match "XEmacs\\|Lucid" emacs-version))
@@ -323,6 +342,8 @@
     ;; newline and formfeed end coments
     (modify-syntax-entry ?\n "> b" table)
     (modify-syntax-entry ?\f "> b" table)
+    ;; single quotes (') quotes delimit strings
+    (modify-syntax-entry ?' "\"" table)
     table)
   "Syntax table used in `sql-mode' and `sql-interactive-mode'.")
 
@@ -520,11 +541,12 @@
 Use the following commands to start a specific SQL interpreter:
 
 psql by PostGres: \\[sql-postgres]
-SQL*Plus: \\[sql-oracle]
-dbaccess: \\[sql-informix]
-isql (Sybase): \\[sql-sybase]
-sql (Ingres): \\[sql-ingres]
-isql (Microsoft): \\[sql-ms]
+mysql by TcX: \\[sql-mysql]
+SQL*Plus by Oracle: \\[sql-oracle]
+dbaccess by Informix: \\[sql-informix]
+isql by Sybase: \\[sql-sybase]
+sql by Ingres: \\[sql-ingres]
+isql by Microsoft: \\[sql-ms]
 
 Once you have the SQLi buffer, you can enter SQL statements in the
 buffer.  The output generated is appended to the buffer and a new prompt
@@ -635,6 +657,7 @@
 	(if (string-match "\n$" (buffer-substring start end))
 	    ()
 	  (comint-send-string sql-buffer "\n"))
+	(message "Sent string to buffer %s." (buffer-name sql-buffer))
 	(if sql-pop-to-buffer-after-send-region 
 	    (pop-to-buffer sql-buffer)
 	  (display-buffer sql-buffer)))
@@ -685,6 +708,8 @@
   (make-local-variable 'font-lock-defaults)
   (setq font-lock-defaults '(sql-mode-font-lock-keywords 
 			     nil t ((95 . "w") (46 . "w"))))
+  (make-local-variable 'comment-start)
+  (setq comment-start "--")
   (setq local-abbrev-table sql-mode-abbrev-table)
   (setq abbrev-all-caps 1)
   (run-hooks 'sql-mode-hook))
@@ -748,13 +773,20 @@
        \(function (lambda (STR) (comint-show-output))))"
   (comint-mode)
   (setq comint-prompt-regexp sql-prompt-regexp)
+  (setq left-margin sql-prompt-length)
   (setq major-mode 'sql-interactive-mode)
   (setq mode-name "SQLi")
   (use-local-map sql-interactive-mode-map)
   (set-syntax-table sql-mode-syntax-table)
   (make-local-variable 'font-lock-defaults)
-  (setq font-lock-defaults '(sql-mode-font-lock-keywords t t ((95 . "w") (46 . "w"))))
-  (setq left-margin 5)
+  ;; 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 hilighting
+  ;; is disabled for interactive buffers.
+  (setq font-lock-defaults '(sql-mode-font-lock-keywords 
+			     t t ((95 . "w") (46 . "w"))))
+  (make-local-variable 'comment-start)
+  (setq comment-start "--")
   (setq local-abbrev-table sql-mode-abbrev-table)
   (setq abbrev-all-caps 1)
   (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop)
@@ -821,6 +853,7 @@
 	  (set-buffer (make-comint "SQL" sql-oracle-program nil parameter))
 	(set-buffer (make-comint "SQL" sql-oracle-program nil))))
     (setq sql-prompt-regexp "^SQL> ")
+    (setq sql-prompt-length 5)
     (setq sql-buffer (current-buffer))
     ;; set sql-mode-font-lock-keywords to something different before
     ;; calling sql-interactive-mode.
@@ -872,6 +905,7 @@
       (set-buffer (apply 'make-comint "SQL" sql-sybase-program 
 			 nil params)))
     (setq sql-prompt-regexp "^SQL> ")
+    (setq sql-prompt-length 5)
     (setq sql-buffer (current-buffer))
     (sql-interactive-mode)
     (message "Login...done")
@@ -910,6 +944,53 @@
 	(set-buffer (make-comint "SQL" sql-informix-program nil))
       (set-buffer (make-comint "SQL" sql-informix-program nil sql-database)))
     (setq sql-prompt-regexp "^SQL> ")
+    (setq sql-prompt-length 5)
+    (setq sql-buffer (current-buffer))
+    (sql-interactive-mode)
+    (message "Login...done")
+    (pop-to-buffer sql-buffer)))
+
+
+
+(defun sql-mysql ()
+  "Run mysql by TcX as an inferior process.
+
+If buffer *SQL* exists but no process is running, make a new process.
+If buffer exists and a process is running, just switch to buffer
+`*SQL*'.
+
+Interpreter used comes from variable `sql-mysql-program'.  Login uses
+the variable `sql-database' as default, if set.
+
+The buffer is put in sql-interactive-mode, giving commands for sending
+input.  See `sql-interactive-mode'.
+
+To specify a coding system for converting non-ASCII characters
+in the input and output to the process, use \\[universal-coding-system-argument]
+before \\[sql-informix].  You can also specify this with \\[set-buffer-process-coding-system]
+in the SQL buffer, after you start the process.
+The default comes from `process-coding-system-alist' and
+`default-process-coding-system'.
+
+\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
+  (interactive)
+  (if (comint-check-proc "*SQL*")
+      (pop-to-buffer "*SQL*")
+    (sql-get-login 'user 'password 'database)
+    (message "Login...")
+    ;; Put all parameters to the program (if defined) in a list and call
+    ;; make-comint.
+    (let ((params))
+      (if (not (string= "" sql-database))
+	  (setq params (append (list (concat "--host=" sql-database)) params)))
+      (if (not (string= "" sql-password))
+	  (setq params (append (list (concat "--password=" sql-password)) params)))
+      (if (not (string= "" sql-user))
+	  (setq params (append (list (concat "--user=" sql-user)) params)))
+      (set-buffer (apply 'make-comint "SQL" sql-mysql-program 
+			 nil params)))
+    (setq sql-prompt-regexp "^mysql>")
+    (setq sql-prompt-length 6)
     (setq sql-buffer (current-buffer))
     (sql-interactive-mode)
     (message "Login...done")
@@ -948,6 +1029,7 @@
 	(set-buffer (make-comint "SQL" sql-ingres-program nil))
       (set-buffer (make-comint "SQL" sql-ingres-program nil sql-database)))
     (setq sql-prompt-regexp "^\* ")
+    (setq sql-prompt-length 2)
     (setq sql-buffer (current-buffer))
     (sql-interactive-mode)
     (message "Login...done")
@@ -999,6 +1081,7 @@
       (set-buffer (apply 'make-comint "SQL" sql-ms-program
 			 nil params)))
     (setq sql-prompt-regexp "^[0-9]*>")
+    (setq sql-prompt-length 5)
     (setq sql-buffer (current-buffer))
     (sql-interactive-mode)
     (message "Login...done")
@@ -1044,6 +1127,7 @@
 	(set-buffer (make-comint "SQL" sql-postgres-program nil))
       (set-buffer (make-comint "SQL" sql-postgres-program nil sql-database)))
     (setq sql-prompt-regexp "^.*> *")
+    (setq sql-prompt-length 5)
     ;; This is a lousy hack to prevent psql from truncating it's output
     ;; and giving stupid warnings. If s.o. knows a way to prevent psql 
     ;; from acting this way, then I would be very thankful to