25 lines
820 B
EmacsLisp
25 lines
820 B
EmacsLisp
|
|
||
|
(defun sql-area-add-table (table-name)
|
||
|
"A simple function to add a new table to the SQL file."
|
||
|
(interactive "sTable name: ")
|
||
|
|
||
|
(let ((table-name (upcase table-name)))
|
||
|
(if (eq major-mode 'sql-mode)
|
||
|
(if (progn
|
||
|
(goto-char (point-min))
|
||
|
(re-search-forward (format "^-- Table: %s$" table-name) nil t))
|
||
|
(error "Table %s is already there" table-name)
|
||
|
(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 "select count(*) %s\nfrom %s;\n\n"
|
||
|
table-name table-name))
|
||
|
)
|
||
|
(error "Are you in an sql-mode buffer?")
|
||
|
)
|
||
|
)
|
||
|
)
|
||
|
|
||
|
(provide 'sql-extras)
|