Author: turnstep
Date: Fri May  2 10:11:54 2008
New Revision: 11187

Modified:
   DBD-Pg/trunk/Changes
   DBD-Pg/trunk/META.yml
   DBD-Pg/trunk/Makefile.PL
   DBD-Pg/trunk/Pg.pm
   DBD-Pg/trunk/Pg.xs
   DBD-Pg/trunk/README
   DBD-Pg/trunk/TODO
   DBD-Pg/trunk/dbdimp.c
   DBD-Pg/trunk/lib/Bundle/DBD/Pg.pm
   DBD-Pg/trunk/quote.c
   DBD-Pg/trunk/quote.h
   DBD-Pg/trunk/t/02attribs.t

Log:
Begin support for standard_conforming_strings.
This is not a full solution yet.


Modified: DBD-Pg/trunk/Changes
==============================================================================
--- DBD-Pg/trunk/Changes        (original)
+++ DBD-Pg/trunk/Changes        Fri May  2 10:11:54 2008
@@ -1,6 +1,10 @@
 ('GSM' is Greg Sabino Mullane, [EMAIL PROTECTED])
 
-2.6.4 Released May 2, 2008
+2.7.0 
+
+       - Support for standard_conforming_strings [GSM]
+
+2.6.4 Released May 2, 2008 (subversion r11186)
 
        - More tweaks to the test suite.
 

Modified: DBD-Pg/trunk/META.yml
==============================================================================
--- DBD-Pg/trunk/META.yml       (original)
+++ DBD-Pg/trunk/META.yml       Fri May  2 10:11:54 2008
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name                  : DBD-Pg
-version               : 2.6.4
+version               : 2.7.0
 abstract              : DBI PostgreSQL interface
 author:              
   - Greg Sabino Mullane <[EMAIL PROTECTED]>
@@ -34,10 +34,10 @@
 provides:
   DBD::Pg:
     file              : Pg.pm
-    version           : 2.6.4
+    version           : 2.7.0
   Bundle::DBD::Pg:
     file              : lib/Bundle/DBD/Pg.pm
-    version           : 2.6.4
+    version           : 2.7.0
 
 keywords:
   - Postgres

Modified: DBD-Pg/trunk/Makefile.PL
==============================================================================
--- DBD-Pg/trunk/Makefile.PL    (original)
+++ DBD-Pg/trunk/Makefile.PL    Fri May  2 10:11:54 2008
@@ -7,7 +7,7 @@
 use 5.006001;
 
 ## No version.pm for this one, as the prereqs are not loaded yet.
