From 8b37786e5b640c7a1c270388ac1158cce45ebf72 Mon Sep 17 00:00:00 2001 From: David Steele Date: Fri, 22 Nov 2013 23:24:37 -0500 Subject: [PATCH] Now connecting to db. --- test/test.pl | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/test/test.pl b/test/test.pl index 9612a5ca9..215edbbe2 100755 --- a/test/test.pl +++ b/test/test.pl @@ -1,6 +1,7 @@ #!/usr/bin/perl #use strict; +use DBI; my $strPgBinPath = '/Library/PostgreSQL/9.3/bin/'; @@ -11,9 +12,10 @@ sub execute print("$strCommand\n"); $strOutput = qx($strCommand) or return 0; + $strOutput =~ s/^\s+|\s+$//g; print("$strOutput\n"); - return 1; + return $strOutput; } sub pg_create @@ -32,6 +34,14 @@ sub pg_start execute($strCommand); } +sub pg_password_set +{ + local($strPath, $strUser) = @_; + my $strCommand = $strPgBinPath . "psql --port=6000 -c \"alter user $strUser with password 'password'\" postgres"; + + execute($strCommand); +} + sub pg_stop { local($strPath) = @_; @@ -48,9 +58,35 @@ sub pg_drop execute($strCommand); } -pg_stop("/Users/dsteele/test/test2"); -pg_drop("/Users/dsteele/test/test2"); -pg_create("/Users/dsteele/test/test2"); -pg_start("/Users/dsteele/test/test2"); -pg_stop("/Users/dsteele/test/test2"); +sub pg_execute +{ + local($dbh, $strSql) = @_; + $sth = $dbh->prepare($strSql); + $sth->execute(); +} + +my $strUser = execute('whoami'); +my $strTestPath = "/Users/dsteele/test/"; +my $strTestDir = "test2"; +my $strArchiveDir = "archive"; + +pg_stop("$strTestPath$strTestDir"); +pg_drop("$strTestPath$strTestDir"); +pg_create("$strTestPath$strTestDir"); +pg_start("$strTestPath$strTestDir"); +pg_password_set("$strTestPath$strTestDir", $strUser); + +$dbh = DBI->connect("dbi:Pg:dbname=postgres;port=6000;host=127.0.0.1", 'dsteele', 'password', {AutoCommit => 1}); +pg_execute($dbh, "create table test (id int)"); + +pg_execute($dbh, "insert into test values (1)"); +pg_execute($dbh, "select pg_switch_xlog()"); + +pg_execute($dbh, "insert into test values (2)"); +pg_execute($dbh, "select pg_switch_xlog()"); + +pg_execute($dbh, "insert into test values (3)"); +pg_execute($dbh, "select pg_switch_xlog()"); + +#pg_stop($strTestPath);