[DBD::Pg] Make pg_enable_utf8 accept ints, and reject invalid values.

dbdpg-commits-gENoVmVU/[email protected] Tue, 2 Jul 2013 21:36:11 -0400
Newsgroups gmane.comp.db.postgresql.dbdpg.cvs
Message-ID <[email protected]>
Committed by Greg Sabino Mullane <greg-O9fzpki4YnJWk0Htik3J/[email protected]>

Make pg_enable_utf8 accept ints, and reject invalid values.

---
 dbdimp.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/dbdimp.c b/dbdimp.c
index 1f293e6..c65a3ff 100644
--- a/dbdimp.c
+++ b/dbdimp.c
@@ -877,6 +877,9 @@ int dbd_db_STORE_attrib (SV * dbh, imp_dbh_t * imp_dbh, SV * keysv, SV * valuesv
 		*/
 		else if (strEQ("pg_enable_utf8", key)) {
 			/* Technically, we only allow -1, 0, and 1 */
+			if (SvOK(valuesv)) {
+				newval = (unsigned)SvIV(valuesv);
+			}
 			imp_dbh->pg_enable_utf8 = newval;
 
 			/* Never use the utf8 flag, no matter what */
@@ -888,13 +891,16 @@ int dbd_db_STORE_attrib (SV * dbh, imp_dbh_t * imp_dbh, SV * keysv, SV * valuesv
 				imp_dbh->pg_utf8_flag = DBDPG_TRUE;
 			}
 			/* Do The Right Thing */
-			else {
+			else if (-1 == imp_dbh->pg_enable_utf8) {
 				imp_dbh->client_encoding_utf8 =
 					(0 == strncmp(PQparameterStatus(imp_dbh->conn, "client_encoding"), "UTF8", 4))
 					? DBDPG_TRUE : DBDPG_FALSE;
 				imp_dbh->pg_enable_utf8 = -1;
 				imp_dbh->pg_utf8_flag = imp_dbh->client_encoding_utf8;
 			}
+			else {
+				warn("The pg_enable_utf8 setting can only be set to 0, 1, or -1");
+			}
 			retval = 1;
 		}
 		break;
-- 
1.7.1