aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks
diff options
context:
space:
mode:
Diffstat (limited to 'Frameworks')
-rw-r--r--Frameworks/PostgresKit/PostgresKit.xcodeproj/project.pbxproj2
-rw-r--r--Frameworks/PostgresKit/Source/FLXConstants.h19
-rw-r--r--Frameworks/PostgresKit/Source/FLXConstants.m10
-rw-r--r--Frameworks/PostgresKit/Source/FLXPostgresResult.h10
-rw-r--r--Frameworks/PostgresKit/Source/FLXPostgresResult.m13
-rw-r--r--Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m69
-rw-r--r--Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.h2
-rw-r--r--Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.m3
-rw-r--r--Frameworks/PostgresKit/Source/FLXPostgresTypeHandlerProtocol.h14
-rw-r--r--Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m19
-rw-r--r--Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m64
11 files changed, 119 insertions, 106 deletions
diff --git a/Frameworks/PostgresKit/PostgresKit.xcodeproj/project.pbxproj b/Frameworks/PostgresKit/PostgresKit.xcodeproj/project.pbxproj
index 4b447687..ed554b9c 100644
--- a/Frameworks/PostgresKit/PostgresKit.xcodeproj/project.pbxproj
+++ b/Frameworks/PostgresKit/PostgresKit.xcodeproj/project.pbxproj
@@ -42,7 +42,7 @@
173D4F5715BAD3030007F267 /* FLXPostgresTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4F5615BAD3030007F267 /* FLXPostgresTypes.h */; settings = {ATTRIBUTES = (); }; };
173D506A15BB93470007F267 /* libssl.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 173D506915BB93470007F267 /* libssl.dylib */; };
173D507015BB93E40007F267 /* libcrypto.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 173D506F15BB93E40007F267 /* libcrypto.dylib */; };
- 173D508C15BBD98D0007F267 /* FLXConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D508B15BBD98D0007F267 /* FLXConstants.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 173D508C15BBD98D0007F267 /* FLXConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D508B15BBD98D0007F267 /* FLXConstants.h */; settings = {ATTRIBUTES = (); }; };
173D508F15BBD9BF0007F267 /* FLXConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 173D508E15BBD9BF0007F267 /* FLXConstants.m */; };
173D513515BBE50D0007F267 /* FLXPostgresConnectionDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D513415BBE50D0007F267 /* FLXPostgresConnectionDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
177AC5F015C50F6E00A3658D /* FLXPostgresConnectionTypeHandling.h in Headers */ = {isa = PBXBuildFile; fileRef = 177AC5EE15C50F6E00A3658D /* FLXPostgresConnectionTypeHandling.h */; };
diff --git a/Frameworks/PostgresKit/Source/FLXConstants.h b/Frameworks/PostgresKit/Source/FLXConstants.h
index 95ab17f6..b3aeaed9 100644
--- a/Frameworks/PostgresKit/Source/FLXConstants.h
+++ b/Frameworks/PostgresKit/Source/FLXConstants.h
@@ -20,14 +20,6 @@
// License for the specific language governing permissions and limitations under
// the License.
-// Result set row types
-typedef enum
-{
- FLXPostgresResultRowAsArray = 1,
- FLXPostgresResultRowAsDictionary = 2
-}
-FLXPostgresResultRowType;
-
// Defaults
extern NSString *FLXPostgresConnectionDefaultEncoding;
extern NSString *FLXPostgresConnectionErrorDomain;
@@ -39,3 +31,14 @@ extern NSString *FLXPostgresParameterClientEncoding;
extern NSString *FLXPostgresParameterSuperUser;
extern NSString *FLXPostgresParameterTimeZone;
extern NSString *FLXPostgresParameterIntegerDateTimes;
+
+// Value specifiers
+extern const char *FLXPostgresResultValueMacAddr;
+extern const char *FLXPostgresResultValueInet;
+extern const char *FLXPostgresResultValueCidr;
+extern const char *FLXPostgresResultValueDate;
+extern const char *FLXPostgresResultValueTime;
+extern const char *FLXPostgresResultValueTimeTZ;
+extern const char *FLXPostgresResultValueTimestamp;
+extern const char *FLXPostgresResultValueTimestmpTZ;
+extern const char *FLXPostgresResultValueInterval;
diff --git a/Frameworks/PostgresKit/Source/FLXConstants.m b/Frameworks/PostgresKit/Source/FLXConstants.m
index 3dc68ff9..14771072 100644
--- a/Frameworks/PostgresKit/Source/FLXConstants.m
+++ b/Frameworks/PostgresKit/Source/FLXConstants.m
@@ -29,3 +29,13 @@ NSString *FLXPostgresParameterClientEncoding = @"client_encoding";
NSString *FLXPostgresParameterSuperUser = @"is_superuser";
NSString *FLXPostgresParameterTimeZone = @"TimeZone";
NSString *FLXPostgresParameterIntegerDateTimes = @"integer_datetimes";
+
+const char *FLXPostgresResultValueMacAddr = "%macaddr";
+const char *FLXPostgresResultValueInet = "%inet";
+const char *FLXPostgresResultValueCidr = "%cidr";
+const char *FLXPostgresResultValueDate = "%date";
+const char *FLXPostgresResultValueTime = "%time";
+const char *FLXPostgresResultValueTimeTZ = "%timetz";
+const char *FLXPostgresResultValueTimestamp = "%timestamp";
+const char *FLXPostgresResultValueTimestmpTZ = "%timestamptz";
+const char *FLXPostgresResultValueInterval = "%interval";
diff --git a/Frameworks/PostgresKit/Source/FLXPostgresResult.h b/Frameworks/PostgresKit/Source/FLXPostgresResult.h
index b779e1b1..4148ba3d 100644
--- a/Frameworks/PostgresKit/Source/FLXPostgresResult.h
+++ b/Frameworks/PostgresKit/Source/FLXPostgresResult.h
@@ -20,10 +20,16 @@
// License for the specific language governing permissions and limitations under
// the License.
-#import "FLXConstants.h"
-
@class FLXPostgresConnection;
+// Result set row types
+typedef enum
+{
+ FLXPostgresResultRowAsArray = 1,
+ FLXPostgresResultRowAsDictionary = 2
+}
+FLXPostgresResultRowType;
+
@interface FLXPostgresResult : NSObject
{
void *_result;
diff --git a/Frameworks/PostgresKit/Source/FLXPostgresResult.m b/Frameworks/PostgresKit/Source/FLXPostgresResult.m
index 0d9656d0..9fd44d8c 100644
--- a/Frameworks/PostgresKit/Source/FLXPostgresResult.m
+++ b/Frameworks/PostgresKit/Source/FLXPostgresResult.m
@@ -215,9 +215,18 @@ static NSString *FLXPostgresResultError = @"FLXPostgresResultError";
if (!bytes || !length) return nil;
return [NSData dataWithBytes:bytes length:length];
- }
+ }
+
+ [handler setRow:row];
+ [handler setType:type];
+ [handler setColumn:column];
+ [handler setResult:_result];
+
+ id object = [handler objectFromResult];
+
+ [handler setResult:nil];
- return [handler objectFromResult:_result atRow:row column:column];
+ return object;
}
/**
diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m b/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m
index 25b74b4c..3fe08d97 100644
--- a/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m
+++ b/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m
@@ -43,18 +43,23 @@ static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] =
@interface FLXPostgresTypeDateTimeHandler ()
-- (NSDate *)_dateFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column;
-- (id)_timeIntervalFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column;
-
-- (id)_timeFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column type:(FLXPostgresOid)type;
-- (id)_timestmpFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column type:(FLXPostgresOid)type;
+- (id)_timeFromResult;
+- (id)_timestmpFromResult;
+- (id)_timeIntervalFromResult;
+- (NSDate *)_dateFromResult;
- (NSDate *)_dateFromComponents:(NSDateComponents *)components;
@end
@implementation FLXPostgresTypeDateTimeHandler
+@synthesize row = _row;
+@synthesize type = _type;
+@synthesize column = _column;
+@synthesize result = _result;
+@synthesize connection = _connection;
+
#pragma mark -
#pragma mark Protocol Implementation
@@ -73,23 +78,21 @@ static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] =
return nil;
}
-- (id)objectFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column
-{
- FLXPostgresOid type = PQftype(result, column);
-
- switch (type)
+- (id)objectFromResult
+{
+ switch (_type)
{
case FLXPostgresOidDate:
- return [self _dateFromResult:result atRow:row column:column];
+ return [self _dateFromResult];
case FLXPostgresOidTime:
case FLXPostgresOidTimeTZ:
case FLXPostgresOidAbsTime:
- return [self _timeFromResult:result atRow:row column:column type:type];
+ return [self _timeFromResult];
case FLXPostgresOidTimestamp:
case FLXPostgresOidTimestampTZ:
- return [self _timestmpFromResult:result atRow:row column:column type:type];
+ return [self _timestmpFromResult];
case FLXPostgresOidInterval:
- return [self _timeIntervalFromResult:result atRow:row column:column];
+ return [self _timeIntervalFromResult];
default:
return [NSNull null];
}
@@ -100,18 +103,14 @@ static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] =
/**
* Returns an NSDate created from a date value.
- *
- * @param result The result to extract the value from.
- * @param row The row to extract the value from.
- * @param column The column to extract the value from.
*
* @return The NSDate representation.
*/
-- (id)_dateFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column
+- (id)_dateFromResult
{
PGdate date;
- if (!PQgetf(result, row, "%date", column, &date)) return [NSNull null];
+ if (!PQgetf(_result, _row, FLXPostgresResultValueDate, _column, &date)) return [NSNull null];
NSDateComponents *components = [[NSDateComponents alloc] init];
@@ -124,18 +123,14 @@ static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] =
/**
* Converts a time interval value to a FLXPostgresTimeInterval instance.
- *
- * @param result The result to extract the value from.
- * @param row The row to extract the value from.
- * @param column The column to extract the value from.
*
* @return The FLXPostgresTimeInterval representation.
*/
-- (id)_timeIntervalFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column
+- (id)_timeIntervalFromResult
{
PGinterval interval;
- if (!PQgetf(result, row, "%interval", column, &interval)) return [NSNull null];
+ if (!PQgetf(_result, _row, FLXPostgresResultValueInterval, _column, &interval)) return [NSNull null];
return [FLXPostgresTimeInterval intervalWithPGInterval:&interval];
}
@@ -145,20 +140,15 @@ static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] =
*
* @note The date part should be ignored as it's set to a default value.
*
- * @param result The result to extract the value from.
- * @param row The row to extract the value from.
- * @param column The column to extract the value from.
- * @type type The type to be converted from (handles times and times with a time zone).
- *
* @return The object representation.
*/
-- (id)_timeFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column type:(FLXPostgresOid)type
+- (id)_timeFromResult
{
PGtime time;
- BOOL hasTimeZone = type == FLXPostgresOidTimeTZ;
+ BOOL hasTimeZone = _type == FLXPostgresOidTimeTZ;
- if (!PQgetf(result, row, hasTimeZone ? "%timetz" : "%time", column, &time)) return [NSNull null];
+ if (!PQgetf(_result, _row, hasTimeZone ? FLXPostgresResultValueTimeTZ : FLXPostgresResultValueTime, _column, &time)) return [NSNull null];
NSDateComponents *components = [[NSDateComponents alloc] init];
@@ -179,20 +169,15 @@ static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] =
/**
* Returns a native object created from a timestamp value.
*
- * @param result The result to extract the value from.
- * @param row The row to extract the value from.
- * @param column The column to extract the value from.
- * @type type The type to be converted from (handles timestamps and timestamps with a time zone).
- *
* @return The object representation.
*/
-- (id)_timestmpFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column type:(FLXPostgresOid)type
+- (id)_timestmpFromResult
{
PGtimestamp timestamp;
- BOOL hasTimeZone = type == FLXPostgresOidTimestampTZ;
+ BOOL hasTimeZone = _type == FLXPostgresOidTimestampTZ;
- if (!PQgetf(result, row, hasTimeZone ? "%timstamptz" : "%timestamp", column, &timestamp)) return [NSNull null];
+ if (!PQgetf(_result, _row, hasTimeZone ? FLXPostgresResultValueTimestmpTZ : FLXPostgresResultValueTimestamp, _column, &timestamp)) return [NSNull null];
FLXPostgresTimeTZ *timestampTZ = nil;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:timestamp.epoch];
diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.h b/Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.h
index 1b3146b8..7c639100 100644
--- a/Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.h
+++ b/Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.h
@@ -30,6 +30,8 @@
const PGresult *_result;
+ FLXPostgresOid _type;
+
FLXPostgresConnection *_connection;
}
diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.m b/Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.m
index a7b98909..41903d91 100644
--- a/Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.m
+++ b/Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.m
@@ -30,6 +30,7 @@
- (id)initWithConnection:(FLXPostgresConnection *)connection
{
if ((self = [super init])) {
+ _type = -1;
_result = nil;
_connection = [connection retain];
}
@@ -41,6 +42,8 @@
- (void)dealloc
{
+ _result = nil;
+
if (_connection) [_connection release], _connection = nil;
[super dealloc];
diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeHandlerProtocol.h b/Frameworks/PostgresKit/Source/FLXPostgresTypeHandlerProtocol.h
index a0c04c26..8b22c158 100644
--- a/Frameworks/PostgresKit/Source/FLXPostgresTypeHandlerProtocol.h
+++ b/Frameworks/PostgresKit/Source/FLXPostgresTypeHandlerProtocol.h
@@ -27,6 +27,14 @@
*/
@protocol FLXPostgresTypeHandlerProtocol
+@property (readwrite, assign) NSUInteger row;
+
+@property (readwrite, assign) NSUInteger column;
+
+@property (readwrite, assign) FLXPostgresOid type;
+
+@property (readwrite, assign) const PGresult *result;
+
/**
* The remote type values handled by this class (terminated by 0).
*
@@ -51,12 +59,8 @@
/**
* Convert the value at the specified row and column in the supplied result to a native object.
*
- * @param result The result to extract the value from.
- * @param row The row to extract the value from.
- * @param column The column to extract the value from.
- *
* @return An object represenation of the data.
*/
-- (id)objectFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column;
+- (id)objectFromResult;
@end
diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m b/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m
index 467a8821..25fd3839 100644
--- a/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m
+++ b/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m
@@ -48,6 +48,12 @@ static FLXPostgresOid FLXPostgresTypeNumberTypes[] =
@implementation FLXPostgresTypeNumberHandler
+@synthesize row = _row;
+@synthesize type = _type;
+@synthesize column = _column;
+@synthesize result = _result;
+@synthesize connection = _connection;
+
#pragma mark -
#pragma mark Integer
@@ -145,15 +151,14 @@ static FLXPostgresOid FLXPostgresTypeNumberTypes[] =
return nil;
}
-- (id)objectFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column
-{
- FLXPostgresOid type = PQftype(result, column);
- NSUInteger length = PQgetlength(result, row, column);
- const void *bytes = PQgetvalue(result, row, column);
+- (id)objectFromResult
+{
+ NSUInteger length = PQgetlength(_result, _row, _column);
+ const void *bytes = PQgetvalue(_result, _row, _column);
- if (!bytes || !length) return nil;
+ if (!bytes || !length) return [NSNull null];
- switch (type)
+ switch (_type)
{
case FLXPostgresOidInt8:
case FLXPostgresOidInt2:
diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m b/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m
index 2c49ee64..dab3dd41 100644
--- a/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m
+++ b/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m
@@ -45,15 +45,20 @@ static FLXPostgresOid FLXPostgresTypeStringTypes[] =
@interface FLXPostgresTypeStringHandler ()
-- (id)_stringFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column;
-- (id)_macAddressFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column;
-- (id)_inetAddressFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column type:(FLXPostgresOid)type;
+- (id)_stringFromResult;
+- (id)_macAddressFromResult;
+- (id)_inetAddressFromResult;
@end
-
@implementation FLXPostgresTypeStringHandler
+@synthesize row = _row;
+@synthesize type = _type;
+@synthesize column = _column;
+@synthesize result = _result;
+@synthesize connection = _connection;
+
#pragma mark -
#pragma mark Protocol Implementation
@@ -72,21 +77,10 @@ static FLXPostgresOid FLXPostgresTypeStringTypes[] =
return [NSArray arrayWithObject:@"NSCFString"];
}
-- (id)objectFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column
-{
- FLXPostgresOid type = PQftype(result, column);
-
- _row = row;
- _column = column;
- _result = result;
-
- switch (type)
+- (id)objectFromResult
+{
+ switch (_type)
{
- case FLXPostgresOidMacAddr:
- return [self _macAddressFromResult:result atRow:row column:column];
- case FLXPostgresOidInetAddr:
- case FLXPostgresOidCidrAddr:
- return [self _inetAddressFromResult:result atRow:row column:column type:type];
case FLXPostgresOidText:
case FLXPostgresOidChar:
case FLXPostgresOidName:
@@ -97,7 +91,12 @@ static FLXPostgresOid FLXPostgresTypeStringTypes[] =
case FLXPostgresOidBit:
case FLXPostgresOidVarBit:
case FLXPostgresOidUnknown:
- return [self _stringFromResult:result atRow:row column:column];
+ return [self _stringFromResult];
+ case FLXPostgresOidMacAddr:
+ return [self _macAddressFromResult];
+ case FLXPostgresOidInetAddr:
+ case FLXPostgresOidCidrAddr:
+ return [self _inetAddressFromResult];
default:
return [NSNull null];
}
@@ -109,16 +108,12 @@ static FLXPostgresOid FLXPostgresTypeStringTypes[] =
/**
* Converts a char value to a string.
*
- * @param result The result to extract the value from.
- * @param row The row to extract the value from.
- * @param column The column to extract the value from.
- *
* @return A string representation of the value.
*/
-- (id)_stringFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column
+- (id)_stringFromResult
{
- const void *bytes = PQgetvalue(result, row, column);
- NSUInteger length = PQgetlength(result, row, column);
+ const void *bytes = PQgetvalue(_result, _row, _column);
+ NSUInteger length = PQgetlength(_result, _row, _column);
if (!bytes || !length) return [NSNull null];
@@ -128,17 +123,13 @@ static FLXPostgresOid FLXPostgresTypeStringTypes[] =
/**
* Converts a MAC address value to a string.
*
- * @param result The result to extract the value from.
- * @param row The row to extract the value from.
- * @param column The column to extract the value from.
- *
* @return A string representation of the MAC address.
*/
-- (id)_macAddressFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column
+- (id)_macAddressFromResult
{
PGmacaddr address;
- if (!PQgetf(result, row, "%macaddr", column, &address)) return [NSNull null];
+ if (!PQgetf(_result, _row, FLXPostgresResultValueMacAddr, _column, &address)) return [NSNull null];
return [NSString stringWithFormat:@"%02d:%02d:%02d:%02d:%02d:%02d", address.a, address.b, address.c, address.d, address.e, address.f];
}
@@ -146,18 +137,13 @@ static FLXPostgresOid FLXPostgresTypeStringTypes[] =
/**
* Converts a network address value to a string.
*
- * @param result The result to extract the value from.
- * @param row The row to extract the value from.
- * @param column The column to extract the value from.
- * @param type The type of the value to extract.
- *
* @return A string representation of the network address.
*/
-- (id)_inetAddressFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column type:(FLXPostgresOid)type
+- (id)_inetAddressFromResult
{
PGinet inet;
- if (!PQgetf(result, row, type == FLXPostgresOidInetAddr ? "%inet" : "%cidr", column, &inet)) return [NSNull null];
+ if (!PQgetf(_result, _row, _type == FLXPostgresOidInetAddr ? FLXPostgresResultValueInet : FLXPostgresResultValueCidr, _column, &inet)) return [NSNull null];
char ip[80];
struct sockaddr *sa = (struct sockaddr *)inet.sa_buf;