Author: turnstep
Date: Sat Nov 20 21:42:15 2010
New Revision: 14544
Modified:
DBD-Pg/trunk/Pg.pm
DBD-Pg/trunk/dbdimp.c
DBD-Pg/trunk/dbdimp.h
DBD-Pg/trunk/t/09arrays.t
Log:
Quick swipe at the utf8 problem. Doesn't work yet :)
Modified: DBD-Pg/trunk/Pg.pm
==============================================================================
--- DBD-Pg/trunk/Pg.pm (original)
+++ DBD-Pg/trunk/Pg.pm Sat Nov 20 21:42:15 2010
@@ -3124,9 +3124,10 @@
=head3 B<pg_enable_utf8> (boolean)
-DBD::Pg specific attribute. If true, then the C<utf8> flag will be turned on
-for returned character data (if the data is valid UTF-8). For details about
-the C<utf8> flag, see the C<Encode> module. This attribute is only relevant
under
+DBD::Pg specific attribute. Partially deprecated, as we now mark all strings
+coming from a database with a client_encoding of 'UTF8' as utf8. However,
+setting pg_enable_utf8 to false will override this automatic check, for
+backwards compatibility with applications. This attribute is only relevant
under
perl 5.8 and later.
=head3 B<pg_errorlevel> (integer)
Modified: DBD-Pg/trunk/dbdimp.c
==============================================================================
--- DBD-Pg/trunk/dbdimp.c (original)
+++ DBD-Pg/trunk/dbdimp.c Sat Nov 20 21:42:15 2010
@@ -229,6 +229,9 @@
}
}
+ /* Figure out the client_encoding for UTF work */
+ imp_dbh->is_utf8 = strncmp("UTF8", PQparameterStatus(imp_dbh->conn,
"client_encoding"), 4)
+ ? DBDPG_FALSE : DBDPG_TRUE;
imp_dbh->pg_bool_tf = DBDPG_FALSE;
imp_dbh->pg_enable_utf8 = DBDPG_FALSE;
imp_dbh->prepare_now = DBDPG_FALSE;
@@ -281,7 +284,7 @@
sv_setpv(DBIc_STATE(imp_xxh), (char*)imp_dbh->sqlstate);
/* Set as utf-8 */
- if (imp_dbh->pg_enable_utf8)
+ if (imp_dbh->is_utf8)
SvUTF8_on(DBIc_ERRSTR(imp_xxh));
if (TEND) TRC(DBILOGFP, "%sEnd pg_error\n", THEADER);
@@ -736,7 +739,7 @@
else if (strEQ("pg_prepare_now", key))
retsv = newSViv((IV)imp_dbh->prepare_now);
#ifdef is_utf8_string
- else if (strEQ("pg_enable_utf8", key))
+ else if (strEQ("pg_enable_utf8", key))
retsv = newSViv((IV)imp_dbh->pg_enable_utf8);
#endif
break;
@@ -857,6 +860,10 @@
#ifdef is_utf8_string
else if (strEQ("pg_enable_utf8", key)) {
imp_dbh->pg_enable_utf8 = newval!=0 ? DBDPG_TRUE :
DBDPG_FALSE;
+ /* Turning on does nothing now, but explicit off will
force is_utf8 off! */
+ if (imp_dbh->pg_enable_utf8 == DBDPG_FALSE) {
+ imp_dbh->is_utf8 = DBDPG_FALSE;
+ }
retval = 1;
}
#endif
@@ -2623,11 +2630,8 @@
else {
SV *sv = newSVpvn(string, section_size);
#ifdef is_utf8_string
- if (imp_dbh->pg_enable_utf8) {
- SvUTF8_off(sv);
- if (is_high_bit_set(aTHX_
(unsigned char *)string, section_size) && is_utf8_string((unsigned
char*)string, section_size)) {
- SvUTF8_on(sv);
- }
+ if (imp_dbh->is_utf8) {
+ SvUTF8_on(sv);
}
#endif
av_push(currentav, sv);
@@ -3426,20 +3430,8 @@
}
}
#ifdef is_utf8_string
- if (imp_dbh->pg_enable_utf8 && type_info) {
- SvUTF8_off(sv);
- switch (type_info->type_id) {
- case PG_CHAR:
- case PG_TEXT:
- case PG_BPCHAR:
- case PG_VARCHAR:
- if (is_high_bit_set(aTHX_ value,
value_len) && is_utf8_string((unsigned char*)value, value_len)) {
- SvUTF8_on(sv);
- }
- break;
- default:
- break;
- }
+ if (imp_dbh->is_utf8) {
+ SvUTF8_on(sv);
}
#endif
}
Modified: DBD-Pg/trunk/dbdimp.h
==============================================================================
--- DBD-Pg/trunk/dbdimp.h (original)
+++ DBD-Pg/trunk/dbdimp.h Sat Nov 20 21:42:15 2010
@@ -32,6 +32,7 @@
PGconn *conn; /* connection structure */
char *sqlstate; /* from the last result */
+ bool is_utf8; /* does the client_encoding return UTF8? */
bool pg_bool_tf; /* do bools return 't'/'f'? Set by user,
default is 0 */
bool pg_enable_utf8; /* should we attempt to make utf8 strings?
Set by user, default is 0 */
bool prepare_now; /* force immediate prepares, even with
placeholders. Set by user, default is 0 */
Modified: DBD-Pg/trunk/t/09arrays.t
==============================================================================
--- DBD-Pg/trunk/t/09arrays.t (original)
+++ DBD-Pg/trunk/t/09arrays.t Sat Nov 20 21:42:15 2010
@@ -569,7 +569,6 @@
if $server_encoding ne 'UTF8';
$t='String should be UTF-8';
- local $dbh->{pg_enable_utf8} = 1;
my $utf8_str = chr(0x100).'dam'; # LATIN CAPITAL LETTER A WITH MACRON
ok (Encode::is_utf8( $utf8_str ), $t);
@@ -624,6 +623,8 @@
};
is ($@, q{}, $t);
+ local $dbh->{pg_enable_utf8} = 1;
+
$t='Retreiving an array containing utf-8 works';
$SQL = q{SELECT id, testarray, val FROM dbd_pg_test WHERE id = 1};
$sth = $dbh->prepare($SQL);
@@ -632,8 +633,8 @@
$expected = [1,['Bob',$utf8_str],'one'];
is_deeply ($result, $expected, $t);
- $t='Selected ASCII string should not be UTF-8';
- ok (!Encode::is_utf8( $result->[1][0] ), $t);
+ $t='Selected ASCII string should be UTF-8';
+ ok (Encode::is_utf8( $result->[1][0] ), $t);
$t='Selected string should be UTF-8';
ok (Encode::is_utf8( $result->[1][1] ), $t);