From 3f5d9472823001e4da5cdfa71aea141d6c671f66 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 24 Mar 2008 16:13:24 +0000 Subject: [PATCH] Get rid of buildDataTableStructure. --- lib/WebGUI/SQL.pm | 2 +- lib/WebGUI/Shop/Tax.pm | 17 +++++++++++++---- lib/WebGUI/Shop/Transaction.pm | 17 +++++++++++++---- t/SQL.t | 18 +----------------- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/lib/WebGUI/SQL.pm b/lib/WebGUI/SQL.pm index 6292f0038..800efd733 100644 --- a/lib/WebGUI/SQL.pm +++ b/lib/WebGUI/SQL.pm @@ -268,7 +268,7 @@ sub buildDataTableStructure { } $hash{records} = \@array; $hash{totalRecords} = $self->quickScalar('select found_rows()') + 0; ##Convert to numeric - $hash{recordsReturned} = $sth->rows(); + $hash{recordsReturned} = $sth->rows()+0; $sth->finish; return %hash; } diff --git a/lib/WebGUI/Shop/Tax.pm b/lib/WebGUI/Shop/Tax.pm index 7955447d4..f42aacd69 100644 --- a/lib/WebGUI/Shop/Tax.pm +++ b/lib/WebGUI/Shop/Tax.pm @@ -366,10 +366,19 @@ sub www_getTaxesAsJson { } push(@placeholders, $startIndex, $numberOfResults); $sql .= ' order by country desc limit ?,?'; - my %results = $db->buildDataTableStructure($sql, \@placeholders); - $results{'startIndex'} = $startIndex; - $results{'sort'} = undef; - $results{'dir'} = "desc"; + my %results = (); + my @records = (); + my $sth = $db->read($sql, \@placeholders); + while (my $record = $sth->hashRef) { + push(@records,$record); + } + $results{'recordsReturned'} = $sth->rows()+0; + $sth->finish; + $results{'records'} = \@records; + $results{'totalRecords'} = $db->quickScalar('select found_rows()') + 0; ##Convert to numeric + $results{'startIndex'} = $startIndex; + $results{'sort'} = undef; + $results{'dir'} = "desc"; $session->http->setMimeType('text/json'); return JSON::to_json(\%results); } diff --git a/lib/WebGUI/Shop/Transaction.pm b/lib/WebGUI/Shop/Transaction.pm index b191f5ee3..eb7eefca9 100644 --- a/lib/WebGUI/Shop/Transaction.pm +++ b/lib/WebGUI/Shop/Transaction.pm @@ -432,10 +432,19 @@ sub www_getTransactionsAsJson { } push(@placeholders, $startIndex, $numberOfResults); $sql .= ' order by dateOfPurchase desc limit ?,?'; - my %results = $db->buildDataTableStructure($sql, \@placeholders); - $results{'startIndex'} = $startIndex; - $results{'sort'} = undef; - $results{'dir'} = "desc"; + my %results = (); + my @records = (); + my $sth = $db->read($sql, \@placeholders); + while (my $record = $sth->hashRef) { + push(@records,$record); + } + $results{'recordsReturned'} = $sth->rows()+0; + $sth->finish; + $results{'totalRecords'} = $db->quickScalar('select found_rows()') + 0; ##Convert to numeric + $results{'records'} = \@records; + $results{'startIndex'} = $startIndex; + $results{'sort'} = undef; + $results{'dir'} = "desc"; $session->http->setMimeType('text/json'); return JSON::to_json(\%results); } diff --git a/t/SQL.t b/t/SQL.t index f381bd684..1a591e85a 100644 --- a/t/SQL.t +++ b/t/SQL.t @@ -17,7 +17,7 @@ use WebGUI::Session; use Data::Dumper; use Test::Deep; -use Test::More tests => 57; # increment this value for each test you create +use Test::More tests => 53; # increment this value for each test you create my $session = WebGUI::Test->session; @@ -285,22 +285,6 @@ cmp_deeply( 'Check table structure', ); -####################################################################### -# -# buildSearchQuery -# -####################################################################### - -my ($searchQuery, @placeHolders) = $session->db->buildSearchQuery('select * from users', 'Admin', [qw{username alias}]); -like($searchQuery, qr{^select \* from users}, 'returned query begins with original query'); -cmp_deeply( - \@placeHolders, - [('%Admin%') x 2], - 'placeholders are the keyword repeated 2 times, one for each column, sandwiched in %' -); -like($searchQuery, qr{where username like \?}, 'returned query searches username column, first column uses where'); -like($searchQuery, qr{or alias like \?}, 'returned query searches alias column, second column uses or'); - END: { $session->db->dbh->do('DROP TABLE IF EXISTS testTable'); }