From 7f26b16da881ad16186db75ecd5585f63b6fee5c Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Thu, 20 Oct 2011 12:19:43 +1300 Subject: [PATCH] Support DOSQL to to arbitrary SQL before actual regression test. --- testing/dav_test | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/testing/dav_test b/testing/dav_test index 185b2f75..5aa53201 100755 --- a/testing/dav_test +++ b/testing/dav_test @@ -85,7 +85,10 @@ while( ) { if ( $state eq "SQL" ) { get_sql_value( $sql_variable, $sql_values, $sql_statement ); } - elsif ( $state eq "SQL" || $state eq "QUERY" ) { + elsif ( $state eq "DOSQL" ) { + do_sql( $sql_statement ); + } + elsif ( $state eq "QUERY" ) { push @$queries, $sql_statement; } $state = ""; @@ -93,7 +96,7 @@ while( ) { elsif ( $state eq "DATA" ) { $data_binary .= $line; } - elsif ( $state eq "SQL" || $state eq "QUERY" ) { + elsif ( $state eq "SQL" || $state eq "QUERY" || $state eq "DOSQL" ) { $sql_statement .= $line; } next; @@ -150,6 +153,11 @@ while( ) { $state = "SQL"; }; + $line =~ /^DOSQL\s*$/ && do { + $sql_statement = ""; + $state = "DOSQL"; + }; + $line =~ /^REPLACE\s*=\s*(\S)(.*)$/ && do { my $separator = $1; $2 =~ /^([^$separator]*)$separator([^$separator]*)$separator$/ && do { @@ -270,6 +278,24 @@ if ( defined(@{$queries}) && @{$queries} ) { exit(0); +=item do_sql( $sql_statement ) +Queries the database using the specified statement and +ignores the result. +=cut +sub do_sql { + my $sql = shift; + + opendb() unless defined($dbh); + $dbh->do($sql); + if ( $dbh->err ) { + print $dbh->errstr, "\n"; + return; + } + print "SQL executed successfully.\n"; + print $sql, "\n"; +} + + =item get_sql_value( $sql_variable, $sql_values, $sql_statement ) Queries the database using the specified statement and puts the first column of the first row returned into the @@ -298,7 +324,7 @@ with DBD::Pg. =cut sub opendb { $dsn = "dbi:Pg:dbname=$dsn"; - $dbh = DBI->connect($dsn, $dbuser, $dbpass, { AutoCommit => 0 } ) or die "Can't connect to database $dsn"; + $dbh = DBI->connect($dsn, $dbuser, $dbpass, { AutoCommit => 1 } ) or die "Can't connect to database $dsn"; }