Committed by Greg Sabino Mullane <[email protected]>
More UTF-8 tweaking; tweak tests to use the new 'use
charnames' pragma. Use Encode to strip utf8 flag for testing.
---
dbdimp.c | 14 +++++++-------
t/30unicode.t | 12 +++++++-----
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/dbdimp.c b/dbdimp.c
index 5378244..eb411a0 100644
--- a/dbdimp.c
+++ b/dbdimp.c
@@ -287,7 +287,7 @@ static void pg_error (pTHX_ SV * h, int error_num, const
char * error_msg)
/* Set as utf-8 */
if (imp_dbh->pg_utf8_flag)
- sv_utf8_upgrade(DBIc_ERRSTR(imp_xxh));
+ SvUTF8_on(DBIc_ERRSTR(imp_xxh));
if (TEND_slow) TRC(DBILOGFP, "%sEnd pg_error\n", THEADER_slow);
@@ -1151,7 +1151,7 @@ SV * dbd_st_FETCH_attrib (SV * sth, imp_sth_t * imp_sth,
SV * keysv)
TRACE_PQFNAME;
fieldname = PQfname(imp_sth->result, fields);
sv_fieldname = newSVpv(fieldname,0);
- sv_utf8_upgrade(sv_fieldname);
+ SvUTF8_on(sv_fieldname);
(void)av_store(av, fields, sv_fieldname);
}
}
@@ -2754,7 +2754,7 @@ static SV * pg_destringify_array(pTHX_ imp_dbh_t
*imp_dbh, unsigned char * input
else {
SV *sv = newSVpvn(string, section_size);
if (imp_dbh->pg_utf8_flag) {
- sv_utf8_upgrade(sv);
+ SvUTF8_on(sv);
}
av_push(currentav, sv);
@@ -3570,14 +3570,14 @@ AV * dbd_st_fetch (SV * sth, imp_sth_t * imp_sth)
}
if (imp_dbh->pg_utf8_flag) {
/*
- The only exception to our rule about setting
utf8 if the client_encoding
- is set to UTF8 is bytea.
+ The only exception to our rule about setting
utf8 (when the client_encoding
+ is set to UTF8) is bytea.
*/
if (type_info && PG_BYTEA ==
type_info->type_id) {
SvUTF8_off(sv);
}
else {
- sv_utf8_upgrade(sv);
+ SvUTF8_on(sv);
}
}
}
@@ -3965,7 +3965,7 @@ int pg_db_getcopydata (SV * dbh, SV * dataline, int async)
if (copystatus > 0) {
sv_setpv(dataline, tempbuf);
if (imp_dbh->pg_utf8_flag)
- sv_utf8_upgrade(dataline);
+ SvUTF8_on(dataline);
TRACE_PQFREEMEM;
PQfreemem(tempbuf);
}
diff --git a/t/30unicode.t b/t/30unicode.t
index 851326e..7c4da06 100644
--- a/t/30unicode.t
+++ b/t/30unicode.t
@@ -27,8 +27,7 @@ my $pgversion = $dbh->{pg_server_version};
my $t;
-my $name = 'Émilie du Châtelet';
-utf8::encode($name);
+my $name = "\N{LATIN CAPITAL LETTER E WITH ACUTE}milie du Ch\N{LATIN SMALL
LETTER A WITH CIRCUMFLEX}telet";
my $SQL = 'SELECT ?::text';
my $sth = $dbh->prepare($SQL);
@@ -43,13 +42,16 @@ $dbh->{pg_enable_utf8} = 0;
$sth->execute($name);
$result = $sth->fetchall_arrayref->[0][0];
$t = 'Fetching UTF-8 string from the database returns proper string
(pg_enable_utf8=0)';
-is ($result, $name, $t);
+my $noutfname = $name;
+Encode::_utf8_off($noutfname);
+is ($result, $noutfname, $t);
$t = 'Fetching UTF-8 string from the database returns string with UTF-8 flag
off (pg_enable_utf8=0)';
ok (!utf8::is_utf8($result), $t);
-
+$t = 'Generated string is not utf8';
$name = 'Ada Lovelace';
utf8::encode($name);
+ok (!utf8::is_utf8($name), $t);
$dbh->{pg_enable_utf8} = -1;
$SQL = 'SELECT ?::text';
@@ -69,12 +71,12 @@ is ($result, $name, $t);
$t = 'Fetching ASCII string from the database returns string with UTF-8 flag
off (pg_enable_utf8=0)';
ok (!utf8::is_utf8($result), $t);
+$dbh->{pg_enable_utf8} = 1;
my $before = "\N{WHITE SMILING FACE}";
my ($after) = $dbh->selectrow_array('SELECT ?::text', {}, $before);
is($after, $before, 'string is the same after round trip');
ok(utf8::is_utf8($after), 'string has utf8 flag set');
-
cleanup_database($dbh,'test');
$dbh->disconnect();
--
1.8.4