-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathedbi.el
2104 lines (1883 loc) · 88 KB
/
edbi.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; edbi.el --- Database independent interface for Emacs
;; Copyright (C) 2011, 2012, 2013 SAKURAI Masashi
;; Author: SAKURAI Masashi <m.sakurai at kiwanami.net>
;; Version: 0.1.3
;; Keywords: database, epc
;; URL: https://github.com/kiwanami/emacs-edbi
;; This program 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.
;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This program connects the database server through Perl's DBI,
;; and provides DB-accessing API and the simple management UI.
;;; Installation:
;; This program depends on following programs:
;; - deferred.el, concurrent.el / https://github.com/kiwanami/emacs-deferred
;; - epc.el / https://github.com/kiwanami/emacs-epc
;; - ctable.el / https://github.com/kiwanami/emacs-ctable
;; - Perl/CPAN
;; - RPC::EPC::Service (and some dependent modules)
;; - DBI and drivers, DBD::Sqlite, DBD::Pg, DBD::mysql
;; Place this program (edbi.el and edbi-bridge.pl) in your load path
;; and add following code.
;; (require 'edbi)
;; Then, M-x `edbi:open-db-viewer' opens a dialog for DB connection.
;; - Data Source : URI string for DBI::connect (Ex. dbi:SQLite:dbname=/path/db.sqlite )
;; - User Name, Auth : user name and password for DBI::connect
;; - History button : you can choose a data source from your connection history.
;; - OK button : connect DB and open the database view
;; * Database view
;; This buffer enumerates tables and views.
;; Check the key-bind `edbi:dbview-keymap'.
;; - j,k, n,p : navigation for rows
;; - c : switch to query editor buffer
;; - RET : show table data
;; - SPC : show table definition
;; - q : quit and disconnect
;; * Table definition view
;; This buffer shows the table definition information.
;; Check the key-bind `edbi:dbview-table-keymap'.
;; - j,k, n,p : navigation for rows
;; - c : switch to query editor buffer
;; - V : show table data
;; - q : kill buffer
;; * Query editor
;; You can edit SQL in this buffer, which supports SQL syntax
;; highlight and auto completion by auto-complete.el.
;; Check the key-bind `edbi:sql-mode-map'.
;; - C-c C-c : Execute SQL
;; - C-c q : kill buffer
;; - M-p : SQL history back
;; - M-n : SQL history forward
;; - C-c C-k : Clear buffer
;; * Query result viewer
;; You can browser the results for executed SQL.
;; Check the key-bind `edbi:dbview-query-result-keymap'.
;; - j,k, n,p : navigation for rows
;; - q : kill buffer
;;; Code:
(eval-when-compile (require 'cl)
(require 'auto-complete nil t))
(require 'epc)
(require 'sql)
;;; Configurations
(defgroup edbi nil "Emacs Database Interface"
:group 'tools
:group 'extensions)
(defcustom edbi:completion-tool 'auto-complete
"Completion engine which you use. You can choose `auto-complete'(defaut) or `none'.
If you want to customize the completion mechanism in yourself, selecting
`none', edbi do nothing about completion."
:type '(choice
(const none)
(const auto-complete)
)
:group 'edbi)
(defvar edbi:driver-libpath (file-name-directory (or load-file-name "."))
"directory for the driver program.")
(defvar edbi:driver-info (list "perl"
(expand-file-name
"edbi-bridge.pl"
edbi:driver-libpath))
"driver program info.")
;;; Utility
(defmacro edbi:seq (first-d &rest elements)
"Deferred sequence macro."
(let* ((pit 'it)
(vsym (gensym))
(fs
(cond
((eq '<- (nth 1 first-d))
(let ((var (car first-d)) (f (nth 2 first-d)))
`(deferred:nextc ,f
(lambda (,vsym) (setq ,var ,vsym)))))
(t first-d)))
(ds (loop for i in elements
collect
(cond
((eq 'lambda (car i))
`(deferred:nextc ,pit ,i))
((eq '<- (nth 1 i))
(let ((var (car i)) (f (nth 2 i)))
`(deferred:nextc ,pit
(lambda (x)
(deferred:$ ,f
(deferred:nextc ,pit
(lambda (,vsym) (setq ,var ,vsym))))))))
(t
`(deferred:nextc ,pit (lambda (x) ,i)))))))
`(deferred:$ ,fs ,@ds)))
(defmacro edbi:liftd (f deferred)
"Deferred function utility, like liftM."
(let ((vsym (gensym)))
`(deferred:nextc ,deferred
(lambda (,vsym) (,f ,vsym)))))
(defmacro edbi:sync (fsym conn &rest args)
"Synchronous calling wrapper macro. FSYM is deferred function in the edbi."
`(epc:sync (edbi:connection-mngr ,conn) (,fsym ,conn ,@args)))
(defun edbi:column-selector (columns name)
"[internal] Return a column selector function."
(lexical-let (num)
(or
(loop for c in columns
for i from 0
if (equal c name)
return (progn
(setq num i)
(lambda (xs) (nth num xs))))
(lambda (xs) nil))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Low level API
;; data types
(defun edbi:data-source (uri &optional username auth)
"Create data source object."
(list uri username auth))
(defun edbi:data-source-uri (data-source)
"Return the uri slot of the DATA-SOURCE."
(car data-source))
(defun edbi:data-source-username (data-source)
"Return the username slot of the DATA-SOURCE."
(nth 1 data-source))
(defun edbi:data-source-auth (data-source)
"Return the auth slot of the DATA-SOURCE."
(nth 2 data-source))
(defstruct edbi:ac-candidates tables columns types keywords)
(defun edbi:connection (epc-mngr)
"Create an `edbi:connection' object."
;; edbi:manager, edbi:data-source, query-buffers, ac-sources
(list epc-mngr nil nil nil))
(defsubst edbi:connection-mngr (conn)
"Return the `epc:manager' object."
(car conn))
(defsubst edbi:connection-ds (conn)
"Return the `edbi:data-source' object."
(nth 1 conn))
(defun edbi:connection-ds-set (conn ds)
"[internal] Store data-source object at CONN object."
(if (nth 1 conn) (error "BUG: Data Source object is set unexpectedly.")
(setf (nth 1 conn) ds)))
(defun edbi:connection-buffers (conn)
"Return the buffer list of query editors."
(let ((buf-list (nth 2 conn)))
(setq buf-list
(loop for i in buf-list
if (buffer-live-p i)
collect i))
(setf (nth 2 conn) buf-list)
buf-list))
(defun edbi:connection-buffers-set (conn buffer-list)
"[internal] Store BUFFER-LIST at CONN object."
(setf (nth 2 conn) buffer-list))
(defun edbi:connection-ac (conn)
"Return ac-candidate object."
(nth 3 conn))
(defun edbi:connection-ac-set (conn ac-candidate)
"[internal] Store ac-candidate object at CONN object."
(setf (nth 3 conn) ac-candidate))
;; API
(defun edbi:start ()
"Start the EPC process. This function returns an `edbi:connection' object.
The functions `edbi:start' and `edbi:connect' are separated so as
for library users to inspect where the problem is occurred. If
`edbi:start' is failed, the EPC peer process may be wrong. If
`edbi:connect' is failed, the DB setting or environment is
wrong."
(edbi:connection
(epc:start-epc (car edbi:driver-info) (cdr edbi:driver-info))))
(defun edbi:finish (conn)
"Terminate the EPC process."
(epc:stop-epc (edbi:connection-mngr conn)))
(defun edbi:connect (conn data-source)
"Connect to the DB. DATA-SOURCE is a `edbi:data-source' object.
This function executes peer's API synchronously.
This function returns the value of '$dbh->get_info(18)' which
shows the DB version string. (Some DB may return nil.)"
(let ((mngr (edbi:connection-mngr conn)))
(prog1
(epc:call-sync mngr 'connect
(list (edbi:data-source-uri data-source)
(edbi:data-source-username data-source)
(edbi:data-source-auth data-source)))
(edbi:connection-ds-set conn data-source)
(setf (epc:manager-title mngr) (edbi:data-source-uri data-source)))))
(defun edbi:do-d (conn sql &optional params)
"Execute SQL and return a number of affected rows."
(epc:call-deferred
(edbi:connection-mngr conn) 'do (cons sql params)))
(defun edbi:select-all-d (conn sql &optional params)
"Execute the query SQL and returns all result rows."
(epc:call-deferred
(edbi:connection-mngr conn) 'select-all (cons sql params)))
(defun edbi:prepare-d (conn sql)
"[STH] Prepare the statement for SQL.
This function holds the statement as a state in the edbi-bridge.
The programmer should be aware of the internal state so as not to break the state."
(epc:call-deferred
(edbi:connection-mngr conn) 'prepare sql))
(defun edbi:execute-d (conn &optional params)
"[STH] Execute the statement."
(epc:call-deferred
(edbi:connection-mngr conn) 'execute params))
(defun edbi:fetch-columns-d (conn)
"[STH] Fetch a list of the column titles."
(epc:call-deferred
(edbi:connection-mngr conn) 'fetch-columns nil))
(defun edbi:fetch-d (conn &optional num)
"[STH] Fetch a row object. NUM is a number of retrieving rows. If NUM is nil, this function retrieves all rows."
(epc:call-deferred
(edbi:connection-mngr conn) 'fetch num))
(defun edbi:auto-commit-d (conn flag)
"Set the auto-commit flag. FLAG is 'true' or 'false' string."
(epc:call-deferred
(edbi:connection-mngr conn) 'auto-commit flag))
(defun edbi:commit-d (conn)
"Commit transaction."
(epc:call-deferred
(edbi:connection-mngr conn) 'commit nil))
(defun edbi:rollback-d (conn)
"Rollback transaction."
(epc:call-deferred
(edbi:connection-mngr conn) 'rollback nil))
(defun edbi:disconnect-d (conn)
"Close the DB connection."
(epc:stop-epc conn))
(defun edbi:status-info-d (conn)
"Return a list of `err' code, `errstr' and `state'."
(epc:call-deferred (edbi:connection-mngr conn) 'status nil))
(defun edbi:type-info-all-d (conn)
"Return a list of type info."
(epc:call-deferred (edbi:connection-mngr conn) 'type-info-all nil))
(defun edbi:table-info-d (conn catalog schema table type)
"Return a table info as (COLUMN-LIST ROW-LIST)."
(epc:call-deferred
(edbi:connection-mngr conn) 'table-info (list catalog schema table type)))
(defun edbi:column-info-d (conn catalog schema table column)
"Return a column info as (COLUMN-LIST ROW-LIST)."
(epc:call-deferred
(edbi:connection-mngr conn) 'column-info (list catalog schema table column)))
(defun edbi:primary-key-info-d (conn catalog schema table)
"Return a primary key info as (COLUMN-LIST ROW-LIST)."
(epc:call-deferred
(edbi:connection-mngr conn) 'primary-key-info (list catalog schema table)))
(defun edbi:foreign-key-info-d (conn pk-catalog pk-schema pk-table
fk-catalog fk-schema fk-table)
"Return a foreign key info as (COLUMN-LIST ROW-LIST)."
(epc:call-deferred (edbi:connection-mngr conn) 'foreign-key-info
(list pk-catalog pk-schema pk-table
fk-catalog fk-schema fk-table)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; DB Driver Abstraction
;; [edbi:dbd structure]
;;
;; name : driver name
;; table-info-args : a function that receives an `edbi:connection' object
;; and returns a list for the arguments of `edbi:table-info-d'.
;; table-info-filter : a function that receives the return value of `edbi:table-info-d'
;; and returns a filtered list (catalog schema table-name type remarks).
;; column-info-args : argument function for `edbi:column-info-d'.
;; column-info-filter : filter function for `edbi:column-info-d'.
;; this function returns a list of
;; (table-name column-name type-name column-size nullable remarks)
;; type-info-filter : filter function for `edbi:type-info-all-d'.
;; this function returns a list of type-name.
;; limit-format : a format string for the limited select statement.
;; keywords : return a SQL keywords function
;;
;; TODO: collectiong indexes
(defstruct edbi:dbd name table-info-args table-info-filter
column-info-args column-info-filter type-info-filter limit-format keywords)
(defvar edbi:dbd-alist nil "[internal] List of the dbd name and `edbi:dbd' object.")
(defvar edbi:dbd-default nil "[internal] Default `edbi:dbd' object.")
(defun edbi:dbd-register (dbd)
"Register the `edbi:dbd' object to `edbi:dbd-alist'."
(let ((name (edbi:dbd-name dbd)))
(setq edbi:dbd-alist
(loop for i in edbi:dbd-alist
unless (equal (car i) name) collect i))
(push (cons name dbd) edbi:dbd-alist))
edbi:dbd-alist)
(defun edbi:dbd-get (conn)
"[internal] Return the `edbi:dbd' object for CONN."
(let* ((uri (edbi:data-source-uri (edbi:connection-ds conn)))
(ps (string-match "^dbi:[^:]+" uri)) ret)
(when ps
(let ((name (match-string 0 uri)))
(setq ret (cdr (assoc name edbi:dbd-alist)))))
(unless ret
(setq ret edbi:dbd-default))
ret))
(defun edbi:dbd-extract-table-info (table-info)
"[internal] Extract TABLE-INFO as follows:
((CATALOG SCHEMA TABLE TYPE REMARKS) ...)"
(loop
with hrow = (and table-info (car table-info))
with rows = (and table-info (cadr table-info))
with catalog-f = (edbi:column-selector hrow "TABLE_CAT")
with schema-f = (edbi:column-selector hrow "TABLE_SCHEM")
with table-f = (edbi:column-selector hrow "TABLE_NAME")
with type-f = (edbi:column-selector hrow "TABLE_TYPE")
with remarks-f = (edbi:column-selector hrow "REMARKS")
for row in rows
for catalog = (funcall catalog-f row)
for schema = (funcall schema-f row)
for type = (or (funcall type-f row) "")
for table = (funcall table-f row)
for remarks = (or (funcall remarks-f row) "")
if table
collect (list catalog schema table type remarks)))
(defun edbi:dbd-default-table-info-filter (table-info)
"[internal] Default table name filter."
(loop for rec in (edbi:dbd-extract-table-info table-info)
for (catalog schema table type remarks) = rec
if (not (or (string-match "\\(INDEX\\|SYSTEM\\)" type)
(string-match "\\(information_schema\\|SYSTEM\\)" schema)))
collect rec))
(defun edbi:dbd-extract-column-info (column-info)
"[internal] Extract COLUMN-INFO as follows:
((TABLE-NAME COLUMN-NAME TYPE-NAME COLUMN-SIZE NULLABLE REMARKS)...)"
(loop
with hrow = (and column-info (car column-info))
with rows = (and column-info (cadr column-info))
with table-name-f = (edbi:column-selector hrow "TABLE_NAME")
with column-name-f = (edbi:column-selector hrow "COLUMN_NAME")
with type-name-f = (edbi:column-selector hrow "TYPE_NAME")
with column-size-f = (edbi:column-selector hrow "COLUMN_SIZE")
with nullable-f = (edbi:column-selector hrow "NULLABLE")
with remarks-f = (edbi:column-selector hrow "REMARKS")
for row in rows
for table-name = (funcall table-name-f row)
for column-name = (funcall column-name-f row)
for type-name = (funcall type-name-f row)
for column-size = (or (funcall column-size-f row) "")
for nullable = (if (equal 0 (funcall nullable-f row)) "NOT NULL" "")
for remarks = (or (funcall remarks-f row) "")
if column-name
collect (list table-name column-name type-name column-size nullable remarks)))
(defun edbi:dbd-default-column-info-filter (column-info)
"[internal] Default column name filter."
(edbi:dbd-extract-column-info column-info))
(defun edbi:dbd-default-type-info-filter (type-info)
"[internal] Default type info filter."
(let (ret)
(when type-info
(let ((name-col
(loop for (n . i) in (car type-info)
if (equal n "TYPE_NAME") return i)))
(when name-col
(setq ret
(loop for type-row in (cdr type-info)
for name = (nth name-col type-row)
collect
(cons (propertize name 'summary "TYPE") name))))))
(unless ret
;; fallback : enumerate well known types
(setq ret (list "INT" "INTEGER" "TINYINT" "SMALLINT" "MEDIUMINT"
"BIGINT" "UNSIGNED" "BIG" "INTEGER" "CHARACTER"
"VARCHAR" "NCHAR" "NVARCHAR" "CLOB" "TEXT" "BLOB"
"REAL" "DOUBLE" "FLOAT" "NUMERIC" "DECIMAL" "BOOLEAN"
"DATE" "DATETIME")))
ret))
(defun edbi:dbd-default-keywords ()
"[internal] Default SQL keywords, following format:
(list (\"keyword type\" . (keyword list)) ... )"
(list
(cons "Keyword"
(list
"ABSOLUTE" "ACTION" "ADD" "ADMIN" "AFTER" "AGGREGATE" "ALIAS" "ALL"
"ALLOCATE" "ALTER" "AND" "ANY" "ARE" "AS" "ASC" "ASSERTION" "AT"
"AUTHORIZATION" "BEFORE" "BEGIN" "BOTH" "BREADTH" "BY" "CALL"
"CASCADE" "CASCADED" "CASE" "CATALOG" "CHECK" "CLASS" "CLOSE"
"COLLATE" "COLLATION" "COLUMN" "COMMIT" "COMPLETION" "CONNECT"
"CONNECTION" "CONSTRAINT" "CONSTRAINTS" "CONSTRUCTOR" "CONTINUE"
"CORRESPONDING" "CREATE" "CROSS" "CUBE" "CURRENT" "CURSOR" "CYCLE"
"DATA" "DAY" "DEALLOCATE" "DECLARE" "DEFAULT" "DEFERRABLE" "DEFERRED"
"DELETE" "DEPTH" "DEREF" "DESC" "DESCRIBE" "DESCRIPTOR" "DESTROY"
"DESTRUCTOR" "DETERMINISTIC" "DIAGNOSTICS" "DICTIONARY" "DISCONNECT"
"DISTINCT" "DOMAIN" "DROP" "DYNAMIC" "EACH" "ELSE" "END" "EQUALS"
"ESCAPE" "EVERY" "EXCEPT" "EXCEPTION" "EXEC" "EXECUTE" "EXTERNAL"
"FALSE" "FETCH" "FIRST" "FOR" "FOREIGN" "FOUND" "FREE" "FROM" "FULL"
"FUNCTION" "GENERAL" "GET" "GLOBAL" "GO" "GOTO" "GRANT" "GROUP"
"GROUPING" "HAVING" "HOST" "HOUR" "IDENTITY" "IGNORE" "IMMEDIATE" "IN"
"INDICATOR" "INITIALIZE" "INITIALLY" "INNER" "INOUT" "INPUT" "INSERT"
"INTERSECT" "INTO" "IS" "ISOLATION" "ITERATE" "JOIN" "KEY" "LANGUAGE"
"LAST" "LATERAL" "LEADING" "LEFT" "LESS" "LEVEL" "LIKE" "LIMIT"
"LOCAL" "LOCATOR" "MAP" "MATCH" "MINUTE" "MODIFIES" "MODIFY" "MODULE"
"MONTH" "NAMES" "NATURAL" "NEW" "NEXT" "NO" "NONE" "NOT" "NULL" "OF"
"OFF" "OLD" "ON" "ONLY" "OPEN" "OPERATION" "OPTION" "OR" "ORDER"
"ORDINALITY" "OUT" "OUTER" "OUTPUT" "PAD" "PARAMETER" "PARAMETERS"
"PARTIAL" "PATH" "POSTFIX" "PREFIX" "PREORDER" "PREPARE" "PRESERVE"
"PRIMARY" "PRIOR" "PRIVILEGES" "PROCEDURE" "PUBLIC" "READ" "READS"
"RECURSIVE" "REFERENCES" "REFERENCING" "RELATIVE" "RESTRICT" "RESULT"
"RETURN" "RETURNS" "REVOKE" "RIGHT" "ROLE" "ROLLBACK" "ROLLUP"
"ROUTINE" "ROWS" "SAVEPOINT" "SCHEMA" "SCROLL" "SEARCH" "SECOND"
"SECTION" "SELECT" "SEQUENCE" "SESSION" "SET" "SETS" "SIZE" "SOME"
"SPACE" "SPECIFIC" "SPECIFICTYPE" "SQL" "SQLEXCEPTION" "SQLSTATE"
"SQLWARNING" "START" "STATE" "STATEMENT" "STATIC" "STRUCTURE" "TABLE"
"TEMPORARY" "TERMINATE" "THAN" "THEN" "TIMEZONE_HOUR"
"TIMEZONE_MINUTE" "TO" "TRAILING" "TRANSACTION" "TRANSLATION"
"TRIGGER" "TRUE" "UNDER" "UNION" "UNIQUE" "UNKNOWN" "UNNEST" "UPDATE"
"USAGE" "USING" "VALUE" "VALUES" "VARIABLE" "VIEW" "WHEN" "WHENEVER"
"WHERE" "WITH" "WITHOUT" "WORK" "WRITE" "YEAR"))
(cons "Functions"
(list
"abs" "avg" "bit_length" "cardinality" "cast" "char_length"
"character_length" "coalesce" "convert" "count" "current_date"
"current_path" "current_role" "current_time" "current_timestamp"
"current_user" "extract" "localtime" "localtimestamp" "lower" "max"
"min" "mod" "nullif" "octet_length" "overlay" "placing" "session_user"
"substring" "sum" "system_user" "translate" "treat" "trim" "upper"
"user"))))
(defun edbi:dbd-limit-format-fill (dbd table-name limit-num)
"[internal] Fill the format and return a SQL string."
(replace-regexp-in-string
"%limit%" (format "%s" limit-num)
(replace-regexp-in-string
"%table%" table-name (edbi:dbd-limit-format dbd))))
(defun edbi:dbd-init ()
"[internal] Initialize `edbi:dbd' objects."
(setq edbi:dbd-default
(make-edbi:dbd :name "dbi:SQLite"
:table-info-args
(lambda (conn) (list nil nil nil nil))
:table-info-filter
'edbi:dbd-default-table-info-filter
:column-info-args
(lambda (conn table) (list nil nil table nil))
:column-info-filter
'edbi:dbd-default-column-info-filter
:type-info-filter
'edbi:dbd-default-type-info-filter
:limit-format
"SELECT * FROM %table% LIMIT %limit%"
:keywords
'edbi:dbd-default-keywords))
(loop for i in (list edbi:dbd-default
(edbi:dbd-init-postgresql)
(edbi:dbd-init-mysql)
(edbi:dbd-init-oracle))
do
(edbi:dbd-register i))
;; add word-collection hook here for completion-at-point-functions
(add-hook 'edbi:dbview-update-hook 'edbi:ac-editor-word-candidate-update))
(defun edbi:dbd-init-postgresql ()
"[internal] Initialize `edbi:dbd' object for Postgresql."
(make-edbi:dbd :name "dbi:Pg"
:table-info-args
(lambda (conn) (list nil nil nil nil))
:table-info-filter
'edbi:dbd-default-table-info-filter
:column-info-args
(lambda (conn table) (list nil nil table nil))
:column-info-filter
'edbi:dbd-default-column-info-filter
:type-info-filter
'edbi:dbd-default-type-info-filter
:limit-format
"SELECT * FROM %table% LIMIT %limit%"
:keywords
'edbi:dbd-init-postgresql-keywords))
(defun edbi:dbd-init-postgresql-keywords ()
"[internal] "
(list
(cons "Function"
(list
"abbrev" "abs" "acos" "age" "area" "ascii" "asin" "atab2" "atan"
"atan2" "avg" "bit_length" "both" "broadcast" "btrim" "cbrt" "ceil"
"center" "char_length" "chr" "coalesce" "col_description" "convert"
"cos" "cot" "count" "current_database" "current_date" "current_schema"
"current_schemas" "current_setting" "current_time" "current_timestamp"
"current_user" "currval" "date_part" "date_trunc" "decode" "degrees"
"diameter" "encode" "exp" "extract" "floor" "get_bit" "get_byte"
"has_database_privilege" "has_function_privilege"
"has_language_privilege" "has_schema_privilege" "has_table_privilege"
"height" "host" "initcap" "isclosed" "isfinite" "isopen" "leading"
"length" "ln" "localtime" "localtimestamp" "log" "lower" "lpad"
"ltrim" "masklen" "max" "min" "mod" "netmask" "network" "nextval"
"now" "npoints" "nullif" "obj_description" "octet_length" "overlay"
"pclose" "pg_client_encoding" "pg_function_is_visible"
"pg_get_constraintdef" "pg_get_indexdef" "pg_get_ruledef"
"pg_get_userbyid" "pg_get_viewdef" "pg_opclass_is_visible"
"pg_operator_is_visible" "pg_table_is_visible" "pg_type_is_visible"
"pi" "popen" "position" "pow" "quote_ident" "quote_literal" "radians"
"radius" "random" "repeat" "replace" "round" "rpad" "rtrim"
"session_user" "set_bit" "set_byte" "set_config" "set_masklen"
"setval" "sign" "sin" "split_part" "sqrt" "stddev" "strpos" "substr"
"substring" "sum" "tan" "timeofday" "to_ascii" "to_char" "to_date"
"to_hex" "to_number" "to_timestamp" "trailing" "translate" "trim"
"trunc" "upper" "variance" "version" "width"))
(cons "Keyword"
(list
"ABORT" "ACCESS" "ADD" "AFTER" "AGGREGATE" "ALIGNMENT" "ALL" "ALTER"
"ANALYZE" "AND" "ANY" "AS" "ASC" "ASSIGNMENT" "AUTHORIZATION"
"BACKWARD" "BASETYPE" "BEFORE" "BEGIN" "BETWEEN" "BINARY" "BY" "CACHE"
"CALLED" "CASCADE" "CASE" "CAST" "CHARACTERISTICS" "CHECK"
"CHECKPOINT" "CLASS" "CLOSE" "CLUSTER" "COLUMN" "COMMENT" "COMMIT"
"COMMITTED" "COMMUTATOR" "CONSTRAINT" "CONSTRAINTS" "CONVERSION"
"COPY" "CREATE" "CREATEDB" "CREATEUSER" "CURSOR" "CYCLE" "DATABASE"
"DEALLOCATE" "DECLARE" "DEFAULT" "DEFERRABLE" "DEFERRED" "DEFINER"
"DELETE" "DELIMITER" "DESC" "DISTINCT" "DO" "DOMAIN" "DROP" "EACH"
"ELEMENT" "ELSE" "ENCODING" "ENCRYPTED" "END" "ESCAPE" "EXCEPT"
"EXCLUSIVE" "EXECUTE" "EXISTS" "EXPLAIN" "EXTENDED" "EXTERNAL" "FALSE"
"FETCH" "FINALFUNC" "FOR" "FORCE" "FOREIGN" "FORWARD" "FREEZE" "FROM"
"FULL" "FUNCTION" "GRANT" "GROUP" "GTCMP" "HANDLER" "HASHES" "HAVING"
"IMMEDIATE" "IMMUTABLE" "IMPLICIT" "IN" "INCREMENT" "INDEX" "INHERITS"
"INITCOND" "INITIALLY" "INPUT" "INSENSITIVE" "INSERT" "INSTEAD"
"INTERNALLENGTH" "INTERSECT" "INTO" "INVOKER" "IS" "ISNULL"
"ISOLATION" "JOIN" "KEY" "LANGUAGE" "LEFTARG" "LEVEL" "LIKE" "LIMIT"
"LISTEN" "LOAD" "LOCAL" "LOCATION" "LOCK" "LTCMP" "MAIN" "MATCH"
"MAXVALUE" "MERGES" "MINVALUE" "MODE" "MOVE" "NATURAL" "NEGATOR"
"NEXT" "NOCREATEDB" "NOCREATEUSER" "NONE" "NOT" "NOTHING" "NOTIFY"
"NOTNULL" "NULL" "OF" "OFFSET" "OIDS" "ON" "ONLY" "OPERATOR" "OR"
"ORDER" "OUTPUT" "OWNER" "PARTIAL" "PASSEDBYVALUE" "PASSWORD" "PLAIN"
"PREPARE" "PRIMARY" "PRIOR" "PRIVILEGES" "PROCEDURAL" "PROCEDURE"
"PUBLIC" "READ" "RECHECK" "REFERENCES" "REINDEX" "RELATIVE" "RENAME"
"RESET" "RESTRICT" "RETURNS" "REVOKE" "RIGHTARG" "ROLLBACK" "ROW"
"RULE" "SCHEMA" "SCROLL" "SECURITY" "SELECT" "SEQUENCE" "SERIALIZABLE"
"SESSION" "SET" "SFUNC" "SHARE" "SHOW" "SIMILAR" "SOME" "SORT1"
"SORT2" "STABLE" "START" "STATEMENT" "STATISTICS" "STORAGE" "STRICT"
"STYPE" "SYSID" "TABLE" "TEMP" "TEMPLATE" "TEMPORARY" "THEN" "TO"
"TRANSACTION" "TRIGGER" "TRUE" "TRUNCATE" "TRUSTED" "TYPE"
"UNENCRYPTED" "UNION" "UNIQUE" "UNKNOWN" "UNLISTEN" "UNTIL" "UPDATE"
"USAGE" "USER" "USING" "VACUUM" "VALID" "VALIDATOR" "VALUES"
"VARIABLE" "VERBOSE" "VIEW" "VOLATILE" "WHEN" "WHERE" "WITH" "WITHOUT"
"WORK"))))
(defun edbi:dbd-init-mysql ()
"[internal] Initialize `edbi:dbd' object for MySQL."
(make-edbi:dbd :name "dbi:mysql"
:table-info-args
(lambda (conn) (list nil nil nil nil))
:table-info-filter
'edbi:dbd-default-table-info-filter
:column-info-args
(lambda (conn table) (list nil nil table "%"))
:column-info-filter
'edbi:dbd-default-column-info-filter
:type-info-filter
'edbi:dbd-default-type-info-filter
:limit-format
"SELECT * FROM %table% LIMIT %limit%"
:keywords
'edbi:dbd-init-mysql-keywords))
(defun edbi:dbd-init-mysql-keywords ()
"[internal] "
(list
(cons "Function"
(list
"ascii" "avg" "bdmpolyfromtext" "bdmpolyfromwkb" "bdpolyfromtext"
"bdpolyfromwkb" "benchmark" "bin" "bit_and" "bit_length" "bit_or"
"bit_xor" "both" "cast" "char_length" "character_length" "coalesce"
"concat" "concat_ws" "connection_id" "conv" "convert" "count"
"curdate" "current_date" "current_time" "current_timestamp" "curtime"
"elt" "encrypt" "export_set" "field" "find_in_set" "found_rows" "from"
"geomcollfromtext" "geomcollfromwkb" "geometrycollectionfromtext"
"geometrycollectionfromwkb" "geometryfromtext" "geometryfromwkb"
"geomfromtext" "geomfromwkb" "get_lock" "group_concat" "hex" "ifnull"
"instr" "interval" "isnull" "last_insert_id" "lcase" "leading"
"length" "linefromtext" "linefromwkb" "linestringfromtext"
"linestringfromwkb" "load_file" "locate" "lower" "lpad" "ltrim"
"make_set" "master_pos_wait" "max" "mid" "min" "mlinefromtext"
"mlinefromwkb" "mpointfromtext" "mpointfromwkb" "mpolyfromtext"
"mpolyfromwkb" "multilinestringfromtext" "multilinestringfromwkb"
"multipointfromtext" "multipointfromwkb" "multipolygonfromtext"
"multipolygonfromwkb" "now" "nullif" "oct" "octet_length" "ord"
"pointfromtext" "pointfromwkb" "polyfromtext" "polyfromwkb"
"polygonfromtext" "polygonfromwkb" "position" "quote" "rand"
"release_lock" "repeat" "replace" "reverse" "rpad" "rtrim" "soundex"
"space" "std" "stddev" "substring" "substring_index" "sum" "sysdate"
"trailing" "trim" "ucase" "unix_timestamp" "upper" "user" "variance"))
(cons "Keyword"
(list
"ACTION" "ADD" "AFTER" "AGAINST" "ALL" "ALTER" "AND" "AS" "ASC"
"AUTO_INCREMENT" "AVG_ROW_LENGTH" "BDB" "BETWEEN" "BY" "CASCADE"
"CASE" "CHANGE" "CHARACTER" "CHECK" "CHECKSUM" "CLOSE" "COLLATE"
"COLLATION" "COLUMN" "COLUMNS" "COMMENT" "COMMITTED" "CONCURRENT"
"CONSTRAINT" "CREATE" "CROSS" "DATA" "DATABASE" "DEFAULT"
"DELAY_KEY_WRITE" "DELAYED" "DELETE" "DESC" "DIRECTORY" "DISABLE"
"DISTINCT" "DISTINCTROW" "DO" "DROP" "DUMPFILE" "DUPLICATE" "ELSE"
"ENABLE" "ENCLOSED" "END" "ESCAPED" "EXISTS" "FIELDS" "FIRST" "FOR"
"FORCE" "FOREIGN" "FROM" "FULL" "FULLTEXT" "GLOBAL" "GROUP" "HANDLER"
"HAVING" "HEAP" "HIGH_PRIORITY" "IF" "IGNORE" "IN" "INDEX" "INFILE"
"INNER" "INSERT" "INSERT_METHOD" "INTO" "IS" "ISAM" "ISOLATION" "JOIN"
"KEY" "KEYS" "LAST" "LEFT" "LEVEL" "LIKE" "LIMIT" "LINES" "LOAD"
"LOCAL" "LOCK" "LOW_PRIORITY" "MATCH" "MAX_ROWS" "MERGE" "MIN_ROWS"
"MODE" "MODIFY" "MRG_MYISAM" "MYISAM" "NATURAL" "NEXT" "NO" "NOT"
"NULL" "OFFSET" "OJ" "ON" "OPEN" "OPTIONALLY" "OR" "ORDER" "OUTER"
"OUTFILE" "PACK_KEYS" "PARTIAL" "PASSWORD" "PREV" "PRIMARY"
"PROCEDURE" "QUICK" "RAID0" "RAID_TYPE" "READ" "REFERENCES" "RENAME"
"REPEATABLE" "RESTRICT" "RIGHT" "ROLLBACK" "ROLLUP" "ROW_FORMAT"
"SAVEPOINT" "SELECT" "SEPARATOR" "SERIALIZABLE" "SESSION" "SET"
"SHARE" "SHOW" "SQL_BIG_RESULT" "SQL_BUFFER_RESULT" "SQL_CACHE"
"SQL_CALC_FOUND_ROWS" "SQL_NO_CACHE" "SQL_SMALL_RESULT" "STARTING"
"STRAIGHT_JOIN" "STRIPED" "TABLE" "TABLES" "TEMPORARY" "TERMINATED"
"THEN" "TO" "TRANSACTION" "TRUNCATE" "TYPE" "UNCOMMITTED" "UNION"
"UNIQUE" "UNLOCK" "UPDATE" "USE" "USING" "VALUES" "WHEN" "WHERE"
"WITH" "WRITE" "XOR"))))
(defun edbi:dbd-init-mssql ()
"[internal] Initialize `edbi:dbd' object for MS SQLServer (Sybase DBD)."
;; TODO
;; define edbi:dbd and register
;; also define? ADO.NET, ODBC
)
(defun edbi:dbd-init-oracle ()
"[internal] Initialize `edbi:dbd' object for Oracle."
(make-edbi:dbd :name "dbi:Oracle"
:table-info-args
(lambda (conn) (list nil nil nil nil))
:table-info-filter
'edbi:dbd-oracle-table-info-filter
:column-info-args
(lambda (conn table) (list nil nil table "%"))
:column-info-filter
'edbi:dbd-default-column-info-filter
:type-info-filter
'edbi:dbd-default-type-info-filter
:limit-format
"SELECT * FROM (SELECT * FROM %table%) WHERE ROWNUM <= %limit%"
:keywords
'edbi:dbd-init-oracle-keywords))
(defun edbi:dbd-oracle-table-info-filter (table-info)
"[internal] Default table name filter."
(loop for rec in (edbi:dbd-extract-table-info table-info)
for (catalog schema table type remarks) = rec
if (and (string-match "^\\(TABLE\\|VIEW\\)$" type)
(not (string-match "^\\(.*SYS\\|SYSTEM\\|PUBLIC\\|APEX_.+\\|XDB\\|ORDDATA\\)$" schema)))
collect rec))
(defun edbi:dbd-init-oracle-keywords ()
"[internal] "
(list
(cons "Function"
(list
"abs" "acos" "add_months" "ascii" "asciistr" "asin" "atan" "atan2"
"avg" "bfilename" "bin_to_num" "bitand" "cast" "ceil" "chartorowid"
"chr" "coalesce" "compose" "concat" "convert" "corr" "cos" "cosh"
"count" "covar_pop" "covar_samp" "cume_dist" "current_date"
"current_timestamp" "current_user" "dbtimezone" "decode" "decompose"
"dense_rank" "depth" "deref" "dump" "empty_clob" "existsnode" "exp"
"extract" "extractvalue" "first" "first_value" "floor" "following"
"from_tz" "greatest" "group_id" "grouping_id" "hextoraw" "initcap"
"instr" "lag" "last" "last_day" "last_value" "lead" "least" "length"
"ln" "localtimestamp" "lower" "lpad" "ltrim" "make_ref" "max" "min"
"mod" "months_between" "new_time" "next_day" "nls_charset_decl_len"
"nls_charset_id" "nls_charset_name" "nls_initcap" "nls_lower"
"nls_upper" "nlssort" "ntile" "nullif" "numtodsinterval"
"numtoyminterval" "nvl" "nvl2" "over" "path" "percent_rank"
"percentile_cont" "percentile_disc" "power" "preceding" "rank"
"ratio_to_report" "rawtohex" "rawtonhex" "reftohex" "regr_"
"regr_avgx" "regr_avgy" "regr_count" "regr_intercept" "regr_r2"
"regr_slope" "regr_sxx" "regr_sxy" "regr_syy" "replace" "round"
"row_number" "rowidtochar" "rowidtonchar" "rpad" "rtrim"
"sessiontimezone" "sign" "sin" "sinh" "soundex" "sqrt" "stddev"
"stddev_pop" "stddev_samp" "substr" "sum" "sys_connect_by_path"
"sys_context" "sys_dburigen" "sys_extract_utc" "sys_guid" "sys_typeid"
"sys_xmlagg" "sys_xmlgen" "sysdate" "systimestamp" "tan" "tanh"
"to_char" "to_clob" "to_date" "to_dsinterval" "to_lob" "to_multi_byte"
"to_nchar" "to_nclob" "to_number" "to_single_byte" "to_timestamp"
"to_timestamp_tz" "to_yminterval" "translate" "treat" "trim" "trunc"
"tz_offset" "uid" "unbounded" "unistr" "updatexml" "upper" "user"
"userenv" "var_pop" "var_samp" "variance" "vsize" "width_bucket" "xml"
"xmlagg" "xmlattribute" "xmlcolattval" "xmlconcat" "xmlelement"
"xmlforest" "xmlsequence" "xmltransform"
))
(cons "Keyword"
(list
"ABORT" "ACCESS" "ACCESSED" "ACCOUNT" "ACTIVATE" "ADD" "ADMIN"
"ADVISE" "AFTER" "AGENT" "AGGREGATE" "ALL" "ALLOCATE" "ALLOW" "ALTER"
"ALWAYS" "ANALYZE" "ANCILLARY" "AND" "ANY" "APPLY" "ARCHIVE"
"ARCHIVELOG" "ARRAY" "AS" "ASC" "ASSOCIATE" "AT" "ATTRIBUTE"
"ATTRIBUTES" "AUDIT" "AUTHENTICATED" "AUTHID" "AUTHORIZATION" "AUTO"
"AUTOALLOCATE" "AUTOMATIC" "AVAILABILITY" "BACKUP" "BEFORE" "BEGIN"
"BEHALF" "BETWEEN" "BINDING" "BITMAP" "BLOCK" "BLOCKSIZE" "BODY"
"BOTH" "BUFFER_POOL" "BUILD" "BY" "CACHE" "CALL" "CANCEL"
"CASCADE" "CASE" "CATEGORY" "CERTIFICATE" "CHAINED" "CHANGE" "CHECK"
"CHECKPOINT" "CHILD" "CHUNK" "CLASS" "CLEAR" "CLONE" "CLOSE" "CLUSTER"
"COLUMN" "COLUMN_VALUE" "COLUMNS" "COMMENT" "COMMIT" "COMMITTED"
"COMPATIBILITY" "COMPILE" "COMPLETE" "COMPOSITE_LIMIT" "COMPRESS"
"COMPUTE" "CONNECT" "CONNECT_TIME" "CONSIDER" "CONSISTENT"
"CONSTRAINT" "CONSTRAINTS" "CONSTRUCTOR" "CONTENTS" "CONTEXT"
"CONTINUE" "CONTROLFILE" "CORRUPTION" "COST" "CPU_PER_CALL"
"CPU_PER_SESSION" "CREATE" "CROSS" "CUBE" "CURRENT" "CURRVAL" "CYCLE"
"DANGLING" "DATA" "DATABASE" "DATAFILE" "DATAFILES" "DAY" "DDL"
"DEALLOCATE" "DEBUG" "DEFAULT" "DEFERRABLE" "DEFERRED" "DEFINER"
"DELAY" "DELETE" "DEMAND" "DESC" "DETERMINES" "DETERMINISTIC"
"DICTIONARY" "DIMENSION" "DIRECTORY" "DISABLE" "DISASSOCIATE"
"DISCONNECT" "DISTINCT" "DISTINGUISHED" "DISTRIBUTED" "DML" "DROP"
"EACH" "ELEMENT" "ELSE" "ENABLE" "END" "EQUALS_PATH" "ESCAPE"
"ESTIMATE" "EXCEPT" "EXCEPTIONS" "EXCHANGE" "EXCLUDING" "EXISTS"
"EXPIRE" "EXPLAIN" "EXTENT" "EXTERNAL" "EXTERNALLY"
"FAILED_LOGIN_ATTEMPTS" "FAST" "FILE" "FINAL" "FINISH" "FLUSH" "FOR"
"FORCE" "FOREIGN" "FREELIST" "FREELISTS" "FREEPOOLS" "FRESH" "FROM"
"FULL" "FUNCTION" "FUNCTIONS" "GENERATED" "GLOBAL" "GLOBAL_NAME"
"GLOBALLY" "GRANT" "GROUP" "GROUPING" "GROUPS" "GUARD" "HASH"
"HASHKEYS" "HAVING" "HEAP" "HIERARCHY" "ID" "IDENTIFIED" "IDENTIFIER"
"IDLE_TIME" "IMMEDIATE" "IN" "INCLUDING" "INCREMENT" "INDEX" "INDEXED"
"INDEXES" "INDEXTYPE" "INDEXTYPES" "INDICATOR" "INITIAL" "INITIALIZED"
"INITIALLY" "INITRANS" "INNER" "INSERT" "INSTANCE" "INSTANTIABLE"
"INSTEAD" "INTERSECT" "INTO" "INVALIDATE" "IS" "ISOLATION" "JAVA"
"JOIN" "KEEP" "KEY" "KILL" "LANGUAGE" "LEFT" "LESS" "LEVEL"
"LEVELS" "LIBRARY" "LIKE" "LIKE2" "LIKE4" "LIKEC" "LIMIT" "LINK"
"LIST" "LOB" "LOCAL" "LOCATION" "LOCATOR" "LOCK" "LOG" "LOGFILE"
"LOGGING" "LOGICAL" "LOGICAL_READS_PER_CALL"
"LOGICAL_READS_PER_SESSION" "MANAGED" "MANAGEMENT" "MANUAL" "MAP"
"MAPPING" "MASTER" "MATCHED" "MATERIALIZED" "MAXDATAFILES"
"MAXEXTENTS" "MAXIMIZE" "MAXINSTANCES" "MAXLOGFILES" "MAXLOGHISTORY"
"MAXLOGMEMBERS" "MAXSIZE" "MAXTRANS" "MAXVALUE" "MEMBER" "MEMORY"
"MERGE" "MIGRATE" "MINEXTENTS" "MINIMIZE" "MINIMUM" "MINUS" "MINVALUE"
"MODE" "MODIFY" "MONITORING" "MONTH" "MOUNT" "MOVE" "MOVEMENT" "NAME"
"NAMED" "NATURAL" "NESTED" "NEVER" "NEW" "NEXT" "NEXTVAL" "NO"
"NOARCHIVELOG" "NOAUDIT" "NOCACHE" "NOCOMPRESS" "NOCOPY" "NOCYCLE"
"NODELAY" "NOFORCE" "NOLOGGING" "NOMAPPING" "NOMAXVALUE" "NOMINIMIZE"
"NOMINVALUE" "NOMONITORING" "NONE" "NOORDER" "NOPARALLEL" "NORELY"
"NORESETLOGS" "NOREVERSE" "NORMAL" "NOROWDEPENDENCIES" "NOSORT"
"NOSWITCH" "NOT" "NOTHING" "NOTIMEOUT" "NOVALIDATE" "NOWAIT" "NULL"
"NULLS" "OBJECT" "OF" "OFF" "OFFLINE" "OIDINDEX" "OLD" "ON" "ONLINE"
"ONLY" "OPEN" "OPERATOR" "OPTIMAL" "OPTION" "OR" "ORDER"
"ORGANIZATION" "OUT" "OUTER" "OUTLINE" "OVERFLOW" "OVERRIDING"
"PACKAGE" "PACKAGES" "PARALLEL" "PARALLEL_ENABLE" "PARAMETERS"
"PARENT" "PARTITION" "PARTITIONS" "PASSWORD" "PASSWORD_GRACE_TIME"
"PASSWORD_LIFE_TIME" "PASSWORD_LOCK_TIME" "PASSWORD_REUSE_MAX"
"PASSWORD_REUSE_TIME" "PASSWORD_VERIFY_FUNCTION" "PCTFREE"
"PCTINCREASE" "PCTTHRESHOLD" "PCTUSED" "PCTVERSION" "PERCENT"
"PERFORMANCE" "PERMANENT" "PFILE" "PHYSICAL" "PIPELINED" "PLAN"
"POST_TRANSACTION" "PRAGMA" "PREBUILT" "PRESERVE" "PRIMARY" "PRIVATE"
"PRIVATE_SGA" "PRIVILEGES" "PROCEDURE" "PROFILE" "PROTECTION" "PUBLIC"
"PURGE" "QUERY" "QUIESCE" "QUOTA" "RANGE" "READ" "READS" "REBUILD"
"RECORDS_PER_BLOCK" "RECOVER" "RECOVERY" "RECYCLE" "REDUCED" "REF"
"REFERENCES" "REFERENCING" "REFRESH" "REGISTER" "REJECT" "RELATIONAL"
"RELY" "RENAME" "RESET" "RESETLOGS" "RESIZE" "RESOLVE" "RESOLVER"
"RESOURCE" "RESTRICT" "RESTRICT_REFERENCES" "RESTRICTED" "RESULT"
"RESUMABLE" "RESUME" "RETENTION" "RETURN" "RETURNING" "REUSE"
"REVERSE" "REVOKE" "REWRITE" "RIGHT" "RNDS" "RNPS" "ROLE" "ROLES"
"ROLLBACK" "ROLLUP" "ROW" "ROWDEPENDENCIES" "ROWNUM" "ROWS" "SAMPLE"
"SAVEPOINT" "SCAN" "SCHEMA" "SCN" "SCOPE" "SEGMENT" "SELECT"
"SELECTIVITY" "SELF" "SEQUENCE" "SERIALIZABLE" "SESSION"
"SESSIONS_PER_USER" "SET" "SETS" "SETTINGS" "SHARED" "SHARED_POOL"
"SHRINK" "SHUTDOWN" "SIBLINGS" "SID" "SINGLE" "SIZE" "SKIP" "SOME"
"SORT" "SOURCE" "SPACE" "SPECIFICATION" "SPFILE" "SPLIT" "STANDBY"
"START" "STATEMENT_ID" "STATIC" "STATISTICS" "STOP" "STORAGE" "STORE"
"STRUCTURE" "SUBPARTITION" "SUBPARTITIONS" "SUBSTITUTABLE"
"SUCCESSFUL" "SUPPLEMENTAL" "SUSPEND" "SWITCH" "SWITCHOVER" "SYNONYM"
"SYS" "SYSTEM" "TABLE" "TABLES" "TABLESPACE" "TEMPFILE" "TEMPLATE"
"TEMPORARY" "TEST" "THAN" "THEN" "THREAD" "THROUGH" "TIME_ZONE"
"TIMEOUT" "TO" "TRACE" "TRANSACTION" "TRIGGER" "TRIGGERS" "TRUNCATE"
"TRUST" "TYPE" "TYPES" "UNARCHIVED" "UNDER" "UNDER_PATH" "UNDO"
"UNIFORM" "UNION" "UNIQUE" "UNLIMITED" "UNLOCK" "UNQUIESCE"
"UNRECOVERABLE" "UNTIL" "UNUSABLE" "UNUSED" "UPDATE" "UPGRADE" "USAGE"
"USE" "USING" "VALIDATE" "VALIDATION" "VALUE" "VALUES" "VARIABLE"
"VARRAY" "VERSION" "VIEW" "WAIT" "WHEN" "WHENEVER" "WHERE" "WITH"
"WITHOUT" "WNDS" "WNPS" "WORK" "WRITE" "XMLDATA" "XMLSCHEMA" "XMLTYPE"
))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; User Interface
(defface edbi:face-title
'((((class color) (background light))
:foreground "DarkGrey" :weight bold :height 1.2 :inherit variable-pitch)
(((class color) (background dark))
:foreground "darkgoldenrod3" :weight bold :height 1.2 :inherit variable-pitch)
(t :height 1.2 :weight bold :inherit variable-pitch))
"Face for title" :group 'edbi)
(defface edbi:face-header
'((((class color) (background light))
:foreground "Slategray4" :background "Gray90" :weight bold)
(((class color) (background dark))
:foreground "maroon2" :weight bold))
"Face for headers" :group 'edbi)
(defface edbi:face-error
'((((class color) (background light))
:foreground "red" :weight bold)
(((class color) (background dark))
:foreground "red" :weight bold))
"Face for error" :group 'edbi)
;; Data Source history
(defvar edbi:ds-history-file (expand-file-name ".edbi-ds-history" user-emacs-directory) "Data source history file.")
(defvar edbi:ds-history-list-num 10 "Maximum history number.")
(defvar edbi:ds-history-list nil "[internal] data source history.")
(defun edbi:ds-history-add (ds)
"[internal] Add the given data source into `edbi:ds-history-list'. This function truncates the list, if the length of the list is more than `edbi:ds-history-list-num'."
(let ((dsc (edbi:data-source
(edbi:data-source-uri ds)
(edbi:data-source-username ds) "")))
(setq edbi:ds-history-list
(remove-if (lambda (i)
(equal (edbi:data-source-uri i)
(edbi:data-source-uri dsc)))
edbi:ds-history-list))
(push dsc edbi:ds-history-list)
(setq edbi:ds-history-list
(loop for i in edbi:ds-history-list
for idx from 0 below (min (length edbi:ds-history-list)
edbi:ds-history-list-num)
collect i))
(edbi:ds-history-save)))
(defun edbi:ds-history-save ()
"[internal] Save the data source history `edbi:ds-history-list' into the file `edbi:ds-history-file'."
(let* ((file (expand-file-name edbi:ds-history-file))
(coding-system-for-write 'utf-8)
after-save-hook before-save-hook
(buf (find-file-noselect file)))
(unwind-protect
(with-current-buffer buf
(set-visited-file-name nil)
(buffer-disable-undo)
(erase-buffer)
(insert
(prin1-to-string edbi:ds-history-list))
(write-region (point-min) (point-max) file nil 'ok))
(kill-buffer buf)))
nil)
(defun edbi:ds-history-load ()
"[internal] Read the data source history file and store the data into `edbi:ds-history-list'."
(let* ((coding-system-for-read 'utf-8)
(file (expand-file-name edbi:ds-history-file)))
(when (file-exists-p file)
(let ((buf (find-file-noselect file)) ret)
(unwind-protect
(with-current-buffer buf
(goto-char (point-min))
(setq ret (loop for i in (read buf)
collect
(edbi:data-source (car i) (nth 1 i) ""))))
(kill-buffer buf))
(setq edbi:ds-history-list ret)))))
;; Data Source dialog
(defun edbi:get-new-buffer (buffer-name)
"[internal] Create and return a buffer object.
This function kills the old buffer if it exists."
(let ((buf (get-buffer buffer-name)))
(when (and buf (buffer-live-p buf))
(kill-buffer buf)))
(get-buffer-create buffer-name))
(defvar edbi:dialog-buffer-name "*edbi-dialog-ds*" "[internal] edbi:dialog-buffer-name.")
(defun edbi:dialog-ds-buffer (data-source on-ok-func
&optional password-show error-msg)
"[internal] Create and return the editing buffer for the given DATA-SOURCE."
(let ((buf (edbi:get-new-buffer edbi:dialog-buffer-name)))
(with-current-buffer buf
(let ((inhibit-read-only t)) (erase-buffer))
(kill-all-local-variables)
(remove-overlays)
(erase-buffer)
(widget-insert (format "Data Source: [driver: %s]\n\n" edbi:driver-info))
(when error-msg
(widget-insert
(let ((text (substring-no-properties error-msg)))
(put-text-property 0 (length text) 'face 'font-lock-warning-face text)
text))
(widget-insert "\n\n"))
(lexical-let
((data-source data-source) (on-ok-func on-ok-func) (error-msg error-msg)
fdata-source fusername fauth cbshow menu-history fields)
;; create dialog fields
(setq fdata-source
(widget-create
'editable-field
:size 30 :format " Data Source: %v \n"
:value (or (edbi:data-source-uri data-source) ""))
fusername
(widget-create
'editable-field
:size 20 :format " User Name : %v \n"
:value (or (edbi:data-source-username data-source) ""))
fauth
(widget-create