From 6f112057bb8e8c7bd54c40c2e97f3c48d697c141 Mon Sep 17 00:00:00 2001 From: Matthew Wilson Date: Wed, 18 Jan 2006 07:05:19 +0000 Subject: [PATCH] still more fixes. --- lib/WebGUI/SQL.pm | 4 ++-- lib/WebGUI/SQL/ResultSet.pm | 4 ++-- lib/WebGUI/Session/ErrorHandler.pm | 26 ++++++++++++++++++++--- lib/WebGUI/Session/Var.pm | 2 +- t/Session/Scratch.t | 33 +++++++----------------------- 5 files changed, 35 insertions(+), 34 deletions(-) diff --git a/lib/WebGUI/SQL.pm b/lib/WebGUI/SQL.pm index 8dc67c05d..e8d0fa373 100644 --- a/lib/WebGUI/SQL.pm +++ b/lib/WebGUI/SQL.pm @@ -653,7 +653,7 @@ sub setRow { my ($self, $table, $keyColumn, $data, $id) = @_; if ($data->{$keyColumn} eq "new" || $id) { $data->{$keyColumn} = $id || $self->session->id->generate(); - $self->write("insert into $table ($keyColumn) values (".$self->quote($data->{$keyColumn}).")"); + $self->write("replace into $table ($keyColumn) values (".$self->quote($data->{$keyColumn}).")"); } my (@pairs); foreach my $key (keys %{$data}) { @@ -707,7 +707,7 @@ An SQL insert or update. sub write { my $self = shift; my $sql = shift; - $self->session->errorHandler->debug("query: ".$sql); + $self->session->errorHandler->query($sql); $self->dbh->do($sql) or $self->session->errorHandler->fatal("Couldn't write to the database: ".$sql." : ". $self->dbh->errstr); } diff --git a/lib/WebGUI/SQL/ResultSet.pm b/lib/WebGUI/SQL/ResultSet.pm index 0a6de226d..d1c9a316a 100644 --- a/lib/WebGUI/SQL/ResultSet.pm +++ b/lib/WebGUI/SQL/ResultSet.pm @@ -209,7 +209,7 @@ sub prepare { my $class = shift; my $sql = shift; my $db = shift; - $db->session->errorHandler->debug("query: ".$sql); + $db->session->errorHandler->query($sql); my $sth = $db->dbh->prepare($sql) or $db->session->errorHandler->fatal("Couldn't prepare statement: ".$sql." : ". $db->dbh->errstr); bless {_sth => $sth, _sql => $sql, _db=>$db}, $class; } @@ -298,7 +298,7 @@ sub unconditionalRead { my $sql = shift; my $db = shift; my $placeholders = shift; - $db->session->errorHandler->debug("query: ".$sql); + $db->session->errorHandler->query($sql); my $sth = $db->dbh->prepare($sql) or $db->session->errorHandler->warn("Unconditional read failed: ".$sql." : ".$db->dbh->errstr); if ($sth) { $sth->execute(@$placeholders) or $db->session->errorHandler->warn("Unconditional read failed: ".$sql." : ".$sth->errstr); diff --git a/lib/WebGUI/Session/ErrorHandler.pm b/lib/WebGUI/Session/ErrorHandler.pm index 06dc14089..461c6cee9 100644 --- a/lib/WebGUI/Session/ErrorHandler.pm +++ b/lib/WebGUI/Session/ErrorHandler.pm @@ -89,7 +89,7 @@ sub canShowDebug { my @ips = split(" ",$self->session->setting->get("debugIp")); my $ok = 0; foreach my $ip (@ips) { - if ($self->session->env("REMOTE_ADDR") =~ /^$ip/) { + if ($self->session->env->get("REMOTE_ADDR") =~ /^$ip/) { $ok = 1; last; } @@ -108,7 +108,7 @@ Returns true if the user meets the conditions to see performance indicators and sub canShowPerformanceIndicators { my $self = shift; my $mask = $self->session->setting->get("debugIp"); - my $ip = $self->session->env("REMOTE_ADDR"); + my $ip = $self->session->env->get("REMOTE_ADDR"); return ( ( $self->session->setting->get("showPerformanceIndicators") @@ -324,6 +324,26 @@ sub new { bless {_logger=>$logger, _session=>$session}, $class; } +#------------------------------------------------------------------- + +=head2 query ( sql ) + +Logs a sql statement for the debugger output. Keeps track of the #. + +=head3 sql + +A sql statement string. + +=cut + +sub query { + my $self = shift; + $self->{_query} = 0 unless $self->{_query}; + $self->{_query} = $self->{_query} + 1; + $self->debug("query ".$self->{_query}.' '.shift); +} + + #------------------------------------------------------------------- @@ -341,7 +361,7 @@ sub security { my $self = shift; my $message = shift; $self->warn($self->session->user->username." (".$self->session->user->userId.") connecting from " - .$self->session->env("REMOTE_ADDR")." attempted to ".$message); + .$self->session->env->get("REMOTE_ADDR")." attempted to ".$message); } diff --git a/lib/WebGUI/Session/Var.pm b/lib/WebGUI/Session/Var.pm index a7debd28b..386a4b9ed 100644 --- a/lib/WebGUI/Session/Var.pm +++ b/lib/WebGUI/Session/Var.pm @@ -170,7 +170,7 @@ sub new { $self->end; } elsif ($self->{_var}{sessionId} ne "") { $self->{_var}{lastPageView} = $session->datetime->time(); - $self->{_var}{lastIP} = $session->env("REMOTE_ADDR"); + $self->{_var}{lastIP} = $session->env->get("REMOTE_ADDR"); $self->{_var}{expires} = $session->datetime->time() + $session->setting->get("sessionTimeout"); $self->session->{_sessionId} = $self->{_var}{sessionId}; $session->db->setRow("userSession","sessionId",$self->{_var}); diff --git a/t/Session/Scratch.t b/t/Session/Scratch.t index 4226ff7a7..6f1e03c65 100644 --- a/t/Session/Scratch.t +++ b/t/Session/Scratch.t @@ -8,20 +8,19 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -# ---- BEGIN DO NOT EDIT ---- +use FindBin; use strict; -use lib '../../lib'; -use Getopt::Long; +use lib "$FindBin::Bin/../lib"; + +use WebGUI::Test; use WebGUI::Session; -# ---- END DO NOT EDIT ---- + use Test::More tests => 14; # increment this value for each test you create -my $session = initialize(); # this line is required - -# put your tests here +my $session = WebGUI::Test->session; my $scratch = $session->scratch; -my $maxCount = 14; +my $maxCount = 10; $scratch->deleteAll(); @@ -49,21 +48,3 @@ is($scratch->get("Test2"), undef, "deleteAll()"); my $testScratchSession = $scratch->session(); is($testScratchSession, $session, "session()"); - - -cleanup($session); # this line is required - -# ---- DO NOT EDIT BELOW THIS LINE ----- -sub initialize { - $|=1; # disable output buffering - my $configFile; - GetOptions( - 'configFile=s'=>\$configFile - ); - exit 1 unless ($configFile); - my $session = WebGUI::Session->open("../..",$configFile); -} -sub cleanup { - my $session = shift; - $session->close(); -}