Use dot syntax
FossilOrigin-Name: dfb0336763997b766d56a302c7534656f518a37c06178af7f15edbed5790dabf
This commit is contained in:
parent
6120fa8fea
commit
e822541c1e
4 changed files with 27 additions and 29 deletions
|
@ -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>
|
* Jonathan Schleifer <js@heap.zone>
|
||||||
*
|
*
|
||||||
* https://heap.zone/git/objpgsql.git
|
* https://heap.zone/git/objpgsql.git
|
||||||
|
@ -61,7 +61,7 @@
|
||||||
@"%@=%@", key, object];
|
@"%@=%@", key, object];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((_connection = PQconnectdb([connectionInfo UTF8String])) == NULL)
|
if ((_connection = PQconnectdb(connectionInfo.UTF8String)) == NULL)
|
||||||
@throw [OFOutOfMemoryException exception];
|
@throw [OFOutOfMemoryException exception];
|
||||||
|
|
||||||
if (PQstatus(_connection) == CONNECTION_BAD)
|
if (PQstatus(_connection) == CONNECTION_BAD)
|
||||||
|
@ -86,7 +86,7 @@
|
||||||
|
|
||||||
- (PGResult *)executeCommand: (OFConstantString *)command
|
- (PGResult *)executeCommand: (OFConstantString *)command
|
||||||
{
|
{
|
||||||
PGresult *result = PQexec(_connection, [command UTF8String]);
|
PGresult *result = PQexec(_connection, command.UTF8String);
|
||||||
|
|
||||||
if (PQresultStatus(result) == PGRES_FATAL_ERROR) {
|
if (PQresultStatus(result) == PGRES_FATAL_ERROR) {
|
||||||
PQclear(result);
|
PQclear(result);
|
||||||
|
@ -134,26 +134,26 @@
|
||||||
else if ([parameter isKindOfClass: [OFNumber class]]) {
|
else if ([parameter isKindOfClass: [OFNumber class]]) {
|
||||||
OFNumber *number = parameter;
|
OFNumber *number = parameter;
|
||||||
|
|
||||||
switch ([number type]) {
|
switch (number.type) {
|
||||||
case OF_NUMBER_TYPE_BOOL:
|
case OF_NUMBER_TYPE_BOOL:
|
||||||
if ([number boolValue])
|
if (number.boolValue)
|
||||||
values[i++] = "t";
|
values[i++] = "t";
|
||||||
else
|
else
|
||||||
values[i++] = "f";
|
values[i++] = "f";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
values[i++] = [[number description]
|
values[i++] =
|
||||||
UTF8String];
|
number.description.UTF8String;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if ([parameter isKindOfClass: [OFNull class]])
|
} else if ([parameter isKindOfClass: [OFNull class]])
|
||||||
values[i++] = NULL;
|
values[i++] = NULL;
|
||||||
else
|
else
|
||||||
values[i++] = [[parameter description]
|
values[i++] =
|
||||||
UTF8String];
|
[parameter description].UTF8String;
|
||||||
} while ((parameter = va_arg(args, id)) != nil);
|
} while ((parameter = va_arg(args, id)) != nil);
|
||||||
|
|
||||||
result = PQexecParams(_connection, [command UTF8String],
|
result = PQexecParams(_connection, command.UTF8String,
|
||||||
argsCount, NULL, values, NULL, NULL, 0);
|
argsCount, NULL, values, NULL, NULL, 0);
|
||||||
} @finally {
|
} @finally {
|
||||||
[self freeMemory: values];
|
[self freeMemory: values];
|
||||||
|
@ -190,7 +190,7 @@
|
||||||
[command appendString: table];
|
[command appendString: table];
|
||||||
[command appendString: @" ("];
|
[command appendString: @" ("];
|
||||||
|
|
||||||
count = [row count];
|
count = row.count;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
enumerator = [row keyEnumerator];
|
enumerator = [row keyEnumerator];
|
||||||
|
@ -214,14 +214,14 @@
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
[command appendString: @", "];
|
[command appendString: @", "];
|
||||||
|
|
||||||
values[i] = [value UTF8String];
|
values[i] = value.UTF8String;
|
||||||
|
|
||||||
[command appendFormat: @"$%zd", ++i];
|
[command appendFormat: @"$%zd", ++i];
|
||||||
}
|
}
|
||||||
|
|
||||||
[command appendString: @")"];
|
[command appendString: @")"];
|
||||||
|
|
||||||
result = PQexecParams(_connection, [command UTF8String],
|
result = PQexecParams(_connection, command.UTF8String,
|
||||||
(int)count, NULL, values, NULL, NULL, 0);
|
(int)count, NULL, values, NULL, NULL, 0);
|
||||||
} @finally {
|
} @finally {
|
||||||
[self freeMemory: values];
|
[self freeMemory: values];
|
||||||
|
|
|
@ -29,8 +29,7 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
@property (readonly, nonatomic) PGresult *pg_result;
|
@property (readonly, nonatomic) PGresult *pg_result;
|
||||||
|
|
||||||
+ (instancetype)pg_resultWithResult: (PGresult *)result;
|
+ (instancetype)pg_resultWithResult: (PGresult *)result;
|
||||||
- (instancetype)pg_initWithResult: (PGresult *)result OF_METHOD_FAMILY(init)
|
- (instancetype)pg_initWithResult: (PGresult *)result;
|
||||||
OF_DESIGNATED_INITIALIZER;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
OF_ASSUME_NONNULL_END
|
OF_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -29,8 +29,7 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
+ (instancetype)pg_rowWithResult: (PGResult *)result
|
+ (instancetype)pg_rowWithResult: (PGResult *)result
|
||||||
row: (int)row;
|
row: (int)row;
|
||||||
- (instancetype)pg_initWithResult: (PGResult *)result
|
- (instancetype)pg_initWithResult: (PGResult *)result
|
||||||
row: (int)row OF_METHOD_FAMILY(init)
|
row: (int)row;
|
||||||
OF_DESIGNATED_INITIALIZER;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
OF_ASSUME_NONNULL_END
|
OF_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -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>
|
* Jonathan Schleifer <js@heap.zone>
|
||||||
*
|
*
|
||||||
* https://heap.zone/git/objpgsql.git
|
* https://heap.zone/git/objpgsql.git
|
||||||
|
@ -35,17 +35,17 @@ convertType(PGresult *res, int column, OFString *string)
|
||||||
return [OFNumber numberWithBool: NO];
|
return [OFNumber numberWithBool: NO];
|
||||||
case 21: /* INT2OID */
|
case 21: /* INT2OID */
|
||||||
return [OFNumber numberWithInt16:
|
return [OFNumber numberWithInt16:
|
||||||
(int16_t)[string decimalValue]];
|
(int16_t)string.decimalValue];
|
||||||
case 23: /* INT4OID */
|
case 23: /* INT4OID */
|
||||||
return [OFNumber numberWithInt32:
|
return [OFNumber numberWithInt32:
|
||||||
(int32_t)[string decimalValue]];
|
(int32_t)string.decimalValue];
|
||||||
case 20: /* INT8OID */
|
case 20: /* INT8OID */
|
||||||
return [OFNumber numberWithInt64:
|
return [OFNumber numberWithInt64:
|
||||||
(int64_t)[string decimalValue]];
|
(int64_t)string.decimalValue];
|
||||||
case 700: /* FLOAT4OID */
|
case 700: /* FLOAT4OID */
|
||||||
return [OFNumber numberWithFloat: [string floatValue]];
|
return [OFNumber numberWithFloat: string.floatValue];
|
||||||
case 701: /* FLOAT8OID */
|
case 701: /* FLOAT8OID */
|
||||||
return [OFNumber numberWithDouble: [string doubleValue]];
|
return [OFNumber numberWithDouble: string.doubleValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
|
@ -76,13 +76,13 @@ convertType(PGresult *res, int column, OFString *string)
|
||||||
row: row] autorelease];
|
row: row] autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
- initWithResult: (PGResult *)result
|
- (instancetype)initWithResult: (PGResult *)result
|
||||||
row: (int)row
|
row: (int)row
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
_result = [result retain];
|
_result = [result retain];
|
||||||
_res = [result pg_result];
|
_res = result.pg_result;
|
||||||
_row = row;
|
_row = row;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
@ -170,13 +170,13 @@ convertType(PGresult *res, int column, OFString *string)
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation PGResultRowEnumerator
|
@implementation PGResultRowEnumerator
|
||||||
- initWithResult: (PGResult *)result
|
- (instancetype)initWithResult: (PGResult *)result
|
||||||
row: (int)row
|
row: (int)row
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
_result = [result retain];
|
_result = [result retain];
|
||||||
_res = [result pg_result];
|
_res = result.pg_result;
|
||||||
_row = row;
|
_row = row;
|
||||||
_count = PQnfields(_res);
|
_count = PQnfields(_res);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue