--- PApp-SQL/SQL.pm 2001/04/22 14:38:27 1.15 +++ PApp-SQL/SQL.pm 2002/04/07 16:22:56 1.22 @@ -1,6 +1,6 @@ =head1 NAME -PApp::SQL - absolutely easy yet fast and powerful sql access +PApp::SQL - absolutely easy yet fast and powerful sql access. =head1 SYNOPSIS @@ -15,7 +15,7 @@ my $a = sql_fetch "select a from ..."; sql_fetch \my($a, $b), "select a,b ..."; - sql_exists "name from table where name like 'a%'" + sql_exists "table where name like 'a%'" or die "a* required but not existent"; my $db = new PApp::SQL::Database "", "DBI:mysql:test", "user", "pass"; @@ -46,10 +46,10 @@ BEGIN { use base qw(Exporter DynaLoader); - $VERSION = 0.123; + $VERSION = 0.13; @EXPORT = qw( - sql_exec sql_fetch sql_fetchall sql_exists sql_insertid $sql_exec - sql_ufetch sql_ufetchall sql_uexists + sql_exec sql_fetch sql_fetchall sql_exists sql_insertid $sql_exec + sql_uexec sql_ufetch sql_ufetchall sql_uexists ); @EXPORT_OK = qw( connect_cached @@ -71,7 +71,7 @@ =item $sql_exec Since the C family of functions return a statement handle there -must eb another way to test the return value of the C call. This +must be another way to test the return value of the C call. This global variable contains the result of the most recent call to C done by this module. @@ -113,8 +113,8 @@ The reason C<$id> is necessary is that you might specify special connect arguments or special flags, or you might want to configure your $DBH differently than maybe other applications requesting the same database -connection. If none of this is becessary for your application you can -leave $id empty (i.e. ""). +connection. If none of this is necessary for your application you can +leave C<$id> empty (i.e. ""). If specified, C<$connect> is a callback (e.g. a coderef) that will be called each time a new connection is being established, with the new @@ -125,6 +125,9 @@ # try your luck opening the papp database without access info $dbh = connect_cached __FILE__, "DBI:mysql:papp"; +Mysql-specific behaviour: The default setting of +C is TRUE, you can overwrite this, though. + =cut sub connect_cached { @@ -132,9 +135,14 @@ # the following line is duplicated in PApp::SQL::Database::new $id = "$id\0$dsn\0$user\0$pass"; unless ($dbcache{$id} && $dbcache{$id}->ping) { - #warn "connecting to ($dsn|$user|$pass|$flags)\n";#d# # first, nuke our statement cache (sooory ;) cachesize cachesize 0; + + # then make mysql behave more standardly by default + $dsn =~ /^[Dd][Bb][Ii]:mysql:/ + and $dsn !~ /;mysql_client_found_rows/ + and $dsn .= ";mysql_client_found_rows=1"; + # then connect anew $dbcache{$id} = eval { DBI->connect($dsn, $user, $pass, $flags) } @@ -214,7 +222,9 @@ ... and it's still quite fast unless you fetch large amounts of data. C is similar to C but upgrades all input values to -utf8 and forces all result values to utf8. +utf8 and forces all result values to utf8 (this does I include result +parameters, only return values. Using bind variables in cinjunction with +sql_u* functions results in undefined behaviour). =item sql_fetchall @@ -241,9 +251,10 @@ } C is similar to C but upgrades all input -values to utf8 and forces all result values to utf8. +values to utf8 and forces all result values to utf8 (see the caveats in +the description of C, though). -=item sql_exists " where ...", args... +=item sql_exists " where ...", args... =item sql_uexists