1 ;;; sql-complete.el --- provide completion for tables and columns
3 ;; Copyright (C) 2001 Free Software Foundation, Inc.
5 ;; Author: Alex Schroeder <alex@gnu.org>
6 ;; Maintainer: Alex Schroeder <alex@gnu.org>
8 ;; Keywords: comm languages processes
10 ;; This file is NOT part of GNU Emacs.
12 ;; This is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; This is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; Trying to provide a framework for completion that will eventually
30 ;; make it into sql.el.
38 (defcustom sql-oracle-data-dictionary
39 "select '(\"'||table_name||'\" \"'||column_name||'\")'
42 "SQL Statement to determine all tables and columns."
48 (defun sql-data-dictionary (statement)
49 "Return table and columns from the Oracle Data Dictionary using SQL.
50 STATEMENT must be a SQL statement that returns the data dictionary
51 one column per line. Each line must look like this:
53 \(\"table-name\" \"column-name\")
55 Any lines not looking like this will be skipped to allow for column
56 headers and other fancy markup.
58 This currently depends very much on a good `comint-prompt-regexp'."
59 (when (null sql-buffer)
60 (error "No SQLi buffer available"))
62 (set-buffer sql-buffer)
64 (comint-simple-send sql-buffer statement)
65 (comint-previous-prompt 1)
66 (while (= 0 (forward-line 1))
67 (message "%S" (point))
68 (when (looking-at "^(.*)$")
69 (let* ((entry (car (read-from-string (match-string 0))))
72 (item (cdr (assoc table result))))
74 (nconc item (list column))
75 (setq result (append (list entry) result))))))
80 (defvar sql-data-dictionary nil
81 "The data dictionary to use for completion.
82 Each element of the list has the form
83 \(TABLE COLUMN1 COLUMN2 ...)")
85 (defun sql-oracle-data-dictionary ()
88 (setq sql-data-dictionary
89 (sql-data-dictionary sql-oracle-data-dictionary)))
91 (defun sql-complete ()
93 (let ((completions (apply 'append sql-data-dictionary)))
94 (comint-dynamic-simple-complete
95 (comint-word "A-Za-z_")
98 (defun sql-complete-table ()
100 (let ((completions (mapcar 'car sql-data-dictionary)))
101 (comint-dynamic-simple-complete
102 (comint-word "A-Za-z_")
105 ;;; sql-complete.el ends here