aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/PostgresKit/Source
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2012-09-09 08:45:15 +0000
committerstuconnolly <stuart02@gmail.com>2012-09-09 08:45:15 +0000
commit8c8d1d7ca715c6534e02b7a4f78adf0d8c590185 (patch)
tree9ccd70f83b155ae66e79a4901b9893b5d299158d /Frameworks/PostgresKit/Source
parent686fa6b54f408a3d81e8467aad8a5238edf35466 (diff)
downloadsequelpro-8c8d1d7ca715c6534e02b7a4f78adf0d8c590185.tar.gz
sequelpro-8c8d1d7ca715c6534e02b7a4f78adf0d8c590185.tar.bz2
sequelpro-8c8d1d7ca715c6534e02b7a4f78adf0d8c590185.zip
Add MAC address type support.
Diffstat (limited to 'Frameworks/PostgresKit/Source')
-rw-r--r--Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m1
-rw-r--r--Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m39
-rw-r--r--Frameworks/PostgresKit/Source/FLXPostgresTypes.h14
3 files changed, 45 insertions, 9 deletions
diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m b/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m
index d9395398..f3342684 100644
--- a/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m
+++ b/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m
@@ -31,6 +31,7 @@ static FLXPostgresOid FLXPostgresTypeNumberTypes[] =
FLXPostgresOidFloat8,
FLXPostgresOidBool,
FLXPostgresOidOid,
+ FLXPostgresOidMoney,
0
};
diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m b/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m
index 2b1d4330..7d328aa1 100644
--- a/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m
+++ b/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m
@@ -29,13 +29,23 @@ static FLXPostgresOid FLXPostgresTypeStringTypes[] =
FLXPostgresOidChar,
FLXPostgresOidName,
FLXPostgresOidNumeric,
- FLXPostgresOidVarchar,
+ FLXPostgresOidVarChar,
FLXPostgresOidXML,
FLXPostgresOidUUID,
+ FLXPostgresOidBit,
+ FLXPostgresOidVarBit,
+ FLXPostgresOidMacAddr,
FLXPostgresOidUnknown,
0
};
+@interface FLXPostgresTypeStringHandler ()
+
+- (NSString *)_macAddressFromResult:(const PGresult *)result atRow:(unsigned int)row column:(unsigned int)column;
+
+@end
+
+
@implementation FLXPostgresTypeStringHandler
#pragma mark -
@@ -58,12 +68,37 @@ static FLXPostgresOid FLXPostgresTypeStringTypes[] =
- (id)objectFromResult:(const PGresult *)result atRow:(unsigned int)row column:(unsigned int)column
{
+ if (PQftype(result, column) == FLXPostgresOidMacAddr) {
+ return [self _macAddressFromResult:result atRow:row column:column];
+ }
+
const void *bytes = PQgetvalue(result, row, column);
NSUInteger length = PQgetlength(result, row, column);
- if (!bytes || !length) return @"";
+ if (!bytes || !length) return nil;
return [[[NSString alloc] initWithBytes:bytes length:length encoding:[_connection stringEncoding]] autorelease];
}
+#pragma mark -
+#pragma mark Private API
+
+/**
+ * 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.
+ */
+- (NSString *)_macAddressFromResult:(const PGresult *)result atRow:(unsigned int)row column:(unsigned int)column
+{
+ PGmacaddr address;
+
+ if (!PQgetf(result, row, "%macaddr", column, &address)) return nil;
+
+ return [NSString stringWithFormat:@"%02d:%02d:%02d:%02d:%02d:%02d", address.a, address.b, address.c, address.d, address.e, address.f];
+}
+
@end
diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypes.h b/Frameworks/PostgresKit/Source/FLXPostgresTypes.h
index 039a8282..625a7083 100644
--- a/Frameworks/PostgresKit/Source/FLXPostgresTypes.h
+++ b/Frameworks/PostgresKit/Source/FLXPostgresTypes.h
@@ -71,11 +71,11 @@ enum
FLXPostgresOidCircle = 718, // Currently not supported
// Monetary
- FLXPostgresOidMoney = 790, // Currently not supported
+ FLXPostgresOidMoney = 790, // NumberHandler => NSNumber
// Network
- FLXPostgresOidMacAddr = 829, // Currently not supported
- FLXPostgresOidIPAddr = 869, // Currently not supported
+ FLXPostgresOidMacAddr = 829, // StringHandler => NSString
+ FLXPostgresOidIPAddr = 869, //
// Arrays
FLXPostgresOidArrayBool = 1000, // Currently not supported
@@ -94,7 +94,7 @@ enum
// Text
FLXPostgresOidChar = 1042, // StringHandler => NSString
- FLXPostgresOidVarchar = 1043, // StringHandler => NSString
+ FLXPostgresOidVarChar = 1043, // StringHandler => NSString
// Date/time
FLXPostgresOidDate = 1082, // DateHandler => NSDate
@@ -104,9 +104,9 @@ enum
FLXPostgresOidInterval = 1186, // DateHandler => FLXPostgresTimeInterval
FLXPostgresOidTimeTZ = 1266, // DateHandler => FLXPostgresTimeTZ
- // Binary
- FLXPostgresOidBit = 1560, // Currently not supported
- FLXPostgresOidVarbit = 1562, // Currently not supported
+ // Bit strings
+ FLXPostgresOidBit = 1560, // StringHandler => NSString
+ FLXPostgresOidVarBit = 1562, // StringHandler => NSString
// Numeric
FLXPostgresOidNumeric = 1700, // StringHandler => NSString