-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql.el
3422 lines (2874 loc) · 130 KB
/
sql.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; sql.el --- specialized comint.el for SQL interpreters
;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
;; Free Software Foundation, Inc.
;; Author: Alex Schroeder <[email protected]>
;; Maintainer: Michael Mauger <[email protected]>
;; Version: 2.1.0
;; Keywords: comm languages processes
;; URL: http://savannah.gnu.org/cgi-bin/viewcvs/emacs/emacs/lisp/progmodes/sql.el
;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; Please send bug reports and bug fixes to the mailing list at
;; [email protected]. If you want to subscribe to the mailing
;; list, see the web page at
;; http://lists.gnu.org/mailman/listinfo/help-gnu-emacs for
;; instructions. I monitor this list actively. If you send an e-mail
;; to Alex Schroeder it usually makes it to me when Alex has a chance
;; to forward them along (Thanks, Alex).
;; This file provides a sql-mode and a sql-interactive-mode. The
;; original goals were two simple modes providing syntactic
;; highlighting. The interactive mode had to provide a command-line
;; history; the other mode had to provide "send region/buffer to SQL
;; interpreter" functions. "simple" in this context means easy to
;; use, easy to maintain and little or no bells and whistles. This
;; has changed somewhat as experience with the mode has accumulated.
;; Support for different flavors of SQL and command interpreters was
;; available in early versions of sql.el. This support has been
;; extended and formalized in later versions. Part of the impetus for
;; the improved support of SQL flavors was borne out of the current
;; maintainer's consulting experience. In the past fifteen years, I
;; have used Oracle, Sybase, Informix, MySQL, Postgres, and SQLServer.
;; On some assignments, I have used two or more of these concurrently.
;; If anybody feels like extending this sql mode, take a look at the
;; above mentioned modes and write a sqlx-mode on top of this one. If
;; this proves to be difficult, please suggest changes that will
;; facilitate your plans. Facilities have been provided to add
;; products and product-specific configuration.
;; sql-interactive-mode is used to interact with a SQL interpreter
;; process in a SQLi buffer (usually called `*SQL*'). The SQLi buffer
;; is created by calling a SQL interpreter-specific entry function or
;; sql-product-interactive. Do *not* call sql-interactive-mode by
;; itself.
;; The list of currently supported interpreters and the corresponding
;; entry function used to create the SQLi buffers is shown with
;; `sql-help' (M-x sql-help).
;; Since sql-interactive-mode is built on top of the general
;; command-interpreter-in-a-buffer mode (comint mode), it shares a
;; common base functionality, and a common set of bindings, with all
;; modes derived from comint mode. This makes these modes easier to
;; use.
;; sql-mode can be used to keep editing SQL statements. The SQL
;; statements can be sent to the SQL process in the SQLi buffer.
;; For documentation on the functionality provided by comint mode, and
;; the hooks available for customizing it, see the file `comint.el'.
;; Hint for newbies: take a look at `dabbrev-expand', `abbrev-mode', and
;; `imenu-add-menubar-index'.
;;; Requirements for Emacs 19.34:
;; If you are using Emacs 19.34, you will have to get and install
;; the file regexp-opt.el
;; <URL:ftp://ftp.ifi.uio.no/pub/emacs/emacs-20.3/lisp/emacs-lisp/regexp-opt.el>
;; and the custom package
;; <URL:http://www.dina.kvl.dk/~abraham/custom/>.
;;; Bugs:
;; sql-ms now uses osql instead of isql. Osql flushes its error
;; stream more frequently than isql so that error messages are
;; available. There is no prompt and some output still is buffered.
;; This improves the interaction under Emacs but it still is somewhat
;; awkward.
;; Quoted identifiers are not supported for highlighting. Most
;; databases support the use of double quoted strings in place of
;; identifiers; ms (Microsoft SQLServer) also supports identifiers
;; enclosed within brackets [].
;;; Product Support:
;; To add support for additional SQL products the following steps must
;; be followed ("xyz" is the name of the product in the examples
;; below):
;; 1) Add the product to the list of known products.
;; (sql-add-product 'xyz "XyzDB"
;; '(:free-software t))
;; 2) Define font lock settings. All ANSI keywords will be
;; highlighted automatically, so only product specific keywords
;; need to be defined here.
;; (defvar my-sql-mode-xyz-font-lock-keywords
;; '(("\\b\\(red\\|orange\\|yellow\\)\\b"
;; . font-lock-keyword-face))
;; "XyzDB SQL keywords used by font-lock.")
;; (sql-set-product-feature 'xyz
;; :font-lock
;; 'my-sql-mode-xyz-font-lock-keywords)
;; 3) Define any special syntax characters including comments and
;; identifier characters.
;; (sql-set-product-feature 'xyz
;; :syntax-alist ((?# . "w")))
;; 4) Define the interactive command interpreter for the database
;; product.
;; (defcustom my-sql-xyz-program "ixyz"
;; "Command to start ixyz by XyzDB."
;; :type 'file
;; :group 'SQL)
;; (sql-set-product-feature 'xyz
;; :sql-program 'my-sql-xyz-program)
;; (sql-set-product-feature 'xyz
;; :sqli-prompt-regexp "^xyzdb> ")
;; (sql-set-product-feature 'xyz
;; :sqli-prompt-length 7)
;; 5) Define login parameters and command line formatting.
;; (defcustom my-sql-xyz-login-params '(user password server database)
;; "Login parameters to needed to connect to XyzDB."
;; :type '(repeat (choice
;; (const user)
;; (const password)
;; (const server)
;; (const database)))
;; :group 'SQL)
;; (defcustom my-sql-xyz-options '("-X" "-Y" "-Z")
;; "List of additional options for `sql-xyz-program'."
;; :type '(repeat string)
;; :group 'SQL)
;; (defun my-sql-connect-xyz ()
;; "Connect ti XyzDB in a comint buffer."
;;
;; ;; Do something with `sql-user', `sql-password',
;; ;; `sql-database', and `sql-server'.
;; (let ((params my-sql-xyz-options))
;; (if (not (string= "" sql-server))
;; (setq params (append (list "-S" sql-server) params)))
;; (if (not (string= "" sql-database))
;; (setq params (append (list "-D" sql-database) params)))
;; (if (not (string= "" sql-password))
;; (setq params (append (list "-P" sql-password) params)))
;; (if (not (string= "" sql-user))
;; (setq params (append (list "-U" sql-user) params)))
;; (sql-connect-1 my-sql-xyz-program params)))
;; (sql-set-product-feature 'xyz
;; :sqli-login 'my-sql-xyz-login-params)
;; (sql-set-product-feature 'xyz
;; :sqli-connect 'my-connect-xyz)
;; 6) Define a convienence function to invoke the SQL interpreter.
;; (defun my-sql-xyz ()
;; "Run ixyz by XyzDB as an inferior process."
;; (interactive)
;; (sql-product-interactive 'xyz))
;;; To Do:
;; Improve keyword highlighting for individual products. I have tried
;; to update those database that I use. Feel free to send me updates,
;; or direct me to the reference manuals for your favorite database.
;; When there are no keywords defined, the ANSI keywords are
;; highlighted. ANSI keywords are highlighted even if the keyword is
;; not used for your current product. This should help identify
;; portability concerns.
;; Add different highlighting levels.
;; Add support for listing available tables or the columns in a table.
;;; Thanks to all the people who helped me out:
;; Alex Schroeder <[email protected]> -- the original author
;; Kai Blauberg <[email protected]>
;; <[email protected]>
;; Yair Friedman <[email protected]>
;; Gregor Zych <[email protected]>
;; nino <[email protected]>
;; Berend de Boer <[email protected]>
;; Adam Jenkins <[email protected]>
;; Michael Mauger <[email protected]> -- improved product support
;; Drew Adams <[email protected]> -- Emacs 20 support
;; Harald Maier <[email protected]> -- idea for sql-send-string
;; Stefan Monnier <[email protected]> -- font-lock corrections
;;; Code:
(require 'comint)
;; Need the following to allow GNU Emacs 19 to compile the file.
(eval-when-compile
(require 'regexp-opt))
(require 'custom)
(eval-when-compile ;; needed in Emacs 19, 20
(setq max-specpdl-size 2000))
(defvar font-lock-keyword-face)
(defvar font-lock-set-defaults)
(defvar font-lock-string-face)
;;; Allow customization
(defgroup SQL nil
"Running a SQL interpreter from within Emacs buffers."
:version "20.4"
:group 'languages
:group 'processes)
;; These four variables will be used as defaults, if set.
(defcustom sql-user ""
"Default username."
:type 'string
:group 'SQL)
(defcustom sql-password ""
"Default password.
Storing your password in a textfile such as ~/.emacs could be dangerous.
Customizing your password will store it in your ~/.emacs file."
:type 'string
:group 'SQL)
(defcustom sql-database ""
"Default database."
:type 'string
:group 'SQL)
(defcustom sql-server ""
"Default server or host."
:type 'string
:group 'SQL)
;; SQL Product support
(defvar sql-product-alist
'((ansi
:display "ANSI"
:font-lock sql-mode-ansi-font-lock-keywords)
(db2
:display "DB2"
:font-lock sql-mode-db2-font-lock-keywords
:sql-program sql-db2-program
:sqli-login sql-db2-login-params
:sqli-connect sql-connect-db2
:sqli-prompt-regexp "^db2 => "
:sqli-prompt-length 7)
(informix
:display "Informix"
:font-lock sql-mode-informix-font-lock-keywords
:sql-program sql-informix-program
:sqli-login sql-informix-login-params
:sqli-connect sql-connect-informix
:sqli-prompt-regexp "^> "
:sqli-prompt-length 2
:syntax-alist ((?{ . "<") (?} . ">")))
(ingres
:display "Ingres"
:font-lock sql-mode-ingres-font-lock-keywords
:sql-program sql-ingres-program
:sqli-login sql-ingres-login-params
:sqli-connect sql-connect-ingres
:sqli-prompt-regexp "^\* "
:sqli-prompt-length 2)
(interbase
:display "Interbase"
:font-lock sql-mode-interbase-font-lock-keywords
:sql-program sql-interbase-program
:sqli-login sql-interbase-login-params
:sqli-connect sql-connect-interbase
:sqli-prompt-regexp "^SQL> "
:sqli-prompt-length 5)
(linter
:display "Linter"
:font-lock sql-mode-linter-font-lock-keywords
:sql-program sql-linter-program
:sqli-login sql-linter-login-params
:sqli-connect sql-connect-linter
:sqli-prompt-regexp "^SQL>"
:sqli-prompt-length 4)
(ms
:display "Microsoft"
:font-lock sql-mode-ms-font-lock-keywords
:sql-program sql-ms-program
:sqli-login sql-ms-login-params
:sqli-connect sql-connect-ms
:sqli-prompt-regexp "^[0-9]*>"
:sqli-prompt-length 5
:syntax-alist ((?@ . "w"))
:sql-send-terminator ("^go" . "go"))
(mysql
:display "MySQL"
:free-software t
:font-lock sql-mode-mysql-font-lock-keywords
:sql-program sql-mysql-program
:sqli-login sql-mysql-login-params
:sqli-connect sql-connect-mysql
:sqli-prompt-regexp "^mysql> "
:sqli-prompt-length 6
:sql-input-filter sql-send-remove-tabs-filter)
(oracle
:display "Oracle"
:font-lock sql-mode-oracle-font-lock-keywords
:sql-program sql-oracle-program
:sqli-login sql-oracle-login-params
:sqli-connect sql-connect-oracle
:sqli-prompt-regexp "^SQL> "
:sqli-prompt-length 5
:syntax-alist ((?$ . "w") (?# . "w"))
:sql-send-terminator ("\\(^/\\|;\\)" . "/"))
(postgres
:display "Postgres"
:free-software t
:font-lock sql-mode-postgres-font-lock-keywords
:sql-program sql-postgres-program
:sqli-login sql-postgres-login-params
:sqli-connect sql-connect-postgres
:sqli-prompt-regexp "^.*[#>] *"
:sqli-prompt-length 5
:sql-input-filter sql-send-remove-tabs-filter
:sql-send-terminator ("\\(^[\\]g\\|;\\)" . ";"))
(solid
:display "Solid"
:font-lock sql-mode-solid-font-lock-keywords
:sql-program sql-solid-program
:sqli-login sql-solid-login-params
:sqli-connect sql-connect-solid
:sqli-prompt-regexp "^"
:sqli-prompt-length 0)
(sqlite
:display "SQLite"
:free-software t
:font-lock sql-mode-sqlite-font-lock-keywords
:sql-program sql-sqlite-program
:sqli-login sql-sqlite-login-params
:sqli-connect sql-connect-sqlite
:sqli-prompt-regexp "^sqlite> "
:sqli-prompt-length 8)
(sybase
:display "Sybase"
:font-lock sql-mode-sybase-font-lock-keywords
:sql-program sql-sybase-program
:sqli-login sql-sybase-login-params
:sqli-connect sql-connect-sybase
:sqli-prompt-regexp "^SQL> "
:sqli-prompt-length 5
:syntax-alist ((?@ . "w"))
:sql-send-terminator ("^go" . "go"))
)
"An alist of product specific configuration settings.
Without an entry in this list a product will not be properly
highlighted and will not support `sql-interactive-mode'.
Each element in the list is in the following format:
\(PRODUCT FEATURE VALUE ...)
where PRODUCT is the appropriate value of `sql-product'. The
product name is then followed by FEATURE-VALUE pairs. If a
FEATURE is not specified, its VALUE is treated as nil. FEATURE
may be any one of the following:
:display string containing the displayable name of
the product.
:free-software is the product Free (as in Freedom) software?
:font-lock name of the variable containing the product
specific font lock highlighting patterns.
:sql-program name of the variable containing the product
specific interactive program name.
:sqli-login name of the variable containing the list of
login parameters (i.e., user, password,
database and server) needed to connect to
the database.
:sqli-connect name of a function which accepts no
parameters that will use the values of
`sql-user', `sql-password',
`sql-database' and `sql-server' to open a
comint buffer and connect to the
database. Do product specific
configuration of comint in this function.
:sqli-prompt-regexp regular expression string that matches
the prompt issued by the product
interpreter.
:sqli-prompt-length length of the prompt on the line.
:sql-input-filter name of a function which can filter the
string sent to the command interpreter by
the `sql-send-string', `sql-send-region',
`sql-send-paragraph' and
`sql-send-buffer' functions. The
function is passed the string sent to the
command interpreter and must return the
filtered string.
:sql-send-terminator the terminator to be sent after a
`sql-send-string', `sql-send-region',
`sql-send-paragraph' and
`sql-send-buffer' command. May be the
literal string or a cons of a regexp to
match an existing terminator in the
string and the terminator to be used if
its absent. By default \";\".
:syntax-alist alist of syntax table entries to enable
special character treatment by font-lock
and imenu.
Other features can be stored but they will be ignored. However,
you can develop new functionality which is product independent by
using `sql-get-product-feature' to lookup the product specific
settings.")
(defvar sql-product)
(defun sql-set-product (product)
"Set `sql-product' to PRODUCT and enable font locking."
(interactive "SEnter SQL product: ")
(when (not (assoc product sql-product-alist))
(error "SQL product %s is not supported; treated as ANSI" product)
(setq product 'ansi))
;; Save product setting and fontify.
(setq sql-product product)
(when (fboundp 'sql-highlight-product)
(sql-highlight-product)))
(defcustom sql-product 'ansi
"The default SQL database product."
:type '(choice (const :tag "ANSI" ansi)
(const :tag "DB2" db2)
(const :tag "Informix" informix)
(const :tag "Ingres" ingres)
(const :tag "Interbase" interbase)
(const :tag "Linter" linter)
(const :tag "Microsoft" ms)
(const :tag "MySQL" mysql)
(const :tag "Oracle" oracle)
(const :tag "Postgres" postgres)
(const :tag "Solid" solid)
(const :tag "SQLite" sqlite)
(const :tag "Sybase" sybase))
:set (lambda (symbol value) (sql-set-product value))
:group 'SQL)
(defvar sql-interactive-product nil
"Product under `sql-interactive-mode'.")
;; misc customization of sql.el behaviour
(defcustom sql-electric-stuff nil
"Treat some input as electric.
If set to the symbol `semicolon', then hitting `;' will send current
input in the SQLi buffer to the process.
If set to the symbol `go', then hitting `go' on a line by itself will
send current input in the SQLi buffer to the process.
If set to nil, then you must use \\[comint-send-input] in order to send
current input in the SQLi buffer to the process."
:type '(choice (const :tag "Nothing" nil)
(const :tag "The semikolon `;'" semicolon)
(const :tag "The string `go' by itself" go))
:version "20.8"
:group 'SQL)
(defcustom sql-send-terminator nil
"When non-nil, add a terminator to text sent to the SQL interpreter.
When text is sent to the SQL interpreter (via `sql-send-string',
`sql-send-region', `sql-send-paragraph' or `sql-send-buffer'), a
command terminator can be automatically sent as well. The
terminator is not sent, if the string sent already ends with the
terminator.
If this value is t, then the default command terminator for the
SQL interpreter is sent. If this value is a string, then the
string is sent.
If the value is a cons cell of the form (PAT . TERM), then PAT is
a regexp used to match the terminator in the string and TERM is
the terminator to be sent. This form is useful if the SQL
interpreter has more than one way of submitting a SQL command.
The PAT regexp can match any of them, and TERM is the way we do
it automatically."
:type '(choice (const :tag "No Terminator" nil)
(const :tag "Default Terminator" t)
(string :tag "Terminator String")
(cons :tag "Terminator Pattern and String"
(string :tag "Terminator Pattern")
(string :tag "Terminator String")))
:version "22.2"
:group 'SQL)
(defcustom sql-pop-to-buffer-after-send-region nil
"When non-nil, pop to the buffer SQL statements are sent to.
After a call to `sql-sent-string', `sql-send-region',
`sql-send-paragraph' or `sql-send-buffer', the window is split
and the SQLi buffer is shown. If this variable is not nil, that
buffer's window will be selected by calling `pop-to-buffer'. If
this variable is nil, that buffer is shown using
`display-buffer'."
:type 'boolean
:group 'SQL)
;; imenu support for sql-mode.
(defvar sql-imenu-generic-expression
;; Items are in reverse order because they are rendered in reverse.
'(("Rules/Defaults" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*\\(rule\\|default\\)\\s-+\\(\\w+\\)" 3)
("Sequences" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*sequence\\s-+\\(\\w+\\)" 2)
("Triggers" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*trigger\\s-+\\(\\w+\\)" 2)
("Functions" "^\\s-*\\(create\\s-+\\(\\w+\\s-+\\)*\\)?function\\s-+\\(\\w+\\)" 3)
("Procedures" "^\\s-*\\(create\\s-+\\(\\w+\\s-+\\)*\\)?proc\\(edure\\)?\\s-+\\(\\w+\\)" 4)
("Packages" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*package\\s-+\\(body\\s-+\\)?\\(\\w+\\)" 3)
("Types" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*type\\s-+\\(body\\s-+\\)?\\(\\w+\\)" 3)
("Indexes" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*index\\s-+\\(\\w+\\)" 2)
("Tables/Views" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*\\(table\\|view\\)\\s-+\\(\\w+\\)" 3))
"Define interesting points in the SQL buffer for `imenu'.
This is used to set `imenu-generic-expression' when SQL mode is
entered. Subsequent changes to `sql-imenu-generic-expression' will not
affect existing SQL buffers because `imenu-generic-expression' is a
local variable.")
;; history file
(defcustom sql-input-ring-file-name nil
"If non-nil, name of the file to read/write input history.
You have to set this variable if you want the history of your commands
saved from one Emacs session to the next. If this variable is set,
exiting the SQL interpreter in an SQLi buffer will write the input
history to the specified file. Starting a new process in a SQLi buffer
will read the input history from the specified file.
This is used to initialize `comint-input-ring-file-name'.
Note that the size of the input history is determined by the variable
`comint-input-ring-size'."
:type '(choice (const :tag "none" nil)
(file))
:group 'SQL)
(defcustom sql-input-ring-separator "\n--\n"
"Separator between commands in the history file.
If set to \"\\n\", each line in the history file will be interpreted as
one command. Multi-line commands are split into several commands when
the input ring is initialized from a history file.
This variable used to initialize `comint-input-ring-separator'.
`comint-input-ring-separator' is part of Emacs 21; if your Emacs
does not have it, setting `sql-input-ring-separator' will have no
effect. In that case multiline commands will be split into several
commands when the input history is read, as if you had set
`sql-input-ring-separator' to \"\\n\"."
:type 'string
:group 'SQL)
;; The usual hooks
(defcustom sql-interactive-mode-hook '()
"Hook for customizing `sql-interactive-mode'."
:type 'hook
:group 'SQL)
(defcustom sql-mode-hook '()
"Hook for customizing `sql-mode'."
:type 'hook
:group 'SQL)
(defcustom sql-set-sqli-hook '()
"Hook for reacting to changes of `sql-buffer'.
This is called by `sql-set-sqli-buffer' when the value of `sql-buffer'
is changed."
:type 'hook
:group 'SQL)
;; Customization for Oracle
(defcustom sql-oracle-program "sqlplus"
"Command to start sqlplus by Oracle.
Starts `sql-interactive-mode' after doing some setup.
Under NT, \"sqlplus\" usually starts the sqlplus \"GUI\". In order to
start the sqlplus console, use \"plus33\" or something similar. You
will find the file in your Orant\\bin directory."
:type 'file
:group 'SQL)
(defcustom sql-oracle-options nil
"List of additional options for `sql-oracle-program'."
:type '(repeat string)
:version "20.8"
:group 'SQL)
(defcustom sql-oracle-login-params '(user password database)
"List of login parameters needed to connect to Oracle."
:type '(repeat (choice
(const user)
(const password)
(const server)
(const database)))
:group 'SQL)
;; Customization for SQLite
(defcustom sql-sqlite-program "sqlite"
"Command to start SQLite.
Starts `sql-interactive-mode' after doing some setup."
:type 'file
:group 'SQL)
(defcustom sql-sqlite-options nil
"List of additional options for `sql-sqlite-program'.
The following list of options is reported to make things work
on Windows: \"-C\" \"-t\" \"-f\" \"-n\"."
:type '(repeat string)
:version "20.8"
:group 'SQL)
(defcustom sql-sqlite-login-params '(user password server database)
"List of login parameters needed to connect to Oracle."
:type '(repeat (choice
(const user)
(const password)
(const server)
(const database)))
:group 'SQL)
;; Customization for MySql
(defcustom sql-mysql-program "mysql"
"Command to start mysql by TcX.
Starts `sql-interactive-mode' after doing some setup."
:type 'file
:group 'SQL)
(defcustom sql-mysql-options nil
"List of additional options for `sql-mysql-program'.
The following list of options is reported to make things work
on Windows: \"-C\" \"-t\" \"-f\" \"-n\"."
:type '(repeat string)
:version "20.8"
:group 'SQL)
(defcustom sql-mysql-login-params '(user password database server)
"List of login parameters needed to connect to MySql."
:type '(repeat (choice
(const user)
(const password)
(const server)
(const database)))
:group 'SQL)
;; Customization for Solid
(defcustom sql-solid-program "solsql"
"Command to start SOLID SQL Editor.
Starts `sql-interactive-mode' after doing some setup."
:type 'file
:group 'SQL)
(defcustom sql-solid-login-params '(user password server)
"List of login parameters needed to connect to Solid."
:type '(repeat (choice
(const user)
(const password)
(const server)
(const database)))
:group 'SQL)
;; Customization for SyBase
(defcustom sql-sybase-program "isql"
"Command to start isql by SyBase.
Starts `sql-interactive-mode' after doing some setup."
:type 'file
:group 'SQL)
(defcustom sql-sybase-options nil
"List of additional options for `sql-sybase-program'.
Some versions of isql might require the -n option in order to work."
:type '(repeat string)
:version "20.8"
:group 'SQL)
(defcustom sql-sybase-login-params '(server user password database)
"List of login parameters needed to connect to Sybase."
:type '(repeat (choice
(const user)
(const password)
(const server)
(const database)))
:group 'SQL)
;; Customization for Informix
(defcustom sql-informix-program "dbaccess"
"Command to start dbaccess by Informix.
Starts `sql-interactive-mode' after doing some setup."
:type 'file
:group 'SQL)
(defcustom sql-informix-login-params '(database)
"List of login parameters needed to connect to Informix."
:type '(repeat (choice
(const user)
(const password)
(const server)
(const database)))
:group 'SQL)
;; Customization for Ingres
(defcustom sql-ingres-program "sql"
"Command to start sql by Ingres.
Starts `sql-interactive-mode' after doing some setup."
:type 'file
:group 'SQL)
(defcustom sql-ingres-login-params '(database)
"List of login parameters needed to connect to Ingres."
:type '(repeat (choice
(const user)
(const password)
(const server)
(const database)))
:group 'SQL)
;; Customization for Microsoft
(defcustom sql-ms-program "osql"
"Command to start osql by Microsoft.
Starts `sql-interactive-mode' after doing some setup."
:type 'file
:group 'SQL)
(defcustom sql-ms-options '("-w" "300" "-n")
;; -w is the linesize
"List of additional options for `sql-ms-program'."
:type '(repeat string)
:version "22.1"
:group 'SQL)
(defcustom sql-ms-login-params '(user password server database)
"List of login parameters needed to connect to Microsoft."
:type '(repeat (choice
(const user)
(const password)
(const server)
(const database)))
:group 'SQL)
;; Customization for Postgres
(defcustom sql-postgres-program "psql"
"Command to start psql by Postgres.
Starts `sql-interactive-mode' after doing some setup."
:type 'file
:group 'SQL)
(defcustom sql-postgres-options '("-P" "pager=off")
"List of additional options for `sql-postgres-program'.
The default setting includes the -P option which breaks older versions
of the psql client (such as version 6.5.3). The -P option is equivalent
to the --pset option. If you want the psql to prompt you for a user
name, add the string \"-u\" to the list of options. If you want to
provide a user name on the command line (newer versions such as 7.1),
add your name with a \"-U\" prefix (such as \"-Umark\") to the list."
:type '(repeat string)
:version "20.8"
:group 'SQL)
(defcustom sql-postgres-login-params '(user database server)
"List of login parameters needed to connect to Postgres."
:type '(repeat (choice
(const user)
(const password)
(const server)
(const database)))
:group 'SQL)
;; Customization for Interbase
(defcustom sql-interbase-program "isql"
"Command to start isql by Interbase.
Starts `sql-interactive-mode' after doing some setup."
:type 'file
:group 'SQL)
(defcustom sql-interbase-options nil
"List of additional options for `sql-interbase-program'."
:type '(repeat string)
:version "20.8"
:group 'SQL)
(defcustom sql-interbase-login-params '(user password database)
"List of login parameters needed to connect to Interbase."
:type '(repeat (choice
(const user)
(const password)
(const server)
(const database)))
:group 'SQL)
;; Customization for DB2
(defcustom sql-db2-program "db2"
"Command to start db2 by IBM.
Starts `sql-interactive-mode' after doing some setup."
:type 'file
:group 'SQL)
(defcustom sql-db2-options nil
"List of additional options for `sql-db2-program'."
:type '(repeat string)
:version "20.8"
:group 'SQL)
(defcustom sql-db2-login-params nil
"List of login parameters needed to connect to DB2."
:type '(repeat (choice
(const user)
(const password)
(const server)
(const database)))
:group 'SQL)
;; Customization for Linter
(defcustom sql-linter-program "inl"
"Command to start inl by RELEX.
Starts `sql-interactive-mode' after doing some setup."
:type 'file
:group 'SQL)
(defcustom sql-linter-options nil
"List of additional options for `sql-linter-program'."
:type '(repeat string)
:version "21.3"
:group 'SQL)
(defcustom sql-linter-login-params '(user password database server)
"Login parameters to needed to connect to Linter."
:type '(repeat (choice
(const user)
(const password)
(const server)
(const database)))
:group 'SQL)
;;; Variables which do not need customization
(defvar sql-user-history nil
"History of usernames used.")
(defvar sql-database-history nil
"History of databases used.")
(defvar sql-server-history nil
"History of servers used.")
;; Passwords are not kept in a history.
(defvar sql-buffer nil
"Current SQLi buffer.
The global value of `sql-buffer' is the name of the latest SQLi buffer
created. Any SQL buffer created will make a local copy of this value.
See `sql-interactive-mode' for more on multiple sessions. If you want
to change the SQLi buffer a SQL mode sends its SQL strings to, change
the local value of `sql-buffer' using \\[sql-set-sqli-buffer].")
(defvar sql-prompt-regexp nil
"Prompt used to initialize `comint-prompt-regexp'.
You can change `sql-prompt-regexp' on `sql-interactive-mode-hook'.")
(defvar sql-prompt-length 0
"Prompt used to set `left-margin' in `sql-interactive-mode'.
You can change `sql-prompt-length' on `sql-interactive-mode-hook'.")
(defvar sql-alternate-buffer-name nil
"Buffer-local string used to possibly rename the SQLi buffer.
Used by `sql-rename-buffer'.")
;; Keymap for sql-interactive-mode.
(defvar sql-interactive-mode-map
(let ((map (make-sparse-keymap)))
(if (fboundp 'set-keymap-parent)
(set-keymap-parent map comint-mode-map); Emacs
(if (fboundp 'set-keymap-parents)
(set-keymap-parents map (list comint-mode-map)))); XEmacs
(if (fboundp 'set-keymap-name)
(set-keymap-name map 'sql-interactive-mode-map)); XEmacs
(define-key map (kbd "C-j") 'sql-accumulate-and-indent)
(define-key map (kbd "C-c C-w") 'sql-copy-column)
(define-key map (kbd "O") 'sql-magic-go)
(define-key map (kbd "o") 'sql-magic-go)
(define-key map (kbd ";") 'sql-magic-semicolon)
map)
"Mode map used for `sql-interactive-mode'.
Based on `comint-mode-map'.")
;; Keymap for sql-mode.
(defvar sql-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-c") 'sql-send-paragraph)
(define-key map (kbd "C-c C-r") 'sql-send-region)
(define-key map (kbd "C-c C-s") 'sql-send-string)
(define-key map (kbd "C-c C-b") 'sql-send-buffer)
map)
"Mode map used for `sql-mode'.")
;; easy menu for sql-mode.
(easy-menu-define
sql-mode-menu sql-mode-map
"Menu for `sql-mode'."
'("SQL"
["Send Paragraph" sql-send-paragraph (and (buffer-live-p sql-buffer)
(get-buffer-process sql-buffer))]
["Send Region" sql-send-region (and (or (and (boundp 'mark-active); Emacs
mark-active)
(mark t)); XEmacs
(buffer-live-p sql-buffer)
(get-buffer-process sql-buffer))]
["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer)