diff options
Diffstat (limited to 'lib/RHRD/rddb.pm')
-rwxr-xr-x | lib/RHRD/rddb.pm | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index 02cd457..c5e0a1a 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -191,7 +191,7 @@ sub check_log_exists $sth->execute($logname) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); - my $log_exists = $sth->fetchrow_array(); + my ($log_exists) = $sth->fetchrow_array(); $sth->finish(); if(!defined $log_exists || $log_exists ne 'Y') { @@ -202,16 +202,43 @@ sub check_log_exists sub get_log_table_name { - my ($ctx, $logname) = @_; + my ($logname) = @_; $logname=~s/ /_/g; - return $ctx->{'dbh'}->quote_identifier($logname . '_LOG'); + return $logname . '_LOG'; +} + +sub get_log_table_name_escaped +{ + my ($ctx, $logname) = @_; + return $ctx->{'dbh'}->quote_identifier(get_log_table_name($logname)); +} + +sub check_log_table_exists +{ + my ($ctx, $logname) = @_; + + my $sql = qq{select count(*) from information_schema.tables where table_schema = DATABASE() and table_name = ?;}; + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + my $log_tabname = get_log_table_name($logname); + $sth->execute($log_tabname) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + my ($cnt) = $sth->fetchrow_array(); + $sth->finish(); + + unless($cnt) { + return ($cnt, 'OK', 'log table does not exist'); + } + return ($cnt, 'OK', 'log table exists'); } sub create_log_table { my ($ctx, $logname) = @_; - $logname = get_log_table_name($ctx, $logname); + $logname = get_log_table_name_escaped($ctx, $logname); my $sql = qq{ create table if not exists $logname (ID INT NOT NULL PRIMARY KEY, @@ -275,7 +302,7 @@ sub fill_log_table my $logname = shift; my @carts = @_; - $logname = get_log_table_name($ctx, $logname); + $logname = get_log_table_name_escaped($ctx, $logname); my $sql_log = qq{insert into $logname (ID, COUNT, TYPE, START_TIME, CART_NUMBER, TRANS_TYPE) values (?, ?, ?, ?, ?, ?);}; my $sql_cart_type = qq{select TYPE from CART where NUMBER = ?;}; @@ -307,7 +334,7 @@ sub drop_log_table { my ($ctx, $logname) = @_; - $logname = get_log_table_name($ctx, $logname); + $logname = get_log_table_name_escaped($ctx, $logname); my $sql = qq{drop table $logname;}; $ctx->{'dbh'}->do($sql) @@ -910,6 +937,28 @@ sub get_dropboxes return @allowed_dbs; } +########################### Log handling ###################### + +sub list_logs +{ + my ($ctx) = @_; + + my $sql = qq{select NAME from LOGS;}; + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute() + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + my @logs; + while(my ($log) = $sth->fetchrow_array()) { + push @logs, $log; + } + $sth->finish(); + + return @logs; +} + ########################### SHOW handling ########################### sub get_shows_cart_range @@ -1174,7 +1223,7 @@ sub get_show_carts return (undef, 'ERROR', "Log with name '$log' does not exist") } - $log = get_log_table_name($ctx, $log); + $log = get_log_table_name_escaped($ctx, $log); my $sql = qq{select COUNT,CART_NUMBER from $log order by COUNT;}; my $sth = $ctx->{'dbh'}->prepare($sql) |