[DBD::Pg] Quick trial implmentation of new utf8 work.
dbdpg-commits-gENoVmVU/[email protected]
| Newsgroups | gmane.comp.db.postgresql.dbdpg.cvs |
|---|---|
| Message-ID | <[email protected]> |
Committed by Greg Sabino Mullane <greg-O9fzpki4YnJWk0Htik3J/[email protected]> Quick trial implmentation of new utf8 work. --- dbdimp.c | 27 +++++++++++++++++++++++++++ dbdimp.h | 1 + 2 files changed, 28 insertions(+), 0 deletions(-) diff --git a/dbdimp.c b/dbdimp.c index 8055330..09e7b8d 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -105,11 +105,13 @@ int dbd_db_login6 (SV * dbh, imp_dbh_t * imp_dbh, char * dbname, char * uid, cha dTHR; dTHX; + SV ** svp; char * conn_str; char * dest; bool inquote = DBDPG_FALSE; STRLEN connect_string_size; ConnStatusType connstatus; + int utf8int; if (TSTART) TRC(DBILOGFP, "%sBegin dbd_db_login\n", THEADER); @@ -215,6 +217,31 @@ int dbd_db_login6 (SV * dbh, imp_dbh_t * imp_dbh, char * dbname, char * uid, cha /* Grab the server encoding so we can set out utf8 flags intelligently */ imp_dbh->server_encoding = PQparameterStatus(imp_dbh->conn, "server_encoding"); + /* Check the value of the pg_enable_utf8 attribute. Default to not there or -1 */ + utf8int = -1; + DBD_ATTRIB_GET_IV(attr, "pg_enable_utf8", 14, svp, utf8int); + + /* + We need to see if we are treating things with utf8 respect, or as byte soup + The rules are: + pg_enable_utf8 trumps everything else + SQL_ASCII is always byte soup + Everything else is not + */ + if (utf8int > 1) { /* Force it on, no matter what */ + imp_dbh->utf8 = 1; + } + else { + if (utf8int == 0) { /* Force it off, no matter what */ + imp_dbh->utf8 = 0; + } + else { + imp_dbh->utf8 = + (0 == strncmp(imp_dbh->server_encoding, "SQL_ASCII", 9)) + ? 0 : 1; + } + } + /* Figure out this particular backend's version */ imp_dbh->pg_server_version = -1; #if PGLIBVERSION >= 80000 diff --git a/dbdimp.h b/dbdimp.h index 968cb28..0dd02fe 100644 --- a/dbdimp.h +++ b/dbdimp.h @@ -32,6 +32,7 @@ struct imp_dbh_st { PGconn *conn; /* connection structure */ char *sqlstate; /* from the last result */ const char *server_encoding; /* encoding detected at login */ + int 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 */ -- 1.7.0.5