DBIwrap.pm ---- a wrapper for select methods of all DBI versions
use DBIwrap;
my $DSN = [ "dbi:SQLite2:dbname=database.sqlite","","" ]; my $ATTR = { RaiseError => 1, AutoCommit => 1 }; my $dbh = DBIwrap::delay->connect( @$DSN, $ATTR );
my $where = $dbh->sql_where( { aa => 'abc' } ); my $sql1 = "SELECT * FROM table WHERE $where ORDER BY aa;";
$value = $dbh->select_1st_value( $sql1 ); # scalar selectrow_array $array = $dbh->select_1st_array( $sql1 ); # selectrow_arrayref $hash = $dbh->select_1st_hash( $sql1 ); # selectrow_hashref $array = $dbh->select_all_value( $sql1 ); # selectcol_arrayref $array = $dbh->select_all_array( $sql1 ); # selectall_arrayref $array = $dbh->select_all_hash( $sql1 ); # selectall_hashref
my( $ikey, $ival ) = DBIwrap::sql_insert( $dbh, $hash ); my $sql2 = "INSERT INTO table ($ikey) VALUES ($ival);"; $dbh->do( $sql2 );
my $uset = DBIwrap::sql_update( $dbh, $hash ); my $sql3 = "UPDATE table SET $uset WHERE $where;"; $dbh->do( $sql3 );
All methods in DBIwrap use only some methods and propaties following:
$dbh->prepare( STATEMENT ); $sth->execute( BIND_VALUES ); $sth->fetchrow_arrayref(); $sth->{NAME_lc};
so DBIwrap is not require the current version of DBI.pm, but is also available under older versions.