From dd5ca5e3c2f5b9fcaee35af80535f1f030c1cd80 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Thu, 4 Sep 2008 00:19:07 +0200 Subject: [PATCH] Allow any length queries in admin dump --- PciIds/DBQ.pm | 39 +++++++++++++++++++++++++-------------- PciIds/Html/Admin.pm | 5 +++-- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/PciIds/DBQ.pm b/PciIds/DBQ.pm index 5d1ee3f..c3cc1b8 100644 --- a/PciIds/DBQ.pm +++ b/PciIds/DBQ.pm @@ -3,6 +3,18 @@ use strict; use warnings; use base 'PciIds::DBQAny'; +my $adminDumpSql = 'SELECT + locations.id, locations.name, locations.note, locations.mainhistory, musers.email, musers.login, main.discussion, main.time, + history.id, history.discussion, history.nodename, history.nodenote, users.email, users.login, history.time + FROM + locations INNER JOIN history ON history.location = locations.id + LEFT OUTER JOIN users ON history.owner = users.id + LEFT OUTER JOIN history AS main ON locations.mainhistory = main.id + LEFT OUTER JOIN users AS musers ON main.owner = musers.id + WHERE history.seen = "0" AND locations.id LIKE ? + ORDER BY locations.id, history.id + LIMIT '; + sub new( $ ) { my( $dbh ) = @_; my $node = 'SELECT id, name, note, mainhistory FROM locations WHERE parent = ? ORDER BY '; @@ -30,17 +42,7 @@ sub new( $ ) { 'newitem' => 'INSERT INTO locations (id, parent) VALUES(?, ?)', 'newhistory' => 'INSERT INTO history (location, owner, discussion, nodename, nodenote) VALUES(?, ?, ?, ?, ?)', 'history' => 'SELECT history.id, history.discussion, history.time, history.nodename, history.nodenote, history.seen, users.login, users.email FROM history LEFT OUTER JOIN users ON history.owner = users.id WHERE history.location = ? ORDER BY history.time', - 'admindump' => 'SELECT - locations.id, locations.name, locations.note, locations.mainhistory, musers.email, musers.login, main.discussion, main.time, - history.id, history.discussion, history.nodename, history.nodenote, users.email, users.login, history.time - FROM - locations INNER JOIN history ON history.location = locations.id - LEFT OUTER JOIN users ON history.owner = users.id - LEFT OUTER JOIN history AS main ON locations.mainhistory = main.id - LEFT OUTER JOIN users AS musers ON main.owner = musers.id - WHERE history.seen = "0" AND locations.id LIKE ? - ORDER BY locations.id, history.id - LIMIT 100',#Dumps new discussion submits with their senders and corresponding main history and names + 'admindump' => "$adminDumpSql 100",#Dumps new discussion submits with their senders and corresponding main history and names 'delete-hist' => 'DELETE FROM history WHERE id = ?', 'mark-checked' => 'UPDATE history SET seen = 1 WHERE id = ?', 'delete-item' => 'DELETE FROM locations WHERE id = ?', @@ -226,9 +228,18 @@ sub submitHistory( $$$$ ) { return $self->last(); } -sub adminDump( $$ ) { - my( $self, $prefix ) = @_; - return $self->query( 'admindump', [ "$prefix%" ] ); +sub adminDump( $$$ ) { + my( $self, $prefix, $limit ) = @_; + if( $limit ) { + $limit = int( $limit * 1.2 ); + my $q = $self->{'dbh'}->prepare( "$adminDumpSql $limit" ); + $q->execute( "$prefix%" ); + my @result = @{$q->fetchall_arrayref()};#Copy the array, finish() deletes the content + $q->finish(); + return \@result; + } else { + return $self->query( 'admindump', [ "$prefix%" ] ); + } } sub deleteHistory( $$ ) { diff --git a/PciIds/Html/Admin.pm b/PciIds/Html/Admin.pm index 7408792..4002888 100644 --- a/PciIds/Html/Admin.pm +++ b/PciIds/Html/Admin.pm @@ -54,6 +54,7 @@ sub genNewAdminForm( $$$$$ ) { my( $req, $args, $tables, $error, $auth ) = @_; my $address = PciIds::Address::new( $req->uri() ); my $prefix = $address->get(); + my $limit = $args->{'limit'}; $prefix = '' if( $args->{'global'} ); my $caption = 'Administration '.( $args->{'global'} ? '(Global)' : '('.encode( $address->pretty() ).')' ); genHtmlHead( $req, $caption, undef ); @@ -66,11 +67,11 @@ sub genNewAdminForm( $$$$$ ) { my $cnt = 0; my $hiscnt = 0; my $subcnt; - foreach( @{$tables->adminDump( $prefix )} ) { + foreach( @{$tables->adminDump( $prefix, $limit )} ) { my( $locId, $actName, $actNote, $actHist, $actEmail, $actLogin, $actDisc, $actTime, $hist, $disc, $name, $note, $email, $login, $time ) = @{$_}; if( !defined( $lastId ) || ( $lastId ne $locId ) ) { - last if( $hiscnt > 80 ); + last if( $hiscnt > ( defined $limit ? $limit : 80 ) ); $lastId = $locId; if( $started ) { genNewForm( $cnt ); -- 2.39.2