al-mysql.el 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. ;;; al-mysql.el --- Additional functionality for mysql package
  2. ;; Copyright © 2015-2016 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; Code:
  14. (require 'mysql)
  15. ;; XXX The code of `mysql' and `sql-completion' is horrible. It would
  16. ;; be better to fork these packages and fix (rewrite) everything.
  17. ;;
  18. ;; Sources:
  19. ;;
  20. ;; - https://code.google.com/p/ywb-codes/source/browse/trunk/emacs/site-lisp/contrib/mysql.el
  21. ;; - https://code.google.com/p/ywb-codes/source/browse/trunk/emacs/site-lisp/contrib/sql-completion.el
  22. (defun al/mysql-shell-query (sql &optional db)
  23. "Same as `mysql-shell-query' but works.
  24. In `mysql-shell-query' SQL code is not quoted properly, so the
  25. shell command may fail."
  26. (let ((cmd (mapconcat
  27. 'identity
  28. (append (append (list mysql-program)
  29. ;; -s option inhibit header in output
  30. (remove "-s" mysql-options))
  31. (list
  32. "-u" mysql-user
  33. db
  34. (and (string< "" mysql-password)
  35. (concat "-p" mysql-password))
  36. ;; This line (↓) is the only difference.
  37. "-e" (shell-quote-argument sql)))
  38. " ")))
  39. (mysql-output-table (shell-command-to-string cmd))))
  40. (provide 'al-mysql)
  41. ;;; al-mysql.el ends here