Committed by =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <[email protected]>

Subject: [DBD::Pg 1/3] Force client_encoding=utf8 in tests

Some tests were doing SET NAMES 'UTF8' for the non-ASCII bits, while
others were doing nothing and hoping, so just be consistent and use
UTF8 throughout.
---
 t/02attribs.t         | 12 ------------
 t/09arrays.t          |  6 ------
 t/12placeholders.t    |  6 ------
 t/dbdpg_test_setup.pl |  8 ++++++--
 4 files changed, 6 insertions(+), 26 deletions(-)

diff --git a/t/02attribs.t b/t/02attribs.t
index 5f43432..76bd6d4 100644
--- a/t/02attribs.t
+++ b/t/02attribs.t
@@ -403,13 +403,6 @@ SKIP: {
        is ($result, 'off', $t);
 }
 
-## If Encode is available, we will insert some non-ASCII into the test table
-## Since this will fail with client encodings such as BIG5, we force UTF8
-my $old_encoding = $dbh->selectall_arrayref('SHOW client_encoding')->[0][0];
-if ($old_encoding ne 'UTF8') {
-       $dbh->do(q{SET NAMES 'UTF8'});
-}
-
 # Attempt to test whether or not we can get unicode out of the database
 SKIP: {
        eval { require Encode; };
@@ -961,11 +954,6 @@ q{SELECT * FROM dbd_pg_test},
        like ($result, qr/^$expected/, $t);
 }
 
-## From this point forward, it is safe to use the client's native encoding 
again
-if ($old_encoding ne 'UTF8') {
-       $dbh->do(qq{SET NAMES '$old_encoding'});
-}
-
 #
 # Test of the handle attribute "Active"
 #
diff --git a/t/09arrays.t b/t/09arrays.t
index 806e90c..764e500 100644
--- a/t/09arrays.t
+++ b/t/09arrays.t
@@ -541,12 +541,6 @@ SKIP: {
        $t='Quoted array of strings should be UTF-8';
     ok (Encode::is_utf8( $quoted ), $t);
 
-       ## Workaround for client encodings such as SJIS
-       my $old_encoding = $dbh->selectall_arrayref('SHOW 
client_encoding')->[0][0];
-       if ($old_encoding ne 'UTF8') {
-               $dbh->do(q{SET NAMES 'UTF8'});
-       }
-
        $t='Inserting utf-8 into an array via quoted do() works';
        $dbh->do('DELETE FROM dbd_pg_test');
        $SQL = qq{INSERT INTO dbd_pg_test (id, testarray, val) VALUES (1, 
$quoted, 'one')};
diff --git a/t/12placeholders.t b/t/12placeholders.t
index c81bd43..912e449 100644
--- a/t/12placeholders.t
+++ b/t/12placeholders.t
@@ -169,12 +169,6 @@ is ($count, 1, $t);
 
 $sth->finish();
 
-## Force client encoding, as we cannot use backslashes in client-only encodings
-my $old_encoding = $dbh->selectall_arrayref('SHOW client_encoding')->[0][0];
-if ($old_encoding ne 'UTF8') {
-       $dbh->do(q{SET NAMES 'UTF8'});
-}
-
 $t='Prepare with backslashes inside quotes works';
 $SQL = q{SELECT setting FROM pg_settings WHERE name = 'backslash_quote'};
 $count = $dbh->selectall_arrayref($SQL)->[0];
diff --git a/t/dbdpg_test_setup.pl b/t/dbdpg_test_setup.pl
index e31ac55..01fc98c 100644
--- a/t/dbdpg_test_setup.pl
+++ b/t/dbdpg_test_setup.pl
@@ -221,6 +221,10 @@ version: $version
                $testuser = 'postgres';
        }
 
+    # non-ASCII parts of the tests assume UTF8
+    $testdsn =~ s/;?\bclient_encoding=[^;]+//;
+    $testdsn .= ';client_encoding=utf8';
+
        ## From here on out, we don't return directly, but save it first
   GETHANDLE: {
                eval {
@@ -233,7 +237,7 @@ version: $version
                if ($@ =~ /postgres/) {
 
                        if ($helpconnect) {
-                               $testdsn .= 'dbname=postgres';
+                               $testdsn .= ';dbname=postgres';
                                $helpconnect += 2;
                        }
                        $helpconnect += 4;
@@ -536,7 +540,7 @@ version: $version
                }
 
                ## Attempt to connect to this server
-               $testdsn = "dbi:Pg:dbname=postgres;port=$testport";
+               $testdsn = 
"dbi:Pg:dbname=postgres;client_encoding=utf8;port=$testport";
                if ($^O =~ /Win32/) {
                        $testdsn .= ';host=localhost';
                }
-- 
1.8.4

Reply via email to