/[emacs]/emacs/lisp/progmodes/sql.el
ViewVC logotype

Diff of /emacs/lisp/progmodes/sql.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.32.4.1 by miles, Fri Apr 4 06:20:36 2003 UTC revision 1.32.4.2 by miles, Tue Oct 14 23:30:18 2003 UTC
# Line 1  Line 1 
1  ;;; sql.el --- specialized comint.el for SQL interpreters  ;;; sql.el --- specialized comint.el for SQL interpreters
2    
3  ;; Copyright (C) 1998, 1999, 2000, 2001, 2002  Free Software Foundation, Inc.  ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003  Free Software Foundation, Inc.
4    
5  ;; Author: Alex Schroeder <alex@gnu.org>  ;; Author: Alex Schroeder <alex@gnu.org>
6  ;; Maintainer: Alex Schroeder <alex@gnu.org>  ;; Maintainer: Michael Mauger <mmaug@yahoo.com>
7  ;; Version: 1.7.0  ;; Version: 1.8.0
8  ;; Keywords: comm languages processes  ;; Keywords: comm languages processes
9  ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode  ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode
10    
# Line 78  Line 78 
78    
79  ;;; Bugs:  ;;; Bugs:
80    
81  ;; Using sql-ms (isql by Microsoft): When commands with syntax errors  ;; sql-ms now uses osql instead of isql.  Osql flushes its error
82  ;; or execution errors are executed, there is no server feedback.  ;; stream more frequently than isql so that error messages are
83  ;; This happens in stored procedures for example.  The server messages  ;; available.  There is no prompt and some output still is buffered.
84  ;; only appear after the process is exited.  This makes things  ;; This improves the interaction under Emacs but it still is somewhat
85  ;; somewhat unreliable.  ;; awkward.
86    
87    ;; Quoted identifiers are not supported for hilighting.  Most
88    ;; databases support the use of double quoted strings in place of
89    ;; identifiers; ms (Microsoft SQLServer) also supports identifiers
90    ;; enclosed within brackets [].
91    
92  ;; ChangeLog available on request.  ;; ChangeLog available on request.
93    
94    ;;; Product Support:
95    
96    ;; To add support for additional SQL products the following steps
97    ;; must be followed ("xyz" is the name of the product in the examples
98    ;; below):
99    
100    ;; 1) Add the product to `sql-product' choice list.
101    
102    ;;     (const :tag "XyzDB" xyz)
103    
104    ;; 2) Add an entry to the `sql-product-support' list.
105    
106    ;;     (xyz
107    ;;      :font-lock sql-mode-xyz-font-lock-keywords
108    ;;      :sqli-login (user password server database)
109    ;;      :sqli-connect sql-connect-xyz
110    ;;      :sqli-prompt-regexp "^xyzdb> "
111    ;;      :sqli-prompt-length 7
112    ;;      :sqli-input-sender nil
113    ;;      :syntax-alist ((?# . "w")))
114    
115    ;; 3) Add customizable values for the product interpreter and options.
116    
117    ;;     ;; Customization for XyzDB
118    ;;
119    ;;     (defcustom sql-xyz-program "ixyz"
120    ;;       "*Command to start ixyz by XyzDB."
121    ;;       :type 'file
122    ;;       :group 'SQL)
123    ;;
124    ;;     (defcustom sql-xyz-options '("-X" "-Y" "-Z")
125    ;;       "*List of additional options for `sql-xyz-program'."
126    ;;       :type '(repeat string)
127    ;;       :group 'SQL)
128    
129    ;; 4) Add an entry to SQL->Product submenu.
130    
131    ;;     ["XyzDB" sql-highlight-xyz-keywords
132    ;;      :style radio
133    ;;      :selected (eq sql-product 'xyz)]
134    
135    ;; 5) Add the font-lock specifications.  At a minimum, default to
136    ;;    using ANSI keywords.  See sql-mode-oracle-font-lock-keywords for
137    ;;    a more complex example.
138    
139    ;;     (defvar sql-mode-xyz-font-lock-keywords sql-mode-ansi-font-lock-keywords
140    ;;       "XyzDB SQL keywords used by font-lock.")
141    
142    ;; 6) Add a product highlighting function.
143    
144    ;;     (defun sql-highlight-xyz-keywords ()
145    ;;       "Highlight XyzDB keywords."
146    ;;       (interactive)
147    ;;       (sql-set-product 'xyz))
148    
149    ;; 7) Add an autoloaded SQLi function.
150    
151    ;;     ;;;###autoload
152    ;;     (defun sql-xyz ()
153    ;;       "Run ixyz by XyzDB as an inferior process."
154    ;;       (interactive)
155    ;;       (sql-product-interactive 'xyz))
156    
157    ;; 8) Add a connect function which formats the command line arguments
158    ;;    and starts the product interpreter in a comint buffer.  See the
159    ;;    existing connect functions for examples of the types of
160    ;;    processing available.
161    
162    ;;     (defun sql-connect-xyz ()
163    ;;       "Create comint buffer and connect to XyzDB using the login
164    ;;     parameters and command options."
165    ;;
166    ;;         ;; Do something with `sql-user', `sql-password',
167    ;;         ;; `sql-database', and `sql-server'.
168    ;;         (let ((params sql-xyz-options))
169    ;;           (if (not (string= "" sql-server))
170    ;;              (setq params (append (list "-S" sql-server) params)))
171    ;;           (if (not (string= "" sql-database))
172    ;;               (setq params (append (list "-D" sql-database) params)))
173    ;;           (if (not (string= "" sql-password))
174    ;;               (setq params (append (list "-P" sql-password) params)))
175    ;;           (if (not (string= "" sql-user))
176    ;;               (setq params (append (list "-U" sql-user) params)))
177    ;;           (set-buffer (apply 'make-comint "SQL" sql-xyz-program
178    ;;                              nil params))))
179    
180    ;; 9) Save and compile sql.el.
181    
182  ;;; To Do:  ;;; To Do:
183    
184  ;; Add better hilight support for other brands; there is a bias towards  ;; Add better hilight support for other brands; there is a bias towards
# Line 105  Line 198 
198  ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de>  ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de>
199  ;; nino <nino@inform.dk>  ;; nino <nino@inform.dk>
200  ;; Berend de Boer <berend@pobox.com>  ;; Berend de Boer <berend@pobox.com>
201    ;; Michael Mauger <mmaug@yahoo.com>
202    
203    
204    
# Line 112  Line 206 
206    
207  (require 'comint)  (require 'comint)
208  ;; Need the following to allow GNU Emacs 19 to compile the file.  ;; Need the following to allow GNU Emacs 19 to compile the file.
209  (require 'regexp-opt)  (eval-when-compile
210      (require 'regexp-opt))
211  (require 'custom)  (require 'custom)
212    
213  ;;; Allow customization  ;;; Allow customization
# Line 122  Line 217 
217    :version "20.4"    :version "20.4"
218    :group 'processes)    :group 'processes)
219    
220  ;; These three variables will be used as defaults, if set.  ;; These four variables will be used as defaults, if set.
221    
222  (defcustom sql-user ""  (defcustom sql-user ""
223    "*Default username."    "*Default username."
# Line 147  Customizing your password will store it Line 242  Customizing your password will store it
242    :type 'string    :type 'string
243    :group 'SQL)    :group 'SQL)
244    
245    ;; SQL Product support
246    (defcustom sql-product 'ansi
247      "*Select the SQL database product used so that buffers can be
248    highlighted properly when you open them."
249      :type '(choice (const :tag "ANSI" ansi)
250                     (const :tag "DB2" db2)
251                     (const :tag "Informix" informix)
252                     (const :tag "Ingres" ingres)
253                     (const :tag "Interbase" interbase)
254                     (const :tag "Linter" linter)
255                     (const :tag "Microsoft" ms)
256                     (const :tag "MySQL" mysql)
257                     (const :tag "Oracle" oracle)
258                     (const :tag "PostGres" postgres)
259                     (const :tag "Solid" solid)
260                     (const :tag "SQLite" sqlite)
261                     (const :tag "Sybase" sybase))
262      :group 'SQL)
263    
264    (defvar sql-interactive-product nil
265      "Product under `sql-interactive-mode'.")
266    
267    (defvar sql-product-support
268      '((ansi
269         :font-lock sql-mode-ansi-font-lock-keywords)
270        (db2
271         :font-lock sql-mode-db2-font-lock-keywords
272         :sqli-login nil
273         :sqli-connect sql-connect-db2
274         :sqli-prompt-regexp "^db2 => "
275         :sqli-prompt-length 7)
276        (informix
277         :font-lock sql-mode-informix-font-lock-keywords
278         :sqli-login (database)
279         :sqli-connect sql-connect-informix
280         :sqli-prompt-regexp "^SQL> "
281         :sqli-prompt-length 5)
282        (ingres
283         :font-lock sql-mode-ingres-font-lock-keywords
284         :sqli-login (database)
285         :sqli-connect sql-connect-ingres
286         :sqli-prompt-regexp "^\* "
287         :sqli-prompt-length 2)
288        (interbase
289         :font-lock sql-mode-interbase-font-lock-keywords
290         :sqli-login (user password database)
291         :sqli-connect sql-connect-interbase
292         :sqli-prompt-regexp "^SQL> "
293         :sqli-prompt-length 5)
294        (linter
295         :font-lock sql-mode-linter-font-lock-keywords
296         :sqli-login (user password database server)
297         :sqli-connect sql-connect-linter
298         :sqli-prompt-regexp "^SQL>"
299         :sqli-prompt-length 4)
300        (ms
301         :font-lock sql-mode-ms-font-lock-keywords
302         :sqli-login (user password server database)
303         :sqli-connect sql-connect-ms
304         :sqli-prompt-regexp "^[0-9]*>"
305         :sqli-prompt-length 5
306         :syntax-alist ((?@ . "w")))
307        (mysql
308         :font-lock sql-mode-mysql-font-lock-keywords
309         :sqli-login (user password database server)
310         :sqli-connect sql-connect-mysql
311         :sqli-prompt-regexp "^mysql> "
312         :sqli-prompt-length 6)
313        (oracle
314         :font-lock sql-mode-oracle-font-lock-keywords
315         :sqli-login (user password database)
316         :sqli-connect sql-connect-oracle
317         :sqli-prompt-regexp "^SQL> "
318         :sqli-prompt-length 5
319         :syntax-alist ((?$ . "w") (?# . "w")))
320        (postgres
321         :font-lock sql-mode-postgres-font-lock-keywords
322         :sqli-login (database server)
323         :sqli-connect sql-connect-postgres
324         :sqli-prompt-regexp "^.*> *"
325         :sqli-prompt-length 5)
326        (solid
327         :font-lock sql-mode-solid-font-lock-keywords
328         :sqli-login (user password server)
329         :sqli-connect sql-connect-solid
330         :sqli-prompt-regexp "^"
331         :sqli-prompt-length 0)
332        (sqlite
333         :font-lock sql-mode-sqlite-font-lock-keywords
334         :sqli-login (user password server database)
335         :sqli-connect sql-connect-sqlite
336         :sqli-prompt-regexp "^sqlite> "
337         :sqli-prompt-length 8)
338        (sybase
339         :font-lock sql-mode-sybase-font-lock-keywords
340         :sqli-login (server user password database)
341         :sqli-connect sql-connect-sybase
342         :sqli-prompt-regexp "^SQL> "
343         :sqli-prompt-length 5
344         :syntax-alist ((?@ . "w")))
345        )
346      "This variable contains a list of product features for each of the
347    SQL products handled by `sql-mode'.  Without an entry in this list a
348    product will not be properly highlighted and will not support
349    `sql-interactive-mode'.
350    
351    Each element in the list is in the following format:
352    
353     \(PRODUCT FEATURE VALUE ...)
354    
355    where PRODUCT is the appropriate value of `sql-product'.  The product
356    name is then followed by FEATURE-VALUE pairs.  If a FEATURE is not
357    specified, its VALUE is treated as nil.  FEATURE must be one of the
358    following:
359    
360     :font-lock             name of the variable containing the product
361                            specific font lock highlighting patterns.
362    
363     :sqli-login            a list of login parameters (i.e., user,
364                            password, database and server) needed to
365                            connect to the database.
366    
367     :sqli-connect          the name of a function which accepts no
368                            parameters that will use the values of
369                            `sql-user', `sql-password',
370                            `sql-database' and `sql-server' to open a
371                            comint buffer and connect to the
372                            database.  Do product specific
373                            configuration of comint in this function.
374    
375     :sqli-prompt-regexp    a regular expression string that matches the
376                            prompt issued by the product interpreter.
377    
378     :sqli-prompt-length    the length of the prompt on the line.
379    
380     :syntax-alist          an alist of syntax table entries to enable
381                            special character treatment by font-lock and
382                            imenu. ")
383    
384  ;; misc customization of sql.el behaviour  ;; misc customization of sql.el behaviour
385    
386  (defcustom sql-electric-stuff nil  (defcustom sql-electric-stuff nil
# Line 177  buffer is shown using `display-buffer'." Line 411  buffer is shown using `display-buffer'."
411  ;; imenu support for sql-mode.  ;; imenu support for sql-mode.
412    
413  (defvar sql-imenu-generic-expression  (defvar sql-imenu-generic-expression
414    '(("Tables" "^\\s-*create\\s-+table\\s-+\\(\\w+\\)" 1)    ;; Items are in reverse order because they are rendered in reverse.
415      ("Indexes" "^\\s-*create\\s-+index\\s-+\\(\\w+\\)" 1))    '(("Rules/Defaults" "^\\s-*create\\s-+\\(rule\\|default\\)\\s-+\\(\\w+\\)" 2)
416        ("Sequences" "^\\s-*create\\s-+sequence\\s-+\\(\\w+\\)" 1)
417        ("Triggers" "^\\s-*\\(create\\s-+\\(or\\s-+replace\\s-+\\)?\\)?trigger\\s-+\\(\\w+\\)" 3)
418        ("Functions" "^\\s-*\\(create\\s-+\\(or\\s-+replace\\s-+\\)?\\)?function\\s-+\\(\\w+\\)" 3)
419        ("Procedures" "^\\s-*\\(create\\s-+\\(or\\s-+replace\\s-+\\)?\\)?proc\\(edure\\)?\\s-+\\(\\w+\\)" 4)
420        ("Packages" "^\\s-*create\\s-+\\(or\\s-+replace\\s-+\\)?package\\s-+\\(body\\s-+\\)?\\(\\w+\\)" 3)
421        ("Indexes" "^\\s-*create\\s-+index\\s-+\\(\\w+\\)" 1)
422        ("Tables/Views" "^\\s-*create\\s-+\\(\\(global\\s-+\\)?\\(temporary\\s-+\\)?table\\|view\\)\\s-+\\(\\w+\\)" 4))
423    "Define interesting points in the SQL buffer for `imenu'.    "Define interesting points in the SQL buffer for `imenu'.
424    
425  This is used to set `imenu-generic-expression' when SQL mode is  This is used to set `imenu-generic-expression' when SQL mode is
# Line 262  The program can also specify a TCP conne Line 503  The program can also specify a TCP conne
503    :version "20.8"    :version "20.8"
504    :group 'SQL)    :group 'SQL)
505    
506    ;; Customization for SQLite
507    
508    (defcustom sql-sqlite-program "sqlite"
509      "*Command to start SQLite.
510    
511    Starts `sql-interactive-mode' after doing some setup.
512    
513    The program can also specify a TCP connection.  See `make-comint'."
514      :type 'file
515      :group 'SQL)
516    
517    (defcustom sql-sqlite-options nil
518      "*List of additional options for `sql-sqlite-program'.
519    The following list of options is reported to make things work
520    on Windows: \"-C\" \"-t\" \"-f\" \"-n\"."
521      :type '(repeat string)
522      :version "20.8"
523      :group 'SQL)
524    
525  ;; Customization for MySql  ;; Customization for MySql
526    
527  (defcustom sql-mysql-program "mysql"  (defcustom sql-mysql-program "mysql"
# Line 334  The program can also specify a TCP conne Line 594  The program can also specify a TCP conne
594    
595  ;; Customization for Microsoft  ;; Customization for Microsoft
596    
597  (defcustom sql-ms-program "isql"  (defcustom sql-ms-program "osql"
598    "*Command to start isql by Microsoft.    "*Command to start osql by Microsoft.
599    
600  Starts `sql-interactive-mode' after doing some setup.  Starts `sql-interactive-mode' after doing some setup.
601    
# Line 449  the local value of `sql-buffer' using \\ Line 709  the local value of `sql-buffer' using \\
709  (defvar sql-prompt-regexp nil  (defvar sql-prompt-regexp nil
710    "Prompt used to initialize `comint-prompt-regexp'.    "Prompt used to initialize `comint-prompt-regexp'.
711    
712  You can change `comint-prompt-regexp' on `sql-interactive-mode-hook'.")  You can change `sql-prompt-regexp' on `sql-interactive-mode-hook'.")
713    
714  (defvar sql-prompt-length 0  (defvar sql-prompt-length 0
715    "Prompt used to set `left-margin' in `sql-interactive-mode'.    "Prompt used to set `left-margin' in `sql-interactive-mode'.
716    
717  You can change it on `sql-interactive-mode-hook'.")  You can change `sql-prompt-length' on `sql-interactive-mode-hook'.")
718    
719  (defvar sql-alternate-buffer-name nil  (defvar sql-alternate-buffer-name nil
720    "Buffer-local string used to possibly rename the SQLi buffer.    "Buffer-local string used to possibly rename the SQLi buffer.
# Line 499  Based on `comint-mode-map'.") Line 759  Based on `comint-mode-map'.")
759                                               (get-buffer-process sql-buffer))]                                               (get-buffer-process sql-buffer))]
760     ["Send Region" sql-send-region (and (or (and (boundp 'mark-active); Emacs     ["Send Region" sql-send-region (and (or (and (boundp 'mark-active); Emacs
761                                                  mark-active)                                                  mark-active)
762                                             (mark)); XEmacs                                             (mark t)); XEmacs
763                                         (buffer-live-p sql-buffer)                                         (buffer-live-p sql-buffer)
764                                         (get-buffer-process sql-buffer))]                                         (get-buffer-process sql-buffer))]
765     ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer)     ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer)
766                                         (get-buffer-process sql-buffer))]                                         (get-buffer-process sql-buffer))]
767       ["--" nil nil]
768       ["Start SQLi session" sql-product-interactive (sql-product-feature :sqli-connect)]
769     ["Show SQLi buffer" sql-show-sqli-buffer t]     ["Show SQLi buffer" sql-show-sqli-buffer t]
770     ["Set SQLi buffer" sql-set-sqli-buffer t]     ["Set SQLi buffer" sql-set-sqli-buffer t]
771     ["Pop to SQLi buffer after send"     ["Pop to SQLi buffer after send"
772      sql-toggle-pop-to-buffer-after-send-region      sql-toggle-pop-to-buffer-after-send-region
773      :style toggle      :style toggle
774      :selected sql-pop-to-buffer-after-send-region]      :selected sql-pop-to-buffer-after-send-region]
775     ("Highlighting"     ["--" nil nil]
776      ["ANSI SQL keywords" sql-highlight-ansi-keywords t]     ("Product"
777      ["Oracle keywords" sql-highlight-oracle-keywords t]      ["ANSI" sql-highlight-ansi-keywords
778      ["Postgres keywords" sql-highlight-postgres-keywords t]       :style radio
779      ["Linter keywords" sql-highlight-linter-keywords t]       :selected (eq sql-product 'ansi)]
780        ["DB2" sql-highlight-db2-keywords
781         :style radio
782         :selected (eq sql-product 'db2)]
783        ["Informix" sql-highlight-informix-keywords
784         :style radio
785         :selected (eq sql-product 'informix)]
786        ["Ingres" sql-highlight-ingres-keywords
787         :style radio
788         :selected (eq sql-product 'ingres)]
789        ["Interbase" sql-highlight-interbase-keywords
790         :style radio
791         :selected (eq sql-product 'interbase)]
792        ["Linter" sql-highlight-linter-keywords
793         :style radio
794         :selected (eq sql-product 'linter)]
795        ["Microsoft" sql-highlight-ms-keywords
796         :style radio
797         :selected (eq sql-product 'ms)]
798        ["MySQL" sql-highlight-mysql-keywords
799         :style radio
800         :selected (eq sql-product 'mysql)]
801        ["Oracle" sql-highlight-oracle-keywords
802         :style radio
803         :selected (eq sql-product 'oracle)]
804        ["Postgres" sql-highlight-postgres-keywords
805         :style radio
806         :selected (eq sql-product 'postgres)]
807        ["Solid" sql-highlight-solid-keywords
808         :style radio
809         :selected (eq sql-product 'solid)]
810        ["SQLite" sql-highlight-sqlite-keywords
811         :style radio
812         :selected (eq sql-product 'sqlite)]
813        ["Sybase" sql-highlight-sybase-keywords
814         :style radio
815         :selected (eq sql-product 'sybase)]
816      )))      )))
817    
818  ;; easy menu for sql-interactive-mode.  ;; easy menu for sql-interactive-mode.
# Line 532  Based on `comint-mode-map'.") Line 830  Based on `comint-mode-map'.")
830    "Abbrev table used in `sql-mode' and `sql-interactive-mode'.")    "Abbrev table used in `sql-mode' and `sql-interactive-mode'.")
831  (if sql-mode-abbrev-table  (if sql-mode-abbrev-table
832      ()      ()
833    (let ((wrapper))    (let ((nargs (cdr (subr-arity (symbol-function 'define-abbrev))))
834      (define-abbrev-table 'sql-mode-abbrev-table ())          d-a)
835      (define-abbrev sql-mode-abbrev-table  "ins" "insert" nil 0 t)      ;; In Emacs 21.3+, provide SYSTEM-FLAG to define-abbrev.
836      (define-abbrev sql-mode-abbrev-table  "upd" "update" nil 0 t)      (setq d-a
837      (define-abbrev sql-mode-abbrev-table  "del" "delete" nil 0 t)            (if (>= nargs 6)
838      (define-abbrev sql-mode-abbrev-table  "sel" "select" nil 0 t)))                '(lambda (name expansion) (define-abbrev sql-mode-abbrev-table name expansion nil 0 t))
839                '(lambda (name expansion) (define-abbrev sql-mode-abbrev-table name expansion))))
840    
841        (define-abbrev-table 'sql-mode-abbrev-table nil)
842        (funcall d-a "ins" "insert")
843        (funcall d-a "upd" "update")
844        (funcall d-a "del" "delete")
845        (funcall d-a "sel" "select")
846        (funcall d-a "proc" "procedure")
847        (funcall d-a "func" "function")
848        (funcall d-a "cr" "create")))
849    
850  ;; Syntax Table  ;; Syntax Table
851    
# Line 562  Based on `comint-mode-map'.") Line 870  Based on `comint-mode-map'.")
870    
871  ;; Font lock support  ;; Font lock support
872    
873  (defvar sql-mode-ansi-font-lock-keywords nil  (defvar sql-mode-font-lock-object-name
874    "ANSI SQL keywords used by font-lock.    (list (concat "^\\s-*\\(create\\(\\s-+or\\s-+replace\\)?\\|drop\\|alter\\)?\\s-+"
875                    "\\(\\(global\\s-+\\)?\\(temporary\\s-+\\)?table\\|view\\|package\\(\\s-+body\\)?\\|"
876                    "proc\\(edure\\)?\\|function\\|trigger\\|sequence\\|rule\\|default\\)\\s-+\\(\\w+\\)")
877            8 'font-lock-function-name-face)
878    
879  This variable is used by `sql-mode' and `sql-interactive-mode'.  The    "Pattern to match the names of top-level objects in a CREATE,
880  regular expressions are created during compilation by calling the  DROP or ALTER statement.
881  function `regexp-opt'.  Therefore, take a look at the source before  
882  you define your own sql-mode-ansi-font-lock-keywords.  You may want to  The format of variable should be a valid `font-lock-keywords'
883  add functions and PL/SQL keywords.")  entry.")
884  (if sql-mode-ansi-font-lock-keywords  
885      ()  (defvar sql-mode-ansi-font-lock-keywords
886    (let ((ansi-keywords (eval-when-compile    (let ((ansi-keywords (eval-when-compile
887                           (concat "\\b"                           (concat "\\b"
888                                   (regexp-opt '(                                   (regexp-opt '(
889    
890  "authorization" "avg" "begin" "close" "cobol" "commit"  "authorization" "avg" "begin" "close" "cobol" "commit"
891  "continue" "count" "declare" "double" "end" "escape"  "continue" "count" "declare" "double" "end" "escape"
892  "exec" "fetch" "foreign" "fortran" "found" "go" "goto" "indicator"  "exec" "fetch" "foreign" "fortran" "found" "go" "goto" "indicator"
893  "key" "language" "max" "min" "module" "numeric" "open" "pascal" "pli"  "key" "language" "max" "min" "module" "numeric" "open" "pascal" "pli"
894  "precision" "primary" "procedure" "references" "rollback"  "precision" "primary" "procedure" "references" "rollback"
895  "schema" "section" "some" "sqlcode" "sqlerror" "sum" "work") t) "\\b")))  "schema" "section" "some" "sqlcode" "sqlerror" "sum" "work"
896    
897    ) t) "\\b")))
898          (ansi-reserved-words (eval-when-compile          (ansi-reserved-words (eval-when-compile
899                                 (concat "\\b"                                 (concat "\\b"
900                                         (regexp-opt '(                                         (regexp-opt '(
901    
902  "all" "and" "any" "as" "asc" "between" "by" "check" "create"  "all" "and" "any" "as" "asc" "between" "by" "check" "create"
903  "current" "default" "delete" "desc" "distinct" "exists" "float" "for"  "current" "default" "delete" "desc" "distinct" "exists" "float" "for"
904  "from" "grant" "group" "having" "in" "insert" "into" "is"  "from" "grant" "group" "having" "in" "insert" "into" "is"
905  "like" "not" "null" "of" "on" "option" "or" "order" "privileges"  "like" "not" "null" "of" "on" "option" "or" "order" "privileges"
906  "public" "select" "set" "table" "to" "union" "unique"  "public" "select" "set" "table" "to" "union" "unique"
907  "update" "user" "values" "view" "where" "with") t) "\\b")))  "update" "user" "values" "view" "where" "with"
908    
909    ) t) "\\b")))
910          (ansi-types (eval-when-compile          (ansi-types (eval-when-compile
911                        (concat "\\b"                        (concat "\\b"
912                                (regexp-opt '(                                (regexp-opt '(
913    
914  ;; ANSI Keywords that look like types  ;; ANSI Keywords that look like types
915  "character" "cursor" "dec" "int" "real"  "character" "cursor" "dec" "int" "real"
916  ;; ANSI Reserved Word that look like types  ;; ANSI Reserved Word that look like types
917  "char" "integer" "smallint" ) t) "\\b"))))  "char" "integer" "smallint"
918      (setq sql-mode-ansi-font-lock-keywords  
919            (list (cons ansi-keywords 'font-lock-function-name-face)  ) t) "\\b"))))
920        (list (cons ansi-keywords 'font-lock-keyword-face)
921                  (cons ansi-reserved-words 'font-lock-keyword-face)                  (cons ansi-reserved-words 'font-lock-keyword-face)
922                  (cons ansi-types 'font-lock-type-face)))))            (cons ansi-types 'font-lock-type-face)))
923    
924  (defvar sql-mode-oracle-font-lock-keywords nil    "ANSI SQL keywords used by font-lock.
   "Oracle SQL keywords used by font-lock.  
925    
926  This variable is used by `sql-mode' and `sql-interactive-mode'.  The  This variable is used by `sql-mode' and `sql-interactive-mode'.  The
927  regular expressions are created during compilation by calling the  regular expressions are created during compilation by calling the
928  function `regexp-opt'.  Therefore, take a look at the source before  function `regexp-opt'.  Therefore, take a look at the source before
929  you define your own sql-mode-oracle-font-lock-keywords.  You may want  you define your own sql-mode-ansi-font-lock-keywords.  You may want to
930  to add functions and PL/SQL keywords.")  add functions and PL/SQL keywords.")
931  (if sql-mode-oracle-font-lock-keywords  
932      ()  (defvar sql-mode-oracle-font-lock-keywords
933    (let ((oracle-keywords (eval-when-compile    (let ((oracle-keywords (eval-when-compile
934                             (concat "\\b"                             (concat "\\b"
935                                     (regexp-opt '(                                     (regexp-opt '(
936  "admin" "after" "allocate" "analyze" "archive" "archivelog" "backup"  ;; Oracle (+ANSI) SQL keywords
937  "become" "before" "block" "body" "cache" "cancel" "cascade" "change"  
938  "checkpoint" "compile" "constraint" "constraints" "contents"  ; ANSI keywords
939  "controlfile" "cycle" "database" "datafile" "dba" "disable" "dismount"  "authorization" "avg" "begin" "close" "cobol" "commit"
940  "dump" "each" "else" "elsif" "enable" "events" "except" "exceptions"  "continue" "count" "declare" "double" "end" "escape"
941  "execute" "exit" "explain" "extent" "externally" "false" "flush" "force"  "exec" "fetch" "foreign" "fortran" "found" "go" "goto" "indicator"
942  "freelist" "freelists" "function" "groups" "if" "including" "initrans"  "key" "language" "max" "min" "module" "numeric" "open" "pascal" "pli"
943  "instance" "layer" "link" "lists" "logfile" "loop" "manage" "manual"  "precision" "primary" "procedure" "references" "rollback"
944  "maxdatafiles" "maxinistances" "maxlogfiles" "maxloghistory"  "schema" "section" "some" "sqlcode" "sqlerror" "sum" "work"
945  "maxlogmembers" "maxtrans" "maxvalue" "minextents" "minvalue" "mount"  
946  "new" "next" "noarchivelog" "nocache" "nocycle" "nomaxvalue"  ; ANSI reserved words
947  "nominvalue" "none" "noorder" "noresetlogs" "normal" "nosort" "off"  "all" "and" "any" "as" "asc" "between" "by" "check" "create"
948  "old" "only" "optimal" "others" "out" "own" "package" "parallel"  "current" "default" "delete" "desc" "distinct" "exists" "float" "for"
949  "pctincrease" "pctused" "plan" "pragma" "private" "profile" "quota"  "from" "grant" "group" "having" "in" "insert" "into" "is"
950  "raise" "read" "recover" "referencing" "resetlogs" "restrict_references"  "like" "not" "null" "of" "on" "option" "or" "order" "privileges"
951  "restricted" "return" "returning" "reuse" "rnds" "rnps" "role" "roles"  "public" "select" "set" "table" "to" "union" "unique"
952  "savepoint" "scn" "segment" "sequence" "shared" "snapshot" "sort"  "update" "user" "values" "view" "where" "with"
953  "statement_id" "statistics" "stop" "storage" "subtype" "switch" "system"  
954  "tables" "tablespace" "temporary" "thread" "time" "tracing"  "access" "add" "admin" "after" "allocate" "alter" "analyze" "archive"
955  "transaction" "triggers" "true" "truncate" "type" "under" "unlimited"  "archivelog" "audit" "authid" "backup" "become" "before" "block"
956  "until" "use" "using" "when" "while" "wnds" "wnps" "write") t) "\\b")))  "body" "cache" "cancel" "cascade" "change" "checkpoint" "cluster"
957    "comment" "compile" "compress" "compute" "connect" "constraint"
958    "constraints" "contents" "controlfile" "cross" "currval" "cycle"
959    "database" "datafile" "dba" "deterministic" "disable" "dismount"
960    "drop" "dump" "each" "else" "else" "elsif" "enable" "events" "except"
961    "exceptions" "exclusive" "execute" "exit" "explain" "extent"
962    "externally" "false" "file" "flush" "force" "freelist" "freelists"
963    "full" "function" "global" "grant" "groups" "identified" "if"
964    "immediate" "including" "increment" "index" "initial" "initrans"
965    "inner" "instance" "intersect" "join" "layer" "left" "level" "link"
966    "lists" "lock" "logfile" "long" "loop" "manage" "manual"
967    "maxdatafiles" "maxextents" "maxinistances" "maxlogfiles"
968    "maxloghistory" "maxlogmembers" "maxtrans" "maxvalue" "merge"
969    "minextents" "minus" "minvalue" "mode" "modify" "mount" "natural"
970    "new" "next" "nextval" "noarchivelog" "noaudit" "nocache" "nocompress"
971    "nocycle" "nomaxvalue" "nominvalue" "none" "noorder" "noresetlogs"
972    "normal" "nosort" "nowait" "off" "offline" "old" "online" "only"
973    "optimal" "others" "out" "outer" "over" "own" "package" "parallel"
974    "parallel_enable" "pctfree" "pctincrease" "pctused" "plan" "pragma"
975    "preserve" "prior" "private" "profile" "quota" "raise" "raw" "read"
976    "recover" "referencing" "rename" "replace" "resetlogs" "resource"
977    "restrict_references" "restricted" "return" "returning" "reuse"
978    "revoke" "right" "rnds" "rnps" "role" "roles" "row" "rowlabel"
979    "rownum" "rows" "savepoint" "scn" "segment" "sequence" "session"
980    "share" "shared" "size" "snapshot" "sort" "statement_id" "statistics"
981    "stop" "storage" "subtype" "successful" "switch" "synonym" "sysdate"
982    "system" "tables" "tablespace" "temporary" "then" "thread" "tracing"
983    "transaction" "trigger" "triggers" "true" "truncate" "type" "uid"
984    "under" "unlimited" "until" "use" "using" "validate" "when" "while"
985    "wnds" "wnps" "write"
986    
987    ) t) "\\b")))
988          (oracle-warning-words (eval-when-compile          (oracle-warning-words (eval-when-compile
989                                   (concat "\\b"                                   (concat "\\b"
990                                           (regexp-opt '(                                           (regexp-opt '(
991  "cursor_already_open" "dup_val_on_index" "exception" "invalid_cursor"  ;; PLSQL defined exceptions
992    
993    "access_into_null" "case_not_found" "collection_is_null"
994    "cursor_already_open" "dup_val_on_index" "invalid_cursor"
995  "invalid_number" "login_denied" "no_data_found" "not_logged_on"  "invalid_number" "login_denied" "no_data_found" "not_logged_on"
996  "notfound" "others" "pragma" "program_error" "storage_error"  "program_error" "rowtype_mismatch" "self_is_null" "storage_error"
997  "timeout_on_resource" "too_many_rows" "transaction_backed_out"  "subscript_beyond_count" "subscript_outside_limit" "sys_invalid_rowid"
998  "value_error" "zero_divide") t) "\\b")))  "timeout_on_resource" "too_many_rows" "value_error" "zero_divide"
999          (oracle-reserved-words (eval-when-compile  "exception" "notfound"
1000                                   (concat "\\b"  
1001    ) t) "\\b")))
1002    
1003            (oracle-sqlplus-commands
1004             (eval-when-compile
1005               (concat "^\\(\\("
1006                                           (regexp-opt '(                                           (regexp-opt '(
1007  "access" "add" "alter" "audit" "cluster" "column" "comment" "compress"  ;; SQL*Plus commands
1008  "connect" "drop" "else" "exclusive" "file" "grant"  
1009  "identified" "immediate" "increment" "index" "initial" "intersect"  "@" "@@" "accept" "append" "archive" "attribute" "break"
1010  "level" "lock" "long" "maxextents" "minus" "mode" "modify" "noaudit"  "btitle" "change" "clear" "column" "connect" "copy" "define"
1011  "nocompress" "nowait" "number" "offline" "online" "pctfree" "prior"  "del" "describe" "disconnect" "edit" "execute" "exit" "get" "help"
1012  "raw" "rename" "resource" "revoke" "row" "rowlabel" "rownum"  "host" "input" "list" "password" "pause" "print" "prompt" "recover"
1013  "rows" "session" "share" "size" "start" "successful" "synonym" "sysdate"  "remark" "repfooter" "repheader" "run" "save" "show" "shutdown"
1014  "then" "trigger" "uid" "validate" "whenever") t) "\\b")))  "spool" "start" "startup" "store" "timing" "ttitle" "undefine"
1015          (oracle-types (eval-when-compile  "variable" "whenever"
1016    
1017    ) t)
1018    
1019       "\\)\\|"
1020       "\\(compute\\s-+\\(avg\\|cou\\|min\\|max\\|num\\|sum\\|std\\|var\\)\\)\\|"
1021       "\\(set\\s-+\\(appi\\(nfo\\)?\\|array\\(size\\)?\\|"
1022       "auto\\(commit\\)?\\|autop\\(rint\\)?\\|autorecovery\\|"
1023       "autot\\(race\\)?\\|blo\\(ckterminator\\)?\\|cmds\\(ep\\)?\\|"
1024       "colsep\\|com\\(patibility\\)?\\|con\\(cat\\)?\\|"
1025       "copyc\\(ommit\\)?\\|copytypecheck\\|def\\(ine\\)?\\|"
1026       "describe\\|echo\\|editf\\(ile\\)?\\|emb\\(edded\\)?\\|"
1027       "esc\\(ape\\)?\\|feed\\(back\\)?\\|flagger\\|"
1028       "flu\\(sh\\)?\\|hea\\(ding\\)?\\|heads\\(ep\\)?\\|"
1029       "instance\\|lin\\(esize\\)?\\|lobof\\(fset\\)?\\|"
1030       "logsource\\|long\\|longc\\(hunksize\\)?\\|mark\\(up\\)?\\|"
1031       "newp\\(age\\)?\\|null\\|numf\\(ormat\\)?\\|"
1032       "num\\(width\\)?\\|pages\\(ize\\)?\\|pau\\(se\\)?\\|"
1033       "recsep\\|recsepchar\\|serverout\\(put\\)?\\|"
1034       "shift\\(inout\\)?\\|show\\(mode\\)?\\|"
1035       "sqlbl\\(anklines\\)?\\|sqlc\\(ase\\)?\\|"
1036       "sqlco\\(ntinue\\)?\\|sqln\\(umber\\)?\\|"
1037       "sqlpluscompat\\(ibility\\)?\\|sqlpre\\(fix\\)?\\|"
1038       "sqlp\\(rompt\\)?\\|sqlt\\(erminator\\)?\\|"
1039       "suf\\(fix\\)?\\|tab\\|term\\(out\\)?\\|ti\\(me\\)?\\|"
1040       "timi\\(ng\\)?\\|trim\\(out\\)?\\|trims\\(pool\\)?\\|"
1041       "und\\(erline\\)?\\|ver\\(ify\\)?\\|wra\\(p\\)?\\)\\)\\)"
1042       "\\b.*$"
1043       )))
1044    
1045            (oracle-types
1046             (eval-when-compile
1047                          (concat "\\b"                          (concat "\\b"
1048                                  (regexp-opt '(                                  (regexp-opt '(
1049  ;; Oracle Keywords that look like types  ;; Oracle Keywords that look like types
1050  ;; Oracle Reserved Words that look like types  ;; Oracle Reserved Words that look like types
1051  "binary_integer" "blob" "boolean" "constant" "date" "decimal" "rowid"  
1052  "varchar" "varchar2") t) "\\b")))  "bfile" "binary_integer" "blob" "boolean" "byte" "char" "character"
1053    "clob" "date" "day" "dec" "decimal" "double" "float" "int" "integer"
1054    "interval" "local" "long" "month" "natural" "naturaln" "nchar" "nclob"
1055    "number" "numeric" "nvarchar2" "pls_integer" "positive" "positiven"
1056    "precision" "raw" "real" "rowid" "second" "signtype" "smallint"
1057    "string" "time" "timestamp" "urowid" "varchar" "varchar2" "year"
1058    "zone"
1059    
1060    ) t) "\\b")))
1061          (oracle-builtin-functions (eval-when-compile          (oracle-builtin-functions (eval-when-compile
1062                          (concat "\\b"                          (concat "\\b"
1063                                  (regexp-opt '(                                  (regexp-opt '(
1064  ;; Misc Oracle builtin functions  ;; Misc Oracle builtin functions
1065  "abs" "add_months" "ascii" "avg" "ceil" "chartorowid" "chr" "concat"  
1066  "convert" "cos" "cosh" "count" "currval" "decode" "dump" "exp" "floor"  "abs" "acos" "add_months" "ascii" "asciistr" "asin" "atan" "atan2"
1067  "glb" "greatest" "greatest_lb" "hextoraw" "initcap" "instr" "instrb"  "avg" "bfilename" "bin_to_num" "bitand" "case" "cast" "ceil"
1068  "last_day" "least" "least_ub" "length" "lengthb" "ln" "log" "lower"  "chartorowid" "chr" "coalesce" "compose" "concat" "convert" "corr"
1069  "lpad" "ltrim" "lub" "max" "min" "mod" "months_between" "new_time"  "cos" "cosh" "count" "covar_pop" "covar_samp" "cume_dist"
1070  "next_day" "nextval" "nls_initcap" "nls_lower" "nls_upper" "nlssort"  "current_date" "current_timestamp" "current_user" "dbtimezone"
1071  "nvl" "power" "rawtohex" "replace" "round" "rowidtochar" "rpad"  "decode" "decompose" "dense_rank" "depth" "deref" "dump" "empty_blob"
1072  "rtrim" "sign" "sin" "sinh" "soundex" "sqlcode" "sqlerrm" "sqrt"  "empty_clob" "existsnode" "exp" "extract" "extractvalue" "first"
1073  "stddev" "sum" "substr" "substrb" "tan" "tanh" "to_char"  "first_value" "floor" "from_tz" "greatest" "group_id" "grouping"
1074  "to_date" "to_label" "to_multi_byte" "to_number" "to_single_byte"  "grouping_id" "hextoraw" "initcap" "instr" "lag" "last" "last_day"
1075  "translate" "trim" "trunc" "uid" "upper" "userenv" "variance" "vsize") t) "\\b"))))  "last_value" "lead" "least" "length" "ln" "localtimestamp" "log"
1076      (setq sql-mode-oracle-font-lock-keywords  "lower" "lpad" "ltrim" "make_ref" "max" "min" "mod" "months_between"
1077            (append sql-mode-ansi-font-lock-keywords  "nchr" "new_time" "next_day" "nls_charset_decl_len" "nls_charset_id"
1078                    (list (cons oracle-keywords 'font-lock-function-name-face)  "nls_charset_name" "nls_initcap" "nls_lower" "nlssort" "nls_upper"
1079    "ntile" "nullif" "numtodsinterval" "numtoyminterval" "nvl" "nvl2"
1080    "path" "percent_rank" "percentile_cont" "percentile_disc" "power"
1081    "rank" "ratio_to_report" "rawtohex" "rawtonhex" "ref" "reftohex"
1082    "regr_slope" "regr_intercept" "regr_count" "regr_r2" "regr_avgx"
1083    "regr_avgy" "regr_sxx" "regr_syy" "regr_sxy" "round"
1084    "row_number" "rowidtochar" "rowidtonchar" "rpad" "rtrim"
1085    "sessiontimezone" "sign" "sin" "sinh" "soundex" "sqrt" "stddev"
1086    "stddev_pop" "stddev_samp" "substr" "sum" "sys_connect_by_path"
1087    "sys_context" "sys_dburigen" "sys_extract_utc" "sys_guid" "sys_typeid"
1088    "sys_xmlagg" "sys_xmlgen" "sysdate" "systimestamp" "tan" "tanh"
1089    "to_char" "to_clob" "to_date" "to_dsinterval" "to_lob" "to_multi_byte"
1090    "to_nchar" "to_nclob" "to_number" "to_single_byte" "to_timestamp"
1091    "to_timestamp_tz" "to_yminterval" "translate" "treat" "trim" "trunc"
1092    "tz_offset" "uid" "unistr" "updatexml" "upper" "user" "userenv"
1093    "value" "var_pop" "var_samp" "variance" "vsize" "width_bucket"
1094    "xmlagg" "xmlcolattval" "xmlconcat" "xmlelement" "xmlforest"
1095    "xmlsequence" "xmltransform"
1096    
1097    ) t) "\\b"))))
1098        (list (cons oracle-sqlplus-commands 'font-lock-doc-face)
1099              (cons oracle-keywords 'font-lock-keyword-face)
1100                          (cons oracle-warning-words 'font-lock-warning-face)                          (cons oracle-warning-words 'font-lock-warning-face)
                         (cons oracle-reserved-words 'font-lock-keyword-face)  
1101                          ;; XEmacs doesn't have font-lock-builtin-face                          ;; XEmacs doesn't have font-lock-builtin-face
1102                          (if (string-match "XEmacs\\|Lucid" emacs-version)                          (if (string-match "XEmacs\\|Lucid" emacs-version)
1103                              (cons oracle-builtin-functions 'font-lock-preprocessor-face)                              (cons oracle-builtin-functions 'font-lock-preprocessor-face)
1104                            ;; GNU Emacs 19 doesn't have it either                            ;; GNU Emacs 19 doesn't have it either
1105                            (if (string-match "GNU Emacs 19" emacs-version)                            (if (string-match "GNU Emacs 19" emacs-version)
1106                                (cons oracle-builtin-functions 'font-lock-function-name-face)                  (cons oracle-builtin-functions 'font-lock-keyword-face)
1107                              ;; Emacs                              ;; Emacs
1108                              (cons oracle-builtin-functions 'font-lock-builtin-face)))                              (cons oracle-builtin-functions 'font-lock-builtin-face)))
1109                          (cons oracle-types 'font-lock-type-face))))))            (cons oracle-types 'font-lock-type-face)))
1110    
1111  (defvar sql-mode-postgres-font-lock-keywords nil    "Oracle SQL keywords used by font-lock.
   "Postgres SQL keywords used by font-lock.  
1112    
1113  This variable is used by `sql-mode' and `sql-interactive-mode'.  The  This variable is used by `sql-mode' and `sql-interactive-mode'.  The
1114  regular expressions are created during compilation by calling the  regular expressions are created during compilation by calling the
1115  function `regexp-opt'.  Therefore, take a look at the source before  function `regexp-opt'.  Therefore, take a look at the source before
1116  you define your own sql-mode-postgres-font-lock-keywords.")  you define your own sql-mode-oracle-font-lock-keywords.  You may want
1117    to add functions and PL/SQL keywords.")
1118    
1119  (if sql-mode-postgres-font-lock-keywords  (defvar sql-mode-postgres-font-lock-keywords
     ()  
1120    (let ((postgres-reserved-words (eval-when-compile    (let ((postgres-reserved-words (eval-when-compile
1121                                   (concat "\\b"                                   (concat "\\b"
1122                                           (regexp-opt '(                                           (regexp-opt '(
# Line 710  you define your own sql-mode-postgres-fo Line 1125  you define your own sql-mode-postgres-fo
1125          (postgres-types (eval-when-compile          (postgres-types (eval-when-compile
1126                            (concat "\\b"                            (concat "\\b"
1127                                    (regexp-opt '(                                    (regexp-opt '(
1128    
1129  "bool" "box" "circle" "char" "char2" "char4" "char8" "char16" "date"  "bool" "box" "circle" "char" "char2" "char4" "char8" "char16" "date"
1130  "float4" "float8" "int2" "int4" "int8" "line" "lseg" "money" "path"  "float4" "float8" "int2" "int4" "int8" "line" "lseg" "money" "path"
1131  "point" "polygon" "serial" "text" "time" "timespan" "timestamp" "varchar"  "point" "polygon" "serial" "text" "time" "timespan" "timestamp" "varchar"
1132    
1133  ) t)"\\b")))  ) t)"\\b")))
1134          (postgres-builtin-functions (eval-when-compile          (postgres-builtin-functions (eval-when-compile
1135                          (concat "\\b"                          (concat "\\b"
1136                                  (regexp-opt '(                                  (regexp-opt '(
1137  ;; Misc Postgres builtin functions  ;; Misc Postgres builtin functions
1138    
1139  "abstime" "age" "area" "box" "center" "date_part" "date_trunc"  "abstime" "age" "area" "box" "center" "date_part" "date_trunc"
1140  "datetime" "dexp" "diameter" "dpow" "float" "float4" "height"  "datetime" "dexp" "diameter" "dpow" "float" "float4" "height"
1141  "initcap" "integer" "isclosed" "isfinite" "isoldpath" "isopen"  "initcap" "integer" "isclosed" "isfinite" "isoldpath" "isopen"
# Line 725  you define your own sql-mode-postgres-fo Line 1143  you define your own sql-mode-postgres-fo
1143  "position" "radius" "reltime" "revertpoly" "rpad" "rtrim" "substr"  "position" "radius" "reltime" "revertpoly" "rpad" "rtrim" "substr"
1144  "substring" "text" "timespan" "translate" "trim" "upgradepath"  "substring" "text" "timespan" "translate" "trim" "upgradepath"
1145  "upgradepoly" "upper" "varchar" "width"  "upgradepoly" "upper" "varchar" "width"
1146    
1147  ) t) "\\b"))))  ) t) "\\b"))))
     (setq sql-mode-postgres-font-lock-keywords  
1148            (append sql-mode-ansi-font-lock-keywords            (append sql-mode-ansi-font-lock-keywords
1149                    (list (cons postgres-reserved-words 'font-lock-keyword-face)                    (list (cons postgres-reserved-words 'font-lock-keyword-face)
1150                          ;; XEmacs doesn't have 'font-lock-builtin-face                          ;; XEmacs doesn't have 'font-lock-builtin-face
# Line 734  you define your own sql-mode-postgres-fo Line 1152  you define your own sql-mode-postgres-fo
1152                              (cons postgres-builtin-functions 'font-lock-preprocessor-face)                              (cons postgres-builtin-functions 'font-lock-preprocessor-face)
1153                            ;; Emacs                            ;; Emacs
1154                            (cons postgres-builtin-functions 'font-lock-builtin-face))                            (cons postgres-builtin-functions 'font-lock-builtin-face))
1155                          (cons postgres-types 'font-lock-type-face))))))                    (cons postgres-types 'font-lock-type-face))))
   
1156    
1157  (defvar sql-mode-linter-font-lock-keywords nil    "Postgres SQL keywords used by font-lock.
   "Linter SQL keywords used by font-lock.  
1158    
1159  This variable is used by `sql-mode' and `sql-interactive-mode'.  The  This variable is used by `sql-mode' and `sql-interactive-mode'.  The
1160  regular expressions are created during compilation by calling the  regular expressions are created during compilation by calling the
1161  function `regexp-opt'.")  function `regexp-opt'.  Therefore, take a look at the source before
1162    you define your own sql-mode-postgres-font-lock-keywords.")
1163    
1164  (if sql-mode-linter-font-lock-keywords  (defvar sql-mode-linter-font-lock-keywords
     ()  
1165    (let ((linter-keywords (eval-when-compile    (let ((linter-keywords (eval-when-compile
1166                             (concat "\\b"                             (concat "\\b"
1167                                     (regexp-opt '(                                     (regexp-opt '(
1168    
1169  "autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel"  "autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel"
1170  "committed" "count" "countblob" "cross" "current" "data" "database"  "committed" "count" "countblob" "cross" "current" "data" "database"
1171  "datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred"  "datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred"
# Line 773  function `regexp-opt'.") Line 1190  function `regexp-opt'.")
1190  "trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown"  "trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown"
1191  "unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes"  "unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes"
1192  "wait" "windows_code" "workspace" "write" "xml"  "wait" "windows_code" "workspace" "write" "xml"
1193    
1194  ) t) "\\b")))  ) t) "\\b")))
1195          (linter-reserved-words (eval-when-compile          (linter-reserved-words (eval-when-compile
1196                                   (concat "\\b"                                   (concat "\\b"
1197                                           (regexp-opt '(                                           (regexp-opt '(
1198    
1199  "access" "action" "add" "address" "after" "all" "alter" "always" "and"  "access" "action" "add" "address" "after" "all" "alter" "always" "and"
1200  "any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit"  "any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit"
1201  "aud_obj_name_len" "backup" "base" "before" "between" "blobfile"  "aud_obj_name_len" "backup" "base" "before" "between" "blobfile"
# Line 794  function `regexp-opt'.") Line 1213  function `regexp-opt'.")
1213  "start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then"  "start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then"
1214  "to" "union" "unique" "unlock" "until" "update" "using" "values"  "to" "union" "unique" "unlock" "until" "update" "using" "values"
1215  "view" "when" "where" "with" "without"  "view" "when" "where" "with" "without"
1216    
1217  ) t) "\\b")))  ) t) "\\b")))
1218          (linter-types (eval-when-compile          (linter-types (eval-when-compile
1219                          (concat "\\b"                          (concat "\\b"
1220                                  (regexp-opt '(                                  (regexp-opt '(
1221    
1222  "bigint" "bitmap" "blob" "boolean" "char" "character" "date"  "bigint" "bitmap" "blob" "boolean" "char" "character" "date"
1223  "datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar"  "datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar"
1224  "number" "numeric" "real" "smallint" "varbyte" "varchar" "byte"  "number" "numeric" "real" "smallint" "varbyte" "varchar" "byte"
1225  "cursor" "long"  "cursor" "long"
1226    
1227  ) t) "\\b")))  ) t) "\\b")))
1228          (linter-builtin-functions (eval-when-compile          (linter-builtin-functions (eval-when-compile
1229                          (concat "\\b"                          (concat "\\b"
1230                                  (regexp-opt '(                                  (regexp-opt '(
1231    
1232  "abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime"  "abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime"
1233  "exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw"  "exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw"
1234  "getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log"  "getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log"
# Line 816  function `regexp-opt'.") Line 1239  function `regexp-opt'.")
1239  "to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode"  "to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode"
1240  "substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap"  "substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap"
1241  "instr" "least" "multime" "replace" "width"  "instr" "least" "multime" "replace" "width"
1242    
1243  ) t) "\\b"))))  ) t) "\\b"))))
     (setq sql-mode-linter-font-lock-keywords  
1244            (append sql-mode-ansi-font-lock-keywords            (append sql-mode-ansi-font-lock-keywords
1245                    (list (cons linter-keywords 'font-lock-function-name-face)              (list (cons linter-keywords 'font-lock-keywords-face)
1246                          (cons linter-reserved-words 'font-lock-keyword-face)                          (cons linter-reserved-words 'font-lock-keyword-face)
1247                          ;; XEmacs doesn't have font-lock-builtin-face                          ;; XEmacs doesn't have font-lock-builtin-face
1248                          (if (string-match "XEmacs\\|Lucid" emacs-version)                          (if (string-match "XEmacs\\|Lucid" emacs-version)
1249                              (cons linter-builtin-functions 'font-lock-preprocessor-face)                              (cons linter-builtin-functions 'font-lock-preprocessor-face)
1250                            ;; GNU Emacs 19 doesn't have it either                            ;; GNU Emacs 19 doesn't have it either
1251                            (if (string-match "GNU Emacs 19" emacs-version)                            (if (string-match "GNU Emacs 19" emacs-version)
1252                                (cons linter-builtin-functions 'font-lock-function-name-face)                          (cons linter-builtin-functions 'font-lock-keywords-face)
1253                              ;; Emacs                              ;; Emacs
1254                              (cons linter-builtin-functions 'font-lock-builtin-face)))                              (cons linter-builtin-functions 'font-lock-builtin-face)))
1255                          (cons linter-types 'font-lock-type-face))))))                    (cons linter-types 'font-lock-type-face))))
1256    
1257      "Linter SQL keywords used by font-lock.
1258    
1259    This variable is used by `sql-mode' and `sql-interactive-mode'.  The
1260    regular expressions are created during compilation by calling the
1261    function `regexp-opt'.")
1262    
1263    (defvar sql-mode-ms-font-lock-keywords
1264      (let ((ms-reserved-words (eval-when-compile
1265                                 (concat "\\b"
1266                                         (regexp-opt '(
1267    
1268    "absolute" "add" "all" "alter" "and" "any" "as" "asc" "authorization"
1269    "avg" "backup" "begin" "between" "break" "browse" "bulk" "by"
1270    "cascade" "case" "check" "checkpoint" "close" "clustered" "coalesce"
1271    "column" "commit" "committed" "compute" "confirm" "constraint"
1272    "contains" "containstable" "continue" "controlrow" "convert" "count"
1273    "create" "cross" "current" "current_date" "current_time"
1274    "current_timestamp" "current_user" "database" "deallocate"
1275    "declare" "default" "delete" "deny" "desc" "disk" "distinct"
1276    "distributed" "double" "drop" "dummy" "dump" "else" "end" "errlvl"
1277    "errorexit" "escape" "except" "exec" "execute" "exists" "exit" "fetch"
1278    "file" "fillfactor" "first" "floppy" "for" "foreign" "freetext"
1279    "freetexttable" "from" "full" "goto" "grant" "group" "having"
1280    "holdlock" "identity" "identity_insert" "identitycol" "if" "in"
1281    "index" "inner" "insert" "intersect" "into" "is" "isolation" "join"
1282    "key" "kill" "last" "left" "level" "like" "lineno" "load" "max" "min"
1283    "mirrorexit" "national" "next" "nocheck" "nolock" "nonclustered" "not"
1284    "null" "nullif" "of" "off" "offsets" "on" "once" "only" "open"
1285    "opendatasource" "openquery" "openrowset" "option" "or" "order"
1286    "outer" "output" "over" "paglock" "percent" "perm" "permanent" "pipe"
1287    "plan" "precision" "prepare" "primary" "print" "prior" "privileges"
1288    "proc" "procedure" "processexit" "public" "raiserror" "read"
1289    "readcommitted" "readpast" "readtext" "readuncommitted" "reconfigure"
1290    "references" "relative" "repeatable" "repeatableread" "replication"
1291    "restore" "restrict" "return" "revoke" "right" "rollback" "rowcount"
1292    "rowguidcol" "rowlock" "rule" "save" "schema" "select" "serializable"
1293    "session_user" "set" "shutdown" "some" "statistics" "sum"
1294    "system_user" "table" "tablock" "tablockx" "tape" "temp" "temporary"
1295    "textsize" "then" "to" "top" "tran" "transaction" "trigger" "truncate"
1296    "tsequal" "uncommitted" "union" "unique" "update" "updatetext"
1297    "updlock" "use" "user" "values" "view" "waitfor" "when" "where"
1298    "while" "with" "work" "writetext"
1299    "collate" "function" "openxml" "returns"
1300    
1301    ) t) "\\b")))
1302            (ms-types (eval-when-compile
1303                        (concat "\\b"
1304                                (regexp-opt '(
1305    
1306    "binary" "bit" "char" "character" "cursor" "datetime" "dec" "decimal"
1307    "double" "float" "image" "int" "integer" "money" "national" "nchar"
1308    "ntext" "numeric" "numeric" "nvarchar" "precision" "real"
1309    "smalldatetime" "smallint" "smallmoney" "text" "timestamp" "tinyint"
1310    "uniqueidentifier" "varbinary" "varchar" "varying"
1311    
1312    ) t) "\\b")))
1313    
1314            (ms-vars "\\b@[a-zA-Z0-9_]*\\b")
1315    
1316            (ms-builtin-functions (eval-when-compile
1317                                    (concat "\\b"
1318                                            (regexp-opt '(
1319    ;; Misc MS builtin functions
1320    
1321    "@@connections" "@@cpu_busy" "@@cursor_rows" "@@datefirst" "@@dbts"
1322    "@@error" "@@fetch_status" "@@identity" "@@idle" "@@io_busy"
1323    "@@langid" "@@language" "@@lock_timeout" "@@max_connections"
1324    "@@max_precision" "@@nestlevel" "@@options" "@@pack_received"
1325    "@@pack_sent" "@@packet_errors" "@@procid" "@@remserver" "@@rowcount"
1326    "@@servername" "@@servicename" "@@spid" "@@textsize" "@@timeticks"
1327    "@@total_errors" "@@total_read" "@@total_write" "@@trancount"
1328    "@@version" "abs" "acos" "and" "app_name" "ascii" "asin" "atan" "atn2"
1329    "avg" "case" "cast" "ceiling" "char" "charindex" "coalesce"
1330    "col_length" "col_name" "columnproperty" "containstable" "convert"
1331    "cos" "cot" "count" "current_timestamp" "current_user" "cursor_status"
1332    "databaseproperty" "datalength" "dateadd" "datediff" "datename"
1333    "datepart" "day" "db_id" "db_name" "degrees" "difference" "exp"
1334    "file_id" "file_name" "filegroup_id" "filegroup_name"
1335    "filegroupproperty" "fileproperty" "floor" "formatmessage"
1336    "freetexttable" "fulltextcatalogproperty" "fulltextserviceproperty"
1337    "getansinull" "getdate" "grouping" "host_id" "host_name" "ident_incr"
1338    "ident_seed" "identity" "index_col" "indexproperty" "is_member"
1339    "is_srvrolemember" "isdate" "isnull" "isnumeric" "left" "len" "log"
1340    "log10" "lower" "ltrim" "max" "min" "month" "nchar" "newid" "nullif"
1341    "object_id" "object_name" "objectproperty" "openquery" "openrowset"
1342    "parsename" "patindex" "patindex" "permissions" "pi" "power"
1343    "quotename" "radians" "rand" "replace" "replicate" "reverse" "right"
1344    "round" "rtrim" "session_user" "sign" "sin" "soundex" "space" "sqrt"
1345    "square" "stats_date" "stdev" "stdevp" "str" "stuff" "substring" "sum"
1346    "suser_id" "suser_name" "suser_sid" "suser_sname" "system_user" "tan"
1347    "textptr" "textvalid" "typeproperty" "unicode" "upper" "user"
1348    "user_id" "user_name" "var" "varp" "year"
1349    
1350    ) t) "\\b")))
1351    
1352            (ms-config-commands
1353             (eval-when-compile
1354               (concat "^\\(\\(set\\s-+\\("
1355                       (regexp-opt '(
1356    
1357    "datefirst" "dateformat" "deadlock_priority" "lock_timeout"
1358    "concat_null_yields_null" "cursor_close_on_commit"
1359    "disable_def_cnst_chk" "fips_flagger" "identity_insert" "language"
1360    "offsets" "quoted_identifier" "arithabort" "arithignore" "fmtonly"
1361    "nocount" "noexec" "numeric_roundabort" "parseonly"
1362    "query_governor_cost_limit" "rowcount" "textsize" "ansi_defaults"
1363    "ansi_null_dflt_off" "ansi_null_dflt_on" "ansi_nulls" "ansi_padding"
1364    "ansi_warnings" "forceplan" "showplan_all" "showplan_text"
1365    "statistics" "implicit_transactions" "remote_proc_transactions"
1366    "transaction" "xact_abort"
1367    
1368    ) t)
1369                       "\\)\\)\\|go\\s-*\\|use\\s-+\\|setuser\\s-+\\|dbcc\\s-+\\).*$"))))
1370    
1371        (list (cons ms-config-commands 'font-lock-doc-face)
1372              (cons ms-reserved-words 'font-lock-keyword-face)
1373              ;; XEmacs doesn't have 'font-lock-builtin-face
1374              (if (string-match "XEmacs\\|Lucid" emacs-version)
1375                  (cons ms-builtin-functions 'font-lock-preprocessor-face)
1376                ;; Emacs
1377                (cons ms-builtin-functions 'font-lock-builtin-face))
1378              (cons ms-vars  'font-lock-variable-name-face)
1379              (cons ms-types 'font-lock-type-face)))
1380    
1381      "Microsoft SQLServer SQL keywords used by font-lock.
1382    
1383    This variable is used by `sql-mode' and `sql-interactive-mode'.  The
1384    regular expressions are created during compilation by calling the
1385    function `regexp-opt'.  Therefore, take a look at the source before
1386    you define your own sql-mode-ms-font-lock-keywords.")
1387    
1388    (defvar sql-mode-sybase-font-lock-keywords sql-mode-ansi-font-lock-keywords
1389      "Sybase SQL keywords used by font-lock.
1390    
1391    This variable is used by `sql-mode' and `sql-interactive-mode'.  The
1392    regular expressions are created during compilation by calling the
1393    function `regexp-opt'.  Therefore, take a look at the source before
1394    you define your own sql-mode-sybase-font-lock-keywords.")
1395    
1396    (defvar sql-mode-informix-font-lock-keywords sql-mode-ansi-font-lock-keywords
1397      "Informix SQL keywords used by font-lock.
1398    
1399    This variable is used by `sql-mode' and `sql-interactive-mode'.  The
1400    regular expressions are created during compilation by calling the
1401    function `regexp-opt'.  Therefore, take a look at the source before
1402    you define your own sql-mode-informix-font-lock-keywords.")
1403    
1404    (defvar sql-mode-interbase-font-lock-keywords sql-mode-ansi-font-lock-keywords
1405      "Interbase SQL keywords used by font-lock.
1406    
1407    This variable is used by `sql-mode' and `sql-interactive-mode'.  The
1408    regular expressions are created during compilation by calling the
1409    function `regexp-opt'.  Therefore, take a look at the source before
1410    you define your own sql-mode-interbase-font-lock-keywords.")
1411    
1412    (defvar sql-mode-ingres-font-lock-keywords sql-mode-ansi-font-lock-keywords
1413      "Ingres SQL keywords used by font-lock.
1414    
1415    This variable is used by `sql-mode' and `sql-interactive-mode'.  The
1416    regular expressions are created during compilation by calling the
1417    function `regexp-opt'.  Therefore, take a look at the source before
1418    you define your own sql-mode-interbase-font-lock-keywords.")
1419    
1420    (defvar sql-mode-solid-font-lock-keywords sql-mode-ansi-font-lock-keywords
1421      "Solid SQL keywords used by font-lock.
1422    
1423    This variable is used by `sql-mode' and `sql-interactive-mode'.  The
1424    regular expressions are created during compilation by calling the
1425    function `regexp-opt'.  Therefore, take a look at the source before
1426    you define your own sql-mode-solid-font-lock-keywords.")
1427    
1428    (defvar sql-mode-mysql-font-lock-keywords sql-mode-ansi-font-lock-keywords
1429      "MySQL SQL keywords used by font-lock.
1430    
1431    This variable is used by `sql-mode' and `sql-interactive-mode'.  The
1432    regular expressions are created during compilation by calling the
1433    function `regexp-opt'.  Therefore, take a look at the source before
1434    you define your own sql-mode-mysql-font-lock-keywords.")
1435    
1436    (defvar sql-mode-sqlite-font-lock-keywords sql-mode-ansi-font-lock-keywords
1437      "SQLite SQL keywords used by font-lock.
1438    
1439    This variable is used by `sql-mode' and `sql-interactive-mode'.  The
1440    regular expressions are created during compilation by calling the
1441    function `regexp-opt'.  Therefore, take a look at the source before
1442    you define your own sql-mode-sqlite-font-lock-keywords.")
1443    
1444    (defvar sql-mode-db2-font-lock-keywords sql-mode-ansi-font-lock-keywords
1445      "DB2 SQL keywords used by font-lock.
1446    
1447  (defvar sql-mode-font-lock-keywords sql-mode-ansi-font-lock-keywords  This variable is used by `sql-mode' and `sql-interactive-mode'.  The
1448    regular expressions are created during compilation by calling the
1449    function `regexp-opt'.  Therefore, take a look at the source before
1450    you define your own sql-mode-db2-font-lock-keywords.")
1451    
1452    (defvar sql-mode-font-lock-keywords nil
1453    "SQL keywords used by font-lock.    "SQL keywords used by font-lock.
1454    
1455  This variable defaults to `sql-mode-ansi-font-lock-keywords'.  This is  Setting this variable directly no longer has any affect.  Use
1456  used for the default `font-lock-defaults' value in `sql-mode'.  This  `sql-product' and `sql-add-product-keywords' to control the
1457  can be changed by some entry functions to provide more hilighting.")  highlighting rules in sql-mode.")
1458    
1459    
1460    
1461    ;;; SQL Product support functions
1462    
1463    (defun sql-product-feature (feature &optional product)
1464      "Lookup `feature' needed to support the current SQL product.
1465    
1466    See \[sql-product-support] for a list of products and supported features."
1467      (cadr
1468       (memq feature
1469             (assoc (or product sql-product)
1470                    sql-product-support))))
1471    
1472    (defun sql-product-font-lock (keywords-only imenu)
1473      "Sets `font-lock-defaults' and `font-lock-keywords' based on
1474    the product-specific keywords and syntax-alists defined in
1475    `sql-product-support'."
1476      (let
1477          ;; Get the product-specific syntax-alist.
1478          ((syntax-alist
1479            (append
1480             (sql-product-feature :syntax-alist)
1481             '((?_ . "w") (?. . "w")))))
1482    
1483        ;; Get the product-specific keywords.
1484        (setq sql-mode-font-lock-keywords
1485              (append
1486               (eval (sql-product-feature :font-lock))
1487               (list sql-mode-font-lock-object-name)))
1488    
1489        ;; Setup font-lock.  (What is the minimum we should have to do
1490        ;; here?)
1491        (setq font-lock-set-defaults nil
1492              font-lock-keywords sql-mode-font-lock-keywords
1493              font-lock-defaults (list 'sql-mode-font-lock-keywords
1494                                       keywords-only t syntax-alist))
1495    
1496        ;; Setup imenu; it needs the same syntax-alist.
1497        (when imenu
1498            (setq imenu-syntax-alist syntax-alist))))
1499    
1500    ;;;###autoload
1501    (defun sql-add-product-keywords (product keywords)
1502      "Append a `font-lock-keywords' entry to the existing entries defined
1503      for the specified `product'."
1504    
1505      (let ((font-lock (sql-product-feature :font-lock product)))
1506           (set font-lock (append (eval font-lock) (list keywords)))))
1507    
1508    
1509    
1510  ;;; Functions to switch highlighting  ;;; Functions to switch highlighting
1511    
1512    (defun sql-highlight-product ()
1513      "Turns on the appropriate font highlighting for the SQL product
1514    selected."
1515    
1516      (when (eq major-mode 'sql-mode)
1517        ;; Setup font-lock
1518        (sql-product-font-lock nil t)
1519    
1520        ;; Force fontification, if its enabled.
1521        (if font-lock-mode
1522            (font-lock-fontify-buffer))
1523    
1524        ;; Set the mode name to include the product.
1525        (setq mode-name (concat "SQL[" (prin1-to-string sql-product) "]"))))
1526    
1527    (defun sql-set-product (product)
1528      "Set `sql-product' to product and enable appropriate
1529    highlighting."
1530      (interactive "SEnter SQL product: ")
1531      (when (not (assoc product sql-product-support))
1532        (error "SQL product %s is not supported; treated as ANSI" product)
1533        (setq product 'ansi))
1534    
1535      ;; Save product setting and fontify.
1536      (setq sql-product product)
1537      (sql-highlight-product))
1538    
1539  (defun sql-highlight-oracle-keywords ()  (defun sql-highlight-oracle-keywords ()
1540    "Highlight Oracle keywords.    "Highlight Oracle keywords."
 Basically, this just sets `font-lock-keywords' appropriately."  
1541    (interactive)    (interactive)
1542    (setq font-lock-keywords sql-mode-oracle-font-lock-keywords)    (sql-set-product 'oracle))
   (font-lock-fontify-buffer))  
1543    
1544  (defun sql-highlight-postgres-keywords ()  (defun sql-highlight-postgres-keywords ()
1545    "Highlight Postgres keywords.    "Highlight Postgres keywords."
 Basically, this just sets `font-lock-keywords' appropriately."  
1546    (interactive)    (interactive)
1547    (setq font-lock-keywords sql-mode-postgres-font-lock-keywords)    (sql-set-product 'postgres))
   (font-lock-fontify-buffer))  
1548    
1549  (defun sql-highlight-linter-keywords ()  (defun sql-highlight-linter-keywords ()
1550    "Highlight LINTER keywords.    "Highlight LINTER keywords."
1551  Basically, this just sets `font-lock-keywords' appropriately."    (interactive)
1552      (sql-set-product 'linter))
1553    
1554    (defun sql-highlight-ms-keywords ()
1555      "Highlight Microsoft SQLServer keywords."
1556    (interactive)    (interactive)
1557    (setq font-lock-keywords sql-mode-linter-font-lock-keywords)    (sql-set-product 'ms))
   (font-lock-fontify-buffer))  
1558    
1559  (defun sql-highlight-ansi-keywords ()  (defun sql-highlight-ansi-keywords ()
1560    "Highlight ANSI SQL keywords.    "Highlight ANSI SQL keywords."
1561  Basically, this just sets `font-lock-keywords' appropriately."    (interactive)
1562      (sql-set-product 'ansi))
1563    
1564    (defun sql-highlight-sybase-keywords ()
1565      "Highlight Sybase SQL keywords."
1566      (interactive)
1567      (sql-set-product 'sybase))
1568    
1569    (defun sql-highlight-informix-keywords ()
1570      "Highlight Informix SQL keywords."
1571      (interactive)
1572      (sql-set-product 'informix))
1573    
1574    (defun sql-highlight-interbase-keywords ()
1575      "Highlight Interbase SQL keywords."
1576      (interactive)
1577      (sql-set-product 'interbase))
1578    
1579    (defun sql-highlight-ingres-keywords ()
1580      "Highlight Ingres SQL keywords."
1581      (interactive)
1582      (sql-set-product 'ingres))
1583    
1584    (defun sql-highlight-solid-keywords ()
1585      "Highlight Solid SQL keywords."
1586      (interactive)
1587      (sql-set-product 'solid))
1588    
1589    (defun sql-highlight-mysql-keywords ()
1590      "Highlight MySQL SQL keywords."
1591      (interactive)
1592      (sql-set-product 'mysql))
1593    
1594    (defun sql-highlight-sqlite-keywords ()
1595      "Highlight SQLite SQL keywords."
1596      (interactive)
1597      (sql-set-product 'sqlite))
1598    
1599    (defun sql-highlight-db2-keywords ()
1600      "Highlight DB2 SQL keywords."
1601    (interactive)    (interactive)
1602    (setq font-lock-keywords sql-mode-ansi-font-lock-keywords)    (sql-set-product 'db2))
   (font-lock-fontify-buffer))  
1603    
1604    
1605    
# Line 924  Use the following commands to start a sp Line 1655  Use the following commands to start a sp
1655    
1656      PostGres: \\[sql-postgres]      PostGres: \\[sql-postgres]
1657      MySQL: \\[sql-mysql]      MySQL: \\[sql-mysql]
1658        SQLite: \\[sql-sqlite]
1659    
1660  Other non-free SQL implementations are also supported:  Other non-free SQL implementations are also supported:
1661    
# Line 933  Other non-free SQL implementations are a Line 1665  Other non-free SQL implementations are a
1665      Sybase: \\[sql-sybase]      Sybase: \\[sql-sybase]
1666      Ingres: \\[sql-ingres]      Ingres: \\[sql-ingres]
1667      Microsoft: \\[sql-ms]      Microsoft: \\[sql-ms]
1668        DB2: \\[sql-db2]
1669      Interbase: \\[sql-interbase]      Interbase: \\[sql-interbase]
1670      Linter: \\[sql-linter]      Linter: \\[sql-linter]
1671    
# Line 979  Parameter WHAT is a list of the argument Line 1712  Parameter WHAT is a list of the argument
1712  The function asks for the username if WHAT contains symbol `user', for  The function asks for the username if WHAT contains symbol `user', for
1713  the password if it contains symbol `password', for the server if it  the password if it contains symbol `password', for the server if it
1714  contains symbol `server', and for the database if it contains symbol  contains symbol `server', and for the database if it contains symbol
1715  `database'.  `database'.  The members of WHAT are processed in the order in which
1716    they are provided.
1717    
1718  In order to ask the user for username, password and database, call the  In order to ask the user for username, password and database, call the
1719  function like this: (sql-get-login 'user 'password 'database)."  function like this: (sql-get-login 'user 'password 'database)."
1720    (interactive)    (interactive)
1721    (if (memq 'user what)    (while what
1722        (cond
1723         ((eq (car what) 'user)             ; user
1724        (setq sql-user        (setq sql-user
1725              (read-from-minibuffer "User: " sql-user nil nil              (read-from-minibuffer "User: " sql-user nil nil
1726                                    sql-user-history)))                                    sql-user-history)))
1727    (if (memq 'password what)       ((eq (car what) 'password)         ; password
1728        (setq sql-password        (setq sql-password
1729              (sql-read-passwd "Password: " sql-password)))              (sql-read-passwd "Password: " sql-password)))
1730    (if (memq 'server what)       ((eq (car what) 'server)           ; server
1731        (setq sql-server        (setq sql-server
1732              (read-from-minibuffer "Server: " sql-server nil nil              (read-from-minibuffer "Server: " sql-server nil nil
1733                                    sql-server-history)))                                    sql-server-history)))
1734    (if (memq 'database what)       ((eq (car what) 'database)         ; database
1735        (setq sql-database        (setq sql-database
1736              (read-from-minibuffer "Database: " sql-database nil nil              (read-from-minibuffer "Database: " sql-database nil nil
1737                                    sql-database-history))))                                    sql-database-history))))
1738        (setq what (cdr what))))
1739    
1740  (defun sql-find-sqli-buffer ()  (defun sql-find-sqli-buffer ()
1741    "Return the current default SQLi buffer or nil.    "Return the current default SQLi buffer or nil.
# Line 1267  you must tell Emacs.  Here's how to do t Line 2004  you must tell Emacs.  Here's how to do t
2004        (easy-menu-add sql-mode-menu)); XEmacs        (easy-menu-add sql-mode-menu)); XEmacs
2005    (set-syntax-table sql-mode-syntax-table)    (set-syntax-table sql-mode-syntax-table)
2006    (make-local-variable 'font-lock-defaults)    (make-local-variable 'font-lock-defaults)
2007    ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try    (make-local-variable 'sql-mode-font-lock-keywords)
   ;; 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.  `_' and `.' are considered part  
   ;; of words.  
   (setq font-lock-defaults '(sql-mode-font-lock-keywords  
                              nil t ((?_ . "w") (?. . "w"))))  
2008    (make-local-variable 'comment-start)    (make-local-variable 'comment-start)
2009    (setq comment-start "--")    (setq comment-start "--")
2010    ;; Make each buffer in sql-mode remember the "current" SQLi buffer.    ;; Make each buffer in sql-mode remember the "current" SQLi buffer.
# Line 1281  you must tell Emacs.  Here's how to do t Line 2012  you must tell Emacs.  Here's how to do t
2012    ;; Add imenu support for sql-mode.  Note that imenu-generic-expression    ;; Add imenu support for sql-mode.  Note that imenu-generic-expression
2013    ;; is buffer-local, so we don't need a local-variable for it.  SQL is    ;; is buffer-local, so we don't need a local-variable for it.  SQL is
2014    ;; case-insensitive, that's why we have to set imenu-case-fold-search.    ;; case-insensitive, that's why we have to set imenu-case-fold-search.
   ;; imenu-syntax-alist makes sure that `_' is considered part of object  
   ;; names.  
2015    (setq imenu-generic-expression sql-imenu-generic-expression    (setq imenu-generic-expression sql-imenu-generic-expression
2016          imenu-case-fold-search t          imenu-case-fold-search t)
         imenu-syntax-alist '(("_" . "w")))  
2017    ;; Make `sql-send-paragraph' work on paragraphs that contain indented    ;; Make `sql-send-paragraph' work on paragraphs that contain indented
2018    ;; lines.    ;; lines.
2019    (make-local-variable 'paragraph-separate)    (make-local-variable 'paragraph-separate)
# Line 1296  you must tell Emacs.  Here's how to do t Line 2024  you must tell Emacs.  Here's how to do t
2024    (setq local-abbrev-table sql-mode-abbrev-table)    (setq local-abbrev-table sql-mode-abbrev-table)
2025    (setq abbrev-all-caps 1)    (setq abbrev-all-caps 1)
2026    ;; Run hook    ;; Run hook
2027    (run-hooks 'sql-mode-hook))    (run-hooks 'sql-mode-hook)
2028      ;; Catch changes to sql-product and highlight accordingly
2029      (sql-highlight-product)
2030      (add-hook 'hack-local-variables-hook 'sql-highlight-product t t))
2031    
2032    
2033    
# Line 1373  you entered, right above the output it c Line 2104  you entered, right above the output it c
2104  \(setq comint-output-filter-functions  \(setq comint-output-filter-functions
2105         \(function (lambda (STR) (comint-show-output))))"         \(function (lambda (STR) (comint-show-output))))"
2106    (comint-mode)    (comint-mode)
2107    (setq comint-prompt-regexp sql-prompt-regexp)    ;; Get the `sql-product' for this interactive session.
2108    (setq left-margin sql-prompt-length)    (set (make-local-variable 'sql-product)
2109           (or sql-interactive-product
2110               sql-product))
2111      ;; Setup the mode.
2112    (setq major-mode 'sql-interactive-mode)    (setq major-mode 'sql-interactive-mode)
2113    (setq mode-name "SQLi")    (setq mode-name (concat "SQLi[" (prin1-to-string sql-product) "]"))
2114    (use-local-map sql-interactive-mode-map)    (use-local-map sql-interactive-mode-map)
2115    (if sql-interactive-mode-menu    (if sql-interactive-mode-menu
2116        (easy-menu-add sql-interactive-mode-menu)); XEmacs        (easy-menu-add sql-interactive-mode-menu)) ; XEmacs
2117    (set-syntax-table sql-mode-syntax-table)    (set-syntax-table sql-mode-syntax-table)
2118      (make-local-variable 'sql-mode-font-lock-keywords)
2119    (make-local-variable 'font-lock-defaults)    (make-local-variable 'font-lock-defaults)
2120    ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try    ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try
2121    ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column    ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column
2122    ;; will have just one quote.  Therefore syntactic hilighting is    ;; will have just one quote.  Therefore syntactic hilighting is
2123    ;; disabled for interactive buffers.  `_' and `.' are considered part    ;; disabled for interactive buffers.  No imenu support.
2124    ;; of words.    (sql-product-font-lock t nil)
   (setq font-lock-defaults '(sql-mode-font-lock-keywords  
                              t t ((?_ . "w") (?. . "w"))))  
2125    ;; Enable commenting and uncommenting of the region.    ;; Enable commenting and uncommenting of the region.
2126    (make-local-variable 'comment-start)    (make-local-variable 'comment-start)
2127    (setq comment-start "--")    (setq comment-start "--")
2128    ;; Abbreviation table init and case-insensitive.  It is not activatet    ;; Abbreviation table init and case-insensitive.  It is not activated
2129    ;; by default.    ;; by default.
2130    (setq local-abbrev-table sql-mode-abbrev-table)    (setq local-abbrev-table sql-mode-abbrev-table)
2131    (setq abbrev-all-caps 1)    (setq abbrev-all-caps 1)
2132    ;; Exiting the process will call sql-stop.    ;; Exiting the process will call sql-stop.
2133    (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop)    (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop)
2134      ;; Create a usefull name for renaming this buffer later.
2135      (make-local-variable 'sql-alternate-buffer-name)
2136      (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name))
2137      ;; User stuff.  Initialize before the hook.
2138      (set (make-local-variable 'sql-prompt-regexp)
2139           (sql-product-feature :sqli-prompt-regexp))
2140      (set (make-local-variable 'sql-prompt-length)
2141           (sql-product-feature :sqli-prompt-length))
2142      (make-local-variable 'sql-input-ring-separator)
2143      (make-local-variable 'sql-input-ring-file-name)
2144      ;; Run hook.
2145      (run-hooks 'sql-interactive-mode-hook)
2146      ;; Set comint based on user overrides.
2147      (setq comint-prompt-regexp sql-prompt-regexp)
2148      (setq left-margin sql-prompt-length)
2149    ;; People wanting a different history file for each    ;; People wanting a different history file for each
2150    ;; buffer/process/client/whatever can change separator and file-name    ;; buffer/process/client/whatever can change separator and file-name
2151    ;; on the sql-interactive-mode-hook.    ;; on the sql-interactive-mode-hook.
2152    (setq comint-input-ring-separator sql-input-ring-separator    (setq comint-input-ring-separator sql-input-ring-separator
2153          comint-input-ring-file-name sql-input-ring-file-name)          comint-input-ring-file-name sql-input-ring-file-name)
   ;; Create a usefull name for renaming this buffer later.  
   (make-local-variable 'sql-alternate-buffer-name)  
   (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name))  
   ;; User stuff.  
   (run-hooks 'sql-interactive-mode-hook)  
2154    ;; Calling the hook before calling comint-read-input-ring allows users    ;; Calling the hook before calling comint-read-input-ring allows users
2155    ;; to set comint-input-ring-file-name in sql-interactive-mode-hook.    ;; to set comint-input-ring-file-name in sql-interactive-mode-hook.
2156    (comint-read-input-ring t))    (comint-read-input-ring t))
# Line 1431  Sentinels will always get the two parame Line 2174  Sentinels will always get the two parame
2174  ;;; Entry functions for different SQL interpreters.  ;;; Entry functions for different SQL interpreters.
2175    
2176  ;;;###autoload  ;;;###autoload
2177    (defun sql-product-interactive (&optional product)
2178      "Run product interpreter as an inferior process.
2179    
2180    If buffer `*SQL*' exists but no process is running, make a new process.
2181    If buffer exists and a process is running, just switch to buffer
2182    `*SQL*'.
2183    
2184    \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2185      (interactive)
2186      (setq product (or product sql-product))
2187      (when (sql-product-feature :sqli-connect product)
2188        (if (comint-check-proc "*SQL*")
2189            (pop-to-buffer "*SQL*")
2190          ;; Get credentials.
2191          (apply 'sql-get-login (sql-product-feature :sqli-login product))
2192          ;; Connect to database.
2193          (message "Login...")
2194          (funcall (sql-product-feature :sqli-connect product))
2195          ;; Set SQLi mode.
2196          (setq sql-interactive-product product)
2197          (setq sql-buffer (current-buffer))
2198          (sql-interactive-mode)
2199          ;; All done.
2200          (message "Login...done")
2201          (pop-to-buffer sql-buffer))))
2202    
2203    ;;;###autoload
2204  (defun sql-oracle ()  (defun sql-oracle ()
2205    "Run sqlplus by Oracle as an inferior process.    "Run sqlplus by Oracle as an inferior process.
2206    
# Line 1455  The default comes from `process-coding-s Line 2225  The default comes from `process-coding-s
2225    
2226  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2227    (interactive)    (interactive)
2228    (if (comint-check-proc "*SQL*")    (sql-product-interactive 'oracle))
2229        (pop-to-buffer "*SQL*")  
2230      (sql-get-login 'user 'password 'database)  (defun sql-connect-oracle ()
2231      (message "Login...")    "Create comint buffer and connect to Oracle using the login
2232      ;; Produce user/password@database construct.  Password without user  parameters and command options."
2233      ;; is meaningless; database without user/password is meaningless,    ;; Produce user/password@database construct.  Password without user
2234      ;; because "@param" will ask sqlplus to interpret the script    ;; is meaningless; database without user/password is meaningless,
2235      ;; "param".    ;; because "@param" will ask sqlplus to interpret the script
2236      (let ((parameter nil))    ;; "param".
2237        (if (not (string= "" sql-user))    (let ((parameter nil))
2238            (if (not (string= "" sql-password))      (if (not (string= "" sql-user))
2239                (setq parameter (concat sql-user "/" sql-password))          (if (not (string= "" sql-password))
2240              (setq parameter sql-user)))              (setq parameter (concat sql-user "/" sql-password))
2241        (if (and parameter (not (string= "" sql-database)))            (setq parameter sql-user)))
2242            (setq parameter (concat parameter "@" sql-database)))      (if (and parameter (not (string= "" sql-database)))
2243        (if parameter          (setq parameter (concat parameter "@" sql-database)))
2244            (setq parameter (nconc (list parameter) sql-oracle-options))      (if parameter
2245          (setq parameter sql-oracle-options))          (setq parameter (nconc (list parameter) sql-oracle-options))
2246        (if parameter        (setq parameter sql-oracle-options))
2247            (set-buffer (apply 'make-comint "SQL" sql-oracle-program nil      (if parameter
2248                               parameter))          (set-buffer (apply 'make-comint "SQL" sql-oracle-program nil
2249          (set-buffer (make-comint "SQL" sql-oracle-program nil))))                             parameter))
2250      (setq sql-prompt-regexp "^SQL> ")        (set-buffer (make-comint "SQL" sql-oracle-program nil)))
2251      (setq sql-prompt-length 5)      ;; SQL*Plus is buffered on WindowsNT; this handles &placeholders.
     (setq sql-buffer (current-buffer))  
     ;; set sql-mode-font-lock-keywords to something different before  
     ;; calling sql-interactive-mode.  
     (setq sql-mode-font-lock-keywords sql-mode-oracle-font-lock-keywords)  
     (sql-interactive-mode)  
     ;; If running on NT, make sure we do placeholder replacement  
     ;; ourselves.  This must come after sql-interactive-mode because all  
     ;; local variables will be killed, there.  
2252      (if (eq window-system 'w32)      (if (eq window-system 'w32)
2253          (setq comint-input-sender 'sql-query-placeholders-and-send))          (setq comint-input-sender 'sql-query-placeholders-and-send))))
     (message "Login...done")  
     (pop-to-buffer sql-buffer)))  
2254    
2255    
2256    
# Line 1519  The default comes from `process-coding-s Line 2279  The default comes from `process-coding-s
2279    
2280  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2281    (interactive)    (interactive)
2282    (if (comint-check-proc "*SQL*")    (sql-product-interactive 'sybase))
2283        (pop-to-buffer "*SQL*")  
2284      (sql-get-login 'server 'user 'password 'database)  (defun sql-connect-sybase ()
2285      (message "Login...")    "Create comint buffer and connect to Sybase using the login
2286      ;; Put all parameters to the program (if defined) in a list and call  parameters and command options."
2287      ;; make-comint.    ;; Put all parameters to the program (if defined) in a list and call
2288      (let ((params sql-sybase-options))    ;; make-comint.
2289        (if (not (string= "" sql-server))    (let ((params sql-sybase-options))
2290            (setq params (append (list "-S" sql-server) params)))      (if (not (string= "" sql-server))
2291        (if (not (string= "" sql-database))          (setq params (append (list "-S" sql-server) params)))
2292            (setq params (append (list "-D" sql-database) params)))      (if (not (string= "" sql-database))
2293        (if (not (string= "" sql-password))          (setq params (append (list "-D" sql-database) params)))
2294            (setq params (append (list "-P" sql-password) params)))      (if (not (string= "" sql-password))
2295        (if (not (string= "" sql-user))          (setq params (append (list "-P" sql-password) params)))
2296            (setq params (append (list "-U" sql-user) params)))      (if (not (string= "" sql-user))
2297        (set-buffer (apply 'make-comint "SQL" sql-sybase-program          (setq params (append (list "-U" sql-user) params)))
2298                           nil params)))      (set-buffer (apply 'make-comint "SQL" sql-sybase-program
2299      (setq sql-prompt-regexp "^SQL> ")                         nil params))))
     (setq sql-prompt-length 5)  
     (setq sql-buffer (current-buffer))  
     (sql-interactive-mode)  
     (message "Login...done")  
     (pop-to-buffer sql-buffer)))  
2300    
2301    
2302    
# Line 1568  The default comes from `process-coding-s Line 2323  The default comes from `process-coding-s
2323    
2324  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2325    (interactive)    (interactive)
2326    (if (comint-check-proc "*SQL*")    (sql-product-interactive 'informix))
2327        (pop-to-buffer "*SQL*")  
2328      (sql-get-login 'database)  (defun sql-connect-informix ()
2329      (message "Login...")    "Create comint buffer and connect to Informix using the login
2330      ;; username and password are ignored.  parameters and command options."
2331      (if (string= "" sql-database)    ;; username and password are ignored.
2332          (set-buffer (make-comint "SQL" sql-informix-program nil))    (if (string= "" sql-database)
2333        (set-buffer (make-comint "SQL" sql-informix-program nil sql-database "-")))        (set-buffer (make-comint "SQL" sql-informix-program nil))
2334      (setq sql-prompt-regexp "^SQL> ")      (set-buffer (make-comint "SQL" sql-informix-program nil sql-database "-"))))
2335      (setq sql-prompt-length 5)  
2336      (setq sql-buffer (current-buffer))  
2337      (sql-interactive-mode)  
2338      (message "Login...done")  ;;;###autoload
2339      (pop-to-buffer sql-buffer)))  (defun sql-sqlite ()
2340      "Run sqlite as an inferior process.
2341    
2342    SQLite is free software.
2343    
2344    If buffer `*SQL*' exists but no process is running, make a new process.
2345    If buffer exists and a process is running, just switch to buffer
2346    `*SQL*'.
2347    
2348    Interpreter used comes from variable `sql-sqlite-program'.  Login uses
2349    the variables `sql-user', `sql-password', `sql-database', and
2350    `sql-server' as defaults, if set.  Additional command line parameters
2351    can be stored in the list `sql-sqlite-options'.
2352    
2353    The buffer is put in sql-interactive-mode, giving commands for sending
2354    input.  See `sql-interactive-mode'.
2355    
2356    To specify a coding system for converting non-ASCII characters
2357    in the input and output to the process, use \\[universal-coding-system-argument]
2358    before \\[sql-sqlite].  You can also specify this with \\[set-buffer-process-coding-system]
2359    in the SQL buffer, after you start the process.
2360    The default comes from `process-coding-system-alist' and
2361    `default-process-coding-system'.
2362    
2363    \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2364      (interactive)
2365      (sql-product-interactive 'sqlite))
2366    
2367    (defun sql-connect-sqlite ()
2368      "Create comint buffer and connect to SQLite using the login
2369    parameters and command options."
2370      ;; Put all parameters to the program (if defined) in a list and call
2371      ;; make-comint.
2372      (let ((params))
2373        (if (not (string= "" sql-database))
2374            (setq params (append (list sql-database) params)))
2375        (if (not (string= "" sql-server))
2376            (setq params (append (list (concat "--host=" sql-server)) params)))
2377        (if (not (string= "" sql-password))
2378            (setq params (append (list (concat "--password=" sql-password)) params)))
2379        (if (not (string= "" sql-user))
2380            (setq params (append (list (concat "--user=" sql-user)) params)))
2381        (if (not (null sql-sqlite-options))
2382            (setq params (append sql-sqlite-options params)))
2383        (set-buffer (apply 'make-comint "SQL" sql-sqlite-program
2384                           nil params))))
2385    
2386    
2387    
# Line 1612  The default comes from `process-coding-s Line 2412  The default comes from `process-coding-s
2412    
2413  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2414    (interactive)    (interactive)
2415    (if (comint-check-proc "*SQL*")    (sql-product-interactive 'mysql))
2416        (pop-to-buffer "*SQL*")  
2417      (sql-get-login 'user 'password 'database 'server)  (defun sql-connect-mysql ()
2418      (message "Login...")    "Create comint buffer and connect to MySQL using the login
2419      ;; Put all parameters to the program (if defined) in a list and call  parameters and command options."
2420      ;; make-comint.    ;; Put all parameters to the program (if defined) in a list and call
2421      (let ((params))    ;; make-comint.
2422        (if (not (string= "" sql-database))    (let ((params))
2423            (setq params (append (list sql-database) params)))      (if (not (string= "" sql-database))
2424        (if (not (string= "" sql-server))          (setq params (append (list sql-database) params)))
2425            (setq params (append (list (concat "--host=" sql-server)) params)))      (if (not (string= "" sql-server))
2426        (if (not (string= "" sql-password))          (setq params (append (list (concat "--host=" sql-server)) params)))
2427            (setq params (append (list (concat "--password=" sql-password)) params)))      (if (not (string= "" sql-password))
2428        (if (not (string= "" sql-user))          (setq params (append (list (concat "--password=" sql-password)) params)))
2429            (setq params (append (list (concat "--user=" sql-user)) params)))      (if (not (string= "" sql-user))
2430        (if (not (null sql-mysql-options))          (setq params (append (list (concat "--user=" sql-user)) params)))
2431            (setq params (append sql-mysql-options params)))      (if (not (null sql-mysql-options))
2432        (set-buffer (apply 'make-comint "SQL" sql-mysql-program          (setq params (append sql-mysql-options params)))
2433                           nil params)))      (set-buffer (apply 'make-comint "SQL" sql-mysql-program
2434      (setq sql-prompt-regexp "^mysql>")                         nil params))))
     (setq sql-prompt-length 6)  
     (setq sql-buffer (current-buffer))  
     (sql-interactive-mode)  
     (message "Login...done")  
     (pop-to-buffer sql-buffer)))  
2435    
2436    
2437    
# Line 1664  The default comes from `process-coding-s Line 2459  The default comes from `process-coding-s
2459    
2460  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2461    (interactive)    (interactive)
2462    (if (comint-check-proc "*SQL*")    (sql-product-interactive 'solid))
2463        (pop-to-buffer "*SQL*")  
2464      (sql-get-login 'user 'password 'server)  (defun sql-connect-solid ()
2465      (message "Login...")    "Create comint buffer and connect to Solid using the login
2466      ;; Put all parameters to the program (if defined) in a list and call  parameters and command options."
2467      ;; make-comint.    ;; Put all parameters to the program (if defined) in a list and call
2468      (let ((params))    ;; make-comint.
2469        ;; It only makes sense if both username and password are there.    (let ((params))
2470        (if (not (or (string= "" sql-user)      ;; It only makes sense if both username and password are there.
2471                     (string= "" sql-password)))      (if (not (or (string= "" sql-user)
2472            (setq params (append (list sql-user sql-password) params)))                   (string= "" sql-password)))
2473        (if (not (string= "" sql-server))          (setq params (append (list sql-user sql-password) params)))
2474            (setq params (append (list sql-server) params)))      (if (not (string= "" sql-server))
2475        (set-buffer (apply 'make-comint "SQL" sql-solid-program          (setq params (append (list sql-server) params)))
2476                           nil params)))      (set-buffer (apply 'make-comint "SQL" sql-solid-program
2477      (setq sql-prompt-regexp "^")                         nil params))))
     (setq sql-prompt-length 0)  
     (setq sql-buffer (current-buffer))  
     (sql-interactive-mode)  
     (message "Login...done")  
     (pop-to-buffer sql-buffer)))  
2478    
2479    
2480    
# Line 1711  The default comes from `process-coding-s Line 2501  The default comes from `process-coding-s
2501    
2502  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2503    (interactive)    (interactive)
2504    (if (comint-check-proc "*SQL*")    (sql-product-interactive 'ingres))
2505        (pop-to-buffer "*SQL*")  
2506      (sql-get-login 'database)  (defun sql-connect-ingres ()
2507      (message "Login...")    "Create comint buffer and connect to Ingres using the login
2508      ;; username and password are ignored.  parameters and command options."
2509      (if (string= "" sql-database)    ;; username and password are ignored.
2510          (set-buffer (make-comint "SQL" sql-ingres-program nil))    (if (string= "" sql-database)
2511        (set-buffer (make-comint "SQL" sql-ingres-program nil sql-database)))        (set-buffer (make-comint "SQL" sql-ingres-program nil))
2512      (setq sql-prompt-regexp "^\* ")      (set-buffer (make-comint "SQL" sql-ingres-program nil sql-database))))
     (setq sql-prompt-length 2)  
     (setq sql-buffer (current-buffer))  
     (sql-interactive-mode)  
     (message "Login...done")  
     (pop-to-buffer sql-buffer)))  
2513    
2514    
2515    
2516  ;;;###autoload  ;;;###autoload
2517  (defun sql-ms ()  (defun sql-ms ()
2518    "Run isql by Microsoft as an inferior process.    "Run osql by Microsoft as an inferior process.
2519    
2520  If buffer `*SQL*' exists but no process is running, make a new process.  If buffer `*SQL*' exists but no process is running, make a new process.
2521  If buffer exists and a process is running, just switch to buffer  If buffer exists and a process is running, just switch to buffer
# Line 1753  The default comes from `process-coding-s Line 2538  The default comes from `process-coding-s
2538    
2539  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2540    (interactive)    (interactive)
2541    (if (comint-check-proc "*SQL*")    (sql-product-interactive 'ms))
2542        (pop-to-buffer "*SQL*")  
2543      (sql-get-login 'user 'password 'database 'server)  (defun sql-connect-ms ()
2544      (message "Login...")    "Create comint buffer and connect to Microsoft using the login
2545      ;; Put all parameters to the program (if defined) in a list and call  parameters and command options."
2546      ;; make-comint.    ;; Put all parameters to the program (if defined) in a list and call
2547      (let ((params sql-ms-options))    ;; make-comint.
2548        (if (not (string= "" sql-server))    (let ((params sql-ms-options))
2549        (if (not (string= "" sql-server))
2550          (setq params (append (list "-S" sql-server) params)))          (setq params (append (list "-S" sql-server) params)))
2551        (if (not (string= "" sql-database))      (if (not (string= "" sql-database))
2552          (setq params (append (list "-d" sql-database) params)))          (setq params (append (list "-d" sql-database) params)))
2553        (if (not (string= "" sql-user))      (if (not (string= "" sql-user))
2554            (setq params (append (list "-U" sql-user) params)))          (setq params (append (list "-U" sql-user) params)))
2555        (if (not (string= "" sql-password))      (if (not (string= "" sql-password))
2556            (setq params (append (list "-P" sql-password) params))          (setq params (append (list "-P" sql-password) params))
2557          ;; If -P is passed to ISQL as the last argument without a password,        (if (string= "" sql-user)
2558          ;; it's considered null.            ;; if neither user nor password is provided, use system
2559          (setq params (append params (list "-P"))))            ;; credentials.
2560        (set-buffer (apply 'make-comint "SQL" sql-ms-program            (setq params (append (list "-E") params))
2561                           nil params)))          ;; If -P is passed to ISQL as the last argument without a
2562      (setq sql-prompt-regexp "^[0-9]*>")          ;; password, it's considered null.
2563      (setq sql-prompt-length 5)          (setq params (append params (list "-P")))))
2564      (setq sql-buffer (current-buffer))      (set-buffer (apply 'make-comint "SQL" sql-ms-program
2565      (sql-interactive-mode)                         nil params))))
     (message "Login...done")  
     (pop-to-buffer sql-buffer)))  
2566    
2567    
2568    
# Line 1812  Try to set `comint-output-filter-functio Line 2596  Try to set `comint-output-filter-functio
2596    
2597  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2598    (interactive)    (interactive)
2599    (if (comint-check-proc "*SQL*")    (sql-product-interactive 'postgres))
2600        (pop-to-buffer "*SQL*")  
2601      (sql-get-login 'database 'server)  (defun sql-connect-postgres ()
2602      (message "Login...")    "Create comint buffer and connect to Postgres using the login
2603      ;; username and password are ignored.  Mark Stosberg suggest to add  parameters and command options."
2604      ;; the database at the end.  Jason Beegan suggest using --pset and    ;; username and password are ignored.  Mark Stosberg suggest to add
2605      ;; pager=off instead of \\o|cat.  The later was the solution by    ;; the database at the end.  Jason Beegan suggest using --pset and
2606      ;; Gregor Zych.  Jason's suggestion is the default value for    ;; pager=off instead of \\o|cat.  The later was the solution by
2607      ;; sql-postgres-options.    ;; Gregor Zych.  Jason's suggestion is the default value for
2608      (let ((params sql-postgres-options))    ;; sql-postgres-options.
2609        (if (not (string= "" sql-database))    (let ((params sql-postgres-options))
2610            (setq params (append params (list sql-database))))      (if (not (string= "" sql-database))
2611        (if (not (string= "" sql-server))          (setq params (append params (list sql-database))))
2612            (setq params (append (list "-h" sql-server) params)))      (if (not (string= "" sql-server))
2613        (set-buffer (apply 'make-comint "SQL" sql-postgres-program          (setq params (append (list "-h" sql-server) params)))
2614                           nil params)))      (set-buffer (apply 'make-comint "SQL" sql-postgres-program
2615      (setq sql-prompt-regexp "^.*> *")                         nil params))))
     (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  
     ;; incorporate this (Gregor Zych <zych@pool.informatik.rwth-aachen.de>)  
     ;; (comint-send-string "*SQL*" "\\o \| cat\n")  
     (setq sql-mode-font-lock-keywords sql-mode-postgres-font-lock-keywords)  
     (setq sql-buffer (current-buffer))  
     (sql-interactive-mode)  
     (message "Login...done")  
     (pop-to-buffer sql-buffer)))  
2616    
2617    
2618    
# Line 1867  The default comes from `process-coding-s Line 2640  The default comes from `process-coding-s
2640    
2641  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2642    (interactive)    (interactive)
2643    (if (comint-check-proc "*SQL*")    (sql-product-interactive 'interbase))
2644        (pop-to-buffer "*SQL*")  
2645      (sql-get-login 'user 'password 'database)  (defun sql-connect-interbase ()
2646      (message "Login...")    "Create comint buffer and connect to Interbase using the login
2647      ;; Put all parameters to the program (if defined) in a list and call  parameters and command options."
2648      ;; make-comint.    ;; Put all parameters to the program (if defined) in a list and call
2649      (let ((params sql-interbase-options))    ;; make-comint.
2650        (if (not (string= "" sql-user))    (let ((params sql-interbase-options))
2651            (setq params (append (list "-u" sql-user) params)))      (if (not (string= "" sql-user))
2652        (if (not (string= "" sql-password))          (setq params (append (list "-u" sql-user) params)))
2653            (setq params (append (list "-p" sql-password) params)))      (if (not (string= "" sql-password))
2654        (if (not (string= "" sql-database))          (setq params (append (list "-p" sql-password) params)))
2655          (setq params (cons sql-database params))); add to the front!      (if (not (string= "" sql-database))
2656        (set-buffer (apply 'make-comint "SQL" sql-interbase-program          (setq params (cons sql-database params))) ; add to the front!
2657                           nil params)))      (set-buffer (apply 'make-comint "SQL" sql-interbase-program
2658      (setq sql-prompt-regexp "^SQL> ")                         nil params))))
     (setq sql-prompt-length 5)  
     (setq sql-buffer (current-buffer))  
     (sql-interactive-mode)  
     (message "Login...done")  
     (pop-to-buffer sql-buffer)))  
2659    
2660    
2661    
# Line 1919  The default comes from `process-coding-s Line 2687  The default comes from `process-coding-s
2687    
2688  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2689    (interactive)    (interactive)
2690    (if (comint-check-proc "*SQL*")    (sql-product-interactive 'db2))
2691        (pop-to-buffer "*SQL*")  
2692      (message "Login...")  (defun sql-connect-db2 ()
2693      ;; Put all parameters to the program (if defined) in a list and call    "Create comint buffer and connect to DB2 using the login
2694      ;; make-comint.  parameters and command options."
2695      (set-buffer (apply 'make-comint "SQL" sql-db2-program    ;; Put all parameters to the program (if defined) in a list and call
2696                         nil sql-db2-options))    ;; make-comint.
2697      (setq sql-prompt-regexp "^db2 => ")    (set-buffer (apply 'make-comint "SQL" sql-db2-program
2698      (setq sql-prompt-length 7)                       nil sql-db2-options))
2699      (setq sql-buffer (current-buffer))    ;; Properly escape newlines when DB2 is interactive.
2700      (sql-interactive-mode)    (setq comint-input-sender 'sql-escape-newlines-and-send))
     ;; Escape newlines.  This must come after sql-interactive-mode  
     ;; because all local variables will be killed, there.  
     (setq comint-input-sender 'sql-escape-newlines-and-send)  
     (message "Login...done")  
     (pop-to-buffer sql-buffer)))  
2701    
2702  ;;;###autoload  ;;;###autoload
2703  (defun sql-linter ()  (defun sql-linter ()
# Line 1959  an empty password. Line 2722  an empty password.
2722  The buffer is put in sql-interactive-mode, giving commands for sending  The buffer is put in sql-interactive-mode, giving commands for sending
2723  input.  See `sql-interactive-mode'.  input.  See `sql-interactive-mode'.
2724    
 To use LINTER font locking by default, put this line into your .emacs :  
  (setq sql-mode-font-lock-keywords sql-mode-linter-font-lock-keywords)  
   
2725  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"  \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2726    (interactive)    (interactive)
2727    (if (comint-check-proc "*SQL*")    (sql-product-interactive 'linter))
2728        (pop-to-buffer "*SQL*")  
2729      (sql-get-login 'user 'password 'database 'server)  (defun sql-connect-linter ()
2730      (message "Login...")    "Create comint buffer and connect to Linter using the login
2731      ;; Put all parameters to the program (if defined) in a list and call  parameters and command options."
2732      ;; make-comint.    ;; Put all parameters to the program (if defined) in a list and call
2733      (let ((params sql-linter-options) (login nil) (old-mbx (getenv "LINTER_MBX")))    ;; make-comint.
2734        (if (not (string= "" sql-user))    (let ((params sql-linter-options) (login nil) (old-mbx (getenv "LINTER_MBX")))
2735            (setq login (concat sql-user "/" sql-password)))      (if (not (string= "" sql-user))
2736        (setq params (append (list "-u" login) params))          (setq login (concat sql-user "/" sql-password)))
2737        (if (not (string= "" sql-server))      (setq params (append (list "-u" login) params))
2738            (setq params (append (list "-n" sql-server) params)))      (if (not (string= "" sql-server))
2739        (if (string= "" sql-database)          (setq params (append (list "-n" sql-server) params)))
2740            (setenv "LINTER_MBX" nil)      (if (string= "" sql-database)
2741          (setenv "LINTER_MBX" sql-database))          (setenv "LINTER_MBX" nil)
2742        (set-buffer (apply 'make-comint "SQL" sql-linter-program nil        (setenv "LINTER_MBX" sql-database))
2743                           params))      (set-buffer (apply 'make-comint "SQL" sql-linter-program nil
2744        (setenv "LINTER_MBX" old-mbx)                         params))
2745        )      (setenv "LINTER_MBX" old-mbx)))
     (setq sql-prompt-regexp "^SQL>")  
     (setq sql-prompt-length 4)  
     (setq sql-buffer (current-buffer))  
     (sql-interactive-mode)  
     (message "Login...done")  
     (pop-to-buffer sql-buffer)))  
2746    
2747    
2748    
2749  (provide 'sql)  (provide 'sql)
2750    
2751    ;;; arch-tag: 7e1fa1c4-9ca2-402e-87d2-83a5eccb7ac3
2752  ;;; sql.el ends here  ;;; sql.el ends here

Legend:
Removed from v.1.32.4.1  
changed lines
  Added in v.1.32.4.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26