Mercurial > emacs
comparison lisp/progmodes/sql.el @ 108381:aa05f2497948
SQL mode version 2.1
Redesigned product specific definition and handling. Includes many
bug fixes and enhancements.
author | Michael Mauger <mmaug@yahoo.com> |
---|---|
date | Sun, 09 May 2010 22:07:58 -0400 |
parents | cf2043af9228 |
children | 6e7ebe021a2c |
comparison
equal
deleted
inserted
replaced
108380:72fc67fa8fe3 | 108381:aa05f2497948 |
---|---|
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.0.2 | 8 ;; Version: 2.1 |
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. |
101 ;; Quoted identifiers are not supported for hilighting. Most | 101 ;; Quoted identifiers are not supported for hilighting. Most |
102 ;; databases support the use of double quoted strings in place of | 102 ;; databases support the use of double quoted strings in place of |
103 ;; identifiers; ms (Microsoft SQLServer) also supports identifiers | 103 ;; identifiers; ms (Microsoft SQLServer) also supports identifiers |
104 ;; enclosed within brackets []. | 104 ;; enclosed within brackets []. |
105 | 105 |
106 ;; ChangeLog available on request. | |
107 | |
108 ;;; Product Support: | 106 ;;; Product Support: |
109 | 107 |
110 ;; To add support for additional SQL products the following steps | 108 ;; To add support for additional SQL products the following steps |
111 ;; must be followed ("xyz" is the name of the product in the examples | 109 ;; must be followed ("xyz" is the name of the product in the examples |
112 ;; below): | 110 ;; below): |
113 | 111 |
114 ;; 1) Add the product to `sql-product' choice list. | 112 ;; 1) Add the product to the list of known products. |
115 | 113 |
116 ;; (const :tag "XyzDB" xyz) | 114 ;; (sql-add-product 'xyz "XyzDB" |
117 | 115 ;; '(:free-software t)) |
118 ;; 2) Add an entry to the `sql-product-alist' list. | 116 |
119 | 117 ;; 2) Define font lock settings. All ANSI keywords will be |
120 ;; (xyz | 118 ;; highlighted automatically, so only product specific keywords |
121 ;; :font-lock sql-mode-xyz-font-lock-keywords | 119 ;; need to be defined here. |
122 ;; :sqli-login (user password server database) | 120 |
123 ;; :sqli-connect sql-connect-xyz | 121 ;; (defvar my-sql-mode-xyz-font-lock-keywords |
124 ;; :sqli-prompt-regexp "^xyzdb> " | 122 ;; '(("\\b\\(red\\|orange\\|yellow\\)\\b" |
125 ;; :sqli-prompt-length 7 | 123 ;; . font-lock-keyword-face)) |
126 ;; :sqli-input-sender nil | 124 ;; "XyzDB SQL keywords used by font-lock.") |
127 ;; :syntax-alist ((?# . "w"))) | 125 |
128 | 126 ;; (sql-set-product-feature 'xyz |
129 ;; 3) Add customizable values for the product interpreter and options. | 127 ;; :font-lock |
130 | 128 ;; 'my-sql-mode-xyz-font-lock-keywords) |
131 ;; ;; Customization for XyzDB | 129 |
132 ;; | 130 ;; 3) Define any special syntax characters including comments and |
133 ;; (defcustom sql-xyz-program "ixyz" | 131 ;; identifier characters. |
134 ;; "*Command to start ixyz by XyzDB." | 132 |
133 ;; (sql-set-product-feature 'xyz | |
134 ;; :syntax-alist ((?# . "w"))) | |
135 | |
136 ;; 4) Define the interactive command interpreter for the database | |
137 ;; product. | |
138 | |
139 ;; (defcustom my-sql-xyz-program "ixyz" | |
140 ;; "Command to start ixyz by XyzDB." | |
135 ;; :type 'file | 141 ;; :type 'file |
136 ;; :group 'SQL) | 142 ;; :group 'SQL) |
137 ;; | 143 ;; |
138 ;; (defcustom sql-xyz-options '("-X" "-Y" "-Z") | 144 ;; (sql-set-product-feature 'xyz |
139 ;; "*List of additional options for `sql-xyz-program'." | 145 ;; :sqli-program 'my-sql-xyz-program) |
146 ;; (sql-set-product-feature 'xyz | |
147 ;; :prompt-regexp "^xyzdb> ") | |
148 ;; (sql-set-product-feature 'xyz | |
149 ;; :prompt-length 7) | |
150 | |
151 ;; 5) Define login parameters and command line formatting. | |
152 | |
153 ;; (defcustom my-sql-xyz-login-params '(user password server database) | |
154 ;; "Login parameters to needed to connect to XyzDB." | |
155 ;; :type '(repeat (choice | |
156 ;; (const user) | |
157 ;; (const password) | |
158 ;; (const server) | |
159 ;; (const database))) | |
160 ;; :group 'SQL) | |
161 ;; | |
162 ;; (sql-set-product-feature 'xyz | |
163 ;; :sqli-login 'my-sql-xyz-login-params) | |
164 | |
165 ;; (defcustom my-sql-xyz-options '("-X" "-Y" "-Z") | |
166 ;; "List of additional options for `sql-xyz-program'." | |
140 ;; :type '(repeat string) | 167 ;; :type '(repeat string) |
141 ;; :group 'SQL) | 168 ;; :group 'SQL) |
142 | 169 ;; |
143 ;; 4) Add an entry to SQL->Product submenu. | 170 ;; (sql-set-product-feature 'xyz |
144 | 171 ;; :sqli-options 'my-sql-xyz-options)) |
145 ;; ["XyzDB" sql-highlight-xyz-keywords | 172 |
146 ;; :style radio | 173 ;; (defun my-sql-connect-xyz (product options) |
147 ;; :selected (eq sql-product 'xyz)] | 174 ;; "Connect ti XyzDB in a comint buffer." |
148 | |
149 ;; 5) Add the font-lock specifications. At a minimum, default to | |
150 ;; using ANSI keywords. See sql-mode-oracle-font-lock-keywords for | |
151 ;; a more complex example. | |
152 | |
153 ;; (defvar sql-mode-xyz-font-lock-keywords nil | |
154 ;; "XyzDB SQL keywords used by font-lock.") | |
155 | |
156 ;; 6) Add a product highlighting function. | |
157 | |
158 ;; (defun sql-highlight-xyz-keywords () | |
159 ;; "Highlight XyzDB keywords." | |
160 ;; (interactive) | |
161 ;; (sql-set-product 'xyz)) | |
162 | |
163 ;; 7) Add an autoloaded SQLi function. | |
164 | |
165 ;; ;;;###autoload | |
166 ;; (defun sql-xyz () | |
167 ;; "Run ixyz by XyzDB as an inferior process." | |
168 ;; (interactive) | |
169 ;; (sql-product-interactive 'xyz)) | |
170 | |
171 ;; 8) Add a connect function which formats the command line arguments | |
172 ;; and starts the product interpreter in a comint buffer. See the | |
173 ;; existing connect functions for examples of the types of | |
174 ;; processing available. | |
175 | |
176 ;; (defun sql-connect-xyz () | |
177 ;; "Create comint buffer and connect to XyzDB using the login | |
178 ;; parameters and command options." | |
179 ;; | 175 ;; |
180 ;; ;; Do something with `sql-user', `sql-password', | 176 ;; ;; Do something with `sql-user', `sql-password', |
181 ;; ;; `sql-database', and `sql-server'. | 177 ;; ;; `sql-database', and `sql-server'. |
182 ;; (let ((params sql-xyz-options)) | 178 ;; (let ((params options)) |
183 ;; (if (not (string= "" sql-server)) | 179 ;; (if (not (string= "" sql-server)) |
184 ;; (setq params (append (list "-S" sql-server) params))) | 180 ;; (setq params (append (list "-S" sql-server) params))) |
185 ;; (if (not (string= "" sql-database)) | 181 ;; (if (not (string= "" sql-database)) |
186 ;; (setq params (append (list "-D" sql-database) params))) | 182 ;; (setq params (append (list "-D" sql-database) params))) |
187 ;; (if (not (string= "" sql-password)) | 183 ;; (if (not (string= "" sql-password)) |
188 ;; (setq params (append (list "-P" sql-password) params))) | 184 ;; (setq params (append (list "-P" sql-password) params))) |
189 ;; (if (not (string= "" sql-user)) | 185 ;; (if (not (string= "" sql-user)) |
190 ;; (setq params (append (list "-U" sql-user) params))) | 186 ;; (setq params (append (list "-U" sql-user) params))) |
191 ;; (set-buffer (apply 'make-comint "SQL" sql-xyz-program | 187 ;; (sql-connect product params))) |
192 ;; nil params)))) | 188 ;; |
193 | 189 ;; (sql-set-product-feature 'xyz |
194 ;; 9) Save and compile sql.el. | 190 ;; :sqli-connect-func 'my-sql-connect-xyz) |
191 | |
192 ;; 6) Define a convienence function to invoke the SQL interpreter. | |
193 | |
194 ;; (defun my-sql-xyz () | |
195 ;; "Run ixyz by XyzDB as an inferior process." | |
196 ;; (interactive) | |
197 ;; (sql-product-interactive 'xyz)) | |
195 | 198 |
196 ;;; To Do: | 199 ;;; To Do: |
197 | 200 |
198 ;; Add better hilight support for other brands; there is a bias towards | 201 ;; Improve keyword highlighting for individual products. I have tried |
199 ;; Oracle because that's what I use at work. Anybody else just send in | 202 ;; to update those database that I use. Feel free to send me updates, |
200 ;; your lists of reserved words, keywords and builtin functions! As | 203 ;; or direct me to the reference manuals for your favorite database. |
201 ;; long as I don't receive any feedback, everything is hilighted with | 204 |
202 ;; ANSI keywords only. I received the list of ANSI keywords from a | 205 ;; When there are no keywords defined, the ANSI keywords are |
203 ;; user; if you know of any changes, let me know. | 206 ;; highlighted. ANSI keywords are highlighted even if the keyword is |
204 | 207 ;; not used for your current product. This should help identify |
205 ;; Add different hilighting levels. | 208 ;; portability concerns. |
209 | |
210 ;; Add different highlighting levels. | |
211 | |
212 ;; Add support for listing available tables or the columns in a table. | |
206 | 213 |
207 ;;; Thanks to all the people who helped me out: | 214 ;;; Thanks to all the people who helped me out: |
208 | 215 |
209 ;; Alex Schroeder <alex@gnu.org> | 216 ;; Alex Schroeder <alex@gnu.org> -- the original author |
210 ;; Kai Blauberg <kai.blauberg@metla.fi> | 217 ;; Kai Blauberg <kai.blauberg@metla.fi> |
211 ;; <ibalaban@dalet.com> | 218 ;; <ibalaban@dalet.com> |
212 ;; Yair Friedman <yfriedma@JohnBryce.Co.Il> | 219 ;; Yair Friedman <yfriedma@JohnBryce.Co.Il> |
213 ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de> | 220 ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de> |
214 ;; nino <nino@inform.dk> | 221 ;; nino <nino@inform.dk> |
215 ;; Berend de Boer <berend@pobox.com> | 222 ;; Berend de Boer <berend@pobox.com> |
216 ;; Adam Jenkins <adam@thejenkins.org> | 223 ;; Adam Jenkins <adam@thejenkins.org> |
217 ;; Michael Mauger <mmaug@yahoo.com> -- improved product support | 224 ;; Michael Mauger <mmaug@yahoo.com> -- improved product support |
218 ;; Drew Adams <drew.adams@oracle.com> -- Emacs 20 support | 225 ;; Drew Adams <drew.adams@oracle.com> -- Emacs 20 support |
219 ;; Harald Maier <maierh@myself.com> -- sql-send-string | 226 ;; Harald Maier <maierh@myself.com> -- sql-send-string |
220 ;; Stefan Monnier <monnier@iro.umontreal.ca> -- font-lock corrections | 227 ;; Stefan Monnier <monnier@iro.umontreal.ca> -- font-lock corrections; code polish |
221 | 228 |
222 | 229 |
223 | 230 |
224 ;;; Code: | 231 ;;; Code: |
225 | 232 |
238 ;;; Allow customization | 245 ;;; Allow customization |
239 | 246 |
240 (defgroup SQL nil | 247 (defgroup SQL nil |
241 "Running a SQL interpreter from within Emacs buffers." | 248 "Running a SQL interpreter from within Emacs buffers." |
242 :version "20.4" | 249 :version "20.4" |
250 :group 'languages | |
243 :group 'processes) | 251 :group 'processes) |
244 | 252 |
245 ;; These four variables will be used as defaults, if set. | 253 ;; These four variables will be used as defaults, if set. |
246 | 254 |
247 (defcustom sql-user "" | 255 (defcustom sql-user "" |
248 "*Default username." | 256 "Default username." |
249 :type 'string | 257 :type 'string |
250 :group 'SQL) | 258 :group 'SQL) |
259 (put 'sql-user 'safe-local-variable 'stringp) | |
251 | 260 |
252 (defcustom sql-password "" | 261 (defcustom sql-password "" |
253 "*Default password. | 262 "Default password. |
254 | 263 |
255 Storing your password in a textfile such as ~/.emacs could be dangerous. | 264 Storing your password in a textfile such as ~/.emacs could be dangerous. |
256 Customizing your password will store it in your ~/.emacs file." | 265 Customizing your password will store it in your ~/.emacs file." |
257 :type 'string | 266 :type 'string |
258 :group 'SQL) | 267 :group 'SQL) |
268 (put 'sql-password 'risky-local-variable t) | |
259 | 269 |
260 (defcustom sql-database "" | 270 (defcustom sql-database "" |
261 "*Default database." | 271 "Default database." |
262 :type 'string | 272 :type 'string |
263 :group 'SQL) | 273 :group 'SQL) |
274 (put 'sql-database 'safe-local-variable 'stringp) | |
264 | 275 |
265 (defcustom sql-server "" | 276 (defcustom sql-server "" |
266 "*Default server or host." | 277 "Default server or host." |
267 :type 'string | 278 :type 'string |
268 :group 'SQL) | 279 :group 'SQL) |
280 (put 'sql-server 'safe-local-variable 'stringp) | |
281 | |
282 (defcustom sql-port nil | |
283 "Default server or host." | |
284 :type 'number | |
285 :group 'SQL) | |
286 (put 'sql-port 'safe-local-variable 'numberp) | |
269 | 287 |
270 ;; SQL Product support | 288 ;; SQL Product support |
271 | 289 |
272 (defvar sql-interactive-product nil | 290 (defvar sql-interactive-product nil |
273 "Product under `sql-interactive-mode'.") | 291 "Product under `sql-interactive-mode'.") |
274 | 292 |
275 (defvar sql-product-alist | 293 (defvar sql-product-alist |
276 '((ansi | 294 '((ansi |
277 :name "ANSI" | 295 :name "ANSI" |
278 :font-lock sql-mode-ansi-font-lock-keywords) | 296 :font-lock sql-mode-ansi-font-lock-keywords) |
297 | |
279 (db2 | 298 (db2 |
280 :name "DB2" | 299 :name "DB2" |
281 :font-lock sql-mode-db2-font-lock-keywords | 300 :font-lock sql-mode-db2-font-lock-keywords |
282 :sqli-login nil | 301 :sqli-program sql-db2-program |
283 :sqli-connect sql-connect-db2 | 302 :sqli-options sql-db2-options |
284 :sqli-prompt-regexp "^db2 => " | 303 :sqli-login sql-db2-login-params |
285 :sqli-prompt-length 7) | 304 :sqli-connect-func sql-connect-db2 |
305 :prompt-regexp "^db2 => " | |
306 :prompt-length 7 | |
307 :input-filter sql-escape-newlines-filter) | |
308 | |
286 (informix | 309 (informix |
310 :name "Informix" | |
287 :font-lock sql-mode-informix-font-lock-keywords | 311 :font-lock sql-mode-informix-font-lock-keywords |
288 :sqli-login (database) | 312 :sqli-program sql-informix-program |
289 :sqli-connect sql-connect-informix | 313 :sqli-options sql-informix-options |
290 :sqli-prompt-regexp "^SQL> " | 314 :sqli-login sql-informix-login-params |
291 :sqli-prompt-length 5) | 315 :sqli-connect-func sql-connect-informix |
316 :prompt-regexp "^> " | |
317 :prompt-length 2 | |
318 :syntax-alist ((?{ . "<") (?} . ">"))) | |
319 | |
292 (ingres | 320 (ingres |
321 :name "Ingres" | |
293 :font-lock sql-mode-ingres-font-lock-keywords | 322 :font-lock sql-mode-ingres-font-lock-keywords |
294 :sqli-login (database) | 323 :sqli-program sql-ingres-program |
295 :sqli-connect sql-connect-ingres | 324 :sqli-options sql-ingres-options |
296 :sqli-prompt-regexp "^\* " | 325 :sqli-login sql-ingres-login-params |
297 :sqli-prompt-length 2) | 326 :sqli-connect-func sql-connect-ingres |
327 :prompt-regexp "^\* " | |
328 :prompt-length 2) | |
329 | |
298 (interbase | 330 (interbase |
331 :name "Interbase" | |
299 :font-lock sql-mode-interbase-font-lock-keywords | 332 :font-lock sql-mode-interbase-font-lock-keywords |
300 :sqli-login (user password database) | 333 :sqli-program sql-interbase-program |
301 :sqli-connect sql-connect-interbase | 334 :sqli-options sql-interbase-options |
302 :sqli-prompt-regexp "^SQL> " | 335 :sqli-login sql-interbase-login-params |
303 :sqli-prompt-length 5) | 336 :sqli-connect-func sql-connect-interbase |
337 :prompt-regexp "^SQL> " | |
338 :prompt-length 5) | |
339 | |
304 (linter | 340 (linter |
341 :name "Linter" | |
305 :font-lock sql-mode-linter-font-lock-keywords | 342 :font-lock sql-mode-linter-font-lock-keywords |
306 :sqli-login (user password database server) | 343 :sqli-program sql-linter-program |
307 :sqli-connect sql-connect-linter | 344 :sqli-options sql-linter-options |
308 :sqli-prompt-regexp "^SQL>" | 345 :sqli-login sql-linter-login-params |
309 :sqli-prompt-length 4) | 346 :sqli-connect-func sql-connect-linter |
347 :prompt-regexp "^SQL>" | |
348 :prompt-length 4) | |
349 | |
310 (ms | 350 (ms |
311 :name "MS SQLServer" | 351 :name "Microsoft" |
312 :font-lock sql-mode-ms-font-lock-keywords | 352 :font-lock sql-mode-ms-font-lock-keywords |
313 :sqli-login (user password server database) | 353 :sqli-program sql-ms-program |
314 :sqli-connect sql-connect-ms | 354 :sqli-options sql-ms-options |
315 :sqli-prompt-regexp "^[0-9]*>" | 355 :sqli-login sql-ms-login-params |
316 :sqli-prompt-length 5 | 356 :sqli-connect-func sql-connect-ms |
317 :syntax-alist ((?@ . "w"))) | 357 :prompt-regexp "^[0-9]*>" |
358 :prompt-length 5 | |
359 :syntax-alist ((?@ . "w")) | |
360 :terminator ("^go" . "go")) | |
361 | |
318 (mysql | 362 (mysql |
319 :name "MySQL" | 363 :name "MySQL" |
364 :free-software t | |
320 :font-lock sql-mode-mysql-font-lock-keywords | 365 :font-lock sql-mode-mysql-font-lock-keywords |
321 :sqli-login (user password database server) | 366 :sqli-program sql-mysql-program |
322 :sqli-connect sql-connect-mysql | 367 :sqli-options sql-mysql-options |
323 :sqli-prompt-regexp "^mysql> " | 368 :sqli-login sql-mysql-login-params |
324 :sqli-prompt-length 6) | 369 :sqli-connect-func sql-connect-mysql |
370 :prompt-regexp "^mysql> " | |
371 :prompt-length 6 | |
372 :input-filter sql-remove-tabs-filter) | |
373 | |
325 (oracle | 374 (oracle |
375 :name "Oracle" | |
326 :font-lock sql-mode-oracle-font-lock-keywords | 376 :font-lock sql-mode-oracle-font-lock-keywords |
327 :sqli-login (user password database) | 377 :sqli-program sql-oracle-program |
328 :sqli-connect sql-connect-oracle | 378 :sqli-options sql-oracle-options |
329 :sqli-prompt-regexp "^SQL> " | 379 :sqli-login sql-oracle-login-params |
330 :sqli-prompt-length 5 | 380 :sqli-connect-func sql-connect-oracle |
331 :syntax-alist ((?$ . "w") (?# . "w"))) | 381 :prompt-regexp "^SQL> " |
382 :prompt-length 5 | |
383 :syntax-alist ((?$ . "w") (?# . "w")) | |
384 :terminator ("\\(^/\\|;\\)" . "/") | |
385 :input-filter sql-placeholders-filter) | |
386 | |
332 (postgres | 387 (postgres |
388 :name "Postgres" | |
389 :free-software t | |
333 :font-lock sql-mode-postgres-font-lock-keywords | 390 :font-lock sql-mode-postgres-font-lock-keywords |
334 :sqli-login (user database server) | 391 :sqli-program sql-postgres-program |
335 :sqli-connect sql-connect-postgres | 392 :sqli-options sql-postgres-options |
336 :sqli-prompt-regexp "^.*[#>] *" | 393 :sqli-login sql-postgres-login-params |
337 :sqli-prompt-length 5) | 394 :sqli-connect-func sql-connect-postgres |
395 :prompt-regexp "^.*[#>] *" | |
396 :prompt-length 5 | |
397 :input-filter sql-remove-tabs-filter | |
398 :terminator ("\\(^[\\]g\\|;\\)" . ";")) | |
399 | |
338 (solid | 400 (solid |
401 :name "Solid" | |
339 :font-lock sql-mode-solid-font-lock-keywords | 402 :font-lock sql-mode-solid-font-lock-keywords |
340 :sqli-login (user password server) | 403 :sqli-program sql-solid-program |
341 :sqli-connect sql-connect-solid | 404 :sqli-options sql-solid-options |
342 :sqli-prompt-regexp "^" | 405 :sqli-login sql-solid-login-params |
343 :sqli-prompt-length 0) | 406 :sqli-connect-func sql-connect-solid |
407 :prompt-regexp "^" | |
408 :prompt-length 0) | |
409 | |
344 (sqlite | 410 (sqlite |
345 :name "SQLite" | 411 :name "SQLite" |
412 :free-software t | |
346 :font-lock sql-mode-sqlite-font-lock-keywords | 413 :font-lock sql-mode-sqlite-font-lock-keywords |
347 :sqli-login (database) | 414 :sqli-program sql-sqlite-program |
348 :sqli-connect sql-connect-sqlite | 415 :sqli-options sql-sqlite-options |
349 :sqli-prompt-regexp "^sqlite> " | 416 :sqli-login sql-sqlite-login-params |
350 :sqli-prompt-length 8) | 417 :sqli-connect-func sql-connect-sqlite |
418 :prompt-regexp "^sqlite> " | |
419 :prompt-length 8) | |
420 | |
351 (sybase | 421 (sybase |
422 :name "Sybase" | |
352 :font-lock sql-mode-sybase-font-lock-keywords | 423 :font-lock sql-mode-sybase-font-lock-keywords |
353 :sqli-login (server user password database) | 424 :sqli-program sql-sybase-program |
354 :sqli-connect sql-connect-sybase | 425 :sqli-options sql-sybase-options |
355 :sqli-prompt-regexp "^SQL> " | 426 :sqli-login sql-sybase-login-params |
356 :sqli-prompt-length 5 | 427 :sqli-connect-func sql-connect-sybase |
357 :syntax-alist ((?@ . "w"))) | 428 :prompt-regexp "^SQL> " |
429 :prompt-length 5 | |
430 :syntax-alist ((?@ . "w")) | |
431 :terminator ("^go" . "go")) | |
358 ) | 432 ) |
359 "This variable contains a list of product features for each of the | 433 "An alist of product specific configuration settings. |
360 SQL products handled by `sql-mode'. Without an entry in this list a | 434 |
361 product will not be properly highlighted and will not support | 435 Without an entry in this list a product will not be properly |
362 `sql-interactive-mode'. | 436 highlighted and will not support `sql-interactive-mode'. |
363 | 437 |
364 Each element in the list is in the following format: | 438 Each element in the list is in the following format: |
365 | 439 |
366 \(PRODUCT FEATURE VALUE ...) | 440 \(PRODUCT FEATURE VALUE ...) |
367 | 441 |
368 where PRODUCT is the appropriate value of `sql-product'. The product | 442 where PRODUCT is the appropriate value of `sql-product'. The |
369 name is then followed by FEATURE-VALUE pairs. If a FEATURE is not | 443 product name is then followed by FEATURE-VALUE pairs. If a |
370 specified, its VALUE is treated as nil. FEATURE must be one of the | 444 FEATURE is not specified, its VALUE is treated as nil. FEATURE |
371 following: | 445 may be any one of the following: |
446 | |
447 :name string containing the displayable name of | |
448 the product. | |
449 | |
450 :free-software is the product Free (as in Freedom) software? | |
372 | 451 |
373 :font-lock name of the variable containing the product | 452 :font-lock name of the variable containing the product |
374 specific font lock highlighting patterns. | 453 specific font lock highlighting patterns. |
375 | 454 |
376 :sqli-login a list of login parameters (i.e., user, | 455 :sqli-program name of the variable containing the product |
377 password, database and server) needed to | 456 specific interactive program name. |
378 connect to the database. | 457 |
379 | 458 :sqli-options name of the variable containing the list |
380 :sqli-connect the name of a function which accepts no | 459 of product specific options. |
460 | |
461 :sqli-login name of the variable containing the list of | |
462 login parameters (i.e., user, password, | |
463 database and server) needed to connect to | |
464 the database. | |
465 | |
466 :sqli-connect-func name of a function which accepts no | |
381 parameters that will use the values of | 467 parameters that will use the values of |
382 `sql-user', `sql-password', | 468 `sql-user', `sql-password', |
383 `sql-database' and `sql-server' to open a | 469 `sql-database' and `sql-server' to open a |
384 comint buffer and connect to the | 470 comint buffer and connect to the |
385 database. Do product specific | 471 database. Do product specific |
386 configuration of comint in this function. | 472 configuration of comint in this function. |
387 | 473 |
388 :sqli-prompt-regexp a regular expression string that matches | 474 :prompt-regexp regular expression string that matches |
389 the prompt issued by the product | 475 the prompt issued by the product |
390 interpreter. (Not needed in 21.3+) | 476 interpreter. |
391 | 477 |
392 :sqli-prompt-length the length of the prompt on the line.(Not | 478 :prompt-length length of the prompt on the line. |
393 needed in 21.3+) | 479 |
394 | 480 :input-filter function which can filter strings sent to |
395 :syntax-alist an alist of syntax table entries to enable | 481 the command interpreter. It is also used |
396 special character treatment by font-lock and | 482 by the `sql-send-string', |
397 imenu. ") | 483 `sql-send-region', `sql-send-paragraph' |
398 | 484 and `sql-send-buffer' functions. The |
485 function is passed the string sent to the | |
486 command interpreter and must return the | |
487 filtered string. | |
488 | |
489 :terminator the terminator to be sent after a | |
490 `sql-send-string', `sql-send-region', | |
491 `sql-send-paragraph' and | |
492 `sql-send-buffer' command. May be the | |
493 literal string or a cons of a regexp to | |
494 match an existing terminator in the | |
495 string and the terminator to be used if | |
496 its absent. By default \";\". | |
497 | |
498 :syntax-alist alist of syntax table entries to enable | |
499 special character treatment by font-lock | |
500 and imenu. | |
501 | |
502 Other features can be stored but they will be ignored. However, | |
503 you can develop new functionality which is product independent by | |
504 using `sql-get-product-feature' to lookup the product specific | |
505 settings.") | |
506 | |
507 (defvar sql-indirect-features | |
508 '(:font-lock :sqli-program :sqli-options :sqli-login)) | |
509 | |
510 ;;;###autoload | |
399 (defcustom sql-product 'ansi | 511 (defcustom sql-product 'ansi |
400 "*Select the SQL database product used so that buffers can be | 512 "Select the SQL database product used so that buffers can be |
401 highlighted properly when you open them." | 513 highlighted properly when you open them." |
402 :type `(choice | 514 :type `(choice |
403 ,@(mapcar (lambda (prod-info) | 515 ,@(mapcar (lambda (prod-info) |
404 `(const :tag | 516 `(const :tag |
405 ,(or (plist-get (cdr prod-info) :name) | 517 ,(or (plist-get (cdr prod-info) :name) |
406 (capitalize (symbol-name (car prod-info)))) | 518 (capitalize (symbol-name (car prod-info)))) |
407 ,(car prod-info))) | 519 ,(car prod-info))) |
408 sql-product-alist)) | 520 sql-product-alist)) |
409 :group 'SQL) | 521 :group 'SQL) |
410 | 522 (put 'sql-product 'safe-local-variable 'symbolp) |
411 ;; misc customization of sql.el behavior | 523 |
524 (defvar sql-interactive-product nil | |
525 "Product under `sql-interactive-mode'.") | |
526 | |
527 ;; misc customization of sql.el behaviour | |
412 | 528 |
413 (defcustom sql-electric-stuff nil | 529 (defcustom sql-electric-stuff nil |
414 "Treat some input as electric. | 530 "Treat some input as electric. |
415 If set to the symbol `semicolon', then hitting `;' will send current | 531 If set to the symbol `semicolon', then hitting `;' will send current |
416 input in the SQLi buffer to the process. | 532 input in the SQLi buffer to the process. |
422 (const :tag "The semicolon `;'" semicolon) | 538 (const :tag "The semicolon `;'" semicolon) |
423 (const :tag "The string `go' by itself" go)) | 539 (const :tag "The string `go' by itself" go)) |
424 :version "20.8" | 540 :version "20.8" |
425 :group 'SQL) | 541 :group 'SQL) |
426 | 542 |
543 (defcustom sql-send-terminator nil | |
544 "When non-nil, add a terminator to text sent to the SQL interpreter. | |
545 | |
546 When text is sent to the SQL interpreter (via `sql-send-string', | |
547 `sql-send-region', `sql-send-paragraph' or `sql-send-buffer'), a | |
548 command terminator can be automatically sent as well. The | |
549 terminator is not sent, if the string sent already ends with the | |
550 terminator. | |
551 | |
552 If this value is t, then the default command terminator for the | |
553 SQL interpreter is sent. If this value is a string, then the | |
554 string is sent. | |
555 | |
556 If the value is a cons cell of the form (PAT . TERM), then PAT is | |
557 a regexp used to match the terminator in the string and TERM is | |
558 the terminator to be sent. This form is useful if the SQL | |
559 interpreter has more than one way of submitting a SQL command. | |
560 The PAT regexp can match any of them, and TERM is the way we do | |
561 it automatically." | |
562 | |
563 :type '(choice (const :tag "No Terminator" nil) | |
564 (const :tag "Default Terminator" t) | |
565 (string :tag "Terminator String") | |
566 (cons :tag "Terminator Pattern and String" | |
567 (string :tag "Terminator Pattern") | |
568 (string :tag "Terminator String"))) | |
569 :version "22.2" | |
570 :group 'SQL) | |
571 | |
427 (defcustom sql-pop-to-buffer-after-send-region nil | 572 (defcustom sql-pop-to-buffer-after-send-region nil |
428 "*If t, pop to the buffer SQL statements are sent to. | 573 "When non-nil, pop to the buffer SQL statements are sent to. |
429 | 574 |
430 After a call to `sql-send-region' or `sql-send-buffer', | 575 After a call to `sql-sent-string', `sql-send-region', |
431 the window is split and the SQLi buffer is shown. If this | 576 `sql-send-paragraph' or `sql-send-buffer', the window is split |
432 variable is not nil, that buffer's window will be selected | 577 and the SQLi buffer is shown. If this variable is not nil, that |
433 by calling `pop-to-buffer'. If this variable is nil, that | 578 buffer's window will be selected by calling `pop-to-buffer'. If |
434 buffer is shown using `display-buffer'." | 579 this variable is nil, that buffer is shown using |
580 `display-buffer'." | |
435 :type 'boolean | 581 :type 'boolean |
436 :group 'SQL) | 582 :group 'SQL) |
437 | 583 |
438 ;; imenu support for sql-mode. | 584 ;; imenu support for sql-mode. |
439 | 585 |
443 ("Sequences" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*sequence\\s-+\\(\\w+\\)" 2) | 589 ("Sequences" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*sequence\\s-+\\(\\w+\\)" 2) |
444 ("Triggers" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*trigger\\s-+\\(\\w+\\)" 2) | 590 ("Triggers" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*trigger\\s-+\\(\\w+\\)" 2) |
445 ("Functions" "^\\s-*\\(create\\s-+\\(\\w+\\s-+\\)*\\)?function\\s-+\\(\\w+\\)" 3) | 591 ("Functions" "^\\s-*\\(create\\s-+\\(\\w+\\s-+\\)*\\)?function\\s-+\\(\\w+\\)" 3) |
446 ("Procedures" "^\\s-*\\(create\\s-+\\(\\w+\\s-+\\)*\\)?proc\\(edure\\)?\\s-+\\(\\w+\\)" 4) | 592 ("Procedures" "^\\s-*\\(create\\s-+\\(\\w+\\s-+\\)*\\)?proc\\(edure\\)?\\s-+\\(\\w+\\)" 4) |
447 ("Packages" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*package\\s-+\\(body\\s-+\\)?\\(\\w+\\)" 3) | 593 ("Packages" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*package\\s-+\\(body\\s-+\\)?\\(\\w+\\)" 3) |
594 ("Types" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*type\\s-+\\(body\\s-+\\)?\\(\\w+\\)" 3) | |
448 ("Indexes" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*index\\s-+\\(\\w+\\)" 2) | 595 ("Indexes" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*index\\s-+\\(\\w+\\)" 2) |
449 ("Tables/Views" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*\\(table\\|view\\)\\s-+\\(\\w+\\)" 3)) | 596 ("Tables/Views" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*\\(table\\|view\\)\\s-+\\(\\w+\\)" 3)) |
450 "Define interesting points in the SQL buffer for `imenu'. | 597 "Define interesting points in the SQL buffer for `imenu'. |
451 | 598 |
452 This is used to set `imenu-generic-expression' when SQL mode is | 599 This is used to set `imenu-generic-expression' when SQL mode is |
455 a local variable.") | 602 a local variable.") |
456 | 603 |
457 ;; history file | 604 ;; history file |
458 | 605 |
459 (defcustom sql-input-ring-file-name nil | 606 (defcustom sql-input-ring-file-name nil |
460 "*If non-nil, name of the file to read/write input history. | 607 "If non-nil, name of the file to read/write input history. |
461 | 608 |
462 You have to set this variable if you want the history of your commands | 609 You have to set this variable if you want the history of your commands |
463 saved from one Emacs session to the next. If this variable is set, | 610 saved from one Emacs session to the next. If this variable is set, |
464 exiting the SQL interpreter in an SQLi buffer will write the input | 611 exiting the SQL interpreter in an SQLi buffer will write the input |
465 history to the specified file. Starting a new process in a SQLi buffer | 612 history to the specified file. Starting a new process in a SQLi buffer |
472 :type '(choice (const :tag "none" nil) | 619 :type '(choice (const :tag "none" nil) |
473 (file)) | 620 (file)) |
474 :group 'SQL) | 621 :group 'SQL) |
475 | 622 |
476 (defcustom sql-input-ring-separator "\n--\n" | 623 (defcustom sql-input-ring-separator "\n--\n" |
477 "*Separator between commands in the history file. | 624 "Separator between commands in the history file. |
478 | 625 |
479 If set to \"\\n\", each line in the history file will be interpreted as | 626 If set to \"\\n\", each line in the history file will be interpreted as |
480 one command. Multi-line commands are split into several commands when | 627 one command. Multi-line commands are split into several commands when |
481 the input ring is initialized from a history file. | 628 the input ring is initialized from a history file. |
482 | 629 |
490 :group 'SQL) | 637 :group 'SQL) |
491 | 638 |
492 ;; The usual hooks | 639 ;; The usual hooks |
493 | 640 |
494 (defcustom sql-interactive-mode-hook '() | 641 (defcustom sql-interactive-mode-hook '() |
495 "*Hook for customizing `sql-interactive-mode'." | 642 "Hook for customizing `sql-interactive-mode'." |
496 :type 'hook | 643 :type 'hook |
497 :group 'SQL) | 644 :group 'SQL) |
498 | 645 |
499 (defcustom sql-mode-hook '() | 646 (defcustom sql-mode-hook '() |
500 "*Hook for customizing `sql-mode'." | 647 "Hook for customizing `sql-mode'." |
501 :type 'hook | 648 :type 'hook |
502 :group 'SQL) | 649 :group 'SQL) |
503 | 650 |
504 (defcustom sql-set-sqli-hook '() | 651 (defcustom sql-set-sqli-hook '() |
505 "*Hook for reacting to changes of `sql-buffer'. | 652 "Hook for reacting to changes of `sql-buffer'. |
506 | 653 |
507 This is called by `sql-set-sqli-buffer' when the value of `sql-buffer' | 654 This is called by `sql-set-sqli-buffer' when the value of `sql-buffer' |
508 is changed." | 655 is changed." |
509 :type 'hook | 656 :type 'hook |
510 :group 'SQL) | 657 :group 'SQL) |
511 | 658 |
512 ;; Customization for Oracle | 659 ;; Customization for Oracle |
513 | 660 |
514 (defcustom sql-oracle-program "sqlplus" | 661 (defcustom sql-oracle-program "sqlplus" |
515 "*Command to start sqlplus by Oracle. | 662 "Command to start sqlplus by Oracle. |
516 | 663 |
517 Starts `sql-interactive-mode' after doing some setup. | 664 Starts `sql-interactive-mode' after doing some setup. |
518 | 665 |
519 On Windows, \"sqlplus\" usually starts the sqlplus \"GUI\". In order to | 666 On Windows, \"sqlplus\" usually starts the sqlplus \"GUI\". In order to |
520 start the sqlplus console, use \"plus33\" or something similar. You | 667 start the sqlplus console, use \"plus33\" or something similar. You |
521 will find the file in your Orant\\bin directory. | 668 will find the file in your Orant\\bin directory." |
522 | |
523 The program can also specify a TCP connection. See `make-comint'." | |
524 :type 'file | 669 :type 'file |
525 :group 'SQL) | 670 :group 'SQL) |
526 | 671 |
527 (defcustom sql-oracle-options nil | 672 (defcustom sql-oracle-options nil |
528 "*List of additional options for `sql-oracle-program'." | 673 "List of additional options for `sql-oracle-program'." |
529 :type '(repeat string) | 674 :type '(repeat string) |
530 :version "20.8" | 675 :version "20.8" |
531 :group 'SQL) | 676 :group 'SQL) |
532 | 677 |
678 (defcustom sql-oracle-login-params '(user password database) | |
679 "List of login parameters needed to connect to Oracle." | |
680 :type '(repeat (choice | |
681 (const user) | |
682 (const password) | |
683 (const server) | |
684 (const database))) | |
685 :version "24.1" | |
686 :group 'SQL) | |
687 | |
688 (defcustom sql-oracle-scan-on t | |
689 "Non-nil if placeholders should be replaced in Oracle SQLi. | |
690 | |
691 When non-nil, Emacs will scan text sent to sqlplus and prompt | |
692 for replacement text for & placeholders as sqlplus does. This | |
693 is needed on Windows where sqlplus output is buffer and the | |
694 prompts are not shown until after the text is entered. | |
695 | |
696 You will probably want to issue the following command in sqlplus | |
697 to be safe: | |
698 | |
699 SET SCAN OFF" | |
700 :type 'boolean | |
701 :group 'SQL) | |
702 | |
533 ;; Customization for SQLite | 703 ;; Customization for SQLite |
534 | 704 |
535 (defcustom sql-sqlite-program "sqlite" | 705 (defcustom sql-sqlite-program "sqlite" |
536 "*Command to start SQLite. | 706 "Command to start SQLite. |
537 | 707 |
538 Starts `sql-interactive-mode' after doing some setup. | 708 Starts `sql-interactive-mode' after doing some setup." |
539 | |
540 The program can also specify a TCP connection. See `make-comint'." | |
541 :type 'file | 709 :type 'file |
542 :group 'SQL) | 710 :group 'SQL) |
543 | 711 |
544 (defcustom sql-sqlite-options nil | 712 (defcustom sql-sqlite-options nil |
545 "*List of additional options for `sql-sqlite-program'." | 713 "List of additional options for `sql-sqlite-program'." |
546 :type '(repeat string) | 714 :type '(repeat string) |
547 :version "20.8" | 715 :version "20.8" |
548 :group 'SQL) | 716 :group 'SQL) |
549 | 717 |
718 (defcustom sql-sqlite-login-params '(database) | |
719 "List of login parameters needed to connect to SQLite." | |
720 :type '(repeat (choice | |
721 (const user) | |
722 (const password) | |
723 (const server) | |
724 (const database))) | |
725 :version "24.1" | |
726 :group 'SQL) | |
727 | |
550 ;; Customization for MySql | 728 ;; Customization for MySql |
551 | 729 |
552 (defcustom sql-mysql-program "mysql" | 730 (defcustom sql-mysql-program "mysql" |
553 "*Command to start mysql by TcX. | 731 "Command to start mysql by TcX. |
554 | 732 |
555 Starts `sql-interactive-mode' after doing some setup. | 733 Starts `sql-interactive-mode' after doing some setup." |
556 | |
557 The program can also specify a TCP connection. See `make-comint'." | |
558 :type 'file | 734 :type 'file |
559 :group 'SQL) | 735 :group 'SQL) |
560 | 736 |
561 (defcustom sql-mysql-options nil | 737 (defcustom sql-mysql-options nil |
562 "*List of additional options for `sql-mysql-program'. | 738 "List of additional options for `sql-mysql-program'. |
563 The following list of options is reported to make things work | 739 The following list of options is reported to make things work |
564 on Windows: \"-C\" \"-t\" \"-f\" \"-n\"." | 740 on Windows: \"-C\" \"-t\" \"-f\" \"-n\"." |
565 :type '(repeat string) | 741 :type '(repeat string) |
566 :version "20.8" | 742 :version "20.8" |
567 :group 'SQL) | 743 :group 'SQL) |
568 | 744 |
745 (defcustom sql-mysql-login-params '(user password database server) | |
746 "List of login parameters needed to connect to MySql." | |
747 :type '(repeat (choice | |
748 (const user) | |
749 (const password) | |
750 (const server) | |
751 (const database) | |
752 (const port))) | |
753 :version "24.1" | |
754 :group 'SQL) | |
755 | |
569 ;; Customization for Solid | 756 ;; Customization for Solid |
570 | 757 |
571 (defcustom sql-solid-program "solsql" | 758 (defcustom sql-solid-program "solsql" |
572 "*Command to start SOLID SQL Editor. | 759 "Command to start SOLID SQL Editor. |
573 | 760 |
574 Starts `sql-interactive-mode' after doing some setup. | 761 Starts `sql-interactive-mode' after doing some setup." |
575 | |
576 The program can also specify a TCP connection. See `make-comint'." | |
577 :type 'file | 762 :type 'file |
578 :group 'SQL) | 763 :group 'SQL) |
579 | 764 |
765 (defcustom sql-solid-login-params '(user password server) | |
766 "List of login parameters needed to connect to Solid." | |
767 :type '(repeat (choice | |
768 (const user) | |
769 (const password) | |
770 (const server) | |
771 (const database))) | |
772 :version "24.1" | |
773 :group 'SQL) | |
774 | |
580 ;; Customization for SyBase | 775 ;; Customization for SyBase |
581 | 776 |
582 (defcustom sql-sybase-program "isql" | 777 (defcustom sql-sybase-program "isql" |
583 "*Command to start isql by SyBase. | 778 "Command to start isql by SyBase. |
584 | 779 |
585 Starts `sql-interactive-mode' after doing some setup. | 780 Starts `sql-interactive-mode' after doing some setup." |
586 | |
587 The program can also specify a TCP connection. See `make-comint'." | |
588 :type 'file | 781 :type 'file |
589 :group 'SQL) | 782 :group 'SQL) |
590 | 783 |
591 (defcustom sql-sybase-options nil | 784 (defcustom sql-sybase-options nil |
592 "*List of additional options for `sql-sybase-program'. | 785 "List of additional options for `sql-sybase-program'. |
593 Some versions of isql might require the -n option in order to work." | 786 Some versions of isql might require the -n option in order to work." |
594 :type '(repeat string) | 787 :type '(repeat string) |
595 :version "20.8" | 788 :version "20.8" |
596 :group 'SQL) | 789 :group 'SQL) |
597 | 790 |
791 (defcustom sql-sybase-login-params '(server user password database) | |
792 "List of login parameters needed to connect to Sybase." | |
793 :type '(repeat (choice | |
794 (const user) | |
795 (const password) | |
796 (const server) | |
797 (const database))) | |
798 :version "24.1" | |
799 :group 'SQL) | |
800 | |
598 ;; Customization for Informix | 801 ;; Customization for Informix |
599 | 802 |
600 (defcustom sql-informix-program "dbaccess" | 803 (defcustom sql-informix-program "dbaccess" |
601 "*Command to start dbaccess by Informix. | 804 "Command to start dbaccess by Informix. |
602 | 805 |
603 Starts `sql-interactive-mode' after doing some setup. | 806 Starts `sql-interactive-mode' after doing some setup." |
604 | |
605 The program can also specify a TCP connection. See `make-comint'." | |
606 :type 'file | 807 :type 'file |
607 :group 'SQL) | 808 :group 'SQL) |
608 | 809 |
810 (defcustom sql-informix-login-params '(database) | |
811 "List of login parameters needed to connect to Informix." | |
812 :type '(repeat (choice | |
813 (const user) | |
814 (const password) | |
815 (const server) | |
816 (const database))) | |
817 :version "24.1" | |
818 :group 'SQL) | |
819 | |
609 ;; Customization for Ingres | 820 ;; Customization for Ingres |
610 | 821 |
611 (defcustom sql-ingres-program "sql" | 822 (defcustom sql-ingres-program "sql" |
612 "*Command to start sql by Ingres. | 823 "Command to start sql by Ingres. |
613 | 824 |
614 Starts `sql-interactive-mode' after doing some setup. | 825 Starts `sql-interactive-mode' after doing some setup." |
615 | |
616 The program can also specify a TCP connection. See `make-comint'." | |
617 :type 'file | 826 :type 'file |
618 :group 'SQL) | 827 :group 'SQL) |
619 | 828 |
829 (defcustom sql-ingres-login-params '(database) | |
830 "List of login parameters needed to connect to Ingres." | |
831 :type '(repeat (choice | |
832 (const user) | |
833 (const password) | |
834 (const server) | |
835 (const database))) | |
836 :version "24.1" | |
837 :group 'SQL) | |
838 | |
620 ;; Customization for Microsoft | 839 ;; Customization for Microsoft |
621 | 840 |
622 (defcustom sql-ms-program "osql" | 841 (defcustom sql-ms-program "osql" |
623 "*Command to start osql by Microsoft. | 842 "Command to start osql by Microsoft. |
624 | 843 |
625 Starts `sql-interactive-mode' after doing some setup. | 844 Starts `sql-interactive-mode' after doing some setup." |
626 | |
627 The program can also specify a TCP connection. See `make-comint'." | |
628 :type 'file | 845 :type 'file |
629 :group 'SQL) | 846 :group 'SQL) |
630 | 847 |
631 (defcustom sql-ms-options '("-w" "300" "-n") | 848 (defcustom sql-ms-options '("-w" "300" "-n") |
632 ;; -w is the linesize | 849 ;; -w is the linesize |
633 "*List of additional options for `sql-ms-program'." | 850 "List of additional options for `sql-ms-program'." |
634 :type '(repeat string) | 851 :type '(repeat string) |
635 :version "22.1" | 852 :version "22.1" |
636 :group 'SQL) | 853 :group 'SQL) |
637 | 854 |
855 (defcustom sql-ms-login-params '(user password server database) | |
856 "List of login parameters needed to connect to Microsoft." | |
857 :type '(repeat (choice | |
858 (const user) | |
859 (const password) | |
860 (const server) | |
861 (const database))) | |
862 :version "24.1" | |
863 :group 'SQL) | |
864 | |
638 ;; Customization for Postgres | 865 ;; Customization for Postgres |
639 | 866 |
640 (defcustom sql-postgres-program "psql" | 867 (defcustom sql-postgres-program "psql" |
641 "Command to start psql by Postgres. | 868 "Command to start psql by Postgres. |
642 | 869 |
643 Starts `sql-interactive-mode' after doing some setup. | 870 Starts `sql-interactive-mode' after doing some setup." |
644 | |
645 The program can also specify a TCP connection. See `make-comint'." | |
646 :type 'file | 871 :type 'file |
647 :group 'SQL) | 872 :group 'SQL) |
648 | 873 |
649 (defcustom sql-postgres-options '("-P" "pager=off") | 874 (defcustom sql-postgres-options '("-P" "pager=off") |
650 "*List of additional options for `sql-postgres-program'. | 875 "List of additional options for `sql-postgres-program'. |
651 The default setting includes the -P option which breaks older versions | 876 The default setting includes the -P option which breaks older versions |
652 of the psql client (such as version 6.5.3). The -P option is equivalent | 877 of the psql client (such as version 6.5.3). The -P option is equivalent |
653 to the --pset option. If you want the psql to prompt you for a user | 878 to the --pset option. If you want the psql to prompt you for a user |
654 name, add the string \"-u\" to the list of options. If you want to | 879 name, add the string \"-u\" to the list of options. If you want to |
655 provide a user name on the command line (newer versions such as 7.1), | 880 provide a user name on the command line (newer versions such as 7.1), |
656 add your name with a \"-U\" prefix (such as \"-Umark\") to the list." | 881 add your name with a \"-U\" prefix (such as \"-Umark\") to the list." |
657 :type '(repeat string) | 882 :type '(repeat string) |
658 :version "20.8" | 883 :version "20.8" |
659 :group 'SQL) | 884 :group 'SQL) |
660 | 885 |
886 (defcustom sql-postgres-login-params '(user database server) | |
887 "List of login parameters needed to connect to Postgres." | |
888 :type '(repeat (choice | |
889 (const user) | |
890 (const password) | |
891 (const server) | |
892 (const database))) | |
893 :version "24.1" | |
894 :group 'SQL) | |
895 | |
661 ;; Customization for Interbase | 896 ;; Customization for Interbase |
662 | 897 |
663 (defcustom sql-interbase-program "isql" | 898 (defcustom sql-interbase-program "isql" |
664 "*Command to start isql by Interbase. | 899 "Command to start isql by Interbase. |
665 | 900 |
666 Starts `sql-interactive-mode' after doing some setup. | 901 Starts `sql-interactive-mode' after doing some setup." |
667 | |
668 The program can also specify a TCP connection. See `make-comint'." | |
669 :type 'file | 902 :type 'file |
670 :group 'SQL) | 903 :group 'SQL) |
671 | 904 |
672 (defcustom sql-interbase-options nil | 905 (defcustom sql-interbase-options nil |
673 "*List of additional options for `sql-interbase-program'." | 906 "List of additional options for `sql-interbase-program'." |
674 :type '(repeat string) | 907 :type '(repeat string) |
675 :version "20.8" | 908 :version "20.8" |
676 :group 'SQL) | 909 :group 'SQL) |
677 | 910 |
911 (defcustom sql-interbase-login-params '(user password database) | |
912 "List of login parameters needed to connect to Interbase." | |
913 :type '(repeat (choice | |
914 (const user) | |
915 (const password) | |
916 (const server) | |
917 (const database))) | |
918 :version "24.1" | |
919 :group 'SQL) | |
920 | |
678 ;; Customization for DB2 | 921 ;; Customization for DB2 |
679 | 922 |
680 (defcustom sql-db2-program "db2" | 923 (defcustom sql-db2-program "db2" |
681 "*Command to start db2 by IBM. | 924 "Command to start db2 by IBM. |
682 | 925 |
683 Starts `sql-interactive-mode' after doing some setup. | 926 Starts `sql-interactive-mode' after doing some setup." |
684 | |
685 The program can also specify a TCP connection. See `make-comint'." | |
686 :type 'file | 927 :type 'file |
687 :group 'SQL) | 928 :group 'SQL) |
688 | 929 |
689 (defcustom sql-db2-options nil | 930 (defcustom sql-db2-options nil |
690 "*List of additional options for `sql-db2-program'." | 931 "List of additional options for `sql-db2-program'." |
691 :type '(repeat string) | 932 :type '(repeat string) |
692 :version "20.8" | 933 :version "20.8" |
693 :group 'SQL) | 934 :group 'SQL) |
694 | 935 |
936 (defcustom sql-db2-login-params nil | |
937 "List of login parameters needed to connect to DB2." | |
938 :type '(repeat (choice | |
939 (const user) | |
940 (const password) | |
941 (const server) | |
942 (const database))) | |
943 :version "24.1" | |
944 :group 'SQL) | |
945 | |
695 ;; Customization for Linter | 946 ;; Customization for Linter |
696 | 947 |
697 (defcustom sql-linter-program "inl" | 948 (defcustom sql-linter-program "inl" |
698 "*Command to start inl by RELEX. | 949 "Command to start inl by RELEX. |
699 | 950 |
700 Starts `sql-interactive-mode' after doing some setup." | 951 Starts `sql-interactive-mode' after doing some setup." |
701 :type 'file | 952 :type 'file |
702 :group 'SQL) | 953 :group 'SQL) |
703 | 954 |
704 (defcustom sql-linter-options nil | 955 (defcustom sql-linter-options nil |
705 "*List of additional options for `sql-linter-program'." | 956 "List of additional options for `sql-linter-program'." |
706 :type '(repeat string) | 957 :type '(repeat string) |
707 :version "21.3" | 958 :version "21.3" |
708 :group 'SQL) | 959 :group 'SQL) |
709 | 960 |
961 (defcustom sql-linter-login-params '(user password database server) | |
962 "Login parameters to needed to connect to Linter." | |
963 :type '(repeat (choice | |
964 (const user) | |
965 (const password) | |
966 (const server) | |
967 (const database))) | |
968 :version "24.1" | |
969 :group 'SQL) | |
970 | |
710 | 971 |
711 | 972 |
712 ;;; Variables which do not need customization | 973 ;;; Variables which do not need customization |
713 | 974 |
714 (defvar sql-user-history nil | 975 (defvar sql-user-history nil |
717 (defvar sql-database-history nil | 978 (defvar sql-database-history nil |
718 "History of databases used.") | 979 "History of databases used.") |
719 | 980 |
720 (defvar sql-server-history nil | 981 (defvar sql-server-history nil |
721 "History of servers used.") | 982 "History of servers used.") |
983 | |
984 (defvar sql-port-history nil | |
985 "History of ports used.") | |
722 | 986 |
723 ;; Passwords are not kept in a history. | 987 ;; Passwords are not kept in a history. |
724 | 988 |
725 (defvar sql-buffer nil | 989 (defvar sql-buffer nil |
726 "Current SQLi buffer. | 990 "Current SQLi buffer. |
771 (let ((map (make-sparse-keymap))) | 1035 (let ((map (make-sparse-keymap))) |
772 (define-key map (kbd "C-c C-c") 'sql-send-paragraph) | 1036 (define-key map (kbd "C-c C-c") 'sql-send-paragraph) |
773 (define-key map (kbd "C-c C-r") 'sql-send-region) | 1037 (define-key map (kbd "C-c C-r") 'sql-send-region) |
774 (define-key map (kbd "C-c C-s") 'sql-send-string) | 1038 (define-key map (kbd "C-c C-s") 'sql-send-string) |
775 (define-key map (kbd "C-c C-b") 'sql-send-buffer) | 1039 (define-key map (kbd "C-c C-b") 'sql-send-buffer) |
1040 (define-key map (kbd "C-c C-i") 'sql-product-interactive) | |
776 map) | 1041 map) |
777 "Mode map used for `sql-mode'.") | 1042 "Mode map used for `sql-mode'.") |
778 | 1043 |
779 ;; easy menu for sql-mode. | 1044 ;; easy menu for sql-mode. |
780 | 1045 |
782 sql-mode-menu sql-mode-map | 1047 sql-mode-menu sql-mode-map |
783 "Menu for `sql-mode'." | 1048 "Menu for `sql-mode'." |
784 `("SQL" | 1049 `("SQL" |
785 ["Send Paragraph" sql-send-paragraph (and (buffer-live-p sql-buffer) | 1050 ["Send Paragraph" sql-send-paragraph (and (buffer-live-p sql-buffer) |
786 (get-buffer-process sql-buffer))] | 1051 (get-buffer-process sql-buffer))] |
787 ["Send Region" sql-send-region (and (or (and (boundp 'mark-active); Emacs | 1052 ["Send Region" sql-send-region (and mark-active |
788 mark-active) | |
789 (mark t)); XEmacs | |
790 (buffer-live-p sql-buffer) | 1053 (buffer-live-p sql-buffer) |
791 (get-buffer-process sql-buffer))] | 1054 (get-buffer-process sql-buffer))] |
792 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer) | 1055 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer) |
793 (get-buffer-process sql-buffer))] | 1056 (get-buffer-process sql-buffer))] |
794 ["Send String" sql-send-string t] | 1057 ["Send String" sql-send-string (and (buffer-live-p sql-buffer) |
1058 (get-buffer-process sql-buffer))] | |
795 ["--" nil nil] | 1059 ["--" nil nil] |
796 ["Start SQLi session" sql-product-interactive (sql-product-feature :sqli-connect)] | 1060 ["Start SQLi session" sql-product-interactive (sql-get-product-feature sql-product :sqli-connect-func)] |
797 ["Show SQLi buffer" sql-show-sqli-buffer t] | 1061 ["Show SQLi buffer" sql-show-sqli-buffer t] |
798 ["Set SQLi buffer" sql-set-sqli-buffer t] | 1062 ["Set SQLi buffer" sql-set-sqli-buffer t] |
799 ["Pop to SQLi buffer after send" | 1063 ["Pop to SQLi buffer after send" |
800 sql-toggle-pop-to-buffer-after-send-region | 1064 sql-toggle-pop-to-buffer-after-send-region |
801 :style toggle | 1065 :style toggle |
884 | 1148 |
885 The pattern matches the name in a CREATE, DROP or ALTER | 1149 The pattern matches the name in a CREATE, DROP or ALTER |
886 statement. The format of variable should be a valid | 1150 statement. The format of variable should be a valid |
887 `font-lock-keywords' entry.") | 1151 `font-lock-keywords' entry.") |
888 | 1152 |
889 (defmacro sql-keywords-re (&rest keywords) | 1153 ;; While there are international and American standards for SQL, they |
890 "Compile-time generation of regexp matching any one of KEYWORDS." | 1154 ;; are not followed closely, and most vendors offer significant |
891 `(eval-when-compile | 1155 ;; capabilities beyond those defined in the standard specifications. |
892 (concat "\\b" | 1156 |
893 (regexp-opt ',keywords t) | 1157 ;; SQL mode provides support for hilighting based on the product. In |
894 "\\b"))) | 1158 ;; addition to hilighting the product keywords, any ANSI keywords not |
895 | 1159 ;; used by the product are also hilighted. This will help identify |
896 (defvar sql-mode-ansi-font-lock-keywords | 1160 ;; keywords that could be restricted in future versions of the product |
897 (let ((ansi-funcs (sql-keywords-re | 1161 ;; or might be a problem if ported to another product. |
898 "abs" "avg" "bit_length" "cardinality" "cast" "char_length" | 1162 |
899 "character_length" "coalesce" "convert" "count" "current_date" | 1163 ;; To reduce the complexity and size of the regular expressions |
900 "current_path" "current_role" "current_time" "current_timestamp" | 1164 ;; generated to match keywords, ANSI keywords are filtered out of |
901 "current_user" "extract" "localtime" "localtimestamp" "lower" "max" | 1165 ;; product keywords if they are equivalent. To do this, we define a |
902 "min" "mod" "nullif" "octet_length" "overlay" "placing" "session_user" | 1166 ;; function `sql-font-lock-keywords-builder' that removes any keywords |
903 "substring" "sum" "system_user" "translate" "treat" "trim" "upper" | 1167 ;; that are matched by the ANSI patterns and results in the same face |
904 "user" | 1168 ;; being applied. For this to work properly, we must play some games |
905 )) | 1169 ;; with the execution and compile time behavior. This code is a |
906 | 1170 ;; little tricky but works properly. |
907 (ansi-non-reserved (sql-keywords-re | 1171 |
1172 ;; When defining the keywords for individual products you should | |
1173 ;; include all of the keywords that you want matched. The filtering | |
1174 ;; against the ANSI keywords will be automatic if you use the | |
1175 ;; `sql-font-lock-keywords-builder' function and follow the | |
1176 ;; implementation pattern used for the other products in this file. | |
1177 | |
1178 (eval-when-compile | |
1179 (defvar sql-mode-ansi-font-lock-keywords) | |
1180 (setq sql-mode-ansi-font-lock-keywords nil)) | |
1181 | |
1182 (eval-and-compile | |
1183 (defun sql-font-lock-keywords-builder (face boundaries &rest keywords) | |
1184 "Generation of regexp matching any one of KEYWORDS." | |
1185 | |
1186 (let ((bdy (or boundaries '("\\b" . "\\b"))) | |
1187 kwd) | |
1188 | |
1189 ;; Remove keywords that are defined in ANSI | |
1190 (setq kwd keywords) | |
1191 (dolist (k keywords) | |
1192 (catch 'next | |
1193 (dolist (a sql-mode-ansi-font-lock-keywords) | |
1194 (when (and (eq face (cdr a)) | |
1195 (eq (string-match (car a) k 0) 0) | |
1196 (eq (match-end 0) (length k))) | |
1197 (setq kwd (delq k kwd)) | |
1198 (throw 'next nil))))) | |
1199 | |
1200 ;; Create a properly formed font-lock-keywords item | |
1201 (cons (concat (car bdy) | |
1202 (regexp-opt kwd t) | |
1203 (cdr bdy)) | |
1204 face)))) | |
1205 | |
1206 (eval-when-compile | |
1207 (setq sql-mode-ansi-font-lock-keywords | |
1208 (list | |
1209 ;; ANSI Non Reserved keywords | |
1210 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil | |
908 "ada" "asensitive" "assignment" "asymmetric" "atomic" "between" | 1211 "ada" "asensitive" "assignment" "asymmetric" "atomic" "between" |
909 "bitvar" "called" "catalog_name" "chain" "character_set_catalog" | 1212 "bitvar" "called" "catalog_name" "chain" "character_set_catalog" |
910 "character_set_name" "character_set_schema" "checked" "class_origin" | 1213 "character_set_name" "character_set_schema" "checked" "class_origin" |
911 "cobol" "collation_catalog" "collation_name" "collation_schema" | 1214 "cobol" "collation_catalog" "collation_name" "collation_schema" |
912 "column_name" "command_function" "command_function_code" "committed" | 1215 "column_name" "command_function" "command_function_code" "committed" |
930 "transaction_active" "transactions_committed" | 1233 "transaction_active" "transactions_committed" |
931 "transactions_rolled_back" "transform" "transforms" "trigger_catalog" | 1234 "transactions_rolled_back" "transform" "transforms" "trigger_catalog" |
932 "trigger_name" "trigger_schema" "type" "uncommitted" "unnamed" | 1235 "trigger_name" "trigger_schema" "type" "uncommitted" "unnamed" |
933 "user_defined_type_catalog" "user_defined_type_name" | 1236 "user_defined_type_catalog" "user_defined_type_name" |
934 "user_defined_type_schema" | 1237 "user_defined_type_schema" |
935 )) | 1238 ) |
936 | 1239 ;; ANSI Reserved keywords |
937 (ansi-reserved (sql-keywords-re | 1240 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil |
938 "absolute" "action" "add" "admin" "after" "aggregate" "alias" "all" | 1241 "absolute" "action" "add" "admin" "after" "aggregate" "alias" "all" |
939 "allocate" "alter" "and" "any" "are" "as" "asc" "assertion" "at" | 1242 "allocate" "alter" "and" "any" "are" "as" "asc" "assertion" "at" |
940 "authorization" "before" "begin" "both" "breadth" "by" "call" | 1243 "authorization" "before" "begin" "both" "breadth" "by" "call" |
941 "cascade" "cascaded" "case" "catalog" "check" "class" "close" | 1244 "cascade" "cascaded" "case" "catalog" "check" "class" "close" |
942 "collate" "collation" "column" "commit" "completion" "connect" | 1245 "collate" "collation" "column" "commit" "completion" "connect" |
968 "temporary" "terminate" "than" "then" "timezone_hour" | 1271 "temporary" "terminate" "than" "then" "timezone_hour" |
969 "timezone_minute" "to" "trailing" "transaction" "translation" | 1272 "timezone_minute" "to" "trailing" "transaction" "translation" |
970 "trigger" "true" "under" "union" "unique" "unknown" "unnest" "update" | 1273 "trigger" "true" "under" "union" "unique" "unknown" "unnest" "update" |
971 "usage" "using" "value" "values" "variable" "view" "when" "whenever" | 1274 "usage" "using" "value" "values" "variable" "view" "when" "whenever" |
972 "where" "with" "without" "work" "write" "year" | 1275 "where" "with" "without" "work" "write" "year" |
973 )) | 1276 ) |
974 | 1277 |
975 (ansi-types (sql-keywords-re | 1278 ;; ANSI Functions |
1279 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil | |
1280 "abs" "avg" "bit_length" "cardinality" "cast" "char_length" | |
1281 "character_length" "coalesce" "convert" "count" "current_date" | |
1282 "current_path" "current_role" "current_time" "current_timestamp" | |
1283 "current_user" "extract" "localtime" "localtimestamp" "lower" "max" | |
1284 "min" "mod" "nullif" "octet_length" "overlay" "placing" "session_user" | |
1285 "substring" "sum" "system_user" "translate" "treat" "trim" "upper" | |
1286 "user" | |
1287 ) | |
1288 ;; ANSI Data Types | |
1289 (sql-font-lock-keywords-builder 'font-lock-type-face nil | |
976 "array" "binary" "bit" "blob" "boolean" "char" "character" "clob" | 1290 "array" "binary" "bit" "blob" "boolean" "char" "character" "clob" |
977 "date" "dec" "decimal" "double" "float" "int" "integer" "interval" | 1291 "date" "dec" "decimal" "double" "float" "int" "integer" "interval" |
978 "large" "national" "nchar" "nclob" "numeric" "object" "precision" | 1292 "large" "national" "nchar" "nclob" "numeric" "object" "precision" |
979 "real" "ref" "row" "scope" "smallint" "time" "timestamp" "varchar" | 1293 "real" "ref" "row" "scope" "smallint" "time" "timestamp" "varchar" |
980 "varying" "zone" | 1294 "varying" "zone" |
981 ))) | 1295 )))) |
982 | 1296 |
983 `((,ansi-non-reserved . font-lock-keyword-face) | 1297 (defvar sql-mode-ansi-font-lock-keywords |
984 (,ansi-reserved . font-lock-keyword-face) | 1298 (eval-when-compile sql-mode-ansi-font-lock-keywords) |
985 (,ansi-funcs . font-lock-builtin-face) | |
986 (,ansi-types . font-lock-type-face))) | |
987 | |
988 "ANSI SQL keywords used by font-lock. | 1299 "ANSI SQL keywords used by font-lock. |
989 | 1300 |
990 This variable is used by `sql-mode' and `sql-interactive-mode'. The | 1301 This variable is used by `sql-mode' and `sql-interactive-mode'. The |
991 regular expressions are created during compilation by calling the | 1302 regular expressions are created during compilation by calling the |
992 function `regexp-opt'. Therefore, take a look at the source before | 1303 function `regexp-opt'. Therefore, take a look at the source before |
993 you define your own `sql-mode-ansi-font-lock-keywords'. You may want | 1304 you define your own `sql-mode-ansi-font-lock-keywords'. You may want |
994 to add functions and PL/SQL keywords.") | 1305 to add functions and PL/SQL keywords.") |
995 | 1306 |
996 (defvar sql-mode-oracle-font-lock-keywords | 1307 (defvar sql-mode-oracle-font-lock-keywords |
997 (let ((oracle-functions (sql-keywords-re | 1308 (eval-when-compile |
1309 (list | |
1310 ;; Oracle SQL*Plus Commands | |
1311 (cons | |
1312 (concat | |
1313 "^\\(?:\\(?:" (regexp-opt '( | |
1314 "@" "@@" "accept" "append" "archive" "attribute" "break" | |
1315 "btitle" "change" "clear" "column" "connect" "copy" "define" | |
1316 "del" "describe" "disconnect" "edit" "execute" "exit" "get" "help" | |
1317 "host" "input" "list" "password" "pause" "print" "prompt" "recover" | |
1318 "remark" "repfooter" "repheader" "run" "save" "show" "shutdown" | |
1319 "spool" "start" "startup" "store" "timing" "ttitle" "undefine" | |
1320 "variable" "whenever" | |
1321 ) t) | |
1322 | |
1323 "\\)\\|" | |
1324 "\\(?:compute\\s-+\\(?:avg\\|cou\\|min\\|max\\|num\\|sum\\|std\\|var\\)\\)\\|" | |
1325 "\\(?:set\\s-+\\(" | |
1326 | |
1327 (regexp-opt | |
1328 '("appi" "appinfo" "array" "arraysize" "auto" "autocommit" | |
1329 "autop" "autoprint" "autorecovery" "autot" "autotrace" "blo" | |
1330 "blockterminator" "buffer" "closecursor" "cmds" "cmdsep" | |
1331 "colsep" "com" "compatibility" "con" "concat" "constraint" | |
1332 "constraints" "copyc" "copycommit" "copytypecheck" "database" | |
1333 "def" "define" "document" "echo" "editf" "editfile" "emb" | |
1334 "embedded" "esc" "escape" "feed" "feedback" "flagger" "flu" | |
1335 "flush" "hea" "heading" "heads" "headsep" "instance" "lin" | |
1336 "linesize" "lobof" "loboffset" "logsource" "long" "longc" | |
1337 "longchunksize" "maxdata" "newp" "newpage" "null" "num" | |
1338 "numf" "numformat" "numwidth" "pages" "pagesize" "pau" | |
1339 "pause" "recsep" "recsepchar" "role" "scan" "serveroutput" | |
1340 "shift" "shiftinout" "show" "showmode" "space" "sqlbl" | |
1341 "sqlblanklines" "sqlc" "sqlcase" "sqlco" "sqlcontinue" "sqln" | |
1342 "sqlnumber" "sqlp" "sqlpluscompat" "sqlpluscompatibility" | |
1343 "sqlpre" "sqlprefix" "sqlprompt" "sqlt" "sqlterminator" | |
1344 "statement_id" "suf" "suffix" "tab" "term" "termout" "ti" | |
1345 "time" "timi" "timing" "transaction" "trim" "trimout" "trims" | |
1346 "trimspool" "truncate" "und" "underline" "ver" "verify" "wra" | |
1347 "wrap")) "\\)\\)" | |
1348 | |
1349 "\\)\\b.*" | |
1350 ) | |
1351 'font-lock-doc-face) | |
1352 '("^[ \t]*rem\\(?:ark\\)?.*" . font-lock-comment-face) | |
1353 | |
1354 ;; Oracle Functions | |
1355 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil | |
998 "abs" "acos" "add_months" "ascii" "asciistr" "asin" "atan" "atan2" | 1356 "abs" "acos" "add_months" "ascii" "asciistr" "asin" "atan" "atan2" |
999 "avg" "bfilename" "bin_to_num" "bitand" "cast" "ceil" "chartorowid" | 1357 "avg" "bfilename" "bin_to_num" "bitand" "cast" "ceil" "chartorowid" |
1000 "chr" "coalesce" "compose" "concat" "convert" "corr" "cos" "cosh" | 1358 "chr" "coalesce" "compose" "concat" "convert" "corr" "cos" "cosh" |
1001 "count" "covar_pop" "covar_samp" "cume_dist" "current_date" | 1359 "count" "covar_pop" "covar_samp" "cume_dist" "current_date" |
1002 "current_timestamp" "current_user" "dbtimezone" "decode" "decompose" | 1360 "current_timestamp" "current_user" "dbtimezone" "decode" "decompose" |
1023 "to_timestamp_tz" "to_yminterval" "translate" "treat" "trim" "trunc" | 1381 "to_timestamp_tz" "to_yminterval" "translate" "treat" "trim" "trunc" |
1024 "tz_offset" "uid" "unbounded" "unistr" "updatexml" "upper" "user" | 1382 "tz_offset" "uid" "unbounded" "unistr" "updatexml" "upper" "user" |
1025 "userenv" "var_pop" "var_samp" "variance" "vsize" "width_bucket" "xml" | 1383 "userenv" "var_pop" "var_samp" "variance" "vsize" "width_bucket" "xml" |
1026 "xmlagg" "xmlattribute" "xmlcolattval" "xmlconcat" "xmlelement" | 1384 "xmlagg" "xmlattribute" "xmlcolattval" "xmlconcat" "xmlelement" |
1027 "xmlforest" "xmlsequence" "xmltransform" | 1385 "xmlforest" "xmlsequence" "xmltransform" |
1028 )) | 1386 ) |
1029 | 1387 ;; Oracle Keywords |
1030 (oracle-keywords (sql-keywords-re | 1388 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil |
1031 "abort" "access" "accessed" "account" "activate" "add" "admin" | 1389 "abort" "access" "accessed" "account" "activate" "add" "admin" |
1032 "advise" "after" "agent" "aggregate" "all" "allocate" "allow" "alter" | 1390 "advise" "after" "agent" "aggregate" "all" "allocate" "allow" "alter" |
1033 "always" "analyze" "ancillary" "and" "any" "apply" "archive" | 1391 "always" "analyze" "ancillary" "and" "any" "apply" "archive" |
1034 "archivelog" "array" "as" "asc" "associate" "at" "attribute" | 1392 "archivelog" "array" "as" "asc" "associate" "at" "attribute" |
1035 "attributes" "audit" "authenticated" "authid" "authorization" "auto" | 1393 "attributes" "audit" "authenticated" "authid" "authorization" "auto" |
1111 "uniform" "union" "unique" "unlimited" "unlock" "unquiesce" | 1469 "uniform" "union" "unique" "unlimited" "unlock" "unquiesce" |
1112 "unrecoverable" "until" "unusable" "unused" "update" "upgrade" "usage" | 1470 "unrecoverable" "until" "unusable" "unused" "update" "upgrade" "usage" |
1113 "use" "using" "validate" "validation" "value" "values" "variable" | 1471 "use" "using" "validate" "validation" "value" "values" "variable" |
1114 "varray" "version" "view" "wait" "when" "whenever" "where" "with" | 1472 "varray" "version" "view" "wait" "when" "whenever" "where" "with" |
1115 "without" "wnds" "wnps" "work" "write" "xmldata" "xmlschema" "xmltype" | 1473 "without" "wnds" "wnps" "work" "write" "xmldata" "xmlschema" "xmltype" |
1116 )) | 1474 ) |
1117 | 1475 ;; Oracle Data Types |
1118 (oracle-types (sql-keywords-re | 1476 (sql-font-lock-keywords-builder 'font-lock-type-face nil |
1119 "bfile" "blob" "byte" "char" "character" "clob" "date" "dec" "decimal" | 1477 "bfile" "blob" "byte" "char" "character" "clob" "date" "dec" "decimal" |
1120 "double" "float" "int" "integer" "interval" "long" "national" "nchar" | 1478 "double" "float" "int" "integer" "interval" "long" "national" "nchar" |
1121 "nclob" "number" "numeric" "nvarchar2" "precision" "raw" "real" | 1479 "nclob" "number" "numeric" "nvarchar2" "precision" "raw" "real" |
1122 "rowid" "second" "smallint" "time" "timestamp" "urowid" "varchar" | 1480 "rowid" "second" "smallint" "time" "timestamp" "urowid" "varchar" |
1123 "varchar2" "varying" "year" "zone" | 1481 "varchar2" "varying" "year" "zone" |
1124 )) | 1482 ) |
1125 | 1483 |
1126 (plsql-functions (sql-keywords-re | 1484 ;; Oracle PL/SQL Attributes |
1485 (sql-font-lock-keywords-builder 'font-lock-builtin-face '("" . "\\b") | |
1127 "%bulk_rowcount" "%found" "%isopen" "%notfound" "%rowcount" "%rowtype" | 1486 "%bulk_rowcount" "%found" "%isopen" "%notfound" "%rowcount" "%rowtype" |
1128 "%type" "extend" "prior" | 1487 "%type" |
1129 )) | 1488 ) |
1130 | 1489 |
1131 (plsql-keywords (sql-keywords-re | 1490 ;; Oracle PL/SQL Functions |
1491 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil | |
1492 "extend" "prior" | |
1493 ) | |
1494 | |
1495 ;; Oracle PL/SQL Keywords | |
1496 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil | |
1132 "autonomous_transaction" "bulk" "char_base" "collect" "constant" | 1497 "autonomous_transaction" "bulk" "char_base" "collect" "constant" |
1133 "cursor" "declare" "do" "elsif" "exception_init" "execute" "exit" | 1498 "cursor" "declare" "do" "elsif" "exception_init" "execute" "exit" |
1134 "extends" "false" "fetch" "forall" "goto" "hour" "if" "interface" | 1499 "extends" "false" "fetch" "forall" "goto" "hour" "if" "interface" |
1135 "loop" "minute" "number_base" "ocirowid" "opaque" "others" "rowtype" | 1500 "loop" "minute" "number_base" "ocirowid" "opaque" "others" "rowtype" |
1136 "separate" "serially_reusable" "sql" "sqlcode" "sqlerrm" "subtype" | 1501 "separate" "serially_reusable" "sql" "sqlcode" "sqlerrm" "subtype" |
1137 "the" "timezone_abbr" "timezone_hour" "timezone_minute" | 1502 "the" "timezone_abbr" "timezone_hour" "timezone_minute" |
1138 "timezone_region" "true" "varrying" "while" | 1503 "timezone_region" "true" "varrying" "while" |
1139 )) | 1504 ) |
1140 | 1505 |
1141 (plsql-type (sql-keywords-re | 1506 ;; Oracle PL/SQL Data Types |
1507 (sql-font-lock-keywords-builder 'font-lock-type-face nil | |
1142 "binary_integer" "boolean" "naturaln" "pls_integer" "positive" | 1508 "binary_integer" "boolean" "naturaln" "pls_integer" "positive" |
1143 "positiven" "record" "signtype" "string" | 1509 "positiven" "record" "signtype" "string" |
1144 )) | 1510 ) |
1145 | 1511 |
1146 (plsql-warning (sql-keywords-re | 1512 ;; Oracle PL/SQL Exceptions |
1513 (sql-font-lock-keywords-builder 'font-lock-warning-face nil | |
1147 "access_into_null" "case_not_found" "collection_is_null" | 1514 "access_into_null" "case_not_found" "collection_is_null" |
1148 "cursor_already_open" "dup_val_on_index" "invalid_cursor" | 1515 "cursor_already_open" "dup_val_on_index" "invalid_cursor" |
1149 "invalid_number" "login_denied" "no_data_found" "not_logged_on" | 1516 "invalid_number" "login_denied" "no_data_found" "not_logged_on" |
1150 "program_error" "rowtype_mismatch" "self_is_null" "storage_error" | 1517 "program_error" "rowtype_mismatch" "self_is_null" "storage_error" |
1151 "subscript_beyond_count" "subscript_outside_limit" "sys_invalid_rowid" | 1518 "subscript_beyond_count" "subscript_outside_limit" "sys_invalid_rowid" |
1152 "timeout_on_resource" "too_many_rows" "value_error" "zero_divide" | 1519 "timeout_on_resource" "too_many_rows" "value_error" "zero_divide" |
1153 "exception" "notfound" | 1520 "exception" "notfound" |
1154 )) | 1521 ))) |
1155 | |
1156 (sqlplus-commands | |
1157 (eval-when-compile (concat "^\\(\\(" | |
1158 (regexp-opt '( | |
1159 "@" "@@" "accept" "append" "archive" "attribute" "break" | |
1160 "btitle" "change" "clear" "column" "connect" "copy" "define" | |
1161 "del" "describe" "disconnect" "edit" "execute" "exit" "get" "help" | |
1162 "host" "input" "list" "password" "pause" "print" "prompt" "recover" | |
1163 "remark" "repfooter" "repheader" "run" "save" "show" "shutdown" | |
1164 "spool" "start" "startup" "store" "timing" "ttitle" "undefine" | |
1165 "variable" "whenever" | |
1166 | |
1167 ) t) | |
1168 | |
1169 "\\)\\|" | |
1170 "\\(compute\\s-+\\(avg\\|cou\\|min\\|max\\|num\\|sum\\|std\\|var\\)\\)\\|" | |
1171 "\\(set\\s-+\\(appi\\(nfo\\)?\\|array\\(size\\)?\\|" | |
1172 "auto\\(commit\\)?\\|autop\\(rint\\)?\\|autorecovery\\|" | |
1173 "autot\\(race\\)?\\|blo\\(ckterminator\\)?\\|cmds\\(ep\\)?\\|" | |
1174 "colsep\\|com\\(patibility\\)?\\|con\\(cat\\)?\\|" | |
1175 "copyc\\(ommit\\)?\\|copytypecheck\\|def\\(ine\\)?\\|" | |
1176 "describe\\|echo\\|editf\\(ile\\)?\\|emb\\(edded\\)?\\|" | |
1177 "esc\\(ape\\)?\\|feed\\(back\\)?\\|flagger\\|" | |
1178 "flu\\(sh\\)?\\|hea\\(ding\\)?\\|heads\\(ep\\)?\\|" | |
1179 "instance\\|lin\\(esize\\)?\\|lobof\\(fset\\)?\\|" | |
1180 "logsource\\|long\\|longc\\(hunksize\\)?\\|mark\\(up\\)?\\|" | |
1181 "newp\\(age\\)?\\|null\\|numf\\(ormat\\)?\\|" | |
1182 "num\\(width\\)?\\|pages\\(ize\\)?\\|pau\\(se\\)?\\|" | |
1183 "recsep\\|recsepchar\\|serverout\\(put\\)?\\|" | |
1184 "shift\\(inout\\)?\\|show\\(mode\\)?\\|" | |
1185 "sqlbl\\(anklines\\)?\\|sqlc\\(ase\\)?\\|" | |
1186 "sqlco\\(ntinue\\)?\\|sqln\\(umber\\)?\\|" | |
1187 "sqlpluscompat\\(ibility\\)?\\|sqlpre\\(fix\\)?\\|" | |
1188 "sqlp\\(rompt\\)?\\|sqlt\\(erminator\\)?\\|" | |
1189 "suf\\(fix\\)?\\|tab\\|term\\(out\\)?\\|ti\\(me\\)?\\|" | |
1190 "timi\\(ng\\)?\\|trim\\(out\\)?\\|trims\\(pool\\)?\\|" | |
1191 "und\\(erline\\)?\\|ver\\(ify\\)?\\|wra\\(p\\)?\\)\\)\\)" | |
1192 "\\b.*$" | |
1193 )))) | |
1194 | |
1195 `((,sqlplus-commands . font-lock-doc-face) | |
1196 (,oracle-functions . font-lock-builtin-face) | |
1197 (,oracle-keywords . font-lock-keyword-face) | |
1198 (,oracle-types . font-lock-type-face) | |
1199 (,plsql-functions . font-lock-builtin-face) | |
1200 (,plsql-keywords . font-lock-keyword-face) | |
1201 (,plsql-type . font-lock-type-face) | |
1202 (,plsql-warning . font-lock-warning-face))) | |
1203 | 1522 |
1204 "Oracle SQL keywords used by font-lock. | 1523 "Oracle SQL keywords used by font-lock. |
1205 | 1524 |
1206 This variable is used by `sql-mode' and `sql-interactive-mode'. The | 1525 This variable is used by `sql-mode' and `sql-interactive-mode'. The |
1207 regular expressions are created during compilation by calling the | 1526 regular expressions are created during compilation by calling the |
1208 function `regexp-opt'. Therefore, take a look at the source before | 1527 function `regexp-opt'. Therefore, take a look at the source before |
1209 you define your own `sql-mode-oracle-font-lock-keywords'. You may want | 1528 you define your own `sql-mode-oracle-font-lock-keywords'. You may want |
1210 to add functions and PL/SQL keywords.") | 1529 to add functions and PL/SQL keywords.") |
1211 | 1530 |
1212 (defvar sql-mode-postgres-font-lock-keywords | 1531 (defvar sql-mode-postgres-font-lock-keywords |
1213 (let ((pg-funcs (sql-keywords-re | 1532 (eval-when-compile |
1533 (list | |
1534 ;; Postgres Functions | |
1535 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil | |
1214 "abbrev" "abs" "acos" "age" "area" "ascii" "asin" "atab2" "atan" | 1536 "abbrev" "abs" "acos" "age" "area" "ascii" "asin" "atab2" "atan" |
1215 "atan2" "avg" "bit_length" "both" "broadcast" "btrim" "cbrt" "ceil" | 1537 "atan2" "avg" "bit_length" "both" "broadcast" "btrim" "cbrt" "ceil" |
1216 "center" "char_length" "chr" "coalesce" "col_description" "convert" | 1538 "center" "char_length" "chr" "coalesce" "col_description" "convert" |
1217 "cos" "cot" "count" "current_database" "current_date" "current_schema" | 1539 "cos" "cot" "count" "current_database" "current_date" "current_schema" |
1218 "current_schemas" "current_setting" "current_time" "current_timestamp" | 1540 "current_schemas" "current_setting" "current_time" "current_timestamp" |
1233 "session_user" "set_bit" "set_byte" "set_config" "set_masklen" | 1555 "session_user" "set_bit" "set_byte" "set_config" "set_masklen" |
1234 "setval" "sign" "sin" "split_part" "sqrt" "stddev" "strpos" "substr" | 1556 "setval" "sign" "sin" "split_part" "sqrt" "stddev" "strpos" "substr" |
1235 "substring" "sum" "tan" "timeofday" "to_ascii" "to_char" "to_date" | 1557 "substring" "sum" "tan" "timeofday" "to_ascii" "to_char" "to_date" |
1236 "to_hex" "to_number" "to_timestamp" "trailing" "translate" "trim" | 1558 "to_hex" "to_number" "to_timestamp" "trailing" "translate" "trim" |
1237 "trunc" "upper" "variance" "version" "width" | 1559 "trunc" "upper" "variance" "version" "width" |
1238 )) | 1560 ) |
1239 | 1561 ;; Postgres Reserved |
1240 (pg-reserved (sql-keywords-re | 1562 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil |
1241 "abort" "access" "add" "after" "aggregate" "alignment" "all" "alter" | 1563 "abort" "access" "add" "after" "aggregate" "alignment" "all" "alter" |
1242 "analyze" "and" "any" "as" "asc" "assignment" "authorization" | 1564 "analyze" "and" "any" "as" "asc" "assignment" "authorization" |
1243 "backward" "basetype" "before" "begin" "between" "binary" "by" "cache" | 1565 "backward" "basetype" "before" "begin" "between" "binary" "by" "cache" |
1244 "called" "cascade" "case" "cast" "characteristics" "check" | 1566 "called" "cascade" "case" "cast" "characteristics" "check" |
1245 "checkpoint" "class" "close" "cluster" "column" "comment" "commit" | 1567 "checkpoint" "class" "close" "cluster" "column" "comment" "commit" |
1270 "transaction" "trigger" "true" "truncate" "trusted" "type" | 1592 "transaction" "trigger" "true" "truncate" "trusted" "type" |
1271 "unencrypted" "union" "unique" "unknown" "unlisten" "until" "update" | 1593 "unencrypted" "union" "unique" "unknown" "unlisten" "until" "update" |
1272 "usage" "user" "using" "vacuum" "valid" "validator" "values" | 1594 "usage" "user" "using" "vacuum" "valid" "validator" "values" |
1273 "variable" "verbose" "view" "volatile" "when" "where" "with" "without" | 1595 "variable" "verbose" "view" "volatile" "when" "where" "with" "without" |
1274 "work" | 1596 "work" |
1275 )) | 1597 ) |
1276 | 1598 |
1277 (pg-types (sql-keywords-re | 1599 ;; Postgres Data Types |
1600 (sql-font-lock-keywords-builder 'font-lock-type-face nil | |
1278 "anyarray" "bigint" "bigserial" "bit" "boolean" "box" "bytea" "char" | 1601 "anyarray" "bigint" "bigserial" "bit" "boolean" "box" "bytea" "char" |
1279 "character" "cidr" "circle" "cstring" "date" "decimal" "double" | 1602 "character" "cidr" "circle" "cstring" "date" "decimal" "double" |
1280 "float4" "float8" "inet" "int2" "int4" "int8" "integer" "internal" | 1603 "float4" "float8" "inet" "int2" "int4" "int8" "integer" "internal" |
1281 "interval" "language_handler" "line" "lseg" "macaddr" "money" | 1604 "interval" "language_handler" "line" "lseg" "macaddr" "money" |
1282 "numeric" "oid" "opaque" "path" "point" "polygon" "precision" "real" | 1605 "numeric" "oid" "opaque" "path" "point" "polygon" "precision" "real" |
1283 "record" "regclass" "regoper" "regoperator" "regproc" "regprocedure" | 1606 "record" "regclass" "regoper" "regoperator" "regproc" "regprocedure" |
1284 "regtype" "serial" "serial4" "serial8" "smallint" "text" "time" | 1607 "regtype" "serial" "serial4" "serial8" "smallint" "text" "time" |
1285 "timestamp" "varchar" "varying" "void" "zone" | 1608 "timestamp" "varchar" "varying" "void" "zone" |
1286 ))) | 1609 ))) |
1287 | 1610 |
1288 `((,pg-funcs . font-lock-builtin-face) | |
1289 (,pg-reserved . font-lock-keyword-face) | |
1290 (,pg-types . font-lock-type-face))) | |
1291 | |
1292 "Postgres SQL keywords used by font-lock. | 1611 "Postgres SQL keywords used by font-lock. |
1293 | 1612 |
1294 This variable is used by `sql-mode' and `sql-interactive-mode'. The | 1613 This variable is used by `sql-mode' and `sql-interactive-mode'. The |
1295 regular expressions are created during compilation by calling the | 1614 regular expressions are created during compilation by calling the |
1296 function `regexp-opt'. Therefore, take a look at the source before | 1615 function `regexp-opt'. Therefore, take a look at the source before |
1297 you define your own `sql-mode-postgres-font-lock-keywords'.") | 1616 you define your own `sql-mode-postgres-font-lock-keywords'.") |
1298 | 1617 |
1299 (defvar sql-mode-linter-font-lock-keywords | 1618 (defvar sql-mode-linter-font-lock-keywords |
1300 (let ((linter-keywords (sql-keywords-re | 1619 (eval-when-compile |
1620 (list | |
1621 ;; Linter Keywords | |
1622 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil | |
1301 "autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel" | 1623 "autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel" |
1302 "committed" "count" "countblob" "cross" "current" "data" "database" | 1624 "committed" "count" "countblob" "cross" "current" "data" "database" |
1303 "datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred" | 1625 "datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred" |
1304 "denied" "description" "device" "difference" "directory" "error" | 1626 "denied" "description" "device" "difference" "directory" "error" |
1305 "escape" "euc" "exclusive" "external" "extfile" "false" "file" | 1627 "escape" "euc" "exclusive" "external" "extfile" "false" "file" |
1320 "startup" "statement" "station" "success" "sys_guid" "tables" "test" | 1642 "startup" "statement" "station" "success" "sys_guid" "tables" "test" |
1321 "timeout" "trace" "transaction" "translation" "trigger" | 1643 "timeout" "trace" "transaction" "translation" "trigger" |
1322 "trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown" | 1644 "trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown" |
1323 "unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes" | 1645 "unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes" |
1324 "wait" "windows_code" "workspace" "write" "xml" | 1646 "wait" "windows_code" "workspace" "write" "xml" |
1325 )) | 1647 ) |
1326 | 1648 |
1327 (linter-reserved (sql-keywords-re | 1649 ;; Linter Reserved |
1650 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil | |
1328 "access" "action" "add" "address" "after" "all" "alter" "always" "and" | 1651 "access" "action" "add" "address" "after" "all" "alter" "always" "and" |
1329 "any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit" | 1652 "any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit" |
1330 "aud_obj_name_len" "backup" "base" "before" "between" "blobfile" | 1653 "aud_obj_name_len" "backup" "base" "before" "between" "blobfile" |
1331 "blobfiles" "blobpct" "brief" "browse" "by" "case" "cast" "check" | 1654 "blobfiles" "blobpct" "brief" "browse" "by" "case" "cast" "check" |
1332 "clear" "close" "column" "comment" "commit" "connect" "contains" | 1655 "clear" "close" "column" "comment" "commit" "connect" "contains" |
1340 "purge" "rebuild" "resource" "restrict" "revoke" "right" "role" | 1663 "purge" "rebuild" "resource" "restrict" "revoke" "right" "role" |
1341 "rollback" "rownum" "select" "session" "set" "share" "shutdown" | 1664 "rollback" "rownum" "select" "session" "set" "share" "shutdown" |
1342 "start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then" | 1665 "start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then" |
1343 "to" "union" "unique" "unlock" "until" "update" "using" "values" | 1666 "to" "union" "unique" "unlock" "until" "update" "using" "values" |
1344 "view" "when" "where" "with" "without" | 1667 "view" "when" "where" "with" "without" |
1345 )) | 1668 ) |
1346 | 1669 |
1347 (linter-types (sql-keywords-re | 1670 ;; Linter Functions |
1348 "bigint" "bitmap" "blob" "boolean" "char" "character" "date" | 1671 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil |
1349 "datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar" | |
1350 "number" "numeric" "real" "smallint" "varbyte" "varchar" "byte" | |
1351 "cursor" "long" | |
1352 )) | |
1353 | |
1354 (linter-functions (sql-keywords-re | |
1355 "abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime" | 1672 "abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime" |
1356 "exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw" | 1673 "exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw" |
1357 "getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log" | 1674 "getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log" |
1358 "lower" "lpad" "ltrim" "max" "min" "mod" "monthname" "nvl" | 1675 "lower" "lpad" "ltrim" "max" "min" "mod" "monthname" "nvl" |
1359 "octet_length" "power" "rand" "rawtohex" "repeat_string" | 1676 "octet_length" "power" "rand" "rawtohex" "repeat_string" |
1360 "right_substr" "round" "rpad" "rtrim" "sign" "sin" "sinh" "soundex" | 1677 "right_substr" "round" "rpad" "rtrim" "sign" "sin" "sinh" "soundex" |
1361 "sqrt" "sum" "tan" "tanh" "timeint_to_days" "to_char" "to_date" | 1678 "sqrt" "sum" "tan" "tanh" "timeint_to_days" "to_char" "to_date" |
1362 "to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode" | 1679 "to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode" |
1363 "substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap" | 1680 "substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap" |
1364 "instr" "least" "multime" "replace" "width" | 1681 "instr" "least" "multime" "replace" "width" |
1682 ) | |
1683 | |
1684 ;; Linter Data Types | |
1685 (sql-font-lock-keywords-builder 'font-lock-type-face nil | |
1686 "bigint" "bitmap" "blob" "boolean" "char" "character" "date" | |
1687 "datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar" | |
1688 "number" "numeric" "real" "smallint" "varbyte" "varchar" "byte" | |
1689 "cursor" "long" | |
1365 ))) | 1690 ))) |
1366 | |
1367 `((,linter-keywords . font-lock-keyword-face) | |
1368 (,linter-reserved . font-lock-keyword-face) | |
1369 (,linter-functions . font-lock-builtin-face) | |
1370 (,linter-types . font-lock-type-face))) | |
1371 | 1691 |
1372 "Linter SQL keywords used by font-lock. | 1692 "Linter SQL keywords used by font-lock. |
1373 | 1693 |
1374 This variable is used by `sql-mode' and `sql-interactive-mode'. The | 1694 This variable is used by `sql-mode' and `sql-interactive-mode'. The |
1375 regular expressions are created during compilation by calling the | 1695 regular expressions are created during compilation by calling the |
1376 function `regexp-opt'.") | 1696 function `regexp-opt'.") |
1377 | 1697 |
1378 (defvar sql-mode-ms-font-lock-keywords | 1698 (defvar sql-mode-ms-font-lock-keywords |
1379 (let ((ms-reserved (sql-keywords-re | 1699 (eval-when-compile |
1700 (list | |
1701 ;; MS isql/osql Commands | |
1702 (cons | |
1703 (concat | |
1704 "^\\(?:\\(?:set\\s-+\\(?:" | |
1705 (regexp-opt '( | |
1706 "datefirst" "dateformat" "deadlock_priority" "lock_timeout" | |
1707 "concat_null_yields_null" "cursor_close_on_commit" | |
1708 "disable_def_cnst_chk" "fips_flagger" "identity_insert" "language" | |
1709 "offsets" "quoted_identifier" "arithabort" "arithignore" "fmtonly" | |
1710 "nocount" "noexec" "numeric_roundabort" "parseonly" | |
1711 "query_governor_cost_limit" "rowcount" "textsize" "ansi_defaults" | |
1712 "ansi_null_dflt_off" "ansi_null_dflt_on" "ansi_nulls" "ansi_padding" | |
1713 "ansi_warnings" "forceplan" "showplan_all" "showplan_text" | |
1714 "statistics" "implicit_transactions" "remote_proc_transactions" | |
1715 "transaction" "xact_abort" | |
1716 ) t) | |
1717 "\\)\\)\\|go\\s-*\\|use\\s-+\\|setuser\\s-+\\|dbcc\\s-+\\).*$") | |
1718 'font-lock-doc-face) | |
1719 | |
1720 ;; MS Reserved | |
1721 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil | |
1380 "absolute" "add" "all" "alter" "and" "any" "as" "asc" "authorization" | 1722 "absolute" "add" "all" "alter" "and" "any" "as" "asc" "authorization" |
1381 "avg" "backup" "begin" "between" "break" "browse" "bulk" "by" | 1723 "avg" "backup" "begin" "between" "break" "browse" "bulk" "by" |
1382 "cascade" "case" "check" "checkpoint" "close" "clustered" "coalesce" | 1724 "cascade" "case" "check" "checkpoint" "close" "clustered" "coalesce" |
1383 "column" "commit" "committed" "compute" "confirm" "constraint" | 1725 "column" "commit" "committed" "compute" "confirm" "constraint" |
1384 "contains" "containstable" "continue" "controlrow" "convert" "count" | 1726 "contains" "containstable" "continue" "controlrow" "convert" "count" |
1407 "textsize" "then" "to" "top" "tran" "transaction" "trigger" "truncate" | 1749 "textsize" "then" "to" "top" "tran" "transaction" "trigger" "truncate" |
1408 "tsequal" "uncommitted" "union" "unique" "update" "updatetext" | 1750 "tsequal" "uncommitted" "union" "unique" "update" "updatetext" |
1409 "updlock" "use" "user" "values" "view" "waitfor" "when" "where" | 1751 "updlock" "use" "user" "values" "view" "waitfor" "when" "where" |
1410 "while" "with" "work" "writetext" "collate" "function" "openxml" | 1752 "while" "with" "work" "writetext" "collate" "function" "openxml" |
1411 "returns" | 1753 "returns" |
1412 )) | 1754 ) |
1413 | 1755 |
1414 (ms-types (sql-keywords-re | 1756 ;; MS Functions |
1415 "binary" "bit" "char" "character" "cursor" "datetime" "dec" "decimal" | 1757 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil |
1416 "double" "float" "image" "int" "integer" "money" "national" "nchar" | |
1417 "ntext" "numeric" "numeric" "nvarchar" "precision" "real" | |
1418 "smalldatetime" "smallint" "smallmoney" "text" "timestamp" "tinyint" | |
1419 "uniqueidentifier" "varbinary" "varchar" "varying" | |
1420 )) | |
1421 | |
1422 (ms-vars "\\b@[a-zA-Z0-9_]*\\b") | |
1423 | |
1424 (ms-functions (sql-keywords-re | |
1425 "@@connections" "@@cpu_busy" "@@cursor_rows" "@@datefirst" "@@dbts" | 1758 "@@connections" "@@cpu_busy" "@@cursor_rows" "@@datefirst" "@@dbts" |
1426 "@@error" "@@fetch_status" "@@identity" "@@idle" "@@io_busy" | 1759 "@@error" "@@fetch_status" "@@identity" "@@idle" "@@io_busy" |
1427 "@@langid" "@@language" "@@lock_timeout" "@@max_connections" | 1760 "@@langid" "@@language" "@@lock_timeout" "@@max_connections" |
1428 "@@max_precision" "@@nestlevel" "@@options" "@@pack_received" | 1761 "@@max_precision" "@@nestlevel" "@@options" "@@pack_received" |
1429 "@@pack_sent" "@@packet_errors" "@@procid" "@@remserver" "@@rowcount" | 1762 "@@pack_sent" "@@packet_errors" "@@procid" "@@remserver" "@@rowcount" |
1448 "round" "rtrim" "session_user" "sign" "sin" "soundex" "space" "sqrt" | 1781 "round" "rtrim" "session_user" "sign" "sin" "soundex" "space" "sqrt" |
1449 "square" "stats_date" "stdev" "stdevp" "str" "stuff" "substring" "sum" | 1782 "square" "stats_date" "stdev" "stdevp" "str" "stuff" "substring" "sum" |
1450 "suser_id" "suser_name" "suser_sid" "suser_sname" "system_user" "tan" | 1783 "suser_id" "suser_name" "suser_sid" "suser_sname" "system_user" "tan" |
1451 "textptr" "textvalid" "typeproperty" "unicode" "upper" "user" | 1784 "textptr" "textvalid" "typeproperty" "unicode" "upper" "user" |
1452 "user_id" "user_name" "var" "varp" "year" | 1785 "user_id" "user_name" "var" "varp" "year" |
1453 )) | 1786 ) |
1454 | 1787 |
1455 (ms-commands | 1788 ;; MS Variables |
1456 (eval-when-compile | 1789 '("\\b@[a-zA-Z0-9_]*\\b" . font-lock-variable-name-face) |
1457 (concat "^\\(\\(set\\s-+\\(" | 1790 |
1458 (regexp-opt '( | 1791 ;; MS Types |
1459 "datefirst" "dateformat" "deadlock_priority" "lock_timeout" | 1792 (sql-font-lock-keywords-builder 'font-lock-type-face nil |
1460 "concat_null_yields_null" "cursor_close_on_commit" | 1793 "binary" "bit" "char" "character" "cursor" "datetime" "dec" "decimal" |
1461 "disable_def_cnst_chk" "fips_flagger" "identity_insert" "language" | 1794 "double" "float" "image" "int" "integer" "money" "national" "nchar" |
1462 "offsets" "quoted_identifier" "arithabort" "arithignore" "fmtonly" | 1795 "ntext" "numeric" "numeric" "nvarchar" "precision" "real" |
1463 "nocount" "noexec" "numeric_roundabort" "parseonly" | 1796 "smalldatetime" "smallint" "smallmoney" "text" "timestamp" "tinyint" |
1464 "query_governor_cost_limit" "rowcount" "textsize" "ansi_defaults" | 1797 "uniqueidentifier" "varbinary" "varchar" "varying" |
1465 "ansi_null_dflt_off" "ansi_null_dflt_on" "ansi_nulls" "ansi_padding" | 1798 ))) |
1466 "ansi_warnings" "forceplan" "showplan_all" "showplan_text" | |
1467 "statistics" "implicit_transactions" "remote_proc_transactions" | |
1468 "transaction" "xact_abort" | |
1469 ) t) | |
1470 "\\)\\)\\|go\\s-*\\|use\\s-+\\|setuser\\s-+\\|dbcc\\s-+\\).*$")))) | |
1471 | |
1472 `((,ms-commands . font-lock-doc-face) | |
1473 (,ms-reserved . font-lock-keyword-face) | |
1474 (,ms-functions . font-lock-builtin-face) | |
1475 (,ms-vars . font-lock-variable-name-face) | |
1476 (,ms-types . font-lock-type-face))) | |
1477 | 1799 |
1478 "Microsoft SQLServer SQL keywords used by font-lock. | 1800 "Microsoft SQLServer SQL keywords used by font-lock. |
1479 | 1801 |
1480 This variable is used by `sql-mode' and `sql-interactive-mode'. The | 1802 This variable is used by `sql-mode' and `sql-interactive-mode'. The |
1481 regular expressions are created during compilation by calling the | 1803 regular expressions are created during compilation by calling the |
1521 regular expressions are created during compilation by calling the | 1843 regular expressions are created during compilation by calling the |
1522 function `regexp-opt'. Therefore, take a look at the source before | 1844 function `regexp-opt'. Therefore, take a look at the source before |
1523 you define your own `sql-mode-solid-font-lock-keywords'.") | 1845 you define your own `sql-mode-solid-font-lock-keywords'.") |
1524 | 1846 |
1525 (defvar sql-mode-mysql-font-lock-keywords | 1847 (defvar sql-mode-mysql-font-lock-keywords |
1526 (let ((mysql-funcs (sql-keywords-re | 1848 (eval-when-compile |
1849 (list | |
1850 ;; MySQL Functions | |
1851 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil | |
1527 "ascii" "avg" "bdmpolyfromtext" "bdmpolyfromwkb" "bdpolyfromtext" | 1852 "ascii" "avg" "bdmpolyfromtext" "bdmpolyfromwkb" "bdpolyfromtext" |
1528 "bdpolyfromwkb" "benchmark" "bin" "bit_and" "bit_length" "bit_or" | 1853 "bdpolyfromwkb" "benchmark" "bin" "bit_and" "bit_length" "bit_or" |
1529 "bit_xor" "both" "cast" "char_length" "character_length" "coalesce" | 1854 "bit_xor" "both" "cast" "char_length" "character_length" "coalesce" |
1530 "concat" "concat_ws" "connection_id" "conv" "convert" "count" | 1855 "concat" "concat_ws" "connection_id" "conv" "convert" "count" |
1531 "curdate" "current_date" "current_time" "current_timestamp" "curtime" | 1856 "curdate" "current_date" "current_time" "current_timestamp" "curtime" |
1544 "pointfromtext" "pointfromwkb" "polyfromtext" "polyfromwkb" | 1869 "pointfromtext" "pointfromwkb" "polyfromtext" "polyfromwkb" |
1545 "polygonfromtext" "polygonfromwkb" "position" "quote" "rand" | 1870 "polygonfromtext" "polygonfromwkb" "position" "quote" "rand" |
1546 "release_lock" "repeat" "replace" "reverse" "rpad" "rtrim" "soundex" | 1871 "release_lock" "repeat" "replace" "reverse" "rpad" "rtrim" "soundex" |
1547 "space" "std" "stddev" "substring" "substring_index" "sum" "sysdate" | 1872 "space" "std" "stddev" "substring" "substring_index" "sum" "sysdate" |
1548 "trailing" "trim" "ucase" "unix_timestamp" "upper" "user" "variance" | 1873 "trailing" "trim" "ucase" "unix_timestamp" "upper" "user" "variance" |
1549 )) | 1874 ) |
1550 | 1875 |
1551 (mysql-keywords (sql-keywords-re | 1876 ;; MySQL Keywords |
1877 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil | |
1552 "action" "add" "after" "against" "all" "alter" "and" "as" "asc" | 1878 "action" "add" "after" "against" "all" "alter" "and" "as" "asc" |
1553 "auto_increment" "avg_row_length" "bdb" "between" "by" "cascade" | 1879 "auto_increment" "avg_row_length" "bdb" "between" "by" "cascade" |
1554 "case" "change" "character" "check" "checksum" "close" "collate" | 1880 "case" "change" "character" "check" "checksum" "close" "collate" |
1555 "collation" "column" "columns" "comment" "committed" "concurrent" | 1881 "collation" "column" "columns" "comment" "committed" "concurrent" |
1556 "constraint" "create" "cross" "data" "database" "default" | 1882 "constraint" "create" "cross" "data" "database" "default" |
1572 "sql_calc_found_rows" "sql_no_cache" "sql_small_result" "starting" | 1898 "sql_calc_found_rows" "sql_no_cache" "sql_small_result" "starting" |
1573 "straight_join" "striped" "table" "tables" "temporary" "terminated" | 1899 "straight_join" "striped" "table" "tables" "temporary" "terminated" |
1574 "then" "to" "transaction" "truncate" "type" "uncommitted" "union" | 1900 "then" "to" "transaction" "truncate" "type" "uncommitted" "union" |
1575 "unique" "unlock" "update" "use" "using" "values" "when" "where" | 1901 "unique" "unlock" "update" "use" "using" "values" "when" "where" |
1576 "with" "write" "xor" | 1902 "with" "write" "xor" |
1577 )) | 1903 ) |
1578 | 1904 |
1579 (mysql-types (sql-keywords-re | 1905 ;; MySQL Data Types |
1906 (sql-font-lock-keywords-builder 'font-lock-type-face nil | |
1580 "bigint" "binary" "bit" "blob" "bool" "boolean" "char" "curve" "date" | 1907 "bigint" "binary" "bit" "blob" "bool" "boolean" "char" "curve" "date" |
1581 "datetime" "dec" "decimal" "double" "enum" "fixed" "float" "geometry" | 1908 "datetime" "dec" "decimal" "double" "enum" "fixed" "float" "geometry" |
1582 "geometrycollection" "int" "integer" "line" "linearring" "linestring" | 1909 "geometrycollection" "int" "integer" "line" "linearring" "linestring" |
1583 "longblob" "longtext" "mediumblob" "mediumint" "mediumtext" | 1910 "longblob" "longtext" "mediumblob" "mediumint" "mediumtext" |
1584 "multicurve" "multilinestring" "multipoint" "multipolygon" | 1911 "multicurve" "multilinestring" "multipoint" "multipolygon" |
1586 "real" "smallint" "surface" "text" "time" "timestamp" "tinyblob" | 1913 "real" "smallint" "surface" "text" "time" "timestamp" "tinyblob" |
1587 "tinyint" "tinytext" "unsigned" "varchar" "year" "year2" "year4" | 1914 "tinyint" "tinytext" "unsigned" "varchar" "year" "year2" "year4" |
1588 "zerofill" | 1915 "zerofill" |
1589 ))) | 1916 ))) |
1590 | 1917 |
1591 `((,mysql-funcs . font-lock-builtin-face) | |
1592 (,mysql-keywords . font-lock-keyword-face) | |
1593 (,mysql-types . font-lock-type-face))) | |
1594 | |
1595 "MySQL SQL keywords used by font-lock. | 1918 "MySQL SQL keywords used by font-lock. |
1596 | 1919 |
1597 This variable is used by `sql-mode' and `sql-interactive-mode'. The | 1920 This variable is used by `sql-mode' and `sql-interactive-mode'. The |
1598 regular expressions are created during compilation by calling the | 1921 regular expressions are created during compilation by calling the |
1599 function `regexp-opt'. Therefore, take a look at the source before | 1922 function `regexp-opt'. Therefore, take a look at the source before |
1624 | 1947 |
1625 | 1948 |
1626 | 1949 |
1627 ;;; SQL Product support functions | 1950 ;;; SQL Product support functions |
1628 | 1951 |
1629 (defun sql-product-feature (feature &optional product) | 1952 (defun sql-add-product (product display &rest plist) |
1630 "Lookup `feature' needed to support the current SQL product. | 1953 "Add support for a database product in `sql-mode'. |
1954 | |
1955 Add PRODUCT to `sql-product-alist' which enables `sql-mode' to | |
1956 properly support syntax highlighting and interactive interaction. | |
1957 DISPLAY is the name of the SQL product that will appear in the | |
1958 menu bar and in messages. PLIST initializes the product | |
1959 configuration." | |
1960 | |
1961 ;; Don't do anything if the product is already supported | |
1962 (if (assoc product sql-product-alist) | |
1963 (message "Product `%s' is already defined" product) | |
1964 | |
1965 ;; Add product to the alist | |
1966 (add-to-list 'sql-product-alist `((,product :name ,display . ,plist))) | |
1967 ;; Add a menu item to the SQL->Product menu | |
1968 (easy-menu-add-item sql-mode-menu '("Product") | |
1969 ;; Each product is represented by a radio | |
1970 ;; button with it's display name. | |
1971 `[,display | |
1972 (lambda () (interactive) (sql-set-product ',product)) | |
1973 :style radio | |
1974 :selected (eq sql-product ',product)] | |
1975 ;; Maintain the product list in | |
1976 ;; (case-insensitive) alphabetic order of the | |
1977 ;; display names. Loop thru each keymap item | |
1978 ;; looking for an item whose display name is | |
1979 ;; after this product's name. | |
1980 (let ((next-item) | |
1981 (down-display (downcase display))) | |
1982 (map-keymap (lambda (k b) | |
1983 (when (and (not next-item) | |
1984 (string-lessp down-display | |
1985 (downcase (cadr b)))) | |
1986 (setq next-item k))) | |
1987 (easy-menu-get-map sql-mode-menu '("Product"))) | |
1988 next-item)) | |
1989 product)) | |
1990 | |
1991 (defun sql-del-product (product) | |
1992 "Remove support for PRODUCT in `sql-mode'." | |
1993 | |
1994 ;; Remove the menu item based on the display name | |
1995 (easy-menu-remove-item sql-mode-menu '("Product") (sql-get-product-feature product :name)) | |
1996 ;; Remove the product alist item | |
1997 (setq sql-product-alist (assq-delete-all product sql-product-alist)) | |
1998 nil) | |
1999 | |
2000 (defun sql-set-product-feature (product feature newvalue) | |
2001 "Set FEATURE of database PRODUCT to NEWVALUE. | |
2002 | |
2003 The PRODUCT must be a symbol which identifies the database | |
2004 product. The product must have already exist on the product | |
2005 list. See `sql-add-product' to add new products. The FEATURE | |
2006 argument must be a plist keyword accepted by | |
2007 `sql-product-alist'." | |
2008 | |
2009 (let* ((p (assoc product sql-product-alist)) | |
2010 (v (plist-get (cdr p) feature))) | |
2011 (if p | |
2012 (if (and | |
2013 (member feature sql-indirect-features) | |
2014 (symbolp v)) | |
2015 (set v newvalue) | |
2016 (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)))) | |
2018 | |
2019 (defun sql-get-product-feature (product feature &optional fallback) | |
2020 "Lookup FEATURE associated with a SQL PRODUCT. | |
2021 | |
2022 If the FEATURE is nil for PRODUCT, and FALLBACK is specified, | |
2023 then the FEATURE associated with the FALLBACK product is | |
2024 returned. | |
1631 | 2025 |
1632 See `sql-product-alist' for a list of products and supported features." | 2026 See `sql-product-alist' for a list of products and supported features." |
1633 (plist-get | 2027 (let* ((p (assoc product sql-product-alist)) |
1634 (cdr (assoc (or product sql-product) | 2028 (v (plist-get (cdr p) feature))) |
1635 sql-product-alist)) | 2029 |
1636 feature)) | 2030 (if p |
2031 ;; If no value and fallback, lookup feature for fallback | |
2032 (if (and (not v) | |
2033 fallback | |
2034 (not (eq product fallback))) | |
2035 (sql-get-product-feature fallback feature) | |
2036 | |
2037 (if (and | |
2038 (member feature sql-indirect-features) | |
2039 (symbolp v)) | |
2040 (symbol-value v) | |
2041 v)) | |
2042 (message "`%s' is not a known product; use `sql-add-product' to add it first." product)))) | |
1637 | 2043 |
1638 (defun sql-product-font-lock (keywords-only imenu) | 2044 (defun sql-product-font-lock (keywords-only imenu) |
1639 "Sets `font-lock-defaults' and `font-lock-keywords' based on | 2045 "Configures font-lock and imenu with product-specific settings. |
1640 the product-specific keywords and syntax-alists defined in | 2046 |
1641 `sql-product-alist'." | 2047 The KEYWORDS-ONLY flag is passed to font-lock to specify whether |
2048 only keywords should be hilighted and syntactic hilighting | |
2049 skipped. The IMENU flag indicates whether `imenu-mode' should | |
2050 also be configured." | |
2051 | |
1642 (let | 2052 (let |
1643 ;; Get the product-specific syntax-alist. | 2053 ;; Get the product-specific syntax-alist. |
1644 ((syntax-alist | 2054 ((syntax-alist |
1645 (append | 2055 (append |
1646 (sql-product-feature :syntax-alist) | 2056 (sql-get-product-feature sql-product :syntax-alist) |
1647 '((?_ . "w") (?. . "w"))))) | 2057 '((?_ . "w") (?. . "w"))))) |
1648 | 2058 |
1649 ;; Get the product-specific keywords. | 2059 ;; Get the product-specific keywords. |
1650 (setq sql-mode-font-lock-keywords | 2060 (setq sql-mode-font-lock-keywords |
1651 (append | 2061 (append |
1652 (unless (eq sql-product 'ansi) | 2062 (unless (eq sql-product 'ansi) |
1653 (eval (sql-product-feature :font-lock))) | 2063 (sql-get-product-feature sql-product :font-lock)) |
1654 ;; Always highlight ANSI keywords | 2064 ;; Always highlight ANSI keywords |
1655 (eval (sql-product-feature :font-lock 'ansi)) | 2065 (sql-get-product-feature 'ansi :font-lock) |
1656 ;; Fontify object names in CREATE, DROP and ALTER DDL | 2066 ;; Fontify object names in CREATE, DROP and ALTER DDL |
1657 ;; statements | 2067 ;; statements |
1658 (list sql-mode-font-lock-object-name))) | 2068 (list sql-mode-font-lock-object-name))) |
1659 | 2069 |
1660 ;; Setup font-lock. Force re-parsing of `font-lock-defaults'. | 2070 ;; Setup font-lock. Force re-parsing of `font-lock-defaults'. |
1661 (set (make-local-variable 'font-lock-set-defaults) nil) | 2071 (kill-local-variable 'font-lock-set-defaults) |
1662 (setq font-lock-defaults (list 'sql-mode-font-lock-keywords | 2072 (setq font-lock-defaults (list 'sql-mode-font-lock-keywords |
1663 keywords-only t syntax-alist)) | 2073 keywords-only t syntax-alist)) |
1664 | 2074 |
1665 ;; Force font lock to reinitialize if it is already on | 2075 ;; Force font lock to reinitialize if it is already on |
1666 ;; Otherwise, we can wait until it can be started. | 2076 ;; Otherwise, we can wait until it can be started. |
1667 (when (and (fboundp 'font-lock-mode) | 2077 (when (and (fboundp 'font-lock-mode) |
2078 (boundp 'font-lock-mode) | |
1668 font-lock-mode) | 2079 font-lock-mode) |
1669 (font-lock-mode-internal nil) | 2080 (font-lock-mode-internal nil) |
1670 (font-lock-mode-internal t)) | 2081 (font-lock-mode-internal t)) |
1671 | 2082 |
1672 (add-hook 'font-lock-mode-hook | 2083 (add-hook 'font-lock-mode-hook |
1679 (defvar font-lock-doc-face font-lock-string-face)) | 2090 (defvar font-lock-doc-face font-lock-string-face)) |
1680 nil t) | 2091 nil t) |
1681 | 2092 |
1682 ;; Setup imenu; it needs the same syntax-alist. | 2093 ;; Setup imenu; it needs the same syntax-alist. |
1683 (when imenu | 2094 (when imenu |
1684 (setq imenu-syntax-alist syntax-alist)))) | 2095 (setq imenu-syntax-alist syntax-alist)))) |
1685 | 2096 |
1686 ;;;###autoload | 2097 ;;;###autoload |
1687 (defun sql-add-product-keywords (product keywords &optional append) | 2098 (defun sql-add-product-keywords (product keywords &optional append) |
1688 "Add highlighting KEYWORDS for SQL PRODUCT. | 2099 "Add highlighting KEYWORDS for SQL PRODUCT. |
1689 | 2100 |
1701 '((\"\\\\b\\\\w+_t\\\\b\" . font-lock-type-face))) | 2112 '((\"\\\\b\\\\w+_t\\\\b\" . font-lock-type-face))) |
1702 | 2113 |
1703 adds a fontification pattern to fontify identifiers ending in | 2114 adds a fontification pattern to fontify identifiers ending in |
1704 `_t' as data types." | 2115 `_t' as data types." |
1705 | 2116 |
1706 (let ((font-lock (sql-product-feature :font-lock product)) | 2117 (let* ((sql-indirect-features nil) |
1707 old) | 2118 (font-lock-var (sql-get-product-feature product :font-lock)) |
1708 (setq old (eval font-lock)) | 2119 (old-val)) |
1709 (set font-lock | 2120 |
2121 (setq old-val (symbol-value font-lock-var)) | |
2122 (set font-lock-var | |
1710 (if (eq append 'set) | 2123 (if (eq append 'set) |
1711 keywords | 2124 keywords |
1712 (if append | 2125 (if append |
1713 (append old keywords) | 2126 (append old-val keywords) |
1714 (append keywords old)))))) | 2127 (append keywords old-val)))))) |
1715 | 2128 |
1716 | 2129 |
1717 | 2130 |
1718 ;;; Functions to switch highlighting | 2131 ;;; Functions to switch highlighting |
1719 | 2132 |
1720 (defun sql-highlight-product () | 2133 (defun sql-highlight-product () |
1721 "Turn on the appropriate font highlighting for the SQL product selected." | 2134 "Turns on the font highlighting for the SQL product selected." |
1722 (when (derived-mode-p 'sql-mode) | 2135 (when (derived-mode-p 'sql-mode) |
1723 ;; Setup font-lock | 2136 ;; Setup font-lock |
1724 (sql-product-font-lock nil t) | 2137 (sql-product-font-lock nil t) |
1725 | 2138 |
1726 ;; Set the mode name to include the product. | 2139 ;; Set the mode name to include the product. |
1727 (setq mode-name (concat "SQL[" (prin1-to-string sql-product) "]")))) | 2140 (setq mode-name (concat "SQL[" (or (sql-get-product-feature sql-product :name) |
2141 (symbol-name sql-product)) "]")))) | |
1728 | 2142 |
1729 (defun sql-set-product (product) | 2143 (defun sql-set-product (product) |
1730 "Set `sql-product' to product and enable appropriate highlighting." | 2144 "Set `sql-product' to product and enable appropriate highlighting." |
1731 (interactive | 2145 (interactive |
1732 (list (completing-read "Enter SQL product: " | 2146 (list (completing-read "SQL product: " |
1733 (mapcar (lambda (info) (symbol-name (car info))) | 2147 (mapcar (lambda (info) (symbol-name (car info))) |
1734 sql-product-alist) | 2148 sql-product-alist) |
1735 nil 'require-match))) | 2149 nil 'require-match |
2150 (or (and sql-product (symbol-name sql-product)) "ansi")))) | |
1736 (if (stringp product) (setq product (intern product))) | 2151 (if (stringp product) (setq product (intern product))) |
1737 (when (not (assoc product sql-product-alist)) | 2152 (when (not (assoc product sql-product-alist)) |
1738 (error "SQL product %s is not supported; treated as ANSI" product) | 2153 (error "SQL product %s is not supported; treated as ANSI" product) |
1739 (setq product 'ansi)) | 2154 (setq product 'ansi)) |
1740 | 2155 |
1782 (if (fboundp 'comint-accumulate) | 2197 (if (fboundp 'comint-accumulate) |
1783 (comint-accumulate) | 2198 (comint-accumulate) |
1784 (newline)) | 2199 (newline)) |
1785 (indent-according-to-mode)) | 2200 (indent-according-to-mode)) |
1786 | 2201 |
2202 (defun sql-help-list-products (indent freep) | |
2203 "Generate listing of products available for use under SQLi. | |
2204 | |
2205 List products with :free-softare attribute set to FREEP. Indent | |
2206 each line with INDENT." | |
2207 | |
2208 (let (sqli-func doc) | |
2209 (setq doc "") | |
2210 (dolist (p sql-product-alist) | |
2211 (setq sqli-func (intern (concat "sql-" (symbol-name (car p))))) | |
2212 | |
2213 (if (and (fboundp sqli-func) | |
2214 (eq (sql-get-product-feature (car p) :free-software) freep)) | |
2215 (setq doc | |
2216 (concat doc | |
2217 indent | |
2218 (or (sql-get-product-feature (car p) :name) | |
2219 (symbol-name (car p))) | |
2220 ":\t" | |
2221 "\\[" | |
2222 (symbol-name sqli-func) | |
2223 "]\n")))) | |
2224 doc)) | |
2225 | |
1787 ;;;###autoload | 2226 ;;;###autoload |
1788 (defun sql-help () | 2227 (defun sql-help () |
1789 "Show short help for the SQL modes. | 2228 "Show short help for the SQL modes. |
1790 | 2229 |
1791 Use an entry function to open an interactive SQL buffer. This buffer is | 2230 Use an entry function to open an interactive SQL buffer. This buffer is |
1792 usually named `*SQL*'. The name of the major mode is SQLi. | 2231 usually named `*SQL*'. The name of the major mode is SQLi. |
1793 | 2232 |
1794 Use the following commands to start a specific SQL interpreter: | 2233 Use the following commands to start a specific SQL interpreter: |
1795 | 2234 |
1796 PostGres: \\[sql-postgres] | 2235 \\\\FREE |
1797 MySQL: \\[sql-mysql] | |
1798 SQLite: \\[sql-sqlite] | |
1799 | 2236 |
1800 Other non-free SQL implementations are also supported: | 2237 Other non-free SQL implementations are also supported: |
1801 | 2238 |
1802 Solid: \\[sql-solid] | 2239 \\\\NONFREE |
1803 Oracle: \\[sql-oracle] | |
1804 Informix: \\[sql-informix] | |
1805 Sybase: \\[sql-sybase] | |
1806 Ingres: \\[sql-ingres] | |
1807 Microsoft: \\[sql-ms] | |
1808 DB2: \\[sql-db2] | |
1809 Interbase: \\[sql-interbase] | |
1810 Linter: \\[sql-linter] | |
1811 | 2240 |
1812 But we urge you to choose a free implementation instead of these. | 2241 But we urge you to choose a free implementation instead of these. |
2242 | |
2243 You can also use \\[sql-product-interactive] to invoke the | |
2244 interpreter for the current `sql-product'. | |
1813 | 2245 |
1814 Once you have the SQLi buffer, you can enter SQL statements in the | 2246 Once you have the SQLi buffer, you can enter SQL statements in the |
1815 buffer. The output generated is appended to the buffer and a new prompt | 2247 buffer. The output generated is appended to the buffer and a new prompt |
1816 is generated. See the In/Out menu in the SQLi buffer for some functions | 2248 is generated. See the In/Out menu in the SQLi buffer for some functions |
1817 that help you navigate through the buffer, the input history, etc. | 2249 that help you navigate through the buffer, the input history, etc. |
1823 | 2255 |
1824 In this SQL buffer (SQL mode), you can send the region or the entire | 2256 In this SQL buffer (SQL mode), you can send the region or the entire |
1825 buffer to the interactive SQL buffer (SQLi mode). The results are | 2257 buffer to the interactive SQL buffer (SQLi mode). The results are |
1826 appended to the SQLi buffer without disturbing your SQL buffer." | 2258 appended to the SQLi buffer without disturbing your SQL buffer." |
1827 (interactive) | 2259 (interactive) |
2260 | |
2261 ;; Insert references to loaded products into the help buffer string | |
2262 (let ((doc (documentation 'sql-help t)) | |
2263 changedp) | |
2264 (setq changedp nil) | |
2265 | |
2266 ;; Insert FREE software list | |
2267 (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]FREE\\s-*\n" doc 0) | |
2268 (setq doc (replace-match (sql-help-list-products (match-string 1 doc) t) | |
2269 t t doc 0) | |
2270 changedp t)) | |
2271 | |
2272 ;; Insert non-FREE software list | |
2273 (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]NONFREE\\s-*\n" doc 0) | |
2274 (setq doc (replace-match (sql-help-list-products (match-string 1 doc) nil) | |
2275 t t doc 0) | |
2276 changedp t)) | |
2277 | |
2278 ;; If we changed the help text, save the change so that the help | |
2279 ;; sub-system will see it | |
2280 (when changedp | |
2281 (put 'sql-help 'function-documentation doc))) | |
2282 | |
2283 ;; Call help on this function | |
1828 (describe-function 'sql-help)) | 2284 (describe-function 'sql-help)) |
1829 | 2285 |
1830 (defun sql-read-passwd (prompt &optional default) | 2286 (defun sql-read-passwd (prompt &optional default) |
1831 "Read a password using PROMPT. Optional DEFAULT is password to start with." | 2287 "Read a password using PROMPT. Optional DEFAULT is password to start with." |
1832 (read-passwd prompt nil default)) | 2288 (read-passwd prompt nil default)) |
1838 `sql-database' can be customized. They are used as the default values. | 2294 `sql-database' can be customized. They are used as the default values. |
1839 Usernames, servers and databases are stored in `sql-user-history', | 2295 Usernames, servers and databases are stored in `sql-user-history', |
1840 `sql-server-history' and `database-history'. Passwords are not stored | 2296 `sql-server-history' and `database-history'. Passwords are not stored |
1841 in a history. | 2297 in a history. |
1842 | 2298 |
1843 Parameter WHAT is a list of the arguments passed to this function. | 2299 Parameter WHAT is a list of tokens passed as arguments in the |
1844 The function asks for the username if WHAT contains symbol `user', for | 2300 function call. The function asks for the username if WHAT |
1845 the password if it contains symbol `password', for the server if it | 2301 contains the symbol `user', for the password if it contains the |
1846 contains symbol `server', and for the database if it contains symbol | 2302 symbol `password', for the server if it contains the symbol |
1847 `database'. The members of WHAT are processed in the order in which | 2303 `server', and for the database if it contains the symbol |
1848 they are provided. | 2304 `database'. The members of WHAT are processed in the order in |
2305 which they are provided. | |
1849 | 2306 |
1850 In order to ask the user for username, password and database, call the | 2307 In order to ask the user for username, password and database, call the |
1851 function like this: (sql-get-login 'user 'password 'database)." | 2308 function like this: (sql-get-login 'user 'password 'database)." |
1852 (interactive) | 2309 (interactive) |
1853 (while what | 2310 (while what |
1854 (cond | 2311 (cond |
1855 ((eq (car what) 'user) ; user | 2312 ((eq (car what) 'user) ; user |
1856 (setq sql-user | 2313 (setq sql-user |
1857 (read-from-minibuffer "User: " sql-user nil nil | 2314 (read-from-minibuffer "User: " sql-user nil nil |
1858 sql-user-history))) | 2315 'sql-user-history))) |
1859 ((eq (car what) 'password) ; password | 2316 ((eq (car what) 'password) ; password |
1860 (setq sql-password | 2317 (setq sql-password |
1861 (sql-read-passwd "Password: " sql-password))) | 2318 (sql-read-passwd "Password: " sql-password))) |
2319 | |
1862 ((eq (car what) 'server) ; server | 2320 ((eq (car what) 'server) ; server |
1863 (setq sql-server | 2321 (setq sql-server |
1864 (read-from-minibuffer "Server: " sql-server nil nil | 2322 (read-from-minibuffer "Server: " sql-server nil nil |
1865 sql-server-history))) | 2323 'sql-server-history))) |
2324 ((eq (car what) 'port) ; port | |
2325 (setq sql-port | |
2326 (read-from-minibuffer "Port: " sql-port nil nil | |
2327 'sql-port-history))) | |
1866 ((eq (car what) 'database) ; database | 2328 ((eq (car what) 'database) ; database |
1867 (setq sql-database | 2329 (setq sql-database |
1868 (read-from-minibuffer "Database: " sql-database nil nil | 2330 (read-from-minibuffer "Database: " sql-database nil nil |
1869 sql-database-history)))) | 2331 'sql-database-history)))) |
1870 (setq what (cdr what)))) | 2332 (setq what (cdr what)))) |
1871 | 2333 |
1872 (defun sql-find-sqli-buffer () | 2334 (defun sql-find-sqli-buffer () |
1873 "Return the current default SQLi buffer or nil. | 2335 "Returns the current default SQLi buffer or nil. |
1874 In order to qualify, the SQLi buffer must be alive, | 2336 In order to qualify, the SQLi buffer must be alive, |
1875 be in `sql-interactive-mode' and have a process." | 2337 be in `sql-interactive-mode' and have a process." |
1876 (let ((default-buffer (default-value 'sql-buffer))) | 2338 (let ((default-buffer (default-value 'sql-buffer))) |
1877 (if (and (buffer-live-p default-buffer) | 2339 (if (and (buffer-live-p default-buffer) |
1878 (get-buffer-process default-buffer)) | 2340 (get-buffer-process default-buffer)) |
1952 (if (null (get-buffer-process sql-buffer)) | 2414 (if (null (get-buffer-process sql-buffer)) |
1953 (message "Buffer %s has no process." (buffer-name sql-buffer)) | 2415 (message "Buffer %s has no process." (buffer-name sql-buffer)) |
1954 (message "Current SQLi buffer is %s." (buffer-name sql-buffer))))) | 2416 (message "Current SQLi buffer is %s." (buffer-name sql-buffer))))) |
1955 | 2417 |
1956 (defun sql-make-alternate-buffer-name () | 2418 (defun sql-make-alternate-buffer-name () |
1957 "Return a string that can be used to rename a SQLi buffer. | 2419 "Returns a string that can be used to rename a SQLi buffer. |
1958 | 2420 |
1959 This is used to set `sql-alternate-buffer-name' within | 2421 This is used to set `sql-alternate-buffer-name' within |
1960 `sql-interactive-mode'." | 2422 `sql-interactive-mode'." |
1961 (concat (if (string= "" sql-user) | 2423 (concat (if (string= "" sql-user) |
1962 (if (string= "" (user-login-name)) | 2424 (if (string= "" (user-login-name)) |
1978 "Copy current column to the end of buffer. | 2440 "Copy current column to the end of buffer. |
1979 Inserts SELECT or commas if appropriate." | 2441 Inserts SELECT or commas if appropriate." |
1980 (interactive) | 2442 (interactive) |
1981 (let ((column)) | 2443 (let ((column)) |
1982 (save-excursion | 2444 (save-excursion |
1983 (setq column (buffer-substring | 2445 (setq column (buffer-substring-no-properties |
1984 (progn (forward-char 1) (backward-sexp 1) (point)) | 2446 (progn (forward-char 1) (backward-sexp 1) (point)) |
1985 (progn (forward-sexp 1) (point)))) | 2447 (progn (forward-sexp 1) (point)))) |
1986 (goto-char (point-max)) | 2448 (goto-char (point-max)) |
1987 (let ((bol (comint-line-beginning-position))) | 2449 (let ((bol (comint-line-beginning-position))) |
1988 (cond | 2450 (cond |
2009 ;; Emacs query for the placeholders. | 2471 ;; Emacs query for the placeholders. |
2010 | 2472 |
2011 (defvar sql-placeholder-history nil | 2473 (defvar sql-placeholder-history nil |
2012 "History of placeholder values used.") | 2474 "History of placeholder values used.") |
2013 | 2475 |
2014 (defun sql-query-placeholders-and-send (proc string) | 2476 (defun sql-placeholders-filter (string) |
2015 "Send to PROC input STRING, maybe replacing placeholders. | 2477 "Replace placeholders in STRING. |
2016 Placeholders are words starting with an ampersand like &this. | 2478 Placeholders are words starting with and ampersand like &this." |
2017 This function is used for `comint-input-sender' if using | 2479 |
2018 `sql-oracle' on Windows." | 2480 (when sql-oracle-scan-on |
2019 (while (string-match "&\\(\\sw+\\)" string) | 2481 (while (string-match "&\\(\\sw+\\)" string) |
2020 (setq string (replace-match | 2482 (setq string (replace-match |
2021 (read-from-minibuffer | 2483 (read-from-minibuffer |
2022 (format "Enter value for %s: " (match-string 1 string)) | 2484 (format "Enter value for %s: " (match-string 1 string)) |
2023 nil nil nil sql-placeholder-history) | 2485 nil nil nil 'sql-placeholder-history) |
2024 t t string))) | 2486 t t string)))) |
2025 (comint-send-string proc string) | 2487 string) |
2026 (if comint-input-sender-no-newline | |
2027 (if (not (string-equal string "")) | |
2028 (process-send-eof)) | |
2029 (comint-send-string proc "\n"))) | |
2030 | 2488 |
2031 ;; Using DB2 interactively, newlines must be escaped with " \". | 2489 ;; Using DB2 interactively, newlines must be escaped with " \". |
2032 ;; The space before the backslash is relevant. | 2490 ;; The space before the backslash is relevant. |
2033 (defun sql-escape-newlines-and-send (proc string) | 2491 (defun sql-escape-newlines-filter (string) |
2034 "Send to PROC input STRING, escaping newlines if necessary. | 2492 "Escapes newlines in STRING. |
2035 Every newline in STRING will be preceded with a space and a backslash." | 2493 Every newline in STRING will be preceded with a space and a backslash." |
2036 (let ((result "") (start 0) mb me) | 2494 (let ((result "") (start 0) mb me) |
2037 (while (string-match "\n" string start) | 2495 (while (string-match "\n" string start) |
2038 (setq mb (match-beginning 0) | 2496 (setq mb (match-beginning 0) |
2039 me (match-end 0)) | 2497 me (match-end 0) |
2040 (if (and (> mb 1) | 2498 result (concat result |
2041 (string-equal " \\" (substring string (- mb 2) mb))) | 2499 (substring string start mb) |
2042 (setq result (concat result (substring string start me))) | 2500 (if (and (> mb 1) |
2043 (setq result (concat result (substring string start mb) " \\\n"))) | 2501 (string-equal " \\" (substring string (- mb 2) mb))) |
2044 (setq start me)) | 2502 "" " \\\n")) |
2045 (setq result (concat result (substring string start))) | 2503 start me)) |
2046 (comint-send-string proc result) | 2504 (concat result (substring string start)))) |
2047 (if comint-input-sender-no-newline | |
2048 (if (not (string-equal string "")) | |
2049 (process-send-eof)) | |
2050 (comint-send-string proc "\n")))) | |
2051 | 2505 |
2052 | 2506 |
2053 | 2507 |
2508 ;;; Input sender for SQLi buffers | |
2509 | |
2510 (defun sql-input-sender (proc string) | |
2511 "Sends STRING to PROC after applying filters." | |
2512 | |
2513 (let* ((product (with-current-buffer (process-buffer proc) sql-product)) | |
2514 (filter (sql-get-product-feature product :input-filter))) | |
2515 | |
2516 ;; Send the string | |
2517 (comint-simple-send proc (if filter (funcall filter string) string)))) | |
2518 | |
2054 ;;; Sending the region to the SQLi buffer. | 2519 ;;; Sending the region to the SQLi buffer. |
2520 | |
2521 (defun sql-send-string (str) | |
2522 "Send the string STR to the SQL process." | |
2523 (interactive "sSQL Text: ") | |
2524 | |
2525 (let (comint-input-sender-no-newline proc) | |
2526 (if (buffer-live-p sql-buffer) | |
2527 (progn | |
2528 ;; Ignore the hoping around... | |
2529 (save-excursion | |
2530 ;; Get the process | |
2531 (setq proc (get-buffer-process sql-buffer)) | |
2532 | |
2533 ;; Set product context | |
2534 (with-current-buffer sql-buffer | |
2535 ;; Send the string | |
2536 (sql-input-sender proc str) | |
2537 | |
2538 ;; Send a newline if there wasn't one on the end of the string | |
2539 (unless (string-equal "\n" (substring str (1- (length str)))) | |
2540 (comint-send-string proc "\n")) | |
2541 | |
2542 ;; Send a command terminator if we must | |
2543 (if sql-send-terminator | |
2544 (sql-send-magic-terminator sql-buffer str sql-send-terminator)) | |
2545 | |
2546 (message "Sent string to buffer %s." (buffer-name sql-buffer)))) | |
2547 | |
2548 ;; Display the sql buffer | |
2549 (if sql-pop-to-buffer-after-send-region | |
2550 (pop-to-buffer sql-buffer) | |
2551 (display-buffer sql-buffer))) | |
2552 | |
2553 ;; We don't have no stinkin' sql | |
2554 (message "No SQL process started.")))) | |
2055 | 2555 |
2056 (defun sql-send-region (start end) | 2556 (defun sql-send-region (start end) |
2057 "Send a region to the SQL process." | 2557 "Send a region to the SQL process." |
2058 (interactive "r") | 2558 (interactive "r") |
2059 (if (buffer-live-p sql-buffer) | 2559 (sql-send-string (buffer-substring-no-properties start end))) |
2060 (save-excursion | |
2061 (comint-send-region sql-buffer start end) | |
2062 (if (string-match "\n$" (buffer-substring start end)) | |
2063 () | |
2064 (comint-send-string sql-buffer "\n")) | |
2065 (message "Sent string to buffer %s." (buffer-name sql-buffer)) | |
2066 (if sql-pop-to-buffer-after-send-region | |
2067 (pop-to-buffer sql-buffer) | |
2068 (display-buffer sql-buffer))) | |
2069 (message "No SQL process started."))) | |
2070 | 2560 |
2071 (defun sql-send-paragraph () | 2561 (defun sql-send-paragraph () |
2072 "Send the current paragraph to the SQL process." | 2562 "Send the current paragraph to the SQL process." |
2073 (interactive) | 2563 (interactive) |
2074 (let ((start (save-excursion | 2564 (let ((start (save-excursion |
2082 (defun sql-send-buffer () | 2572 (defun sql-send-buffer () |
2083 "Send the buffer contents to the SQL process." | 2573 "Send the buffer contents to the SQL process." |
2084 (interactive) | 2574 (interactive) |
2085 (sql-send-region (point-min) (point-max))) | 2575 (sql-send-region (point-min) (point-max))) |
2086 | 2576 |
2087 (defun sql-send-string (str) | 2577 (defun sql-send-magic-terminator (buf str terminator) |
2088 "Send a string to the SQL process." | 2578 "Sends TERMINATOR to buffer BUF if its not present in STR." |
2089 (interactive "sSQL Text: ") | 2579 (let (pat term) |
2090 (if (buffer-live-p sql-buffer) | 2580 ;; If flag is merely on(t), get product-specific terminator |
2091 (save-excursion | 2581 (if (eq terminator t) |
2092 (comint-send-string sql-buffer str) | 2582 (setq terminator (sql-get-product-feature sql-product :terminator))) |
2093 (comint-send-string sql-buffer "\n") | 2583 |
2094 (message "Sent string to buffer %s." (buffer-name sql-buffer)) | 2584 ;; If there is no terminator specified, use default ";" |
2095 (if sql-pop-to-buffer-after-send-region | 2585 (unless terminator |
2096 (pop-to-buffer sql-buffer) | 2586 (setq terminator ";")) |
2097 (display-buffer sql-buffer))) | 2587 |
2098 (message "No SQL process started."))) | 2588 ;; Parse the setting into the pattern and the terminator string |
2589 (cond ((stringp terminator) | |
2590 (setq pat (regexp-quote terminator) | |
2591 term terminator)) | |
2592 ((consp terminator) | |
2593 (setq pat (car terminator) | |
2594 term (cdr terminator))) | |
2595 (t | |
2596 nil)) | |
2597 | |
2598 ;; Check to see if the pattern is present in the str already sent | |
2599 (unless (and pat term | |
2600 (string-match (concat pat "\n?\\'") str)) | |
2601 (comint-send-string buf (concat term "\n"))))) | |
2602 | |
2603 (defun sql-remove-tabs-filter (str) | |
2604 "Replace tab characters with spaces." | |
2605 (replace-regexp-in-string "\t" " " str nil t)) | |
2099 | 2606 |
2100 (defun sql-toggle-pop-to-buffer-after-send-region (&optional value) | 2607 (defun sql-toggle-pop-to-buffer-after-send-region (&optional value) |
2101 "Toggle `sql-pop-to-buffer-after-send-region'. | 2608 "Toggle `sql-pop-to-buffer-after-send-region'. |
2102 | 2609 |
2103 If given the optional parameter VALUE, sets | 2610 If given the optional parameter VALUE, sets |
2104 `sql-toggle-pop-to-buffer-after-send-region' to VALUE." | 2611 `sql-toggle-pop-to-buffer-after-send-region' to VALUE." |
2105 (interactive "P") | 2612 (interactive "P") |
2106 (if value | 2613 (if value |
2107 (setq sql-pop-to-buffer-after-send-region value) | 2614 (setq sql-pop-to-buffer-after-send-region value) |
2108 (setq sql-pop-to-buffer-after-send-region | 2615 (setq sql-pop-to-buffer-after-send-region |
2109 (null sql-pop-to-buffer-after-send-region )))) | 2616 (null sql-pop-to-buffer-after-send-region)))) |
2110 | 2617 |
2111 | 2618 |
2112 | 2619 |
2113 ;;; SQL mode -- uses SQL interactive mode | 2620 ;;; SQL mode -- uses SQL interactive mode |
2114 | 2621 |
2247 you entered, right above the output it created. | 2754 you entered, right above the output it created. |
2248 | 2755 |
2249 \(setq comint-output-filter-functions | 2756 \(setq comint-output-filter-functions |
2250 \(function (lambda (STR) (comint-show-output))))" | 2757 \(function (lambda (STR) (comint-show-output))))" |
2251 (delay-mode-hooks (comint-mode)) | 2758 (delay-mode-hooks (comint-mode)) |
2759 | |
2252 ;; Get the `sql-product' for this interactive session. | 2760 ;; Get the `sql-product' for this interactive session. |
2253 (set (make-local-variable 'sql-product) | 2761 (set (make-local-variable 'sql-product) |
2254 (or sql-interactive-product | 2762 (or sql-interactive-product |
2255 sql-product)) | 2763 sql-product)) |
2764 | |
2256 ;; Setup the mode. | 2765 ;; Setup the mode. |
2257 (setq major-mode 'sql-interactive-mode) | 2766 (setq major-mode 'sql-interactive-mode) |
2258 (setq mode-name (concat "SQLi[" (prin1-to-string sql-product) "]")) | 2767 (setq mode-name (concat "SQLi[" (or (sql-get-product-feature sql-product :name) |
2768 (symbol-name sql-product)) "]")) | |
2259 (use-local-map sql-interactive-mode-map) | 2769 (use-local-map sql-interactive-mode-map) |
2260 (if sql-interactive-mode-menu | 2770 (if sql-interactive-mode-menu |
2261 (easy-menu-add sql-interactive-mode-menu)) ; XEmacs | 2771 (easy-menu-add sql-interactive-mode-menu)) ; XEmacs |
2262 (set-syntax-table sql-mode-syntax-table) | 2772 (set-syntax-table sql-mode-syntax-table) |
2263 (make-local-variable 'sql-mode-font-lock-keywords) | 2773 (make-local-variable 'sql-mode-font-lock-keywords) |
2264 (make-local-variable 'font-lock-defaults) | 2774 (make-local-variable 'font-lock-defaults) |
2775 | |
2265 ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try | 2776 ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try |
2266 ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column | 2777 ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column |
2267 ;; will have just one quote. Therefore syntactic hilighting is | 2778 ;; will have just one quote. Therefore syntactic hilighting is |
2268 ;; disabled for interactive buffers. No imenu support. | 2779 ;; disabled for interactive buffers. No imenu support. |
2269 (sql-product-font-lock t nil) | 2780 (sql-product-font-lock t nil) |
2781 | |
2270 ;; Enable commenting and uncommenting of the region. | 2782 ;; Enable commenting and uncommenting of the region. |
2271 (make-local-variable 'comment-start) | 2783 (make-local-variable 'comment-start) |
2272 (setq comment-start "--") | 2784 (setq comment-start "--") |
2273 ;; Abbreviation table init and case-insensitive. It is not activated | 2785 ;; Abbreviation table init and case-insensitive. It is not activated |
2274 ;; by default. | 2786 ;; by default. |
2279 ;; Create a usefull name for renaming this buffer later. | 2791 ;; Create a usefull name for renaming this buffer later. |
2280 (make-local-variable 'sql-alternate-buffer-name) | 2792 (make-local-variable 'sql-alternate-buffer-name) |
2281 (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name)) | 2793 (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name)) |
2282 ;; User stuff. Initialize before the hook. | 2794 ;; User stuff. Initialize before the hook. |
2283 (set (make-local-variable 'sql-prompt-regexp) | 2795 (set (make-local-variable 'sql-prompt-regexp) |
2284 (sql-product-feature :sqli-prompt-regexp)) | 2796 (sql-get-product-feature sql-product :prompt-regexp)) |
2285 (set (make-local-variable 'sql-prompt-length) | 2797 (set (make-local-variable 'sql-prompt-length) |
2286 (sql-product-feature :sqli-prompt-length)) | 2798 (sql-get-product-feature sql-product :prompt-length)) |
2287 (make-local-variable 'sql-input-ring-separator) | 2799 (make-local-variable 'sql-input-ring-separator) |
2288 (make-local-variable 'sql-input-ring-file-name) | 2800 (make-local-variable 'sql-input-ring-file-name) |
2289 ;; Run hook. | 2801 (setq comint-process-echoes t) |
2802 ;; Run the mode hook (along with comint's hooks). | |
2290 (run-mode-hooks 'sql-interactive-mode-hook) | 2803 (run-mode-hooks 'sql-interactive-mode-hook) |
2291 ;; Set comint based on user overrides. | 2804 ;; Set comint based on user overrides. |
2292 (setq comint-prompt-regexp sql-prompt-regexp) | 2805 (setq comint-prompt-regexp sql-prompt-regexp) |
2293 (setq left-margin sql-prompt-length) | 2806 (setq left-margin sql-prompt-length) |
2807 ;; Install input sender | |
2808 (set (make-local-variable 'comint-input-sender) 'sql-input-sender) | |
2294 ;; People wanting a different history file for each | 2809 ;; People wanting a different history file for each |
2295 ;; buffer/process/client/whatever can change separator and file-name | 2810 ;; buffer/process/client/whatever can change separator and file-name |
2296 ;; on the sql-interactive-mode-hook. | 2811 ;; on the sql-interactive-mode-hook. |
2297 (setq comint-input-ring-separator sql-input-ring-separator | 2812 (setq comint-input-ring-separator sql-input-ring-separator |
2298 comint-input-ring-file-name sql-input-ring-file-name) | 2813 comint-input-ring-file-name sql-input-ring-file-name) |
2318 | 2833 |
2319 ;;; Entry functions for different SQL interpreters. | 2834 ;;; Entry functions for different SQL interpreters. |
2320 | 2835 |
2321 ;;;###autoload | 2836 ;;;###autoload |
2322 (defun sql-product-interactive (&optional product) | 2837 (defun sql-product-interactive (&optional product) |
2323 "Run product interpreter as an inferior process. | 2838 "Run PRODUCT interpreter as an inferior process. |
2324 | 2839 |
2325 If buffer `*SQL*' exists but no process is running, make a new process. | 2840 If buffer `*SQL*' exists but no process is running, make a new process. |
2326 If buffer exists and a process is running, just switch to buffer `*SQL*'. | 2841 If buffer exists and a process is running, just switch to buffer `*SQL*'. |
2327 | 2842 |
2328 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 2843 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
2329 (interactive) | 2844 (interactive "P") |
2330 (setq product (or product sql-product)) | 2845 |
2331 (when (sql-product-feature :sqli-connect product) | 2846 (setq product |
2332 (if (comint-check-proc "*SQL*") | 2847 (cond |
2333 (pop-to-buffer "*SQL*") | 2848 ((equal product '(4)) ; Universal arg, prompt for product |
2334 ;; Get credentials. | 2849 (intern (completing-read "SQL product: " |
2335 (apply 'sql-get-login (sql-product-feature :sqli-login product)) | 2850 (mapcar (lambda (info) (symbol-name (car info))) |
2336 ;; Connect to database. | 2851 sql-product-alist) |
2337 (message "Login...") | 2852 nil 'require-match |
2338 (funcall (sql-product-feature :sqli-connect product)) | 2853 (or (and sql-product (symbol-name sql-product)) "ansi")))) |
2339 ;; Set SQLi mode. | 2854 ((symbolp product) product) ; Product specified |
2340 (setq sql-interactive-product product) | 2855 (t sql-product))) ; Default to sql-product |
2341 (setq sql-buffer (current-buffer)) | 2856 |
2342 (sql-interactive-mode) | 2857 (when (sql-get-product-feature product :sqli-connect-func) |
2343 ;; All done. | 2858 (if (and sql-buffer |
2344 (message "Login...done") | 2859 (buffer-live-p sql-buffer) |
2345 (pop-to-buffer sql-buffer)))) | 2860 (comint-check-proc sql-buffer)) |
2861 (pop-to-buffer sql-buffer) | |
2862 | |
2863 ;; Is the current buffer in sql-mode and | |
2864 ;; there is a buffer local setting of sql-buffer | |
2865 (let* ((start-buffer | |
2866 (and (derived-mode-p 'sql-mode) | |
2867 (current-buffer))) | |
2868 (start-sql-buffer | |
2869 (and start-buffer | |
2870 (let (found) | |
2871 (dolist (var (buffer-local-variables)) | |
2872 (and (consp var) | |
2873 (eq (car var) 'sql-buffer) | |
2874 (buffer-live-p (cdr var)) | |
2875 (get-buffer-process (cdr var)) | |
2876 (setq found (cdr var)))) | |
2877 found))) | |
2878 new-sqli-buffer) | |
2879 | |
2880 ;; Get credentials. | |
2881 (apply 'sql-get-login (sql-get-product-feature product :sqli-login)) | |
2882 | |
2883 ;; Connect to database. | |
2884 (message "Login...") | |
2885 (funcall (sql-get-product-feature product :sqli-connect-func) | |
2886 product | |
2887 (sql-get-product-feature product :sqli-options)) | |
2888 | |
2889 ;; Set SQLi mode. | |
2890 (setq sql-interactive-product product | |
2891 new-sqli-buffer (current-buffer) | |
2892 sql-buffer new-sqli-buffer) | |
2893 (sql-interactive-mode) | |
2894 | |
2895 ;; Set `sql-buffer' in the start buffer | |
2896 (when (and start-buffer (not start-sql-buffer)) | |
2897 (with-current-buffer start-buffer | |
2898 (setq sql-buffer new-sqli-buffer))) | |
2899 | |
2900 ;; All done. | |
2901 (message "Login...done") | |
2902 (pop-to-buffer sql-buffer))))) | |
2903 | |
2904 (defun sql-connect (product params) | |
2905 "Set up a comint buffer to connect to the SQL processor. | |
2906 | |
2907 PRODUCT is the SQL product. PARAMS is a list of strings which are | |
2908 passed as command line arguments." | |
2909 (let ((program (sql-get-product-feature product :sqli-program))) | |
2910 (set-buffer | |
2911 (if params | |
2912 (apply 'make-comint "SQL" program nil params) | |
2913 (make-comint "SQL" program nil))))) | |
2346 | 2914 |
2347 ;;;###autoload | 2915 ;;;###autoload |
2348 (defun sql-oracle () | 2916 (defun sql-oracle () |
2349 "Run sqlplus by Oracle as an inferior process. | 2917 "Run sqlplus by Oracle as an inferior process. |
2350 | 2918 |
2369 | 2937 |
2370 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 2938 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
2371 (interactive) | 2939 (interactive) |
2372 (sql-product-interactive 'oracle)) | 2940 (sql-product-interactive 'oracle)) |
2373 | 2941 |
2374 (defun sql-connect-oracle () | 2942 (defun sql-connect-oracle (product options) |
2375 "Create comint buffer and connect to Oracle using the login | 2943 "Create comint buffer and connect to Oracle." |
2376 parameters and command options." | |
2377 ;; Produce user/password@database construct. Password without user | 2944 ;; Produce user/password@database construct. Password without user |
2378 ;; is meaningless; database without user/password is meaningless, | 2945 ;; is meaningless; database without user/password is meaningless, |
2379 ;; because "@param" will ask sqlplus to interpret the script | 2946 ;; because "@param" will ask sqlplus to interpret the script |
2380 ;; "param". | 2947 ;; "param". |
2381 (let ((parameter | 2948 (let ((parameter nil)) |
2382 (if (not (string= "" sql-user)) | 2949 (if (not (string= "" sql-user)) |
2383 (if (not (string= "" sql-password)) | 2950 (if (not (string= "" sql-password)) |
2384 (concat sql-user "/" sql-password) | 2951 (setq parameter (concat sql-user "/" sql-password)) |
2385 sql-user)))) | 2952 (setq parameter sql-user))) |
2386 (if (and parameter (not (string= "" sql-database))) | 2953 (if (and parameter (not (string= "" sql-database))) |
2387 (setq parameter (concat parameter "@" sql-database))) | 2954 (setq parameter (concat parameter "@" sql-database))) |
2388 (setq parameter (if parameter | 2955 (if parameter |
2389 (nconc (list parameter) sql-oracle-options) | 2956 (setq parameter (nconc (list parameter) options)) |
2390 sql-oracle-options)) | 2957 (setq parameter options)) |
2391 (set-buffer (apply 'make-comint "SQL" sql-oracle-program nil parameter)) | 2958 (sql-connect product parameter))) |
2392 ;; SQL*Plus is buffered on Windows; this handles &placeholders. | |
2393 (if (eq window-system 'w32) | |
2394 (setq comint-input-sender 'sql-query-placeholders-and-send)))) | |
2395 | 2959 |
2396 | 2960 |
2397 | 2961 |
2398 ;;;###autoload | 2962 ;;;###autoload |
2399 (defun sql-sybase () | 2963 (defun sql-sybase () |
2420 | 2984 |
2421 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 2985 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
2422 (interactive) | 2986 (interactive) |
2423 (sql-product-interactive 'sybase)) | 2987 (sql-product-interactive 'sybase)) |
2424 | 2988 |
2425 (defun sql-connect-sybase () | 2989 (defun sql-connect-sybase (product options) |
2426 "Create comint buffer and connect to Sybase using the login | 2990 "Create comint buffer and connect to Sybase." |
2427 parameters and command options." | |
2428 ;; Put all parameters to the program (if defined) in a list and call | 2991 ;; Put all parameters to the program (if defined) in a list and call |
2429 ;; make-comint. | 2992 ;; make-comint. |
2430 (let ((params sql-sybase-options)) | 2993 (let ((params options)) |
2431 (if (not (string= "" sql-server)) | 2994 (if (not (string= "" sql-server)) |
2432 (setq params (append (list "-S" sql-server) params))) | 2995 (setq params (append (list "-S" sql-server) params))) |
2433 (if (not (string= "" sql-database)) | 2996 (if (not (string= "" sql-database)) |
2434 (setq params (append (list "-D" sql-database) params))) | 2997 (setq params (append (list "-D" sql-database) params))) |
2435 (if (not (string= "" sql-password)) | 2998 (if (not (string= "" sql-password)) |
2436 (setq params (append (list "-P" sql-password) params))) | 2999 (setq params (append (list "-P" sql-password) params))) |
2437 (if (not (string= "" sql-user)) | 3000 (if (not (string= "" sql-user)) |
2438 (setq params (append (list "-U" sql-user) params))) | 3001 (setq params (append (list "-U" sql-user) params))) |
2439 (set-buffer (apply 'make-comint "SQL" sql-sybase-program | 3002 (sql-connect product params))) |
2440 nil params)))) | |
2441 | 3003 |
2442 | 3004 |
2443 | 3005 |
2444 ;;;###autoload | 3006 ;;;###autoload |
2445 (defun sql-informix () | 3007 (defun sql-informix () |
2464 | 3026 |
2465 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 3027 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
2466 (interactive) | 3028 (interactive) |
2467 (sql-product-interactive 'informix)) | 3029 (sql-product-interactive 'informix)) |
2468 | 3030 |
2469 (defun sql-connect-informix () | 3031 (defun sql-connect-informix (product options) |
2470 "Create comint buffer and connect to Informix using the login | 3032 "Create comint buffer and connect to Informix." |
2471 parameters and command options." | |
2472 ;; username and password are ignored. | 3033 ;; username and password are ignored. |
2473 (set-buffer (if (string= "" sql-database) | 3034 (let ((db (if (string= "" sql-database) |
2474 (make-comint "SQL" sql-informix-program nil) | 3035 "-" |
2475 (make-comint "SQL" sql-informix-program nil sql-database "-")))) | 3036 (if (string= "" sql-server) |
3037 sql-database | |
3038 (concat sql-database "@" sql-server))))) | |
3039 (sql-connect product (append `(,db "-") options)))) | |
2476 | 3040 |
2477 | 3041 |
2478 | 3042 |
2479 ;;;###autoload | 3043 ;;;###autoload |
2480 (defun sql-sqlite () | 3044 (defun sql-sqlite () |
2503 | 3067 |
2504 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 3068 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
2505 (interactive) | 3069 (interactive) |
2506 (sql-product-interactive 'sqlite)) | 3070 (sql-product-interactive 'sqlite)) |
2507 | 3071 |
2508 (defun sql-connect-sqlite () | 3072 (defun sql-connect-sqlite (product options) |
2509 "Create comint buffer and connect to SQLite using the login | 3073 "Create comint buffer and connect to SQLite." |
2510 parameters and command options." | |
2511 ;; Put all parameters to the program (if defined) in a list and call | 3074 ;; Put all parameters to the program (if defined) in a list and call |
2512 ;; make-comint. | 3075 ;; make-comint. |
2513 (let ((params)) | 3076 (let ((params)) |
2514 (if (not (string= "" sql-database)) | 3077 (if (not (string= "" sql-database)) |
2515 (setq params (append (list sql-database) params))) | 3078 (setq params (append (list sql-database) params))) |
2516 (if (not (null sql-sqlite-options)) | 3079 (setq params (append options params)) |
2517 (setq params (append sql-sqlite-options params))) | 3080 (sql-connect product params))) |
2518 (set-buffer (apply 'make-comint "SQL" sql-sqlite-program | |
2519 nil params)))) | |
2520 | 3081 |
2521 | 3082 |
2522 | 3083 |
2523 ;;;###autoload | 3084 ;;;###autoload |
2524 (defun sql-mysql () | 3085 (defun sql-mysql () |
2547 | 3108 |
2548 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 3109 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
2549 (interactive) | 3110 (interactive) |
2550 (sql-product-interactive 'mysql)) | 3111 (sql-product-interactive 'mysql)) |
2551 | 3112 |
2552 (defun sql-connect-mysql () | 3113 (defun sql-connect-mysql (product options) |
2553 "Create comint buffer and connect to MySQL using the login | 3114 "Create comint buffer and connect to MySQL." |
2554 parameters and command options." | |
2555 ;; Put all parameters to the program (if defined) in a list and call | 3115 ;; Put all parameters to the program (if defined) in a list and call |
2556 ;; make-comint. | 3116 ;; make-comint. |
2557 (let ((params)) | 3117 (let ((params)) |
2558 (if (not (string= "" sql-database)) | 3118 (if (not (string= "" sql-database)) |
2559 (setq params (append (list sql-database) params))) | 3119 (setq params (append (list sql-database) params))) |
2560 (if (not (string= "" sql-server)) | 3120 (if (not (string= "" sql-server)) |
2561 (setq params (append (list (concat "--host=" sql-server)) params))) | 3121 (setq params (append (list (concat "--host=" sql-server)) params))) |
3122 (if (not (and sql-port (numberp sql-port))) | |
3123 (setq params (append (list (concat "--port=" (number-to-string sql-port))) params))) | |
2562 (if (not (string= "" sql-password)) | 3124 (if (not (string= "" sql-password)) |
2563 (setq params (append (list (concat "--password=" sql-password)) params))) | 3125 (setq params (append (list (concat "--password=" sql-password)) params))) |
2564 (if (not (string= "" sql-user)) | 3126 (if (not (string= "" sql-user)) |
2565 (setq params (append (list (concat "--user=" sql-user)) params))) | 3127 (setq params (append (list (concat "--user=" sql-user)) params))) |
2566 (if (not (null sql-mysql-options)) | 3128 (setq params (append options params)) |
2567 (setq params (append sql-mysql-options params))) | 3129 (sql-connect product params))) |
2568 (set-buffer (apply 'make-comint "SQL" sql-mysql-program | |
2569 nil params)))) | |
2570 | 3130 |
2571 | 3131 |
2572 | 3132 |
2573 ;;;###autoload | 3133 ;;;###autoload |
2574 (defun sql-solid () | 3134 (defun sql-solid () |
2594 | 3154 |
2595 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 3155 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
2596 (interactive) | 3156 (interactive) |
2597 (sql-product-interactive 'solid)) | 3157 (sql-product-interactive 'solid)) |
2598 | 3158 |
2599 (defun sql-connect-solid () | 3159 (defun sql-connect-solid (product options) |
2600 "Create comint buffer and connect to Solid using the login | 3160 "Create comint buffer and connect to Solid." |
2601 parameters and command options." | |
2602 ;; Put all parameters to the program (if defined) in a list and call | 3161 ;; Put all parameters to the program (if defined) in a list and call |
2603 ;; make-comint. | 3162 ;; make-comint. |
2604 (let ((params)) | 3163 (let ((params options)) |
2605 ;; It only makes sense if both username and password are there. | 3164 ;; It only makes sense if both username and password are there. |
2606 (if (not (or (string= "" sql-user) | 3165 (if (not (or (string= "" sql-user) |
2607 (string= "" sql-password))) | 3166 (string= "" sql-password))) |
2608 (setq params (append (list sql-user sql-password) params))) | 3167 (setq params (append (list sql-user sql-password) params))) |
2609 (if (not (string= "" sql-server)) | 3168 (if (not (string= "" sql-server)) |
2610 (setq params (append (list sql-server) params))) | 3169 (setq params (append (list sql-server) params))) |
2611 (set-buffer (apply 'make-comint "SQL" sql-solid-program | 3170 (sql-connect product params))) |
2612 nil params)))) | |
2613 | 3171 |
2614 | 3172 |
2615 | 3173 |
2616 ;;;###autoload | 3174 ;;;###autoload |
2617 (defun sql-ingres () | 3175 (defun sql-ingres () |
2636 | 3194 |
2637 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 3195 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
2638 (interactive) | 3196 (interactive) |
2639 (sql-product-interactive 'ingres)) | 3197 (sql-product-interactive 'ingres)) |
2640 | 3198 |
2641 (defun sql-connect-ingres () | 3199 (defun sql-connect-ingres (product options) |
2642 "Create comint buffer and connect to Ingres using the login | 3200 "Create comint buffer and connect to Ingres." |
2643 parameters and command options." | |
2644 ;; username and password are ignored. | 3201 ;; username and password are ignored. |
2645 (set-buffer (if (string= "" sql-database) | 3202 (sql-connect product |
2646 (make-comint "SQL" sql-ingres-program nil) | 3203 (append (if (string= "" sql-database) |
2647 (make-comint "SQL" sql-ingres-program nil sql-database)))) | 3204 nil |
3205 (list sql-database)) | |
3206 options))) | |
2648 | 3207 |
2649 | 3208 |
2650 | 3209 |
2651 ;;;###autoload | 3210 ;;;###autoload |
2652 (defun sql-ms () | 3211 (defun sql-ms () |
2673 | 3232 |
2674 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 3233 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
2675 (interactive) | 3234 (interactive) |
2676 (sql-product-interactive 'ms)) | 3235 (sql-product-interactive 'ms)) |
2677 | 3236 |
2678 (defun sql-connect-ms () | 3237 (defun sql-connect-ms (product options) |
2679 "Create comint buffer and connect to Microsoft using the login | 3238 "Create comint buffer and connect to Microsoft SQL Server." |
2680 parameters and command options." | |
2681 ;; Put all parameters to the program (if defined) in a list and call | 3239 ;; Put all parameters to the program (if defined) in a list and call |
2682 ;; make-comint. | 3240 ;; make-comint. |
2683 (let ((params sql-ms-options)) | 3241 (let ((params options)) |
2684 (if (not (string= "" sql-server)) | 3242 (if (not (string= "" sql-server)) |
2685 (setq params (append (list "-S" sql-server) params))) | 3243 (setq params (append (list "-S" sql-server) params))) |
2686 (if (not (string= "" sql-database)) | 3244 (if (not (string= "" sql-database)) |
2687 (setq params (append (list "-d" sql-database) params))) | 3245 (setq params (append (list "-d" sql-database) params))) |
2688 (if (not (string= "" sql-user)) | 3246 (if (not (string= "" sql-user)) |
2694 ;; credentials. | 3252 ;; credentials. |
2695 (setq params (append (list "-E") params)) | 3253 (setq params (append (list "-E") params)) |
2696 ;; If -P is passed to ISQL as the last argument without a | 3254 ;; If -P is passed to ISQL as the last argument without a |
2697 ;; password, it's considered null. | 3255 ;; password, it's considered null. |
2698 (setq params (append params (list "-P"))))) | 3256 (setq params (append params (list "-P"))))) |
2699 (set-buffer (apply 'make-comint "SQL" sql-ms-program | 3257 (sql-connect product params))) |
2700 nil params)))) | |
2701 | 3258 |
2702 | 3259 |
2703 | 3260 |
2704 ;;;###autoload | 3261 ;;;###autoload |
2705 (defun sql-postgres () | 3262 (defun sql-postgres () |
2731 | 3288 |
2732 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 3289 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
2733 (interactive) | 3290 (interactive) |
2734 (sql-product-interactive 'postgres)) | 3291 (sql-product-interactive 'postgres)) |
2735 | 3292 |
2736 (defun sql-connect-postgres () | 3293 (defun sql-connect-postgres (product options) |
2737 "Create comint buffer and connect to Postgres using the login | 3294 "Create comint buffer and connect to Postgres." |
2738 parameters and command options." | |
2739 ;; username and password are ignored. Mark Stosberg suggest to add | 3295 ;; username and password are ignored. Mark Stosberg suggest to add |
2740 ;; the database at the end. Jason Beegan suggest using --pset and | 3296 ;; the database at the end. Jason Beegan suggest using --pset and |
2741 ;; pager=off instead of \\o|cat. The later was the solution by | 3297 ;; pager=off instead of \\o|cat. The later was the solution by |
2742 ;; Gregor Zych. Jason's suggestion is the default value for | 3298 ;; Gregor Zych. Jason's suggestion is the default value for |
2743 ;; sql-postgres-options. | 3299 ;; sql-postgres-options. |
2744 (let ((params sql-postgres-options)) | 3300 (let ((params options)) |
2745 (if (not (string= "" sql-database)) | 3301 (if (not (string= "" sql-database)) |
2746 (setq params (append params (list sql-database)))) | 3302 (setq params (append params (list sql-database)))) |
2747 (if (not (string= "" sql-server)) | 3303 (if (not (string= "" sql-server)) |
2748 (setq params (append (list "-h" sql-server) params))) | 3304 (setq params (append (list "-h" sql-server) params))) |
2749 (if (not (string= "" sql-user)) | 3305 (if (not (string= "" sql-user)) |
2750 (setq params (append (list "-U" sql-user) params))) | 3306 (setq params (append (list "-U" sql-user) params))) |
2751 (set-buffer (apply 'make-comint "SQL" sql-postgres-program | 3307 (sql-connect product params))) |
2752 nil params)))) | |
2753 | 3308 |
2754 | 3309 |
2755 | 3310 |
2756 ;;;###autoload | 3311 ;;;###autoload |
2757 (defun sql-interbase () | 3312 (defun sql-interbase () |
2777 | 3332 |
2778 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 3333 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
2779 (interactive) | 3334 (interactive) |
2780 (sql-product-interactive 'interbase)) | 3335 (sql-product-interactive 'interbase)) |
2781 | 3336 |
2782 (defun sql-connect-interbase () | 3337 (defun sql-connect-interbase (product options) |
2783 "Create comint buffer and connect to Interbase using the login | 3338 "Create comint buffer and connect to Interbase." |
2784 parameters and command options." | |
2785 ;; Put all parameters to the program (if defined) in a list and call | 3339 ;; Put all parameters to the program (if defined) in a list and call |
2786 ;; make-comint. | 3340 ;; make-comint. |
2787 (let ((params sql-interbase-options)) | 3341 (let ((params options)) |
2788 (if (not (string= "" sql-user)) | 3342 (if (not (string= "" sql-user)) |
2789 (setq params (append (list "-u" sql-user) params))) | 3343 (setq params (append (list "-u" sql-user) params))) |
2790 (if (not (string= "" sql-password)) | 3344 (if (not (string= "" sql-password)) |
2791 (setq params (append (list "-p" sql-password) params))) | 3345 (setq params (append (list "-p" sql-password) params))) |
2792 (if (not (string= "" sql-database)) | 3346 (if (not (string= "" sql-database)) |
2793 (setq params (cons sql-database params))) ; add to the front! | 3347 (setq params (cons sql-database params))) ; add to the front! |
2794 (set-buffer (apply 'make-comint "SQL" sql-interbase-program | 3348 (sql-connect product params))) |
2795 nil params)))) | |
2796 | 3349 |
2797 | 3350 |
2798 | 3351 |
2799 ;;;###autoload | 3352 ;;;###autoload |
2800 (defun sql-db2 () | 3353 (defun sql-db2 () |
2824 | 3377 |
2825 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 3378 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
2826 (interactive) | 3379 (interactive) |
2827 (sql-product-interactive 'db2)) | 3380 (sql-product-interactive 'db2)) |
2828 | 3381 |
2829 (defun sql-connect-db2 () | 3382 (defun sql-connect-db2 (product options) |
2830 "Create comint buffer and connect to DB2 using the login | 3383 "Create comint buffer and connect to DB2." |
2831 parameters and command options." | |
2832 ;; Put all parameters to the program (if defined) in a list and call | 3384 ;; Put all parameters to the program (if defined) in a list and call |
2833 ;; make-comint. | 3385 ;; make-comint. |
2834 (set-buffer (apply 'make-comint "SQL" sql-db2-program | 3386 (sql-connect product options) |
2835 nil sql-db2-options)) | 3387 ) |
2836 ;; Properly escape newlines when DB2 is interactive. | 3388 ;; ;; Properly escape newlines when DB2 is interactive. |
2837 (setq comint-input-sender 'sql-escape-newlines-and-send)) | 3389 ;; (setq comint-input-sender 'sql-escape-newlines-and-send)) |
2838 | 3390 |
2839 ;;;###autoload | 3391 ;;;###autoload |
2840 (defun sql-linter () | 3392 (defun sql-linter () |
2841 "Run inl by RELEX as an inferior process. | 3393 "Run inl by RELEX as an inferior process. |
2842 | 3394 |
2845 `*SQL*'. | 3397 `*SQL*'. |
2846 | 3398 |
2847 Interpreter used comes from variable `sql-linter-program' - usually `inl'. | 3399 Interpreter used comes from variable `sql-linter-program' - usually `inl'. |
2848 Login uses the variables `sql-user', `sql-password', `sql-database' and | 3400 Login uses the variables `sql-user', `sql-password', `sql-database' and |
2849 `sql-server' as defaults, if set. Additional command line parameters | 3401 `sql-server' as defaults, if set. Additional command line parameters |
2850 can be stored in the list `sql-linter-options'. Run inl -h to get help on | 3402 can be stored in the list `sql-linter-options'. Run inl -h to get help on |
2851 parameters. | 3403 parameters. |
2852 | 3404 |
2853 `sql-database' is used to set the LINTER_MBX environment variable for | 3405 `sql-database' is used to set the LINTER_MBX environment variable for |
2854 local connections, `sql-server' refers to the server name from the | 3406 local connections, `sql-server' refers to the server name from the |
2855 `nodetab' file for the network connection (dbc_tcp or friends must run | 3407 `nodetab' file for the network connection (dbc_tcp or friends must run |
2861 | 3413 |
2862 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 3414 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
2863 (interactive) | 3415 (interactive) |
2864 (sql-product-interactive 'linter)) | 3416 (sql-product-interactive 'linter)) |
2865 | 3417 |
2866 (defun sql-connect-linter () | 3418 (defun sql-connect-linter (product options) |
2867 "Create comint buffer and connect to Linter using the login | 3419 "Create comint buffer and connect to Linter." |
2868 parameters and command options." | |
2869 ;; Put all parameters to the program (if defined) in a list and call | 3420 ;; Put all parameters to the program (if defined) in a list and call |
2870 ;; make-comint. | 3421 ;; make-comint. |
2871 (let ((params sql-linter-options) (login nil) (old-mbx (getenv "LINTER_MBX"))) | 3422 (let ((params options) |
3423 (login nil) | |
3424 (old-mbx (getenv "LINTER_MBX"))) | |
2872 (if (not (string= "" sql-user)) | 3425 (if (not (string= "" sql-user)) |
2873 (setq login (concat sql-user "/" sql-password))) | 3426 (setq login (concat sql-user "/" sql-password))) |
2874 (setq params (append (list "-u" login) params)) | 3427 (setq params (append (list "-u" login) params)) |
2875 (if (not (string= "" sql-server)) | 3428 (if (not (string= "" sql-server)) |
2876 (setq params (append (list "-n" sql-server) params))) | 3429 (setq params (append (list "-n" sql-server) params))) |
2877 (if (string= "" sql-database) | 3430 (if (string= "" sql-database) |
2878 (setenv "LINTER_MBX" nil) | 3431 (setenv "LINTER_MBX" nil) |
2879 (setenv "LINTER_MBX" sql-database)) | 3432 (setenv "LINTER_MBX" sql-database)) |
2880 (set-buffer (apply 'make-comint "SQL" sql-linter-program nil | 3433 (sql-connect product params) |
2881 params)) | |
2882 (setenv "LINTER_MBX" old-mbx))) | 3434 (setenv "LINTER_MBX" old-mbx))) |
2883 | 3435 |
2884 | 3436 |
2885 | 3437 |
2886 (provide 'sql) | 3438 (provide 'sql) |
2887 | 3439 |
2888 ;; arch-tag: 7e1fa1c4-9ca2-402e-87d2-83a5eccb7ac3 | 3440 ;; arch-tag: 7e1fa1c4-9ca2-402e-87d2-83a5eccb7ac3 |
2889 ;;; sql.el ends here | 3441 ;;; sql.el ends here |
3442 |