Author: turnstep
Date: Sat Feb 16 13:12:47 2008
New Revision: 10745
Modified:
DBD-Pg/trunk/t/02attribs.t
DBD-Pg/trunk/t/09arrays.t
DBD-Pg/trunk/t/12placeholders.t
Log:
Workarounds for non-UTF8 client encodings.
Modified: DBD-Pg/trunk/t/02attribs.t
==============================================================================
--- DBD-Pg/trunk/t/02attribs.t (original)
+++ DBD-Pg/trunk/t/02attribs.t Sat Feb 16 13:12:47 2008
@@ -318,6 +318,13 @@
$result = $dbh->{pg_pid};
like( $result, qr/^\d+$/, q{DB handle attribute "pg_pid" returns a value});
+## 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; };
@@ -530,6 +537,11 @@
like ( $result, qr/^$expected/, qq{Statement handle attribute
"pg_cmd_status" works for '$expected'});
}
+## 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"
#
@@ -621,7 +633,7 @@
$warning = '';
local $SIG{__WARN__} = sub { $warning = shift; };
$dbh->{RaiseError} = 0;
-
+
$dbh->{PrintError} = 1;
$sth = $dbh->prepare($SQL);
$sth->execute();
Modified: DBD-Pg/trunk/t/09arrays.t
==============================================================================
--- DBD-Pg/trunk/t/09arrays.t (original)
+++ DBD-Pg/trunk/t/09arrays.t Sat Feb 16 13:12:47 2008
@@ -458,6 +458,12 @@
is( $quoted, qq!{"$utf8_str","$utf8_str"}!, 'quote() handles utf8
inside array' );
ok Encode::is_utf8( $quoted ), 'Quoted array of strings should be UTF-8';
+ ## 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'});
+ }
+
$dbh->do('DELETE FROM dbd_pg_test');
$SQL = qq{INSERT INTO dbd_pg_test (id, testarray, val) VALUES (1,
'$quoted', 'one')};
eval {
Modified: DBD-Pg/trunk/t/12placeholders.t
==============================================================================
--- DBD-Pg/trunk/t/12placeholders.t (original)
+++ DBD-Pg/trunk/t/12placeholders.t Sat Feb 16 13:12:47 2008
@@ -117,12 +117,18 @@
$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'});
+}
+
## Test our parsing of backslashes
$sth = $dbh->prepare(q{SELECT '\\'?'});
eval {
$sth->execute();
};
-ok( !$@, 'prepare with backslashes inside quotes works');
+is($@, q{}, 'prepare with backslashes inside quotes works');
$sth->finish();
$dbh->commit();