See attached for an improved patch on quoting. This gives similar tests
successes for both quoted and unquoted external names.

-- Mark

On 06/05/2017 10:00 PM, Mark Clements wrote:
> Please see attached for a patch to fix quoting of column names and
> Postgresql sequences. I have also included a few formatting changes.
>
> Kindly, Mark.
>
>

Index: EOAccess/EOSQLExpression.m
===================================================================
--- EOAccess/EOSQLExpression.m	(revision 40502)
+++ EOAccess/EOSQLExpression.m	(working copy)
@@ -1784,7 +1784,7 @@
     }
   else
     {
-      NSString* columnName = [attribute columnName];
+      NSString* columnName = [self sqlStringForSchemaObjectName: [attribute columnName]];
       if (columnName == nil)
 	{
 	  [NSException raise: @"NSIllegalStateException"
@@ -1795,7 +1795,7 @@
       if (![self useAliases])
 	sqlString = columnName;
       else
-	sqlString = [@"t0." stringByAppendingString:[self sqlStringForSchemaObjectName:columnName]];
+	sqlString = [@"t0." stringByAppendingString:columnName];
     }
 
   EOFLOGObjectLevelArgs(@"EOSQLExpression", @"sqlString=%@", sqlString);
Index: EOAccess/EOSchemaGeneration.m
===================================================================
--- EOAccess/EOSchemaGeneration.m	(revision 40502)
+++ EOAccess/EOSchemaGeneration.m	(working copy)
@@ -396,11 +396,12 @@
 
   entity = [entityGroup objectAtIndex: 0];
   listString = [NSMutableString stringWithCapacity: 30];
+  sqlExp = [self sqlExpressionWithEntity:[entityGroup objectAtIndex: 0]];
 
   attrEnum = [[entity primaryKeyAttributes] objectEnumerator];
   while ((attr = [attrEnum nextObject]))
     {
-      NSString *columnName = [attr columnName];
+      NSString *columnName = [sqlExp sqlStringForSchemaObjectName: [attr columnName]];
 
       if (!columnName || ![columnName length])
 	continue;
@@ -419,7 +420,6 @@
       return [NSArray array];
     }
 
-  sqlExp = [self sqlExpressionWithEntity:[entityGroup objectAtIndex: 0]];
   tableName = [entity externalName];
   tableName = [sqlExp sqlStringForSchemaObjectName: tableName];
 
@@ -755,16 +755,14 @@
   NSString *allowsNull;
   NSString *str;
 
-
-
   columnType = [self columnTypeStringForAttribute: attribute];
   allowsNull = [self allowsNullClauseForConstraint: [attribute allowsNull]];
 
   if (allowsNull)
-    str = [NSString stringWithFormat: @"%@ %@ %@", [attribute columnName],
+    str = [NSString stringWithFormat: @"%@ %@ %@", [self sqlStringForSchemaObjectName: [attribute columnName]],
 		    columnType, allowsNull];
   else
-    str = [NSString stringWithFormat: @"%@ %@", [attribute columnName],
+    str = [NSString stringWithFormat: @"%@ %@", [self sqlStringForSchemaObjectName: [attribute columnName]],
 		    columnType];
 
   [self appendItem:str toListString: /*_listString*/[self listString]]; // Else no chance to get inited (lazy)
Index: EOAdaptors/PostgreSQLAdaptor/PostgreSQLChannel.m
===================================================================
--- EOAdaptors/PostgreSQLAdaptor/PostgreSQLChannel.m	(revision 40502)
+++ EOAdaptors/PostgreSQLAdaptor/PostgreSQLChannel.m	(working copy)
@@ -1471,7 +1471,7 @@
   fd = lo_open(_pgConn, oid, INV_READ|INV_WRITE);
   if (fd < 0)
     [NSException raise: PostgreSQLException
-		 format: @"cannot open large object Oid = %ld", oid];
+		 format: @"cannot open large object Oid = %u", oid];
 
   lo_lseek(_pgConn, fd, 0, SEEK_END);
   len = lo_tell(_pgConn, fd);
@@ -1479,7 +1479,7 @@
 
   if (len < 0)
     [NSException raise: PostgreSQLException
-		 format: @"error while getting size of large object Oid = %ld", oid];
+		 format: @"error while getting size of large object Oid = %u", oid];
 
   bytes = NSZoneMalloc(zone, len);
   wrt = lo_read(_pgConn, fd, bytes, len);
@@ -1488,7 +1488,7 @@
     {
       NSZoneFree(zone, bytes);
       [NSException raise: PostgreSQLException
-		   format: @"error while reading large object Oid = %ld", oid];
+		   format: @"error while reading large object Oid = %u", oid];
     }
   lo_close(_pgConn, fd);
 
@@ -1519,13 +1519,13 @@
   fd = lo_open(_pgConn, oid, INV_READ|INV_WRITE);
   if (fd < 0)
     [NSException raise: PostgreSQLException
-		 format: @"cannot open large object Oid = %ld", oid];
+		 format: @"cannot open large object Oid = %u", oid];
 
   wrt = lo_write(_pgConn, fd, (char *)bytes, len);
 
   if (len != wrt)
     [NSException raise: PostgreSQLException
-		 format: @"error while writing large object Oid = %ld", oid];
+		 format: @"error while writing large object Oid = %u", oid];
 
   lo_close(_pgConn, fd);
 
@@ -1556,13 +1556,13 @@
   fd = lo_open(_pgConn, oid, INV_READ|INV_WRITE);
   if (fd < 0)
     [NSException raise: PostgreSQLException
-		 format: @"cannot open large object Oid = %ld", oid];
+		 format: @"cannot open large object Oid = %u", oid];
 
   wrt = lo_write(_pgConn, fd, (char*)bytes, len);
 
   if (len != wrt)
     [NSException raise: PostgreSQLException
-		 format: @"error while writing large object Oid = %ld", oid];
+		 format: @"error while writing large object Oid = %u", oid];
 
   lo_close(_pgConn, fd);
 
@@ -2216,6 +2216,7 @@
   NSDictionary *pk = nil;
   NSArray 	   *primaryKeyAttributes = [entity primaryKeyAttributes];
   EOAttribute  *primAttribute;
+  EOSQLExpression *sqlExpr;
   NSString     *sqlString;
   NSNumber     *pkValue = nil;
   NSString     *sqlFormat = nil;
@@ -2233,12 +2234,14 @@
     return nil; // We support only number keys
   }
 
-  sqlFormat=[NSString stringWithFormat: @"SELECT nextval('%@')",
-		      [(PostgreSQLAdaptor*)[[self adaptorContext]adaptor] primaryKeySequenceNameFormat]];
-
+  sqlExpr = [EOSQLExpression sqlExpressionWithEntity: nil];
+  sqlFormat = [(PostgreSQLAdaptor*)[[self adaptorContext]adaptor] primaryKeySequenceNameFormat];
   sqlString = [NSString stringWithFormat: sqlFormat,
 			[entity primaryKeyRootName]];
-  
+  sqlString = [sqlExpr sqlStringForSchemaObjectName: sqlString];
+  sqlString=[NSString stringWithFormat: @"SELECT nextval('%@')",
+		      sqlString];
+
   if ([self isDebugEnabled]) 
   {
     NSLog(@"PostgreSQLAdaptor: '%@'", sqlString);
_______________________________________________
Discuss-gnustep mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnustep

Reply via email to