Changeset 23776 for lang/perl/MENTA/trunk
- Timestamp:
- 11/15/08 17:11:48 (5 years ago)
- Location:
- lang/perl/MENTA/trunk
- Files:
-
- 1 removed
- 2 modified
-
app/controller/users.pl (modified) (1 diff)
-
plugins/dbi_select.pl (deleted)
-
plugins/sql.pl (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/MENTA/trunk/app/controller/users.pl
r23657 r23776 1 load_plugin(" dbi_select");1 load_plugin("sql"); 2 2 3 3 sub do_users { 4 my @rows = dbi_select('DBI:CSV:f_dir=../app/data', 'select * from users'); 5 render('users.html', \@rows); 4 sql_dbh('DBI:CSV:f_dir=../app/data'); 5 my $rows = sql_select_all('select * from users'); 6 render('users.html', $rows); 6 7 } 7 8 -
lang/perl/MENTA/trunk/plugins/sql.pl
r23775 r23776 1 # AUTHOR: tokuhirom 1 # AUTHOR: tokuhirom, mattn 2 2 3 3 use strict; … … 7 7 8 8 sub sql_dbh { 9 $MENTA::STASH->{sql_dbh} ||= do { 10 my $dsn = config->{application}->{sql}->{dsn} or die "設定に application.sql.dsn がありません"; 11 my $dbh = DBI->connect($dsn) or die "DBに接続できません: $DBI::errstr"; 12 $dbh->{unicode}++; 9 if (@_) { 10 my @args = @_; 11 if ($MENTA::STASH->{sql_dbh}) { 12 $MENTA::STASH->{sql_dbh}->disconnect; 13 undef $MENTA::STASH->{sql_dbh}; 14 } 15 my $dbh = DBI->connect(@args) or die "DBに接続できません: $DBI::errstr"; 16 $MENTA::STASH->{sql_dbh} = $dbh; 13 17 $dbh; 14 }; 18 } else { 19 $MENTA::STASH->{sql_dbh} ||= do { 20 my $dsn = config->{application}->{sql}->{dsn} or die "設定に application.sql.dsn がありません"; 21 my $dbh = DBI->connect($dsn) or die "DBに接続できません: $DBI::errstr"; 22 $dbh->{unicode}++; 23 $dbh; 24 }; 25 } 15 26 } 16 27 … … 22 33 $sth->finish(); 23 34 undef $sth; 35 } 36 37 sub sql_select_all { 38 my ($sql, @params) = @_; 39 40 my $dbh = sql_dbh(); 41 my $sth = $dbh->prepare($sql) or die $dbh->errstr; 42 $sth->execute(@params); 43 my @res; 44 while (my $row = $sth->fetchrow_hashref) { 45 push @res, $row; 46 } 47 $sth->finish; 48 undef $sth; 49 50 return \@res; 24 51 } 25 52
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)