-my $VERSION = '2.6.4';
+my $VERSION = '2.7.0';
 
 my $lib;
 BEGIN {

Modified: DBD-Pg/trunk/Pg.pm
==============================================================================
--- DBD-Pg/trunk/Pg.pm  (original)
+++ DBD-Pg/trunk/Pg.pm  Fri May  2 10:11:54 2008
@@ -17,7 +17,7 @@
 {
        package DBD::Pg;
 
-       use version; our $VERSION = qv('2.6.4');
+       use version; our $VERSION = qv('2.7.0');
 
        use DBI ();
        use DynaLoader ();
@@ -1657,7 +1657,7 @@
 
 =head1 VERSION
 
-This documents version 2.6.4 of the DBD::Pg module
+This documents version 2.7.0 of the DBD::Pg module
 
 =head1 SYNOPSIS
 

Modified: DBD-Pg/trunk/Pg.xs
==============================================================================
--- DBD-Pg/trunk/Pg.xs  (original)
+++ DBD-Pg/trunk/Pg.xs  Fri May  2 10:11:54 2008
@@ -248,7 +248,7 @@
                                
                        to_quote = SvPV(to_quote_sv, len);
                        /* Need good debugging here */
-                       quoted = type_info->quote(to_quote, len, &retlen);
+                       quoted = type_info->quote(to_quote, len, &retlen, 0);
                        RETVAL = newSVpvn(quoted, retlen);
                        if (SvUTF8(to_quote_sv)) /* What about overloaded 
objects? */
                                SvUTF8_on(RETVAL);

Modified: DBD-Pg/trunk/README
==============================================================================
--- DBD-Pg/trunk/README (original)
+++ DBD-Pg/trunk/README Fri May  2 10:11:54 2008
@@ -6,7 +6,7 @@
 DESCRIPTION:
 ------------
 
-This is version 2.6.4 of DBD-Pg.  The web site for this interface, and 
+This is version 2.7.0 of DBD-Pg.  The web site for this interface, and 
 the latst vesion, can be found at:
 
        http://search.cpan.org/dist/DBD-Pg/

Modified: DBD-Pg/trunk/TODO
==============================================================================
--- DBD-Pg/trunk/TODO   (original)
+++ DBD-Pg/trunk/TODO   Fri May  2 10:11:54 2008
@@ -1,7 +1,6 @@
 TODO: 
 
 - Mention RETURNING clause support in docs.
-- Play nicely with standard_conforming_strings (CPAN bug #27538)
 - Use WITH HOLD for cursor work
 - Start testing with a thread-enabled Perl
 - Create a .ppm for Windows

Modified: DBD-Pg/trunk/dbdimp.c
==============================================================================
--- DBD-Pg/trunk/dbdimp.c       (original)
+++ DBD-Pg/trunk/dbdimp.c       Fri May  2 10:11:54 2008
@@ -626,12 +626,16 @@
                }
                break;
 
-       case 6: /* pg_pid */
+       case 6: /* pg_pid pg_scs */
 
                if (strEQ("pg_pid", key)) {
                        TRACE_PQBACKENDPID;
                        retsv = newSViv((IV)PQbackendPID(imp_dbh->conn));
                }
+               else if (strEQ("pg_scs", key)) {
+                       TRACE_PQPARAMETERSTATUS;
+                       retsv = 
newSVpv(PQparameterStatus(imp_dbh->conn,"standard_conforming_strings"),0);
+               }
                break;
 
        case 7: /* pg_user  pg_pass  pg_port  pg_host */
@@ -731,8 +735,17 @@
                if (strEQ("pg_placeholder_dollaronly", key))
                        retsv = newSViv((IV)imp_dbh->dollaronly);
                break;
+
+       case 30: /* pg_standard_conforming_strings */
+
+               if (strEQ("pg_standard_conforming_strings", key)) {
+                       TRACE_PQPARAMETERSTATUS;
+                       retsv = 
newSVpv(PQparameterStatus(imp_dbh->conn,"standard_conforming_strings"),0);
+               }
+               break;
+
        }
-       
+
        if (TEND) TRC(DBILOGFP, "%sEnd dbd_db_FETCH_attrib\n", THEADER);
 
        if (!retsv)
@@ -2813,7 +2826,7 @@
                                if (currph->quoted)
                                        Safefree(currph->quoted);
                                currph->quoted = currph->bind_type->quote
-                                       (currph->value, currph->valuelen, 
&currph->quotedlen); /* freed in dbd_st_destroy */
+                                       (currph->value, currph->valuelen, 
&currph->quotedlen, 0); /* freed in dbd_st_destroy */
                        }
                }
                /* Set the size of each actual in-place placeholder */

Modified: DBD-Pg/trunk/lib/Bundle/DBD/Pg.pm
==============================================================================
--- DBD-Pg/trunk/lib/Bundle/DBD/Pg.pm   (original)
+++ DBD-Pg/trunk/lib/Bundle/DBD/Pg.pm   Fri May  2 10:11:54 2008
@@ -4,7 +4,7 @@
 use strict;
 use warnings;
 
-$VERSION = '2.6.4';
+$VERSION = '2.7.0';
 
 1;
 

Modified: DBD-Pg/trunk/quote.c
==============================================================================
--- DBD-Pg/trunk/quote.c        (original)
+++ DBD-Pg/trunk/quote.c        Fri May  2 10:11:54 2008
@@ -11,7 +11,7 @@
 
 #include "Pg.h"
 
-char * null_quote(const char *string, STRLEN len, STRLEN *retlen)
+char * null_quote(const char *string, STRLEN len, STRLEN *retlen, int estring)
 {
        dTHX;
        char *result;
@@ -24,14 +24,14 @@
 }
 
 
