Compare commits

...

10 commits

4 changed files with 153 additions and 9 deletions

66
docs/enode.org Normal file
View file

@ -0,0 +1,66 @@
* Processes
** Startup
- =(enode project)=
+ =(enode-available-projects)=
* =(enode-get-projects)=
- =(load-file enode-projects-file)=
* =(enode-project-available project)=
- Test to see if (e.g.) =~/development/<project>/scripts/sql/<project>_ENODE.sql= exists
+ =(setq enode-current-connection-type <connection-type-of-project>)=
+ =(enode-start-engine)=
* =(enode-oracle-start-sql-engine)=
- =(call-interactively 'sql-oracle)=. The command-line option
set for =sqlplus= in the emacs customisation system include
=/nolog=, which leaves the need to connect to a database
until *after* the process has commenced.
- Set SQL buffer settings
* *MySQL addition* =(enode-mysql-start-engine)=
- =t=: nothing can happen here as mysql doesn't support
starting an interactive shell.
+ Open the =*_ENODE.sql= file for the project
+ =(setq enode-up t)= to declare that enode has started.
+ =(enode-connection)= called interactively
* =(enode-get-connections)=
- =(enode-load-connections-list)=
+ =(load-file enode-connections-file)=
* =(enode-get-connections)=. As above.
* =(enode-add-new-connection connection-description)=
- =(enode-load-connections-list)=. As above.
- =(enode-get-connections)=. As above.
- Get attributes:
+ *MySQL addition*: This needs to be genericised (or,
proxied, really) to support capturing the different
details required for the different connection types:
| Connection type | Username | password | database | hostname | port |
|-----------------+----------+----------+----------------+----------+-----------------------------------|
| =oracle= | Y | Y | tnsnames entry | N | N |
| =mysql= | Y | Y | Optional | Y | Defaults to 3306, yes if not this |
|-----------------+----------+----------+----------------+----------+-----------------------------------|
+ =conn-user=: Username
+ =conn-connection=: Database connection: modelled by Oracle's TNSNames details
+ =conn-prompt=: a three-character designator to use as the SQL*Plus prompt.
- Add these details as a record in the =current-type-connections= list.
- Update =all-connections= with the new =current-type-connections= list.
- Update =enode-connections-file=.
- =(enode-load-connections-list)=. As above.
* =(enode-connect connection-description)=
- =(enode-get-connections)=. As above.
- Access and, maybe, set =enode-passwords-in-use=.
- Based on =enode-current-connection-type=, one of the following:
+ =(enode-oracle-connect conn-user conn-pass conn-connection conn-prompt)=
* Issue the commands to the already-created iSQL session:
: connect <conn-user>/<conn-pass>@<conn-connection>
: set serverout on
: set sqlprompt "<conn-prompt>> "
+ =(enode-mysql-connect conn-user conn-pass conn-database conn-hostname conn-port conn-prompt)=
* If the buffer for the SQL file has an iSQL buffer:
- If that iSQL buffer has a running process:
+ =(enode-mysql-reconnect conn-user conn-pass conn-database conn-hostname conn-port)=
+ Otherwise:
* Kill iSQL buffer
* =(call-interactively 'sql-mysql)=
- Otherwise =(call-interactively 'sql-mysql)=
* =(enode-mysql-set-prompt conn-prompt)=
- =(setq enode-currrent-connection connection-description)=
- =(setq enode-connected t)=

62
enode-lisp/enode-mysql.el Normal file
View file

@ -0,0 +1,62 @@
;; Copyright 2019 Éibhear Ó hAnluain
;; This file is part of ENODE.
;;
;; ENODE is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; ENODE is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with ENODE. If not, see <http://www.gnu.org/licenses/>.
(defun enode-mysql-start-sql-engine ()
"A function to set up the SQL engine for connecting to a mysql
or MariaDB database.
Until further notice, this function does nothing. It just returns
T."
t
)
(defun enode-mysql-connect (conn-user conn-pass conn-connection conn-hostname conn-prompt &optional conn-port)
"A function to create to a mysql/mariadb database"
(if sql-buffer
(if (not (get-buffer-process sql-buffer))
(progn
(kill-buffer sql-buffer)
(enode-mysql-new-session conn-user conn-pass conn-connection conn-hostname conn-prompt conn-port)
)
(enode-mysql-reconnect conn-user conn-pass conn-connection conn-hostname conn-prompt conn-port)
)
(enode-mysql-new-session conn-user conn-pass conn-connection conn-hostname conn-prompt conn-port)
)
;; (setq enode-current-connection connection-description)
;; (setq enode-connected t)
)
(defun enode-mysql-new-session (conn-user conn-pass conn-connection conn-hostname conn-prompt conn-port)
"A function to start a brand-new mysql/mariadb session"
(let ((sql-user conn-user)
(sql-database conn-connection)
(sql-server conn-hostname)
(sql-password conn-pass)
)
(sql-mysql)
)
)
(defun enode-mysql-reconnect (conn-user conn-pass conn-connection conn-hostname conn-prompt conn-port)
"Undocumented, and incomplete"
t
)
(provide 'enode-mysql)

View file

@ -344,11 +344,12 @@
;; is set.
;; If we want oracle shtuff.
(require 'enode-oracle)
(require 'enode-oracle) ;; Oracle only
(require 'enode-mysql) ;; MySQL/MariaDB only
;; Some handy stuff that really should be part of ENODE but isn't
(require 'sql-extras)
(require 'pls-extras)
(require 'pls-extras) ;; Oracle only
;;
;; Customisable stuff
@ -482,7 +483,7 @@ This is the item whose information is displayed in the information window.")
(defvar enode-current-connection-type nil
"The current connection type: 'oracle, 'mysql, etc.")
(defvar enode-supported-connection-types '(oracle)
(defvar enode-supported-connection-types '(oracle mysql)
"The current connection type: 'oracle, 'mysql, etc.")
(defvar enode-current-connection nil
@ -562,6 +563,8 @@ INTERACTIVE"
"A function to start the SQL engine for the connection type"
(cond ((eq 'oracle enode-current-connection-type)
(enode-oracle-start-sql-engine))
((eq 'mysql enode-current-connection-type)
t)
)
)
@ -580,12 +583,12 @@ INTERACTIVE"
(active-buffer (current-buffer))
)
;; The user to connect as
(setq conn-user (car conn-details))
(setq conn-user (plist-get conn-details :conn-user))
;; The database to connect to
(setq conn-connection (caddr conn-details))
(setq conn-connection (plist-get conn-details :conn-connection))
;; The password to use: if it's not in the saved connection
;; details...
(setq conn-pass (if (not (cadr conn-details))
(setq conn-pass (if (not (plist-get conn-details :conn-pass))
;; ... if it's one of the locally saved
;; passwords...
(if (assoc connection-description
@ -607,12 +610,18 @@ INTERACTIVE"
enode-passwords-in-use))
my-conn-pass))))
;; The SQL prompt for the SQL engine
(setq conn-prompt (cadddr conn-details))
(setq conn-prompt (plist-get conn-details :conn-prompt))
(setq conn-hostname (plist-get conn-details :conn-hostname))
(setq conn-port (plist-get conn-details :conn-port))
(cond ((eq 'oracle enode-current-connection-type)
;; Connect.
(enode-oracle-connect conn-user conn-pass conn-connection
conn-prompt)
)
((eq 'mysql enode-current-connection-type)
(enode-mysql-connect conn-user conn-pass conn-connection
conn-hostname conn-prompt conn-port)
)
)
;; Say who we're now connected to.
(setq enode-current-connection connection-description)
@ -895,13 +904,20 @@ of projects that are available."
(read-from-minibuffer (format "Database for %s: " conn-desc)))
;; Get the prompt that will be used
(setq conn-prompt
(read-from-minibuffer (format "SQLPROMPT for %s: " conn-desc)))
(read-from-minibuffer (format "PROMPT for %s: " conn-desc)))
(setq conn-hostname (if (eq enode-current-connection-type 'mysql)
(read-from-minibuffer (format "HOSTNAME for %s: " conn-desc))
nil
)
)
;; Add these details to the list of connections for the current type
(setq current-type-connections
(cons (list conn-desc
conn-user
nil
conn-connection
conn-hostname
conn-prompt)
current-type-connections))
;; Replace the connections for this type in the list of all

View file

@ -29,7 +29,7 @@
(goto-char (point-max))
(goto-char (re-search-backward "^-- Table: .+"))
(insert (format "-- Table: %s\n\n" table-name))
(insert (format "desc %s\n\n" table-name))
(insert (format "desc %s;\n\n" table-name))
(insert (format "select count(*) %s\nfrom %s;\n\n"
table-name table-name))
)