Author: rfm
Date: Mon Mar  2 10:36:50 2015
New Revision: 38373

URL: http://svn.gna.org/viewcvs/gnustep?rev=38373&view=rev
Log:
Improve string quotng support

Modified:
    libs/sqlclient/trunk/ChangeLog
    libs/sqlclient/trunk/Postgres.m

Modified: libs/sqlclient/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/ChangeLog?rev=38373&r1=38372&r2=38373&view=diff
==============================================================================
--- libs/sqlclient/trunk/ChangeLog      (original)
+++ libs/sqlclient/trunk/ChangeLog      Mon Mar  2 10:36:50 2015
@@ -1,3 +1,10 @@
+2015-03-02 Richard Frith-Macdonald  <[email protected]>
+
+       * Postgres.h: Drop support for old versions of postgres which didn't
+       support standard conforming strings.  This allows us to always turn
+       on standard conforming strings and be able to quote string and bytea
+       objects whether the database connection has been established or not.
+
 2014-12-11 Richard Frith-Macdonald  <[email protected]>
 
         * SQLClient.h:

Modified: libs/sqlclient/trunk/Postgres.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/Postgres.m?rev=38373&r1=38372&r2=38373&view=diff
==============================================================================
--- libs/sqlclient/trunk/Postgres.m     (original)
+++ libs/sqlclient/trunk/Postgres.m     Mon Mar  2 10:36:50 2015
@@ -60,14 +60,12 @@
 
 typedef struct {
   PGconn       *_connection;
-  BOOL         _escapeStrings;         /* Can we use E'...' syntax?    */
   int           _backendPID;
 } ConnectionInfo;
 
 #define        cInfo                   ((ConnectionInfo*)(self->extra))
 #define        backendPID              (cInfo->_backendPID)
 #define        connection              (cInfo->_connection)
-#define        escapeStrings           (cInfo->_escapeStrings)
 
 static NSDate  *future = nil;
 static NSNull  *null = nil;
@@ -208,12 +206,6 @@
              p = PQparameterStatus(connection, "standard_conforming_strings");
               if (p != 0)
                 {
-                  /* The standard conforming strings setting exists,
-                   * so the E'...' syntax must exist and we can use
-                   * it for byte arrays.
-                   */
-                  escapeStrings = YES;
-
                   /* If the escape_string_warning setting is on,
                    * the server will warn about backslashes even
                    * in properly quoted strings, so turn it off.
@@ -230,7 +222,10 @@
                 }
               else
                 {
-                  escapeStrings = NO;
+                  PQfinish(connection);
+                  connection = 0;
+                  connected = NO;
+                 [self debug: @"Postgres without standard conforming strings"];
                 }
 
              if ([self debugging] > 0)
@@ -701,10 +696,7 @@
   unsigned             length = 0;
   unsigned             i;
 
-  if (YES == escapeStrings)
-    {
-      ptr[length++] = 'E';
-    }
+  ptr[length++] = 'E';
   ptr[length++] = '\'';
   for (i = 0; i < sLen; i++)
     {
@@ -744,10 +736,7 @@
   unsigned int length = sLen + 2;
   unsigned int i;
 
-  if (YES == escapeStrings)
-    {
-      length++;         // Allow for leading 'E'
-    }
+  length++;         // Allow for leading 'E'
   for (i = 0; i < sLen; i++)
     {
       unsigned char    c = src[i];
@@ -1029,6 +1018,22 @@
   unsigned     l = [d length];
   unsigned char        *to = NSZoneMalloc(NSDefaultMallocZone(), (l * 2) + 3);
 
+#if 1
+  const char    *from = (const char*)[d bytes];
+  unsigned      i = 0;
+  unsigned      j = 0;
+
+  to[j++] = '\'';
+  while (i < l)
+    {
+      if ('\'' == (to[j++] = from[i++]))
+        {
+          to[j++] = '\'';
+        }
+    }
+  to[j++] = '\'';
+  l = j - 2;
+#else
 #ifdef HAVE_PQESCAPESTRINGCONN
   int          err;
 
@@ -1036,7 +1041,8 @@
   NS_DURING
     {
       [self connect];
-      l = PQescapeStringConn(connection, (char*)(to + 1), [d bytes], l, &err);
+      l = PQescapeStringConn(connection,
+        (char*)(to + 1), [d bytes], l, &err);
     }
   NS_HANDLER
     {
@@ -1051,6 +1057,8 @@
 #endif
   to[0] = '\'';
   to[l + 1] = '\'';
+#endif
+
   s = [[NSString alloc] initWithBytesNoCopy: to
                                     length: l + 2
                                   encoding: NSUTF8StringEncoding


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to