Get rid of buildDataTableStructure.
This commit is contained in:
parent
a6cf090545
commit
3f5d947282
4 changed files with 28 additions and 26 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
18
t/SQL.t
18
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');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue