Use dot syntax

FossilOrigin-Name: dfb0336763997b766d56a302c7534656f518a37c06178af7f15edbed5790dabf
This commit is contained in:
Jonathan Schleifer 2019-03-16 22:58:16 +00:00
parent 6120fa8fea
commit e822541c1e
4 changed files with 27 additions and 29 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, 2014, 2015, 2016, 2017
* Copyright (c) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
* Jonathan Schleifer <js@heap.zone>
*
* https://heap.zone/git/objpgsql.git
@ -61,7 +61,7 @@
@"%@=%@", key, object];
}
if ((_connection = PQconnectdb([connectionInfo UTF8String])) == NULL)
if ((_connection = PQconnectdb(connectionInfo.UTF8String)) == NULL)
@throw [OFOutOfMemoryException exception];
if (PQstatus(_connection) == CONNECTION_BAD)
@ -86,7 +86,7 @@
- (PGResult *)executeCommand: (OFConstantString *)command
{
PGresult *result = PQexec(_connection, [command UTF8String]);
PGresult *result = PQexec(_connection, command.UTF8String);
if (PQresultStatus(result) == PGRES_FATAL_ERROR) {
PQclear(result);
@ -134,26 +134,26 @@
else if ([parameter isKindOfClass: [OFNumber class]]) {
OFNumber *number = parameter;
switch ([number type]) {
switch (number.type) {
case OF_NUMBER_TYPE_BOOL:
if ([number boolValue])
if (number.boolValue)
values[i++] = "t";
else
values[i++] = "f";
break;
default:
values[i++] = [[number description]
UTF8String];
values[i++] =
number.description.UTF8String;
break;
}
} else if ([parameter isKindOfClass: [OFNull class]])
values[i++] = NULL;
else
values[i++] = [[parameter description]
UTF8String];
values[i++] =
[parameter description].UTF8String;
} while ((parameter = va_arg(args, id)) != nil);
result = PQexecParams(_connection, [command UTF8String],
result = PQexecParams(_connection, command.UTF8String,
argsCount, NULL, values, NULL, NULL, 0);
} @finally {
[self freeMemory: values];
@ -190,7 +190,7 @@
[command appendString: table];
[command appendString: @" ("];
count = [row count];
count = row.count;
i = 0;
enumerator = [row keyEnumerator];
@ -214,14 +214,14 @@
if (i > 0)
[command appendString: @", "];
values[i] = [value UTF8String];
values[i] = value.UTF8String;
[command appendFormat: @"$%zd", ++i];
}
[command appendString: @")"];
result = PQexecParams(_connection, [command UTF8String],
result = PQexecParams(_connection, command.UTF8String,
(int)count, NULL, values, NULL, NULL, 0);
} @finally {
[self freeMemory: values];

View file

@ -29,8 +29,7 @@ OF_ASSUME_NONNULL_BEGIN
@property (readonly, nonatomic) PGresult *pg_result;
+ (instancetype)pg_resultWithResult: (PGresult *)result;
- (instancetype)pg_initWithResult: (PGresult *)result OF_METHOD_FAMILY(init)
OF_DESIGNATED_INITIALIZER;
- (instancetype)pg_initWithResult: (PGresult *)result;
@end
OF_ASSUME_NONNULL_END

View file

@ -29,8 +29,7 @@ OF_ASSUME_NONNULL_BEGIN
+ (instancetype)pg_rowWithResult: (PGResult *)result
row: (int)row;
- (instancetype)pg_initWithResult: (PGResult *)result
row: (int)row OF_METHOD_FAMILY(init)
OF_DESIGNATED_INITIALIZER;
row: (int)row;
@end
OF_ASSUME_NONNULL_END

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, 2014, 2015, 2016, 2017
* Copyright (c) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
* Jonathan Schleifer <js@heap.zone>
*
* https://heap.zone/git/objpgsql.git
@ -35,17 +35,17 @@ convertType(PGresult *res, int column, OFString *string)
return [OFNumber numberWithBool: NO];
case 21: /* INT2OID */
return [OFNumber numberWithInt16:
(int16_t)[string decimalValue]];
(int16_t)string.decimalValue];
case 23: /* INT4OID */
return [OFNumber numberWithInt32:
(int32_t)[string decimalValue]];
(int32_t)string.decimalValue];
case 20: /* INT8OID */
return [OFNumber numberWithInt64:
(int64_t)[string decimalValue]];
(int64_t)string.decimalValue];
case 700: /* FLOAT4OID */
return [OFNumber numberWithFloat: [string floatValue]];
return [OFNumber numberWithFloat: string.floatValue];
case 701: /* FLOAT8OID */
return [OFNumber numberWithDouble: [string doubleValue]];
return [OFNumber numberWithDouble: string.doubleValue];
}
return string;
@ -76,13 +76,13 @@ convertType(PGresult *res, int column, OFString *string)
row: row] autorelease];
}
- initWithResult: (PGResult *)result
row: (int)row
- (instancetype)initWithResult: (PGResult *)result
row: (int)row
{
self = [super init];
_result = [result retain];
_res = [result pg_result];
_res = result.pg_result;
_row = row;
return self;
@ -170,13 +170,13 @@ convertType(PGresult *res, int column, OFString *string)
@end
@implementation PGResultRowEnumerator
- initWithResult: (PGResult *)result
row: (int)row
- (instancetype)initWithResult: (PGResult *)result
row: (int)row
{
self = [super init];
_result = [result retain];
_res = [result pg_result];
_res = result.pg_result;
_row = row;
_count = PQnfields(_res);