From 46f6104d434889be5dbf0eb2dd3fa334031c0112 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Mon, 7 Jul 2008 16:23:58 +0000 Subject: [PATCH] fixed: More permissive DSN checking to allow use of SQLite (thanks pathma) --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/DatabaseLink.pm | 22 +++++++++++++--------- lib/WebGUI/Paginator.pm | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index a67295f44..5dfbb2a81 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,6 @@ 7.5.16 - Created a migration from 7.4.40 directly to 7.5.16. + - fixed: More permissive DSN checking to allow use of SQLite (thanks pathma) 7.5.15 - fixed: Colorpicker window would not open (Martin Kamerbeek / Oqapi) diff --git a/lib/WebGUI/DatabaseLink.pm b/lib/WebGUI/DatabaseLink.pm index 65842ea4b..e0473b89c 100644 --- a/lib/WebGUI/DatabaseLink.pm +++ b/lib/WebGUI/DatabaseLink.pm @@ -20,6 +20,7 @@ use Tie::CPHash; use WebGUI::SQL; use WebGUI::International; use WebGUI::Utility; +use DBI; =head1 NAME @@ -238,16 +239,19 @@ sub db { if ($self->getId eq "0") { $self->{_dbh} = $self->session->db; return $self->{_dbh}; - } elsif ($dsn =~ /\DBI\:\w+\:\w+/i) { - my $dbh = WebGUI::SQL->connect($self->session,$dsn,$username,$identifier,$parameters); - unless (defined $dbh) { - $self->session->errorHandler->warn("Cannot connect to DatabaseLink [".$self->getId."]"); - } - $self->{_dbh} = $dbh; - return $self->{_dbh}; - } else { - $self->session->errorHandler->warn("DatabaseLink [".$self->getId."] The DSN specified is of an improper format."); } + else { + my ($scheme, $driver, $attr_string, $attr_hash, $driver_dsn) = DBI->parse_dsn($dsn); + if ($driver) { + my $dbh = WebGUI::SQL->connect($self->session,$dsn,$username,$identifier,$parameters); + unless (defined $dbh) { + $self->session->errorHandler->warn("Cannot connect to DatabaseLink [".$self->getId."]"); + } + $self->{_dbh} = $dbh; + return $self->{_dbh}; + } + } + $self->session->errorHandler->warn("DatabaseLink [".$self->getId."] The DSN specified is of an improper format."); return undef; } diff --git a/lib/WebGUI/Paginator.pm b/lib/WebGUI/Paginator.pm index bbf7c0fe9..108e8edaa 100644 --- a/lib/WebGUI/Paginator.pm +++ b/lib/WebGUI/Paginator.pm @@ -103,7 +103,6 @@ sub _setDataByQuery { $sth = $dbh->read($sql,$placeholders); } my $defaultPageNumber = $self->getPageNumber; - $self->{_totalRows} = $sth->rows; $self->{_columnNames} = [ $sth->getColumnNames ]; my $pageCount = 1; while (my $data = $sth->hashRef) { @@ -125,6 +124,7 @@ sub _setDataByQuery { } } } + $self->{_totalRows} = $sth->rows; $sth->finish; $self->{_rowRef} = \@row; #Purposely do not set $self->{_setByQuery} = 1 so the data is processed appropriately