commit d91b597cd21325fc789c448d28d96d10a3d1f1ed parent ec147cb601928af4689c65bec2d90b3f84388454 Author: tomas <tomas@logand.com> Date: Sat, 15 Aug 2009 18:19:13 +0200 configuration using alist Diffstat:
M | dbquery.el | | | 61 | +++++++++++++++++++++++++------------------------------------ |
1 file changed, 25 insertions(+), 36 deletions(-)
diff --git a/dbquery.el b/dbquery.el @@ -15,59 +15,48 @@ ;;; along with this program. If not, see <http://www.gnu.org/licenses/>. (defvar dbquery-dir nil) +(defvar dbquery-db-alist nil) +(defvar dbquery-db-name nil) -(defvar dbquery-username nil) -(defvar dbquery-password nil) -(defvar dbquery-host nil) -(defvar dbquery-port nil) -(defvar dbquery-sid nil) +(defun dbquery-cstr-postgres (alist) + (format "jdbc:postgresql:%s" (cdr (assoc 'sid alist)))) + +(defun dbquery-cstr-mysql (alist) + (format "jdbc:mysql://%s:%s/%s" + (cdr (assoc 'host alist)) + (cdr (assoc 'port alist)) + (cdr (assoc 'sid alist)))) -;;; Postgres: -(defvar dbquery-jar "postgresql-8.3-603.jdbc4.jar") -(defvar dbquery-driver "org.postgresql.Driver") -(defvar dbquery-cstr (format "jdbc:postgresql:%s" dbquery-sid)) - -;;; Oracle: -;;(defvar dbquery-jar "classes12.jar") -;;(defvar dbquery-driver "oracle.jdbc.driver.OracleDriver") -;;(defvar dbquery-cstr -;; (format "jdbc:oracle:thin:@%s:%s:%s" dbquery-host dbquery-port dbquery-sid)) - -;;; MySQL: -;;(defvar dbquery-jar nil) -;;(defvar dbquery-driver "com.mysql.jdbc.Driver") -;;(defvar dbquery-cstr -;; (format "jdbc:mysql://%s:%s/%s" dbquery-host dbquery-port dbquery-sid)) +(defun dbquery-cstr-oracle (alist) + (format "jdbc:oracle:thin:@%s:%s:%s" + (cdr (assoc 'host alist)) + (cdr (assoc 'port alist)) + (cdr (assoc 'sid alist)))) (defun dbquery-cp-separator () - (if (member system-type '(ms-dos windows-nt cygwin vax-vms axp-vms)) - ";" - ":")) + (if (member system-type '(ms-dos windows-nt cygwin vax-vms axp-vms)) ";" ":")) +;;; TODO fix shell escaping " and ' (defun dbquery (query) (with-temp-buffer - (let ((buf (current-buffer))) - (shell-command (format "java -cp \"%s%s%s\" DbQuery %s %s %s %s \"%s\"" + (let ((buf (current-buffer)) + (alist (cdr (assoc dbquery-db-name dbquery-db-alist)))) + (shell-command (format "java -cp '%s%s%s' DbQuery %s %s %s %s \"%s\"" dbquery-dir (dbquery-cp-separator) - dbquery-jar - dbquery-driver - dbquery-cstr - dbquery-username - dbquery-password + (cdr (assoc 'jar alist)) + (cdr (assoc 'driver alist)) + (funcall (cdr (assoc 'cstr alist)) alist) + (cdr (assoc 'username alist)) + (cdr (assoc 'password alist)) query) buf) - ;;(buffer-string)))) (when (> (point-max) (point-min)) (while (search-forward "\\" nil t) (replace-match "\\\\" nil t)) (goto-char (point-min)) (read buf))))) -;;(read-from-string "\"c:\\\\tmp\"") -;;(dbquery "select * from cities*;") -;;(dbquery "SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40');") - (defmacro with-dbquery (query &rest body) (let ((table (gensym)) (header (gensym))