2011/10/28

昨日書いたsonictemplate-vimを使えば...
mattn/sonictemplate-vim - GitHub

sonictemplate chooser for vim

https://github.com/mattn/sonictemplate-vim
注意:DBは既に用意されている物とする
以下をやるにはオプションの設定が必要だったのでデフォルトで動作する様にした
template-vimはthincaさんの物と名前がバッティングしたので、「音速でコーディング出来る」と言う意味でsonictemplate-vimに改名しました。

よーいどん

# vim foo.pl
起動したら :Template script と書いてドーン use strict;
use warnings;
use utf8;

_
_はカーソル位置
ここで use DBI;
を足しておこう。さて :Template dbi-connect-sqlite でドーン use strict;
use warnings;
use utf8;
use DBI;

my $dbh = DBI->connect("dbi:SQLite:dbname=_");
$dbh->disconnect;

SQLiteのDBファイル名を書く部分にカーソルが移動しているので./foo.dbとタイプする。その後一行下に移動して :Template dbi-prepare でドーン use strict;
use warnings;
use utf8;
use DBI;

my $dbh = DBI->connect("dbi:SQLite:dbname=./foo.db");
my $sth = $dbh->prepare("_");
$sth->execute;
while (my @row = $sth->fetchrow_array) {
    # print join(', ', @row), "\n";
}
$dbh->disconnect;

SQLを書く書く部分にカーソルが移動しているのでselect * from priceとタイプ。コメントアウトを外して... use strict;
use warnings;
use utf8;
use DBI;

my $dbh = DBI->connect("dbi:SQLite:dbname=./foo.db");
my $sth = $dbh->prepare("select * from price");
$sth->execute;
while (my @row = $sth->fetchrow_array) {
    print join(''@row), "\n";
}
$dbh->disconnect;

おもむろにvim-quickrunでドーーーン!
みかん, 250
りんご, 100
ってなればいいなーって話です。
Posted at 19:02 | WriteBacks () | Edit
Edit this entry...

wikieditish message: Ready to edit this entry.






















A quick preview will be rendered here when you click "Preview" button.