DBIモジュールの構文も忘れた頃に必要になるので,MySQLバージョンのinsert関数をつくってみた.特に面白いものはなし.Emacs-Lispにヒアドキュメントってないのだろうか.

;;; DBI用
(defun insert-dbi-mysql (dbname uname pass)
  (interactive "sInput database name: \nsInput user name: \ns Input password: ")
  (insert "use DBI;\n\n")
  (insert "# DBI for MySQL ==========================\n")
  (insert (concat "my $database = '" dbname "';\n"))
  (insert (concat "my $dbuser = '" uname "';\n"))
  (insert (concat "my $dbpass = '" pass "';\n"))
  (insert "my $dsn = \"DBI:mysql:database=$database\";\n")
  (insert "# ========================================\n\n")
  (insert "my $dbh = DBI->connect($dsn, $dbuser, $dbpass, {'PrintError' => 1, 'RaiseError' => 1});\n")
  (insert "$dbh->disconnect();\n"))

M-x insert-dbi-mysqlで実行すると,以下のようなコードが挿入される.

use DBI;

# DBI for MySQL =========================
my $database = 'dbname';
my $dbuser = 'username';
my $dbpass = 'piyopiyo';
my $dsn = "DBI:mysql:database=$database";
# =======================================

my $dbh = DBI->connect($dsn, $dbuser, $dbpass, {'PrintError' => 1, 'RaiseError' => 1});
$dbh->disconnect();

disconnectはよく,disconnetというtypoをするので大事.