comparison lisp/progmodes/sql.el @ 109460:597339bd6bef

SQL Mode V2.2 - Added sql-connect and sql-connection-alist
author Michael Mauger <mmaug@yahoo.com>
date Sun, 18 Jul 2010 14:44:32 -0400
parents b2a9d4e48488
children c9df47f7bbf3
comparison
equal deleted inserted replaced
109459:301190722b84 109460:597339bd6bef
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 ;; 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 4 ;; 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 5
6 ;; Author: Alex Schroeder <alex@gnu.org> 6 ;; Author: Alex Schroeder <alex@gnu.org>
7 ;; Maintainer: Michael Mauger <mmaug@yahoo.com> 7 ;; Maintainer: Michael Mauger <mmaug@yahoo.com>
8 ;; Version: 2.1 8 ;; Version: 2.2
9 ;; Keywords: comm languages processes 9 ;; Keywords: comm languages processes
10 ;; URL: http://savannah.gnu.org/cgi-bin/viewcvs/emacs/emacs/lisp/progmodes/sql.el 10 ;; URL: http://savannah.gnu.org/cgi-bin/viewcvs/emacs/emacs/lisp/progmodes/sql.el
11 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode 11 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode
12 12
13 ;; This file is part of GNU Emacs. 13 ;; This file is part of GNU Emacs.
154 ;; "Login parameters to needed to connect to XyzDB." 154 ;; "Login parameters to needed to connect to XyzDB."
155 ;; :type '(repeat (choice 155 ;; :type '(repeat (choice
156 ;; (const user) 156 ;; (const user)
157 ;; (const password) 157 ;; (const password)
158 ;; (const server) 158 ;; (const server)
159 ;; (const database))) 159 ;; (const database)
160 ;; (const port)))
160 ;; :group 'SQL) 161 ;; :group 'SQL)
161 ;; 162 ;;
162 ;; (sql-set-product-feature 'xyz 163 ;; (sql-set-product-feature 'xyz
163 ;; :sqli-login 'my-sql-xyz-login-params) 164 ;; :sqli-login 'my-sql-xyz-login-params)
164 165
168 ;; :group 'SQL) 169 ;; :group 'SQL)
169 ;; 170 ;;
170 ;; (sql-set-product-feature 'xyz 171 ;; (sql-set-product-feature 'xyz
171 ;; :sqli-options 'my-sql-xyz-options)) 172 ;; :sqli-options 'my-sql-xyz-options))
172 173
173 ;; (defun my-sql-connect-xyz (product options) 174 ;; (defun my-sql-comint-xyz (product options)
174 ;; "Connect ti XyzDB in a comint buffer." 175 ;; "Connect ti XyzDB in a comint buffer."
175 ;; 176 ;;
176 ;; ;; Do something with `sql-user', `sql-password', 177 ;; ;; Do something with `sql-user', `sql-password',
177 ;; ;; `sql-database', and `sql-server'. 178 ;; ;; `sql-database', and `sql-server'.
178 ;; (let ((params options)) 179 ;; (let ((params options))
182 ;; (setq params (append (list "-D" sql-database) params))) 183 ;; (setq params (append (list "-D" sql-database) params)))
183 ;; (if (not (string= "" sql-password)) 184 ;; (if (not (string= "" sql-password))
184 ;; (setq params (append (list "-P" sql-password) params))) 185 ;; (setq params (append (list "-P" sql-password) params)))
185 ;; (if (not (string= "" sql-user)) 186 ;; (if (not (string= "" sql-user))
186 ;; (setq params (append (list "-U" sql-user) params))) 187 ;; (setq params (append (list "-U" sql-user) params)))
187 ;; (sql-connect product params))) 188 ;; (sql-comint product params)))
188 ;; 189 ;;
189 ;; (sql-set-product-feature 'xyz 190 ;; (sql-set-product-feature 'xyz
190 ;; :sqli-connect-func 'my-sql-connect-xyz) 191 ;; :sqli-connect-func 'my-sql-comint-xyz)
191 192
192 ;; 6) Define a convienence function to invoke the SQL interpreter. 193 ;; 6) Define a convienence function to invoke the SQL interpreter.
193 194
194 ;; (defun my-sql-xyz () 195 ;; (defun my-sql-xyz ()
195 ;; "Run ixyz by XyzDB as an inferior process." 196 ;; "Run ixyz by XyzDB as an inferior process."
233 (require 'comint) 234 (require 'comint)
234 ;; Need the following to allow GNU Emacs 19 to compile the file. 235 ;; Need the following to allow GNU Emacs 19 to compile the file.
235 (eval-when-compile 236 (eval-when-compile
236 (require 'regexp-opt)) 237 (require 'regexp-opt))
237 (require 'custom) 238 (require 'custom)
239 (require 'assoc)
238 (eval-when-compile ;; needed in Emacs 19, 20 240 (eval-when-compile ;; needed in Emacs 19, 20
239 (setq max-specpdl-size 2000)) 241 (setq max-specpdl-size 2000))
240 242
241 (defvar font-lock-keyword-face) 243 (defvar font-lock-keyword-face)
242 (defvar font-lock-set-defaults) 244 (defvar font-lock-set-defaults)
253 ;; These four variables will be used as defaults, if set. 255 ;; These four variables will be used as defaults, if set.
254 256
255 (defcustom sql-user "" 257 (defcustom sql-user ""
256 "Default username." 258 "Default username."
257 :type 'string 259 :type 'string
258 :group 'SQL) 260 :group 'SQL
259 (put 'sql-user 'safe-local-variable 'stringp) 261 :safe 'stringp)
260 262
261 (defcustom sql-password "" 263 (defcustom sql-password ""
262 "Default password. 264 "Default password.
263 265
264 Storing your password in a textfile such as ~/.emacs could be dangerous. 266 Storing your password in a textfile such as ~/.emacs could be dangerous.
265 Customizing your password will store it in your ~/.emacs file." 267 Customizing your password will store it in your ~/.emacs file."
266 :type 'string 268 :type 'string
267 :group 'SQL) 269 :group 'SQL
268 (put 'sql-password 'risky-local-variable t) 270 :risky t)
269 271
270 (defcustom sql-database "" 272 (defcustom sql-database ""
271 "Default database." 273 "Default database."
272 :type 'string 274 :type 'string
273 :group 'SQL) 275 :group 'SQL
274 (put 'sql-database 'safe-local-variable 'stringp) 276 :safe 'stringp)
275 277
276 (defcustom sql-server "" 278 (defcustom sql-server ""
277 "Default server or host." 279 "Default server or host."
278 :type 'string 280 :type 'string
279 :group 'SQL) 281 :group 'SQL
280 (put 'sql-server 'safe-local-variable 'stringp) 282 :safe 'stringp)
281 283
282 (defcustom sql-port nil 284 (defcustom sql-port nil
283 "Default server or host." 285 "Default server or host."
286 :version "24.1"
284 :type 'number 287 :type 'number
285 :group 'SQL) 288 :group 'SQL
286 (put 'sql-port 'safe-local-variable 'numberp) 289 :safe 'numberp)
287 290
288 ;; SQL Product support 291 ;; SQL Product support
289 292
290 (defvar sql-interactive-product nil 293 (defvar sql-interactive-product nil
291 "Product under `sql-interactive-mode'.") 294 "Product under `sql-interactive-mode'.")
295
296 (defvar sql-connection nil
297 "Connection name if interactive session started by `sql-connect'.")
292 298
293 (defvar sql-product-alist 299 (defvar sql-product-alist
294 '((ansi 300 '((ansi
295 :name "ANSI" 301 :name "ANSI"
296 :font-lock sql-mode-ansi-font-lock-keywords) 302 :font-lock sql-mode-ansi-font-lock-keywords)
299 :name "DB2" 305 :name "DB2"
300 :font-lock sql-mode-db2-font-lock-keywords 306 :font-lock sql-mode-db2-font-lock-keywords
301 :sqli-program sql-db2-program 307 :sqli-program sql-db2-program
302 :sqli-options sql-db2-options 308 :sqli-options sql-db2-options
303 :sqli-login sql-db2-login-params 309 :sqli-login sql-db2-login-params
304 :sqli-connect-func sql-connect-db2 310 :sqli-comint-func sql-comint-db2
305 :prompt-regexp "^db2 => " 311 :prompt-regexp "^db2 => "
306 :prompt-length 7 312 :prompt-length 7
307 :input-filter sql-escape-newlines-filter) 313 :input-filter sql-escape-newlines-filter)
308 314
309 (informix 315 (informix
310 :name "Informix" 316 :name "Informix"
311 :font-lock sql-mode-informix-font-lock-keywords 317 :font-lock sql-mode-informix-font-lock-keywords
312 :sqli-program sql-informix-program 318 :sqli-program sql-informix-program
313 :sqli-options sql-informix-options 319 :sqli-options sql-informix-options
314 :sqli-login sql-informix-login-params 320 :sqli-login sql-informix-login-params
315 :sqli-connect-func sql-connect-informix 321 :sqli-comint-func sql-comint-informix
316 :prompt-regexp "^> " 322 :prompt-regexp "^> "
317 :prompt-length 2 323 :prompt-length 2
318 :syntax-alist ((?{ . "<") (?} . ">"))) 324 :syntax-alist ((?{ . "<") (?} . ">")))
319 325
320 (ingres 326 (ingres
321 :name "Ingres" 327 :name "Ingres"
322 :font-lock sql-mode-ingres-font-lock-keywords 328 :font-lock sql-mode-ingres-font-lock-keywords
323 :sqli-program sql-ingres-program 329 :sqli-program sql-ingres-program
324 :sqli-options sql-ingres-options 330 :sqli-options sql-ingres-options
325 :sqli-login sql-ingres-login-params 331 :sqli-login sql-ingres-login-params
326 :sqli-connect-func sql-connect-ingres 332 :sqli-comint-func sql-comint-ingres
327 :prompt-regexp "^\* " 333 :prompt-regexp "^\* "
328 :prompt-length 2) 334 :prompt-length 2)
329 335
330 (interbase 336 (interbase
331 :name "Interbase" 337 :name "Interbase"
332 :font-lock sql-mode-interbase-font-lock-keywords 338 :font-lock sql-mode-interbase-font-lock-keywords
333 :sqli-program sql-interbase-program 339 :sqli-program sql-interbase-program
334 :sqli-options sql-interbase-options 340 :sqli-options sql-interbase-options
335 :sqli-login sql-interbase-login-params 341 :sqli-login sql-interbase-login-params
336 :sqli-connect-func sql-connect-interbase 342 :sqli-comint-func sql-comint-interbase
337 :prompt-regexp "^SQL> " 343 :prompt-regexp "^SQL> "
338 :prompt-length 5) 344 :prompt-length 5)
339 345
340 (linter 346 (linter
341 :name "Linter" 347 :name "Linter"
342 :font-lock sql-mode-linter-font-lock-keywords 348 :font-lock sql-mode-linter-font-lock-keywords
343 :sqli-program sql-linter-program 349 :sqli-program sql-linter-program
344 :sqli-options sql-linter-options 350 :sqli-options sql-linter-options
345 :sqli-login sql-linter-login-params 351 :sqli-login sql-linter-login-params
346 :sqli-connect-func sql-connect-linter 352 :sqli-comint-func sql-comint-linter
347 :prompt-regexp "^SQL>" 353 :prompt-regexp "^SQL>"
348 :prompt-length 4) 354 :prompt-length 4)
349 355
350 (ms 356 (ms
351 :name "Microsoft" 357 :name "Microsoft"
352 :font-lock sql-mode-ms-font-lock-keywords 358 :font-lock sql-mode-ms-font-lock-keywords
353 :sqli-program sql-ms-program 359 :sqli-program sql-ms-program
354 :sqli-options sql-ms-options 360 :sqli-options sql-ms-options
355 :sqli-login sql-ms-login-params 361 :sqli-login sql-ms-login-params
356 :sqli-connect-func sql-connect-ms 362 :sqli-comint-func sql-comint-ms
357 :prompt-regexp "^[0-9]*>" 363 :prompt-regexp "^[0-9]*>"
358 :prompt-length 5 364 :prompt-length 5
359 :syntax-alist ((?@ . "w")) 365 :syntax-alist ((?@ . "w"))
360 :terminator ("^go" . "go")) 366 :terminator ("^go" . "go"))
361 367
364 :free-software t 370 :free-software t
365 :font-lock sql-mode-mysql-font-lock-keywords 371 :font-lock sql-mode-mysql-font-lock-keywords
366 :sqli-program sql-mysql-program 372 :sqli-program sql-mysql-program
367 :sqli-options sql-mysql-options 373 :sqli-options sql-mysql-options
368 :sqli-login sql-mysql-login-params 374 :sqli-login sql-mysql-login-params
369 :sqli-connect-func sql-connect-mysql 375 :sqli-comint-func sql-comint-mysql
370 :prompt-regexp "^mysql> " 376 :prompt-regexp "^mysql> "
371 :prompt-length 6 377 :prompt-length 6
372 :input-filter sql-remove-tabs-filter) 378 :input-filter sql-remove-tabs-filter)
373 379
374 (oracle 380 (oracle
375 :name "Oracle" 381 :name "Oracle"
376 :font-lock sql-mode-oracle-font-lock-keywords 382 :font-lock sql-mode-oracle-font-lock-keywords
377 :sqli-program sql-oracle-program 383 :sqli-program sql-oracle-program
378 :sqli-options sql-oracle-options 384 :sqli-options sql-oracle-options
379 :sqli-login sql-oracle-login-params 385 :sqli-login sql-oracle-login-params
380 :sqli-connect-func sql-connect-oracle 386 :sqli-comint-func sql-comint-oracle
381 :prompt-regexp "^SQL> " 387 :prompt-regexp "^SQL> "
382 :prompt-length 5 388 :prompt-length 5
383 :syntax-alist ((?$ . "w") (?# . "w")) 389 :syntax-alist ((?$ . "w") (?# . "w"))
384 :terminator ("\\(^/\\|;\\)" . "/") 390 :terminator ("\\(^/\\|;\\)" . "/")
385 :input-filter sql-placeholders-filter) 391 :input-filter sql-placeholders-filter)
389 :free-software t 395 :free-software t
390 :font-lock sql-mode-postgres-font-lock-keywords 396 :font-lock sql-mode-postgres-font-lock-keywords
391 :sqli-program sql-postgres-program 397 :sqli-program sql-postgres-program
392 :sqli-options sql-postgres-options 398 :sqli-options sql-postgres-options
393 :sqli-login sql-postgres-login-params 399 :sqli-login sql-postgres-login-params
394 :sqli-connect-func sql-connect-postgres 400 :sqli-comint-func sql-comint-postgres
395 :prompt-regexp "^.*[#>] *" 401 :prompt-regexp "^.*[#>] *"
396 :prompt-length 5 402 :prompt-length 5
397 :input-filter sql-remove-tabs-filter 403 :input-filter sql-remove-tabs-filter
398 :terminator ("\\(^[\\]g\\|;\\)" . ";")) 404 :terminator ("\\(^[\\]g\\|;\\)" . ";"))
399 405
401 :name "Solid" 407 :name "Solid"
402 :font-lock sql-mode-solid-font-lock-keywords 408 :font-lock sql-mode-solid-font-lock-keywords
403 :sqli-program sql-solid-program 409 :sqli-program sql-solid-program
404 :sqli-options sql-solid-options 410 :sqli-options sql-solid-options
405 :sqli-login sql-solid-login-params 411 :sqli-login sql-solid-login-params
406 :sqli-connect-func sql-connect-solid 412 :sqli-comint-func sql-comint-solid
407 :prompt-regexp "^" 413 :prompt-regexp "^"
408 :prompt-length 0) 414 :prompt-length 0)
409 415
410 (sqlite 416 (sqlite
411 :name "SQLite" 417 :name "SQLite"
412 :free-software t 418 :free-software t
413 :font-lock sql-mode-sqlite-font-lock-keywords 419 :font-lock sql-mode-sqlite-font-lock-keywords
414 :sqli-program sql-sqlite-program 420 :sqli-program sql-sqlite-program
415 :sqli-options sql-sqlite-options 421 :sqli-options sql-sqlite-options
416 :sqli-login sql-sqlite-login-params 422 :sqli-login sql-sqlite-login-params
417 :sqli-connect-func sql-connect-sqlite 423 :sqli-comint-func sql-comint-sqlite
418 :prompt-regexp "^sqlite> " 424 :prompt-regexp "^sqlite> "
419 :prompt-length 8) 425 :prompt-length 8)
420 426
421 (sybase 427 (sybase
422 :name "Sybase" 428 :name "Sybase"
423 :font-lock sql-mode-sybase-font-lock-keywords 429 :font-lock sql-mode-sybase-font-lock-keywords
424 :sqli-program sql-sybase-program 430 :sqli-program sql-sybase-program
425 :sqli-options sql-sybase-options 431 :sqli-options sql-sybase-options
426 :sqli-login sql-sybase-login-params 432 :sqli-login sql-sybase-login-params
427 :sqli-connect-func sql-connect-sybase 433 :sqli-comint-func sql-comint-sybase
428 :prompt-regexp "^SQL> " 434 :prompt-regexp "^SQL> "
429 :prompt-length 5 435 :prompt-length 5
430 :syntax-alist ((?@ . "w")) 436 :syntax-alist ((?@ . "w"))
431 :terminator ("^go" . "go")) 437 :terminator ("^go" . "go"))
432 ) 438 )
461 :sqli-login name of the variable containing the list of 467 :sqli-login name of the variable containing the list of
462 login parameters (i.e., user, password, 468 login parameters (i.e., user, password,
463 database and server) needed to connect to 469 database and server) needed to connect to
464 the database. 470 the database.
465 471
466 :sqli-connect-func name of a function which accepts no 472 :sqli-comint-func name of a function which accepts no
467 parameters that will use the values of 473 parameters that will use the values of
468 `sql-user', `sql-password', 474 `sql-user', `sql-password',
469 `sql-database' and `sql-server' to open a 475 `sql-database' and `sql-server' to open a
470 comint buffer and connect to the 476 comint buffer and connect to the
471 database. Do product specific 477 database. Do product specific
504 using `sql-get-product-feature' to lookup the product specific 510 using `sql-get-product-feature' to lookup the product specific
505 settings.") 511 settings.")
506 512
507 (defvar sql-indirect-features 513 (defvar sql-indirect-features
508 '(:font-lock :sqli-program :sqli-options :sqli-login)) 514 '(:font-lock :sqli-program :sqli-options :sqli-login))
515
516 ;;;###autoload
517 (defcustom sql-connection-alist nil
518 "An alist of connection parameters for interacting with a SQL
519 product.
520
521 Each element of the alist is as follows:
522
523 \(CONNECTION \(SQL-VARIABLE VALUE) ...)
524
525 Where CONNECTION is a symbol identifying the connection, SQL-VARIABLE
526 is the symbol name of a SQL mode variable, and VALUE is the value to
527 be assigned to the variable.
528
529 The most common SQL-VARIABLE settings associated with a connection
530 are:
531
532 `sql-product'
533 `sql-user'
534 `sql-password'
535 `sql-port'
536 `sql-server'
537 `sql-database'
538
539 If a SQL-VARIABLE is part of the connection, it will not be
540 prompted for during login."
541
542 :type `(alist :key-type (symbol :tag "Connection")
543 :value-type
544 (set
545 (group (const :tag "Product" sql-product)
546 (choice
547 ,@(mapcar (lambda (prod-info)
548 `(const :tag
549 ,(or (plist-get (cdr prod-info) :name)
550 (capitalize (symbol-name (car prod-info))))
551 (quote ,(car prod-info))))
552 sql-product-alist)))
553 (group (const :tag "Username" sql-user) string)
554 (group (const :tag "Password" sql-password) string)
555 (group (const :tag "Server" sql-server) string)
556 (group (const :tag "Database" sql-database) string)
557 (group (const :tag "Port" sql-port) integer)))
558 :version "24.1"
559 :group 'SQL)
509 560
510 ;;;###autoload 561 ;;;###autoload
511 (defcustom sql-product 'ansi 562 (defcustom sql-product 'ansi
512 "Select the SQL database product used so that buffers can be 563 "Select the SQL database product used so that buffers can be
513 highlighted properly when you open them." 564 highlighted properly when you open them."
516 `(const :tag 567 `(const :tag
517 ,(or (plist-get (cdr prod-info) :name) 568 ,(or (plist-get (cdr prod-info) :name)
518 (capitalize (symbol-name (car prod-info)))) 569 (capitalize (symbol-name (car prod-info))))
519 ,(car prod-info))) 570 ,(car prod-info)))
520 sql-product-alist)) 571 sql-product-alist))
521 :group 'SQL) 572 :group 'SQL
522 (put 'sql-product 'safe-local-variable 'symbolp) 573 :safe 'symbolp)
523
524 (defvar sql-interactive-product nil
525 "Product under `sql-interactive-mode'.")
526 574
527 ;; misc customization of sql.el behaviour 575 ;; misc customization of sql.el behaviour
528 576
529 (defcustom sql-electric-stuff nil 577 (defcustom sql-electric-stuff nil
530 "Treat some input as electric. 578 "Treat some input as electric.
679 "List of login parameters needed to connect to Oracle." 727 "List of login parameters needed to connect to Oracle."
680 :type '(repeat (choice 728 :type '(repeat (choice
681 (const user) 729 (const user)
682 (const password) 730 (const password)
683 (const server) 731 (const server)
684 (const database))) 732 (const database)
733 (const port)))
685 :version "24.1" 734 :version "24.1"
686 :group 'SQL) 735 :group 'SQL)
687 736
688 (defcustom sql-oracle-scan-on t 737 (defcustom sql-oracle-scan-on t
689 "Non-nil if placeholders should be replaced in Oracle SQLi. 738 "Non-nil if placeholders should be replaced in Oracle SQLi.
719 "List of login parameters needed to connect to SQLite." 768 "List of login parameters needed to connect to SQLite."
720 :type '(repeat (choice 769 :type '(repeat (choice
721 (const user) 770 (const user)
722 (const password) 771 (const password)
723 (const server) 772 (const server)
724 (const database))) 773 (const database)
774 (const port)))
725 :version "24.1" 775 :version "24.1"
726 :group 'SQL) 776 :group 'SQL)
727 777
728 ;; Customization for MySql 778 ;; Customization for MySql
729 779
766 "List of login parameters needed to connect to Solid." 816 "List of login parameters needed to connect to Solid."
767 :type '(repeat (choice 817 :type '(repeat (choice
768 (const user) 818 (const user)
769 (const password) 819 (const password)
770 (const server) 820 (const server)
771 (const database))) 821 (const database)
822 (const port)))
772 :version "24.1" 823 :version "24.1"
773 :group 'SQL) 824 :group 'SQL)
774 825
775 ;; Customization for Sybase 826 ;; Customization for Sybase
776 827
792 "List of login parameters needed to connect to Sybase." 843 "List of login parameters needed to connect to Sybase."
793 :type '(repeat (choice 844 :type '(repeat (choice
794 (const user) 845 (const user)
795 (const password) 846 (const password)
796 (const server) 847 (const server)
797 (const database))) 848 (const database)
849 (const port)))
798 :version "24.1" 850 :version "24.1"
799 :group 'SQL) 851 :group 'SQL)
800 852
801 ;; Customization for Informix 853 ;; Customization for Informix
802 854
811 "List of login parameters needed to connect to Informix." 863 "List of login parameters needed to connect to Informix."
812 :type '(repeat (choice 864 :type '(repeat (choice
813 (const user) 865 (const user)
814 (const password) 866 (const password)
815 (const server) 867 (const server)
816 (const database))) 868 (const database)
869 (const port)))
817 :version "24.1" 870 :version "24.1"
818 :group 'SQL) 871 :group 'SQL)
819 872
820 ;; Customization for Ingres 873 ;; Customization for Ingres
821 874
830 "List of login parameters needed to connect to Ingres." 883 "List of login parameters needed to connect to Ingres."
831 :type '(repeat (choice 884 :type '(repeat (choice
832 (const user) 885 (const user)
833 (const password) 886 (const password)
834 (const server) 887 (const server)
835 (const database))) 888 (const database)
889 (const port)))
836 :version "24.1" 890 :version "24.1"
837 :group 'SQL) 891 :group 'SQL)
838 892
839 ;; Customization for Microsoft 893 ;; Customization for Microsoft
840 894
856 "List of login parameters needed to connect to Microsoft." 910 "List of login parameters needed to connect to Microsoft."
857 :type '(repeat (choice 911 :type '(repeat (choice
858 (const user) 912 (const user)
859 (const password) 913 (const password)
860 (const server) 914 (const server)
861 (const database))) 915 (const database)
916 (const port)))
862 :version "24.1" 917 :version "24.1"
863 :group 'SQL) 918 :group 'SQL)
864 919
865 ;; Customization for Postgres 920 ;; Customization for Postgres
866 921
887 "List of login parameters needed to connect to Postgres." 942 "List of login parameters needed to connect to Postgres."
888 :type '(repeat (choice 943 :type '(repeat (choice
889 (const user) 944 (const user)
890 (const password) 945 (const password)
891 (const server) 946 (const server)
892 (const database))) 947 (const database)
948 (const port)))
893 :version "24.1" 949 :version "24.1"
894 :group 'SQL) 950 :group 'SQL)
895 951
896 ;; Customization for Interbase 952 ;; Customization for Interbase
897 953
912 "List of login parameters needed to connect to Interbase." 968 "List of login parameters needed to connect to Interbase."
913 :type '(repeat (choice 969 :type '(repeat (choice
914 (const user) 970 (const user)
915 (const password) 971 (const password)
916 (const server) 972 (const server)
917 (const database))) 973 (const database)
974 (const port)))
918 :version "24.1" 975 :version "24.1"
919 :group 'SQL) 976 :group 'SQL)
920 977
921 ;; Customization for DB2 978 ;; Customization for DB2
922 979
937 "List of login parameters needed to connect to DB2." 994 "List of login parameters needed to connect to DB2."
938 :type '(repeat (choice 995 :type '(repeat (choice
939 (const user) 996 (const user)
940 (const password) 997 (const password)
941 (const server) 998 (const server)
942 (const database))) 999 (const database)
1000 (const port)))
943 :version "24.1" 1001 :version "24.1"
944 :group 'SQL) 1002 :group 'SQL)
945 1003
946 ;; Customization for Linter 1004 ;; Customization for Linter
947 1005
962 "Login parameters to needed to connect to Linter." 1020 "Login parameters to needed to connect to Linter."
963 :type '(repeat (choice 1021 :type '(repeat (choice
964 (const user) 1022 (const user)
965 (const password) 1023 (const password)
966 (const server) 1024 (const server)
967 (const database))) 1025 (const database)
1026 (const port)))
968 :version "24.1" 1027 :version "24.1"
969 :group 'SQL) 1028 :group 'SQL)
970 1029
971 1030
972 1031
1055 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer) 1114 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer)
1056 (get-buffer-process sql-buffer))] 1115 (get-buffer-process sql-buffer))]
1057 ["Send String" sql-send-string (and (buffer-live-p sql-buffer) 1116 ["Send String" sql-send-string (and (buffer-live-p sql-buffer)
1058 (get-buffer-process sql-buffer))] 1117 (get-buffer-process sql-buffer))]
1059 ["--" nil nil] 1118 ["--" nil nil]
1060 ["Start SQLi session" sql-product-interactive (sql-get-product-feature sql-product :sqli-connect-func)] 1119 ["Start SQLi session" sql-product-interactive (sql-get-product-feature sql-product :sqli-comint-func)]
1061 ["Show SQLi buffer" sql-show-sqli-buffer t] 1120 ["Show SQLi buffer" sql-show-sqli-buffer t]
1062 ["Set SQLi buffer" sql-set-sqli-buffer t] 1121 ["Set SQLi buffer" sql-set-sqli-buffer t]
1063 ["Pop to SQLi buffer after send" 1122 ["Pop to SQLi buffer after send"
1064 sql-toggle-pop-to-buffer-after-send-region 1123 sql-toggle-pop-to-buffer-after-send-region
1065 :style toggle 1124 :style toggle
2014 (symbolp v)) 2073 (symbolp v))
2015 (set v newvalue) 2074 (set v newvalue)
2016 (setcdr p (plist-put (cdr p) feature newvalue))) 2075 (setcdr p (plist-put (cdr p) feature newvalue)))
2017 (message "`%s' is not a known product; use `sql-add-product' to add it first." product)))) 2076 (message "`%s' is not a known product; use `sql-add-product' to add it first." product))))
2018 2077
2019 (defun sql-get-product-feature (product feature &optional fallback) 2078 (defun sql-get-product-feature (product feature &optional fallback not-indirect)
2020 "Lookup FEATURE associated with a SQL PRODUCT. 2079 "Lookup FEATURE associated with a SQL PRODUCT.
2021 2080
2022 If the FEATURE is nil for PRODUCT, and FALLBACK is specified, 2081 If the FEATURE is nil for PRODUCT, and FALLBACK is specified,
2023 then the FEATURE associated with the FALLBACK product is 2082 then the FEATURE associated with the FALLBACK product is
2024 returned. 2083 returned.
2084
2085 If the FEATURE is in the list `sql-indirect-features', and the
2086 NOT-INDIRECT parameter is not set, then the value of the symbol
2087 stored in the connect alist is returned.
2025 2088
2026 See `sql-product-alist' for a list of products and supported features." 2089 See `sql-product-alist' for a list of products and supported features."
2027 (let* ((p (assoc product sql-product-alist)) 2090 (let* ((p (assoc product sql-product-alist))
2028 (v (plist-get (cdr p) feature))) 2091 (v (plist-get (cdr p) feature)))
2029 2092
2034 (not (eq product fallback))) 2097 (not (eq product fallback)))
2035 (sql-get-product-feature fallback feature) 2098 (sql-get-product-feature fallback feature)
2036 2099
2037 (if (and 2100 (if (and
2038 (member feature sql-indirect-features) 2101 (member feature sql-indirect-features)
2102 (not not-indirect)
2039 (symbolp v)) 2103 (symbolp v))
2040 (symbol-value v) 2104 (symbol-value v)
2041 v)) 2105 v))
2042 (message "`%s' is not a known product; use `sql-add-product' to add it first." product)))) 2106 (message "`%s' is not a known product; use `sql-add-product' to add it first." product))))
2043 2107
2327 'sql-port-history))) 2391 'sql-port-history)))
2328 ((eq (car what) 'database) ; database 2392 ((eq (car what) 'database) ; database
2329 (setq sql-database 2393 (setq sql-database
2330 (read-from-minibuffer "Database: " sql-database nil nil 2394 (read-from-minibuffer "Database: " sql-database nil nil
2331 'sql-database-history)))) 2395 'sql-database-history))))
2396
2332 (setq what (cdr what)))) 2397 (setq what (cdr what))))
2333 2398
2334 (defun sql-find-sqli-buffer () 2399 (defun sql-find-sqli-buffer ()
2335 "Returns the current default SQLi buffer or nil. 2400 "Returns the current default SQLi buffer or nil.
2336 In order to qualify, the SQLi buffer must be alive, 2401 In order to qualify, the SQLi buffer must be alive,
2413 (message "%s has no SQLi buffer set." (buffer-name (current-buffer))) 2478 (message "%s has no SQLi buffer set." (buffer-name (current-buffer)))
2414 (if (null (get-buffer-process sql-buffer)) 2479 (if (null (get-buffer-process sql-buffer))
2415 (message "Buffer %s has no process." (buffer-name sql-buffer)) 2480 (message "Buffer %s has no process." (buffer-name sql-buffer))
2416 (message "Current SQLi buffer is %s." (buffer-name sql-buffer))))) 2481 (message "Current SQLi buffer is %s." (buffer-name sql-buffer)))))
2417 2482
2483 (defun sql--alt-buffer-part (delim part)
2484 (unless (string= "" part)
2485 (list delim part)))
2486
2487 (defun sql--alt-if-not-empty (s)
2488 (if (string= "" s) nil s))
2489
2418 (defun sql-make-alternate-buffer-name () 2490 (defun sql-make-alternate-buffer-name ()
2419 "Return a string that can be used to rename a SQLi buffer. 2491 "Return a string that can be used to rename a SQLi buffer.
2420 2492
2421 This is used to set `sql-alternate-buffer-name' within 2493 This is used to set `sql-alternate-buffer-name' within
2422 `sql-interactive-mode'." 2494 `sql-interactive-mode'.
2423 (concat (if (string= "" sql-user) 2495
2424 (if (string= "" (user-login-name)) 2496 If the session was started with `sql-connect' then the alternate
2425 () 2497 name would be the name of the connection.
2426 (concat (user-login-name) "/")) 2498
2427 (concat sql-user "/")) 2499 Otherwise, it uses the parameters identified by the :sqlilogin
2428 (if (string= "" sql-database) 2500 parameter.
2429 (if (string= "" sql-server) 2501
2430 (system-name) 2502 If all else fails, the alternate name would be the user and
2431 sql-server) 2503 server/database name."
2432 sql-database))) 2504
2505 (or
2506 ;; If started by sql-connect, use that
2507 (sql--alt-if-not-empty
2508 (when sql-connection (symbol-name sql-connection)))
2509
2510 ;; based on :sqli-login setting
2511 (sql--alt-if-not-empty
2512 (apply 'concat
2513 (cdr
2514 (apply 'append nil
2515 (mapcar
2516 (lambda (v)
2517 (cond
2518 ((eq v 'user) (sql--alt-buffer-part "/" sql-user))
2519 ((eq v 'server) (sql--alt-buffer-part "@" sql-server))
2520 ((eq v 'database) (sql--alt-buffer-part "@" sql-database))
2521 ((eq v 'port) (sql--alt-buffer-part ":" sql-port))
2522
2523 ((eq v 'password) nil)
2524 (t nil)))
2525 (sql-get-product-feature sql-product :sqli-login))))))
2526
2527 ;; Default: username/server format
2528 (sql--alt-if-not-empty
2529 (concat (if (string= "" sql-user)
2530 (if (string= "" (user-login-name))
2531 ()
2532 (concat (user-login-name) "/"))
2533 (concat sql-user "/"))
2534 (if (string= "" sql-database)
2535 (if (string= "" sql-server)
2536 (system-name)
2537 sql-server)
2538 sql-database)))))
2433 2539
2434 (defun sql-rename-buffer () 2540 (defun sql-rename-buffer ()
2435 "Rename a SQLi buffer." 2541 "Rename a SQLi buffer."
2436 (interactive) 2542 (interactive)
2437 (rename-buffer (format "*SQL: %s*" sql-alternate-buffer-name) t)) 2543 (rename-buffer (format "*SQL: %s*" sql-alternate-buffer-name) t))
2786 ;; by default. 2892 ;; by default.
2787 (setq local-abbrev-table sql-mode-abbrev-table) 2893 (setq local-abbrev-table sql-mode-abbrev-table)
2788 (setq abbrev-all-caps 1) 2894 (setq abbrev-all-caps 1)
2789 ;; Exiting the process will call sql-stop. 2895 ;; Exiting the process will call sql-stop.
2790 (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop) 2896 (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop)
2897 ;; Save the connection name
2898 (make-local-variable 'sql-connection)
2791 ;; Create a usefull name for renaming this buffer later. 2899 ;; Create a usefull name for renaming this buffer later.
2792 (make-local-variable 'sql-alternate-buffer-name) 2900 (make-local-variable 'sql-alternate-buffer-name)
2793 (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name)) 2901 (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name))
2794 ;; User stuff. Initialize before the hook. 2902 ;; User stuff. Initialize before the hook.
2795 (set (make-local-variable 'sql-prompt-regexp) 2903 (set (make-local-variable 'sql-prompt-regexp)
2852 nil 'require-match 2960 nil 'require-match
2853 (or (and sql-product (symbol-name sql-product)) "ansi")))) 2961 (or (and sql-product (symbol-name sql-product)) "ansi"))))
2854 ((symbolp product) product) ; Product specified 2962 ((symbolp product) product) ; Product specified
2855 (t sql-product))) ; Default to sql-product 2963 (t sql-product))) ; Default to sql-product
2856 2964
2857 (when (sql-get-product-feature product :sqli-connect-func) 2965 (when (sql-get-product-feature product :sqli-comint-func)
2858 (if (and sql-buffer 2966 (if (and sql-buffer
2859 (buffer-live-p sql-buffer) 2967 (buffer-live-p sql-buffer)
2860 (comint-check-proc sql-buffer)) 2968 (comint-check-proc sql-buffer))
2861 (pop-to-buffer sql-buffer) 2969 (pop-to-buffer sql-buffer)
2862 2970
2880 ;; Get credentials. 2988 ;; Get credentials.
2881 (apply 'sql-get-login (sql-get-product-feature product :sqli-login)) 2989 (apply 'sql-get-login (sql-get-product-feature product :sqli-login))
2882 2990
2883 ;; Connect to database. 2991 ;; Connect to database.
2884 (message "Login...") 2992 (message "Login...")
2885 (funcall (sql-get-product-feature product :sqli-connect-func) 2993 (funcall (sql-get-product-feature product :sqli-comint-func)
2886 product 2994 product
2887 (sql-get-product-feature product :sqli-options)) 2995 (sql-get-product-feature product :sqli-options))
2888 2996
2889 ;; Set SQLi mode. 2997 ;; Set SQLi mode.
2890 (setq sql-interactive-product product 2998 (setq sql-interactive-product product
2899 3007
2900 ;; All done. 3008 ;; All done.
2901 (message "Login...done") 3009 (message "Login...done")
2902 (pop-to-buffer sql-buffer))))) 3010 (pop-to-buffer sql-buffer)))))
2903 3011
2904 (defun sql-connect (product params) 3012 (defun sql-comint (product params)
2905 "Set up a comint buffer to connect to the SQL processor. 3013 "Set up a comint buffer to run the SQL processor.
2906 3014
2907 PRODUCT is the SQL product. PARAMS is a list of strings which are 3015 PRODUCT is the SQL product. PARAMS is a list of strings which are
2908 passed as command line arguments." 3016 passed as command line arguments."
2909 (let ((program (sql-get-product-feature product :sqli-program))) 3017 (let ((program (sql-get-product-feature product :sqli-program)))
2910 (set-buffer 3018 (set-buffer
2911 (if params 3019 (apply 'make-comint "SQL" program nil params))))
2912 (apply 'make-comint "SQL" program nil params) 3020
2913 (make-comint "SQL" program nil))))) 3021 ;;;###autoload
3022 (defun sql-connect (connection)
3023 "Connect to an interactive session using CONNECTION settings.
3024
3025 See `sql-connection-alist' to see how to define connections and
3026 their settings.
3027
3028 The user will not be prompted for any login parameters if a value
3029 is specified in the connection settings."
3030
3031 ;; Prompt for the connection from those defined in the alist
3032 (interactive
3033 (if sql-connection-alist
3034 (list
3035 (intern
3036 (completing-read "Connection: "
3037 (mapcar (lambda (c) (symbol-name (car c)))
3038 sql-connection-alist)
3039 nil t)))
3040 nil))
3041
3042 ;; Are there connections defined
3043 (if sql-connection-alist
3044 ;; Was one selected
3045 (when connection
3046 ;; Get connection settings
3047 (let ((connect-set (aget sql-connection-alist connection)))
3048 ;; Settings are defined
3049 (if connect-set
3050 ;; Set the desired parameters
3051 (eval `(let*
3052 (,@connect-set
3053 ;; :sqli-login params variable
3054 (param-var (sql-get-product-feature sql-product
3055 :sqli-login nil t))
3056 ;; :sqli-login params value
3057 (login-params (sql-get-product-feature sql-product
3058 :sqli-login))
3059 ;; which params are in the connection
3060 (set-params (mapcar
3061 (lambda (v)
3062 (cond
3063 ((eq (car v) 'sql-user) 'user)
3064 ((eq (car v) 'sql-password) 'password)
3065 ((eq (car v) 'sql-server) 'server)
3066 ((eq (car v) 'sql-database) 'database)
3067 ((eq (car v) 'sql-port) 'port)
3068 (t (car v))))
3069 connect-set))
3070 ;; the remaining params (w/o the connection params)
3071 (rem-params (apply 'append nil
3072 (mapcar
3073 (lambda (l)
3074 (unless (member l set-params)
3075 (list l)))
3076 login-params)))
3077 ;; Remember the connection
3078 (sql-connection connection))
3079
3080 ;; Set the remaining parameters and start the
3081 ;; interactive session
3082 (eval `(let ((,param-var ',rem-params))
3083 (sql-product-interactive sql-product)))))
3084 (message "SQL Connection \"%s\" does not exist" connection)
3085 nil)))
3086 (message "No SQL Connections defined")
3087 nil))
2914 3088
2915 ;;;###autoload 3089 ;;;###autoload
2916 (defun sql-oracle () 3090 (defun sql-oracle ()
2917 "Run sqlplus by Oracle as an inferior process. 3091 "Run sqlplus by Oracle as an inferior process.
2918 3092
2937 3111
2938 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 3112 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2939 (interactive) 3113 (interactive)
2940 (sql-product-interactive 'oracle)) 3114 (sql-product-interactive 'oracle))
2941 3115
2942 (defun sql-connect-oracle (product options) 3116 (defun sql-comint-oracle (product options)
2943 "Create comint buffer and connect to Oracle." 3117 "Create comint buffer and connect to Oracle."
2944 ;; Produce user/password@database construct. Password without user 3118 ;; Produce user/password@database construct. Password without user
2945 ;; is meaningless; database without user/password is meaningless, 3119 ;; is meaningless; database without user/password is meaningless,
2946 ;; because "@param" will ask sqlplus to interpret the script 3120 ;; because "@param" will ask sqlplus to interpret the script
2947 ;; "param". 3121 ;; "param".
2953 (if (and parameter (not (string= "" sql-database))) 3127 (if (and parameter (not (string= "" sql-database)))
2954 (setq parameter (concat parameter "@" sql-database))) 3128 (setq parameter (concat parameter "@" sql-database)))
2955 (if parameter 3129 (if parameter
2956 (setq parameter (nconc (list parameter) options)) 3130 (setq parameter (nconc (list parameter) options))
2957 (setq parameter options)) 3131 (setq parameter options))
2958 (sql-connect product parameter))) 3132 (sql-comint product parameter)))
2959 3133
2960 3134
2961 3135
2962 ;;;###autoload 3136 ;;;###autoload
2963 (defun sql-sybase () 3137 (defun sql-sybase ()
2984 3158
2985 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 3159 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2986 (interactive) 3160 (interactive)
2987 (sql-product-interactive 'sybase)) 3161 (sql-product-interactive 'sybase))
2988 3162
2989 (defun sql-connect-sybase (product options) 3163 (defun sql-comint-sybase (product options)
2990 "Create comint buffer and connect to Sybase." 3164 "Create comint buffer and connect to Sybase."
2991 ;; Put all parameters to the program (if defined) in a list and call 3165 ;; Put all parameters to the program (if defined) in a list and call
2992 ;; make-comint. 3166 ;; make-comint.
2993 (let ((params options)) 3167 (let ((params options))
2994 (if (not (string= "" sql-server)) 3168 (if (not (string= "" sql-server))
2997 (setq params (append (list "-D" sql-database) params))) 3171 (setq params (append (list "-D" sql-database) params)))
2998 (if (not (string= "" sql-password)) 3172 (if (not (string= "" sql-password))
2999 (setq params (append (list "-P" sql-password) params))) 3173 (setq params (append (list "-P" sql-password) params)))
3000 (if (not (string= "" sql-user)) 3174 (if (not (string= "" sql-user))
3001 (setq params (append (list "-U" sql-user) params))) 3175 (setq params (append (list "-U" sql-user) params)))
3002 (sql-connect product params))) 3176 (sql-comint product params)))
3003 3177
3004 3178
3005 3179
3006 ;;;###autoload 3180 ;;;###autoload
3007 (defun sql-informix () 3181 (defun sql-informix ()
3026 3200
3027 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 3201 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3028 (interactive) 3202 (interactive)
3029 (sql-product-interactive 'informix)) 3203 (sql-product-interactive 'informix))
3030 3204
3031 (defun sql-connect-informix (product options) 3205 (defun sql-comint-informix (product options)
3032 "Create comint buffer and connect to Informix." 3206 "Create comint buffer and connect to Informix."
3033 ;; username and password are ignored. 3207 ;; username and password are ignored.
3034 (let ((db (if (string= "" sql-database) 3208 (let ((db (if (string= "" sql-database)
3035 "-" 3209 "-"
3036 (if (string= "" sql-server) 3210 (if (string= "" sql-server)
3037 sql-database 3211 sql-database
3038 (concat sql-database "@" sql-server))))) 3212 (concat sql-database "@" sql-server)))))
3039 (sql-connect product (append `(,db "-") options)))) 3213 (sql-comint product (append `(,db "-") options))))
3040 3214
3041 3215
3042 3216
3043 ;;;###autoload 3217 ;;;###autoload
3044 (defun sql-sqlite () 3218 (defun sql-sqlite ()
3067 3241
3068 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 3242 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3069 (interactive) 3243 (interactive)
3070 (sql-product-interactive 'sqlite)) 3244 (sql-product-interactive 'sqlite))
3071 3245
3072 (defun sql-connect-sqlite (product options) 3246 (defun sql-comint-sqlite (product options)
3073 "Create comint buffer and connect to SQLite." 3247 "Create comint buffer and connect to SQLite."
3074 ;; Put all parameters to the program (if defined) in a list and call 3248 ;; Put all parameters to the program (if defined) in a list and call
3075 ;; make-comint. 3249 ;; make-comint.
3076 (let ((params)) 3250 (let ((params))
3077 (if (not (string= "" sql-database)) 3251 (if (not (string= "" sql-database))
3078 (setq params (append (list sql-database) params))) 3252 (setq params (append (list sql-database) params)))
3079 (setq params (append options params)) 3253 (setq params (append options params))
3080 (sql-connect product params))) 3254 (sql-comint product params)))
3081 3255
3082 3256
3083 3257
3084 ;;;###autoload 3258 ;;;###autoload
3085 (defun sql-mysql () 3259 (defun sql-mysql ()
3108 3282
3109 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 3283 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3110 (interactive) 3284 (interactive)
3111 (sql-product-interactive 'mysql)) 3285 (sql-product-interactive 'mysql))
3112 3286
3113 (defun sql-connect-mysql (product options) 3287 (defun sql-comint-mysql (product options)
3114 "Create comint buffer and connect to MySQL." 3288 "Create comint buffer and connect to MySQL."
3115 ;; Put all parameters to the program (if defined) in a list and call 3289 ;; Put all parameters to the program (if defined) in a list and call
3116 ;; make-comint. 3290 ;; make-comint.
3117 (let ((params)) 3291 (let ((params))
3118 (if (not (string= "" sql-database)) 3292 (if (not (string= "" sql-database))
3124 (if (not (string= "" sql-password)) 3298 (if (not (string= "" sql-password))
3125 (setq params (append (list (concat "--password=" sql-password)) params))) 3299 (setq params (append (list (concat "--password=" sql-password)) params)))
3126 (if (not (string= "" sql-user)) 3300 (if (not (string= "" sql-user))
3127 (setq params (append (list (concat "--user=" sql-user)) params))) 3301 (setq params (append (list (concat "--user=" sql-user)) params)))
3128 (setq params (append options params)) 3302 (setq params (append options params))
3129 (sql-connect product params))) 3303 (sql-comint product params)))
3130 3304
3131 3305
3132 3306
3133 ;;;###autoload 3307 ;;;###autoload
3134 (defun sql-solid () 3308 (defun sql-solid ()
3154 3328
3155 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 3329 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3156 (interactive) 3330 (interactive)
3157 (sql-product-interactive 'solid)) 3331 (sql-product-interactive 'solid))
3158 3332
3159 (defun sql-connect-solid (product options) 3333 (defun sql-comint-solid (product options)
3160 "Create comint buffer and connect to Solid." 3334 "Create comint buffer and connect to Solid."
3161 ;; Put all parameters to the program (if defined) in a list and call 3335 ;; Put all parameters to the program (if defined) in a list and call
3162 ;; make-comint. 3336 ;; make-comint.
3163 (let ((params options)) 3337 (let ((params options))
3164 ;; It only makes sense if both username and password are there. 3338 ;; It only makes sense if both username and password are there.
3165 (if (not (or (string= "" sql-user) 3339 (if (not (or (string= "" sql-user)
3166 (string= "" sql-password))) 3340 (string= "" sql-password)))
3167 (setq params (append (list sql-user sql-password) params))) 3341 (setq params (append (list sql-user sql-password) params)))
3168 (if (not (string= "" sql-server)) 3342 (if (not (string= "" sql-server))
3169 (setq params (append (list sql-server) params))) 3343 (setq params (append (list sql-server) params)))
3170 (sql-connect product params))) 3344 (sql-comint product params)))
3171 3345
3172 3346
3173 3347
3174 ;;;###autoload 3348 ;;;###autoload
3175 (defun sql-ingres () 3349 (defun sql-ingres ()
3194 3368
3195 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 3369 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3196 (interactive) 3370 (interactive)
3197 (sql-product-interactive 'ingres)) 3371 (sql-product-interactive 'ingres))
3198 3372
3199 (defun sql-connect-ingres (product options) 3373 (defun sql-comint-ingres (product options)
3200 "Create comint buffer and connect to Ingres." 3374 "Create comint buffer and connect to Ingres."
3201 ;; username and password are ignored. 3375 ;; username and password are ignored.
3202 (sql-connect product 3376 (sql-comint product
3203 (append (if (string= "" sql-database) 3377 (append (if (string= "" sql-database)
3204 nil 3378 nil
3205 (list sql-database)) 3379 (list sql-database))
3206 options))) 3380 options)))
3207 3381
3232 3406
3233 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 3407 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3234 (interactive) 3408 (interactive)
3235 (sql-product-interactive 'ms)) 3409 (sql-product-interactive 'ms))
3236 3410
3237 (defun sql-connect-ms (product options) 3411 (defun sql-comint-ms (product options)
3238 "Create comint buffer and connect to Microsoft SQL Server." 3412 "Create comint buffer and connect to Microsoft SQL Server."
3239 ;; Put all parameters to the program (if defined) in a list and call 3413 ;; Put all parameters to the program (if defined) in a list and call
3240 ;; make-comint. 3414 ;; make-comint.
3241 (let ((params options)) 3415 (let ((params options))
3242 (if (not (string= "" sql-server)) 3416 (if (not (string= "" sql-server))
3252 ;; credentials. 3426 ;; credentials.
3253 (setq params (append (list "-E") params)) 3427 (setq params (append (list "-E") params))
3254 ;; If -P is passed to ISQL as the last argument without a 3428 ;; If -P is passed to ISQL as the last argument without a
3255 ;; password, it's considered null. 3429 ;; password, it's considered null.
3256 (setq params (append params (list "-P"))))) 3430 (setq params (append params (list "-P")))))
3257 (sql-connect product params))) 3431 (sql-comint product params)))
3258 3432
3259 3433
3260 3434
3261 ;;;###autoload 3435 ;;;###autoload
3262 (defun sql-postgres () 3436 (defun sql-postgres ()
3288 3462
3289 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 3463 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3290 (interactive) 3464 (interactive)
3291 (sql-product-interactive 'postgres)) 3465 (sql-product-interactive 'postgres))
3292 3466
3293 (defun sql-connect-postgres (product options) 3467 (defun sql-comint-postgres (product options)
3294 "Create comint buffer and connect to Postgres." 3468 "Create comint buffer and connect to Postgres."
3295 ;; username and password are ignored. Mark Stosberg suggest to add 3469 ;; username and password are ignored. Mark Stosberg suggest to add
3296 ;; the database at the end. Jason Beegan suggest using --pset and 3470 ;; the database at the end. Jason Beegan suggest using --pset and
3297 ;; pager=off instead of \\o|cat. The later was the solution by 3471 ;; pager=off instead of \\o|cat. The later was the solution by
3298 ;; Gregor Zych. Jason's suggestion is the default value for 3472 ;; Gregor Zych. Jason's suggestion is the default value for
3302 (setq params (append params (list sql-database)))) 3476 (setq params (append params (list sql-database))))
3303 (if (not (string= "" sql-server)) 3477 (if (not (string= "" sql-server))
3304 (setq params (append (list "-h" sql-server) params))) 3478 (setq params (append (list "-h" sql-server) params)))
3305 (if (not (string= "" sql-user)) 3479 (if (not (string= "" sql-user))
3306 (setq params (append (list "-U" sql-user) params))) 3480 (setq params (append (list "-U" sql-user) params)))
3307 (sql-connect product params))) 3481 (sql-comint product params)))
3308 3482
3309 3483
3310 3484
3311 ;;;###autoload 3485 ;;;###autoload
3312 (defun sql-interbase () 3486 (defun sql-interbase ()
3332 3506
3333 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 3507 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3334 (interactive) 3508 (interactive)
3335 (sql-product-interactive 'interbase)) 3509 (sql-product-interactive 'interbase))
3336 3510
3337 (defun sql-connect-interbase (product options) 3511 (defun sql-comint-interbase (product options)
3338 "Create comint buffer and connect to Interbase." 3512 "Create comint buffer and connect to Interbase."
3339 ;; Put all parameters to the program (if defined) in a list and call 3513 ;; Put all parameters to the program (if defined) in a list and call
3340 ;; make-comint. 3514 ;; make-comint.
3341 (let ((params options)) 3515 (let ((params options))
3342 (if (not (string= "" sql-user)) 3516 (if (not (string= "" sql-user))
3343 (setq params (append (list "-u" sql-user) params))) 3517 (setq params (append (list "-u" sql-user) params)))
3344 (if (not (string= "" sql-password)) 3518 (if (not (string= "" sql-password))
3345 (setq params (append (list "-p" sql-password) params))) 3519 (setq params (append (list "-p" sql-password) params)))
3346 (if (not (string= "" sql-database)) 3520 (if (not (string= "" sql-database))
3347 (setq params (cons sql-database params))) ; add to the front! 3521 (setq params (cons sql-database params))) ; add to the front!
3348 (sql-connect product params))) 3522 (sql-comint product params)))
3349 3523
3350 3524
3351 3525
3352 ;;;###autoload 3526 ;;;###autoload
3353 (defun sql-db2 () 3527 (defun sql-db2 ()
3377 3551
3378 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 3552 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3379 (interactive) 3553 (interactive)
3380 (sql-product-interactive 'db2)) 3554 (sql-product-interactive 'db2))
3381 3555
3382 (defun sql-connect-db2 (product options) 3556 (defun sql-comint-db2 (product options)
3383 "Create comint buffer and connect to DB2." 3557 "Create comint buffer and connect to DB2."
3384 ;; Put all parameters to the program (if defined) in a list and call 3558 ;; Put all parameters to the program (if defined) in a list and call
3385 ;; make-comint. 3559 ;; make-comint.
3386 (sql-connect product options) 3560 (sql-comint product options)
3387 ) 3561 )
3388 ;; ;; Properly escape newlines when DB2 is interactive. 3562 ;; ;; Properly escape newlines when DB2 is interactive.
3389 ;; (setq comint-input-sender 'sql-escape-newlines-and-send)) 3563 ;; (setq comint-input-sender 'sql-escape-newlines-and-send))
3390 3564
3391 ;;;###autoload 3565 ;;;###autoload
3413 3587
3414 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 3588 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3415 (interactive) 3589 (interactive)
3416 (sql-product-interactive 'linter)) 3590 (sql-product-interactive 'linter))
3417 3591
3418 (defun sql-connect-linter (product options) 3592 (defun sql-comint-linter (product options)
3419 "Create comint buffer and connect to Linter." 3593 "Create comint buffer and connect to Linter."
3420 ;; Put all parameters to the program (if defined) in a list and call 3594 ;; Put all parameters to the program (if defined) in a list and call
3421 ;; make-comint. 3595 ;; make-comint.
3422 (let ((params options) 3596 (let ((params options)
3423 (login nil) 3597 (login nil)
3428 (if (not (string= "" sql-server)) 3602 (if (not (string= "" sql-server))
3429 (setq params (append (list "-n" sql-server) params))) 3603 (setq params (append (list "-n" sql-server) params)))
3430 (if (string= "" sql-database) 3604 (if (string= "" sql-database)
3431 (setenv "LINTER_MBX" nil) 3605 (setenv "LINTER_MBX" nil)
3432 (setenv "LINTER_MBX" sql-database)) 3606 (setenv "LINTER_MBX" sql-database))
3433 (sql-connect product params) 3607 (sql-comint product params)
3434 (setenv "LINTER_MBX" old-mbx))) 3608 (setenv "LINTER_MBX" old-mbx)))
3435 3609
3436 3610
3437 3611
3438 (provide 'sql) 3612 (provide 'sql)