summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-07-05 18:48:22 +0200
committerYorhel <git@yorhel.nl>2009-07-05 18:48:22 +0200
commit7e659f8b434533799f2dd0fc0a3f03c0e8cab9ba (patch)
tree747552ae48ea53aea0de93e7f5885a5a85e3a0be /lib
parentbabdd23ef1ecc5d859c7708bbdcacf51a2259371 (diff)
Removed some PostgreSQL-specific code from YAWF::DB
The YAWF::DB functions should now be (mostly) database-neutral. The only thing that isn't DB-neutral is the method of getting unicode to work. Only (recent versions of) DBD::mysql, DBD::sqlite and DBD::Pg are currently supported. A later version of DBI might have a better defined interface to do this, let's hope we'll see some new developments in that aspect in the near future.
Diffstat (limited to 'lib')
-rw-r--r--lib/YAWF/DB.pm17
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/YAWF/DB.pm b/lib/YAWF/DB.pm
index 1637269..ec2500b 100644
--- a/lib/YAWF/DB.pm
+++ b/lib/YAWF/DB.pm
@@ -16,8 +16,10 @@ sub dbInit {
my $self = shift;
$self->{_YAWF}{DB} = {
sql => DBI->connect(@{$self->{_YAWF}{db_login}}, {
- PrintError => 0, RaiseError => 1,
- AutoCommit => 0, pg_enable_utf8 => 1,
+ PrintError => 0, RaiseError => 1, AutoCommit => 0,
+ mysql_enable_utf8 => 1, # DBD::mysql
+ pg_enable_utf8 => 1, # DBD::Pg
+ unicode => 1, # DBD::sqlite
}),
queries => [],
};
@@ -105,7 +107,7 @@ sub sqlhelper { # type, query, @list
$sqlq =~ s/\r?\n/ /g;
$sqlq =~ s/ +/ /g;
- my(@q) = @_ ? sqlprint(0, $sqlq, @_) : ($sqlq);
+ my(@q) = @_ ? sqlprint($sqlq, @_) : ($sqlq);
$self->log($q[0].' | "'.join('", "', @q[1..$#q]).'"') if $self->{_YAWF}{log_queries};
my $q = $s->prepare($q[0]);
@@ -135,20 +137,19 @@ sub sqlhelper { # type, query, @list
# Only the ? placeholder is supported, so no dollar sign numbers or named placeholders
# Indeed, this also means you can't use PgSQL operators containing a question mark
-sub sqlprint { # start, query, bind values. Returns new query + bind values
+sub sqlprint { # query, bind values. Returns new query + bind values
my @a;
my $q='';
- my $s = shift;
for my $p (split /(\?|![lHWs])/, shift) {
next if !defined $p;
if($p eq '?') {
push @a, shift;
- $q .= '$'.(@a+$s);
+ $q .= $p;
} elsif($p eq '!s') {
$q .= shift;
} elsif($p eq '!l') {
my $l = shift;
- $q .= join ', ', map '$'.(@a+$s+$_+1), 0..$#$l;
+ $q .= join ', ', map '?', 0..$#$l;
push @a, @$l;
} elsif($p eq '!H' || $p eq '!W') {
my $h=shift;
@@ -156,7 +157,7 @@ sub sqlprint { # start, query, bind values. Returns new query + bind values
my @r;
while(my($k,$v) = (shift(@h), shift(@h))) {
last if !defined $k;
- my($n,@l) = sqlprint($#a+1, $k, ref $v eq 'ARRAY' ? @$v : $v);
+ my($n,@l) = sqlprint($k, ref $v eq 'ARRAY' ? @$v : $v);
push @r, $n;
push @a, @l;
}