-char * quote_string(const char *string, STRLEN len, STRLEN *retlen)
+char * quote_string(const char *string, STRLEN len, STRLEN *retlen, int 
estring)
 {
        dTHX;
        char * result;
        STRLEN oldlen = len;
        const char * const tmp = string;
 
-       (*retlen) = 2;
+       (*retlen) = estring ? 3 : 2;
        while (len > 0 && *string != '\0') {
                if (*string == '\'' || *string == '\\') {
                        (*retlen)++;
@@ -42,7 +42,13 @@
        }
        string = tmp;
        New(0, result, 1+(*retlen), char);
-       *result++ = '\'';
+       if (estring) {
+               *result++ = 'E';
+               *result++ = '\'';
+       }
+       else {
+               *result++ = '\'';
+       }
        len = oldlen;
        while (len > 0 && *string != '\0') {
                if (*string == '\'' || *string == '\\') {
@@ -57,7 +63,7 @@
 }
 
 
-char * quote_geom(const char *string, STRLEN len, STRLEN *retlen)
+char * quote_geom(const char *string, STRLEN len, STRLEN *retlen, int estring)
 {
        dTHX;
        char * result;
@@ -65,7 +71,7 @@
 
        len = 0; /* stops compiler warnings. Remove entirely someday */
        tmp = string;
-       (*retlen) = 2;
+       (*retlen) = estring ? 3 : 2;
        while (*string != '\0') {
                if (*string !=9 && *string != 32 && *string != '(' && *string 
!= ')'
                        && *string != ',' && (*string < '0' || *string > '9'))
@@ -75,7 +81,13 @@
        }
        string = tmp;
        New(0, result, 1+(*retlen), char);
-       *result++ = '\'';
+       if (estring) {
+               *result++ = 'E';
+               *result++ = '\'';
+       }
+       else {
+               *result++ = '\'';
+       }
        while (*string != '\0') {
                *result++ = *string++;
        }
@@ -84,14 +96,14 @@
        return result - (*retlen);
 }
 
-char * quote_path(const char *string, STRLEN len, STRLEN *retlen)
+char * quote_path(const char *string, STRLEN len, STRLEN *retlen, int estring)
 {
        dTHX;
        char * result;
        const char * const tmp = string;
 
        len = 0; /* stops compiler warnings. Remove entirely someday */
-       (*retlen) = 2;
+       (*retlen) = estring ? 3 : 2;
        while (*string != '\0') {
                if (*string !=9 && *string != 32 && *string != '(' && *string 
!= ')'
                        && *string != ',' && *string != '[' && *string != ']'
@@ -102,7 +114,13 @@
        }
        string = tmp;
        New(0, result, 1+(*retlen), char);
-       *result++ = '\'';
+       if (estring) {
+               *result++ = 'E';
+               *result++ = '\'';
+       }
+       else {
+               *result++ = '\'';
+       }
        while (*string != '\0') {
                *result++ = *string++;
        }
@@ -111,14 +129,14 @@
        return result - (*retlen);
 }
 
-char * quote_circle(const char *string, STRLEN len, STRLEN *retlen)
+char * quote_circle(const char *string, STRLEN len, STRLEN *retlen, int 
estring)
 {
        dTHX;
        char * result;
        const char * const tmp = string;
 
        len = 0; /* stops compiler warnings. Remove entirely someday */
-       (*retlen) = 2;
+       (*retlen) = estring ? 3 : 2;
        while (*string != '\0') {
                if (*string !=9 && *string != 32 && *string != '(' && *string 
!= ')'
                        && *string != ',' && *string != '<' && *string != '>'
@@ -129,7 +147,13 @@
        }
        string = tmp;
        New(0, result, 1+(*retlen), char);
-       *result++ = '\'';
+       if (estring) {
+               *result++ = 'E';
+               *result++ = '\'';
+       }
+       else {
+               *result++ = '\'';
+       }
        while (*string != '\0') {
                *result++ = *string++;
        }
@@ -139,14 +163,14 @@
 }
 
 
-char * quote_bytea(char *string, STRLEN len, STRLEN *retlen)
+char * quote_bytea(char *string, STRLEN len, STRLEN *retlen, int estring)
 {
        dTHX;
        char * result;
        STRLEN oldlen = len;
 
        result = string;
-       (*retlen) = 2;
+       (*retlen) = estring ? 3 : 2;
        while (len > 0) {
                if (*string == '\'') {
                        (*retlen) += 2;
@@ -165,7 +189,13 @@
        }
        string = result;
        New(0, result, 1+(*retlen), char);
-       *result++ = '\'';
+       if (estring) {
+               *result++ = 'E';
+               *result++ = '\'';
+       }
+       else {
+               *result++ = '\'';
+       }
        len = oldlen;
        while (len > 0) {
                if (*string == '\'') { /* Single quote becomes double quotes */
@@ -193,19 +223,19 @@
        return (char *)result - (*retlen);
 }
 
-char * quote_sql_binary(char *string, STRLEN len, STRLEN *retlen)
+char * quote_sql_binary(char *string, STRLEN len, STRLEN *retlen, int estring)
 {
        dTHX;
        /* We are going to return a quote_bytea() for backwards compat but
                 we warn first */
        warn("Use of SQL_BINARY invalid in quote()");
-       return quote_bytea(string, len, retlen);
+       return quote_bytea(string, len, retlen, estring);
        
 }
 
 
 
-char * quote_bool(const char *value, STRLEN len, STRLEN *retlen) 
+char * quote_bool(const char *value, STRLEN len, STRLEN *retlen, int estring) 
 {
        dTHX;
        char *result;
@@ -236,7 +266,7 @@
 
 
 
-char * quote_integer(const char *value, STRLEN len, STRLEN *retlen) 
+char * quote_integer(const char *value, STRLEN len, STRLEN *retlen, int 
estring) 
 {
        dTHX;
        char *result;
@@ -259,7 +289,7 @@
 
 
 
-void dequote_char(const char *string, STRLEN *retlen)
+void dequote_char(const char *string, STRLEN *retlen, int estring)
 {
        dTHX;
        /* TODO: chop_blanks if requested */
@@ -267,7 +297,7 @@
 }
 
 
-void dequote_string(const char *string, STRLEN *retlen)
+void dequote_string(const char *string, STRLEN *retlen, int estring)
 {
        dTHX;
        *retlen = strlen(string);
@@ -275,7 +305,7 @@
 
 
 
-void dequote_bytea(char *string, STRLEN *retlen)
+void dequote_bytea(char *string, STRLEN *retlen, int estring)
 {
        dTHX;
        char *result;
@@ -320,20 +350,20 @@
        it might be nice to let people go the other way too. Say when talking
        to something that uses SQL_BINARY
  */
-void dequote_sql_binary(char *string, STRLEN *retlen)
+void dequote_sql_binary(char *string, STRLEN *retlen, int estring)
 {
        dTHX;
 
        /* We are going to retun a dequote_bytea(), JIC */
        warn("Use of SQL_BINARY invalid in dequote()");
-       dequote_bytea(string, retlen);
+       dequote_bytea(string, retlen, estring);
        return;
        /* Put dequote_sql_binary function here at some point */
 }
 
 
 
-void dequote_bool(char *string, STRLEN *retlen)
+void dequote_bool(char *string, STRLEN *retlen, int estring)
 {
        dTHX;
 
@@ -348,7 +378,7 @@
 
 
 
-void null_dequote(const char *string, STRLEN *retlen)
+void null_dequote(const char *string, STRLEN *retlen, int estring)
 {
        dTHX;
        *retlen = strlen(string);

Modified: DBD-Pg/trunk/quote.h
==============================================================================
--- DBD-Pg/trunk/quote.h        (original)
+++ DBD-Pg/trunk/quote.h        Fri May  2 10:11:54 2008
@@ -1,16 +1,16 @@
 
-char * null_quote(const char *string, STRLEN len, STRLEN *retlen);
-char * quote_string(const char *string, STRLEN len, STRLEN *retlen);
-char * quote_bytea(char *string, STRLEN len, STRLEN *retlen);
-char * quote_sql_binary(char *string, STRLEN len, STRLEN *retlen);
-char * quote_bool(const char *string, STRLEN len, STRLEN *retlen);
-char * quote_integer(const char *string, STRLEN len, STRLEN *retlen);
-char * quote_geom(const char *string, STRLEN len, STRLEN *retlen);
-char * quote_path(const char *string, STRLEN len, STRLEN *retlen);
-char * quote_circle(const char *string, STRLEN len, STRLEN *retlen);
-void dequote_char(const char *string, STRLEN *retlen);
-void dequote_string(const char *string, STRLEN *retlen);
-void dequote_bytea(char *string, STRLEN *retlen);
-void dequote_sql_binary(char *string, STRLEN *retlen);
-void dequote_bool(char *string, STRLEN *retlen);
-void null_dequote(const char *string, STRLEN *retlen);
+char * null_quote(const char *string, STRLEN len, STRLEN *retlen, int estring);
+char * quote_string(const char *string, STRLEN len, STRLEN *retlen, int 
estring);
+char * quote_bytea(char *string, STRLEN len, STRLEN *retlen, int estring);
+char * quote_sql_binary(char *string, STRLEN len, STRLEN *retlen, int estring);
+char * quote_bool(const char *string, STRLEN len, STRLEN *retlen, int estring);
+char * quote_integer(const char *string, STRLEN len, STRLEN *retlen, int 
estring);
+char * quote_geom(const char *string, STRLEN len, STRLEN *retlen, int estring);
+char * quote_path(const char *string, STRLEN len, STRLEN *retlen, int estring);
+char * quote_circle(const char *string, STRLEN len, STRLEN *retlen, int 
estring);
+void dequote_char(const char *string, STRLEN *retlen, int estring);
+void dequote_string(const char *string, STRLEN *retlen, int estring);
+void dequote_bytea(char *string, STRLEN *retlen, int estring);
+void dequote_sql_binary(char *string, STRLEN *retlen, int estring);
+void dequote_bool(char *string, STRLEN *retlen, int estring);
+void null_dequote(const char *string, STRLEN *retlen, int estring);

Modified: DBD-Pg/trunk/t/02attribs.t
==============================================================================
--- DBD-Pg/trunk/t/02attribs.t  (original)
+++ DBD-Pg/trunk/t/02attribs.t  Fri May  2 10:11:54 2008
@@ -16,7 +16,7 @@
 if (! defined $dbh) {
        plan skip_all => 'Connection to database failed, cannot continue 
testing';
 }
-plan tests => 132;
+plan tests => 138;
 
 isnt( $dbh, undef, 'Connect to database for handle attributes testing');
 
@@ -90,7 +90,7 @@
 
 };
 
-my ($attrib,$SQL,$sth,$warning,$result,$expected);
+my ($attrib,$SQL,$sth,$warning,$result,$expected,$t);
 
 # Get the DSN and user from the test file, if it exists
 my ($testdsn, $testuser) = get_test_settings();
@@ -320,6 +320,26 @@
 $result = $dbh->{pg_pid};
 like( $result, qr/^\d+$/, q{DB handle attribute "pg_pid" returns a value});
 
+$t=q{DB handle attribute "pg_standard_conforming_strings" returns a valid 
value};
+my $oldscs = $dbh->{pg_standard_conforming_strings};
+like( $oldscs, qr/^on|off$/, $t);
+
+$dbh->do("SET standard_conforming_strings = on");
+$t=q{DB handle attribute "pg_standard_conforming_strings" returns correct 
value};
+$result = $dbh->{pg_standard_conforming_strings};
+is( $result, 'on', $t);
+$t=q{DB handle attribute "pg_scs" returns correct value};
+$result = $dbh->{pg_scs};
+is( $result, 'on', $t);
+
+$dbh->do("SET standard_conforming_strings = off");
+$t=q{DB handle attribute "pg_standard_conforming_strings" returns correct 
value};
+$result = $dbh->{pg_standard_conforming_strings};
+is( $result, 'off', $t);
+$t=q{DB handle attribute "pg_scs" returns correct value};
+$result = $dbh->{pg_scs};
+is( $result, 'off', $t);
+
 ## 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];
@@ -336,7 +356,15 @@
        $sth->execute(1);
        local $dbh->{pg_enable_utf8} = 1;
        my $utf8_str = chr(0x100).'dam'; # LATIN CAPITAL LETTER A WITH MACRON
-       is( $dbh->quote( $utf8_str ), "'$utf8_str'", 'quote() handles utf8.' );
+
+       $dbh->do("SET standard_conforming_strings = off");
+       $t=q{Database method quote() handles utf8};
+       is( $dbh->quote( $utf8_str ),  "'$utf8_str'", $t);
+
+       $dbh->do("SET standard_conforming_strings = on");
+       $t=q{Database method quote() handles utf8};
+       is( $dbh->quote( $utf8_str ),  "E'$utf8_str'", $t);
+
        $SQL = "INSERT INTO dbd_pg_test (id, pname, val) VALUES (40, 
'$utf8_str', 'Orange')";
        is( $dbh->do($SQL), '1', 'Able to insert unicode character into the 
database');
        $sth->execute(40);
@@ -350,6 +378,8 @@
        $sth->finish();
 }
 
+$dbh->do("SET standard_conforming_strings = $oldscs");
+
 
 #
 # Use the handle attribute "Warn" to check inheritance

Reply via email to