aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/PostgresKit
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2012-09-27 22:49:52 +0000
committerstuconnolly <stuart02@gmail.com>2012-09-27 22:49:52 +0000
commit901180573c489a08ac4f22a05c0a80bc51307d5f (patch)
tree27f7cac294c36bbe3b6900a003aea95d777462e6 /Frameworks/PostgresKit
parenta12ab1dd775188342087b848653565d227dd8ecb (diff)
downloadsequelpro-901180573c489a08ac4f22a05c0a80bc51307d5f.tar.gz
sequelpro-901180573c489a08ac4f22a05c0a80bc51307d5f.tar.bz2
sequelpro-901180573c489a08ac4f22a05c0a80bc51307d5f.zip
Add a binary data handler.
Diffstat (limited to 'Frameworks/PostgresKit')
-rw-r--r--Frameworks/PostgresKit/PostgresKit.xcodeproj/project.pbxproj20
-rw-r--r--Frameworks/PostgresKit/Source/PGConstants.h1
-rw-r--r--Frameworks/PostgresKit/Source/PGConstants.m1
-rw-r--r--Frameworks/PostgresKit/Source/PGPostgresConnectionTypeHandling.m2
-rw-r--r--Frameworks/PostgresKit/Source/PGPostgresTypeBinaryHandler.h63
-rw-r--r--Frameworks/PostgresKit/Source/PGPostgresTypeBinaryHandler.m103
6 files changed, 188 insertions, 2 deletions
diff --git a/Frameworks/PostgresKit/PostgresKit.xcodeproj/project.pbxproj b/Frameworks/PostgresKit/PostgresKit.xcodeproj/project.pbxproj
index c3928a59..ad2a51ee 100644
--- a/Frameworks/PostgresKit/PostgresKit.xcodeproj/project.pbxproj
+++ b/Frameworks/PostgresKit/PostgresKit.xcodeproj/project.pbxproj
@@ -56,6 +56,8 @@
177C9BAB15CD37E000128642 /* PGPostgresConnectionEncoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 177C9BA915CD37E000128642 /* PGPostgresConnectionEncoding.h */; };
177C9BAC15CD37E000128642 /* PGPostgresConnectionEncoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 177C9BAA15CD37E000128642 /* PGPostgresConnectionEncoding.m */; };
17E595F214F3058F0054EE08 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 17E595F114F3058F0054EE08 /* Foundation.framework */; };
+ 17F7963116150C0100E21D82 /* PGPostgresTypeBinaryHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 17F7962F16150C0100E21D82 /* PGPostgresTypeBinaryHandler.h */; };
+ 17F7963216150C0100E21D82 /* PGPostgresTypeBinaryHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 17F7963016150C0100E21D82 /* PGPostgresTypeBinaryHandler.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -124,6 +126,8 @@
177C9BAA15CD37E000128642 /* PGPostgresConnectionEncoding.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresConnectionEncoding.m; sourceTree = "<group>"; };
17E595F114F3058F0054EE08 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
17F5B77C15C9D092006DA689 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
+ 17F7962F16150C0100E21D82 /* PGPostgresTypeBinaryHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresTypeBinaryHandler.h; sourceTree = "<group>"; };
+ 17F7963016150C0100E21D82 /* PGPostgresTypeBinaryHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresTypeBinaryHandler.m; sourceTree = "<group>"; };
8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Resources/Info.plist; sourceTree = "<group>"; };
8DC2EF5B0486A6940098B216 /* PostgresKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PostgresKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
@@ -304,6 +308,7 @@
173D4E9F15BAB2A80007F267 /* PostgresKit.h */,
177AC67D15C53FA400A3658D /* PGPostgresKitPrivateAPI.h */,
1731F52B15F48B4400D973EB /* Domain */,
+ 17F7962A1615001D00E21D82 /* Protocols */,
173D513315BBE4230007F267 /* Connection */,
173D508D15BBD99B0007F267 /* Constants */,
173D4E5015BAB17A0007F267 /* Types */,
@@ -315,7 +320,6 @@
isa = PBXGroup;
children = (
173D4F5615BAD3030007F267 /* PGPostgresTypes.h */,
- 173D4EA015BAB2A80007F267 /* PGPostgresTypeHandlerProtocol.h */,
1724CC8715FB4BF400AB2291 /* Domain */,
17F5B62215C7D1DA006DA689 /* Handlers */,
);
@@ -362,7 +366,6 @@
children = (
173D4E9515BAB2A80007F267 /* PGPostgresConnection.h */,
173D4E9615BAB2A80007F267 /* PGPostgresConnection.m */,
- 173D513415BBE50D0007F267 /* PGPostgresConnectionDelegate.h */,
1731F50515F369FE00D973EB /* Encoding */,
1731F50415F369E400D973EB /* Query */,
1731F50615F36A3E00D973EB /* Other */,
@@ -375,6 +378,8 @@
children = (
170465CC15C2960F00DC5BE5 /* PGPostgresTypeHandler.h */,
170465CD15C2960F00DC5BE5 /* PGPostgresTypeHandler.m */,
+ 17F7962F16150C0100E21D82 /* PGPostgresTypeBinaryHandler.h */,
+ 17F7963016150C0100E21D82 /* PGPostgresTypeBinaryHandler.m */,
173D4E5815BAB1DD0007F267 /* PGPostgresTypeStringHandler.h */,
173D4E5915BAB1DD0007F267 /* PGPostgresTypeStringHandler.m */,
173D4E5615BAB1DD0007F267 /* PGPostgresTypeNumberHandler.h */,
@@ -385,6 +390,15 @@
name = Handlers;
sourceTree = "<group>";
};
+ 17F7962A1615001D00E21D82 /* Protocols */ = {
+ isa = PBXGroup;
+ children = (
+ 173D513415BBE50D0007F267 /* PGPostgresConnectionDelegate.h */,
+ 173D4EA015BAB2A80007F267 /* PGPostgresTypeHandlerProtocol.h */,
+ );
+ name = Protocols;
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
@@ -415,6 +429,7 @@
1731F52E15F48BA500D973EB /* PGPostgresError.h in Headers */,
1724CC9215FB4CC200AB2291 /* PGPostgresTimeTZ.h in Headers */,
1724CD5915FB8A3300AB2291 /* PGPostgresTimeInterval.h in Headers */,
+ 17F7963116150C0100E21D82 /* PGPostgresTypeBinaryHandler.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -530,6 +545,7 @@
1731F52F15F48BA500D973EB /* PGPostgresError.m in Sources */,
1724CC9315FB4CC200AB2291 /* PGPostgresTimeTZ.m in Sources */,
1724CD5A15FB8A3300AB2291 /* PGPostgresTimeInterval.m in Sources */,
+ 17F7963216150C0100E21D82 /* PGPostgresTypeBinaryHandler.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/Frameworks/PostgresKit/Source/PGConstants.h b/Frameworks/PostgresKit/Source/PGConstants.h
index d8ac3641..fc0e081c 100644
--- a/Frameworks/PostgresKit/Source/PGConstants.h
+++ b/Frameworks/PostgresKit/Source/PGConstants.h
@@ -53,6 +53,7 @@ extern const char *PGPostgresResultValueInt4;
extern const char *PGPostgresResultValueInt8;
extern const char *PGPostgresResultValueFloat4;
extern const char *PGPostgresResultValueFloat8;
+extern const char *PGPostgresResultValueByteA;
// Connection parameters
extern const char *PGPostgresKitApplicationName;
diff --git a/Frameworks/PostgresKit/Source/PGConstants.m b/Frameworks/PostgresKit/Source/PGConstants.m
index 169dd85c..4cac546e 100644
--- a/Frameworks/PostgresKit/Source/PGConstants.m
+++ b/Frameworks/PostgresKit/Source/PGConstants.m
@@ -53,6 +53,7 @@ const char *PGPostgresResultValueInt4 = "%int4";
const char *PGPostgresResultValueInt8 = "%int8";
const char *PGPostgresResultValueFloat4 = "%float4";
const char *PGPostgresResultValueFloat8 = "%float8";
+const char *PGPostgresResultValueByteA = "%bytea";
// Connection parameters
const char *PGPostgresKitApplicationName = "PostgresKit";
diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnectionTypeHandling.m b/Frameworks/PostgresKit/Source/PGPostgresConnectionTypeHandling.m
index ddd6e745..22394d88 100644
--- a/Frameworks/PostgresKit/Source/PGPostgresConnectionTypeHandling.m
+++ b/Frameworks/PostgresKit/Source/PGPostgresConnectionTypeHandling.m
@@ -23,6 +23,7 @@
#import "PGPostgresTypeStringHandler.h"
#import "PGPostgresTypeNumberHandler.h"
#import "PGPostgresTypeDateTimeHandler.h"
+#import "PGPostgresTypeBinaryHandler.h"
#import "PGPostgresException.h"
@implementation PGPostgresConnection (PGPostgresConnectionTypeHandling)
@@ -41,6 +42,7 @@
[self registerTypeHandler:[PGPostgresTypeStringHandler class]];
[self registerTypeHandler:[PGPostgresTypeNumberHandler class]];
[self registerTypeHandler:[PGPostgresTypeDateTimeHandler class]];
+ [self registerTypeHandler:[PGPostgresTypeBinaryHandler class]];
}
/**
diff --git a/Frameworks/PostgresKit/Source/PGPostgresTypeBinaryHandler.h b/Frameworks/PostgresKit/Source/PGPostgresTypeBinaryHandler.h
new file mode 100644
index 00000000..067c0d8c
--- /dev/null
+++ b/Frameworks/PostgresKit/Source/PGPostgresTypeBinaryHandler.h
@@ -0,0 +1,63 @@
+//
+// $Id$
+//
+// PGPostgresTypeBinaryHandler.h
+// PostgresKit
+//
+// Created by Stuart Connolly (stuconnolly.com) on September 28, 2012.
+// Copyright (c) 2012 Stuart Connolly. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+
+#import "PGPostgresTypeHandler.h"
+
+@interface PGPostgresTypeBinaryHandler : PGPostgresTypeHandler <PGPostgresTypeHandlerProtocol>
+{
+ NSUInteger _row;
+ NSUInteger _column;
+
+ const PGresult *_result;
+
+ PGPostgresOid _type;
+}
+
+/**
+ * @property The row within the result the handler is being queried about.
+ */
+@property (readwrite, assign) NSUInteger row;
+
+/**
+ * @property The column within the result the handler is being queried about.
+ */
+@property (readwrite, assign) NSUInteger column;
+
+/**
+ * @property The type of data within the result the handler is being queried about.
+ */
+@property (readwrite, assign) PGPostgresOid type;
+
+/**
+ * @property The result the handler is being asked to operate on.
+ */
+@property (readwrite, assign) const PGresult *result;
+
+@end
diff --git a/Frameworks/PostgresKit/Source/PGPostgresTypeBinaryHandler.m b/Frameworks/PostgresKit/Source/PGPostgresTypeBinaryHandler.m
new file mode 100644
index 00000000..f544fb39
--- /dev/null
+++ b/Frameworks/PostgresKit/Source/PGPostgresTypeBinaryHandler.m
@@ -0,0 +1,103 @@
+//
+// $Id$
+//
+// PGPostgresTypeBinaryHandler.m
+// PostgresKit
+//
+// Created by Stuart Connolly (stuconnolly.com) on September 28, 2012.
+// Copyright (c) 2012 Stuart Connolly. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+
+#import "PGPostgresTypeBinaryHandler.h"
+
+static PGPostgresOid PGPostgresTypeBinaryTypes[] =
+{
+ PGPostgresOidByteData,
+ 0
+};
+
+@interface PGPostgresTypeBinaryHandler ()
+
+- (id)_binaryDataFromResult;
+
+@end
+
+
+@implementation PGPostgresTypeBinaryHandler
+
+@synthesize row = _row;
+@synthesize type = _type;
+@synthesize column = _column;
+@synthesize result = _result;
+
+#pragma mark -
+#pragma mark Protocol Implementation
+
+- (PGPostgresOid *)remoteTypes
+{
+ return PGPostgresTypeBinaryTypes;
+}
+
+- (Class)nativeClass
+{
+ return [NSString class];
+}
+
+- (NSArray *)classAliases
+{
+ return nil;
+}
+
+- (id)objectFromResult
+{
+ if (!_result || !_type) return [NSNull null];
+
+ switch (_type)
+ {
+ case PGPostgresOidByteData:
+ return [self _binaryDataFromResult];
+ }
+
+ return [NSNull null];
+}
+
+#pragma mark -
+#pragma mark Private API
+
+/**
+ * Converts a binary data value to an NSData instance.
+ *
+ * @return The NSData representation of the data.
+ */
+- (id)_binaryDataFromResult
+{
+ PGbytea data;
+
+ if (!PQgetf(_result, _row, PGPostgresResultValueByteA, _column)) return [NSNull null];
+
+ if (!data.data || !data.len) return [NSNull null];
+
+ return [NSData dataWithBytes:data.data length:data.len];
+}
+
+@end