From 88263061eb326e58fe882bc91d09f52d3d49628d Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Wed, 26 Sep 2012 07:23:08 +0000 Subject: Change project prefix. --- .../PostgresKit.xcodeproj/project.pbxproj | 328 +++++++------- Frameworks/PostgresKit/Source/FLXConstants.h | 67 --- Frameworks/PostgresKit/Source/FLXConstants.m | 67 --- .../PostgresKit/Source/FLXPostgresConnection.h | 101 ----- .../PostgresKit/Source/FLXPostgresConnection.m | 483 --------------------- .../Source/FLXPostgresConnectionDelegate.h | 65 --- .../Source/FLXPostgresConnectionEncoding.h | 39 -- .../Source/FLXPostgresConnectionEncoding.m | 197 --------- .../Source/FLXPostgresConnectionParameters.h | 56 --- .../Source/FLXPostgresConnectionParameters.m | 220 ---------- .../Source/FLXPostgresConnectionQueryExecution.h | 38 -- .../Source/FLXPostgresConnectionQueryExecution.m | 314 -------------- .../Source/FLXPostgresConnectionQueryPreparation.h | 30 -- .../Source/FLXPostgresConnectionQueryPreparation.m | 108 ----- .../Source/FLXPostgresConnectionTypeHandling.h | 34 -- .../Source/FLXPostgresConnectionTypeHandling.m | 107 ----- .../Source/FLXPostgresConnectionUtils.h | 33 -- .../Source/FLXPostgresConnectionUtils.m | 133 ------ Frameworks/PostgresKit/Source/FLXPostgresError.h | 74 ---- Frameworks/PostgresKit/Source/FLXPostgresError.m | 129 ------ .../PostgresKit/Source/FLXPostgresException.h | 28 -- .../PostgresKit/Source/FLXPostgresException.m | 64 --- .../PostgresKit/Source/FLXPostgresKitPrivateAPI.h | 46 -- Frameworks/PostgresKit/Source/FLXPostgresResult.h | 84 ---- Frameworks/PostgresKit/Source/FLXPostgresResult.m | 308 ------------- .../PostgresKit/Source/FLXPostgresStatement.h | 44 -- .../PostgresKit/Source/FLXPostgresStatement.m | 81 ---- .../PostgresKit/Source/FLXPostgresTimeInterval.h | 85 ---- .../PostgresKit/Source/FLXPostgresTimeInterval.m | 76 ---- Frameworks/PostgresKit/Source/FLXPostgresTimeTZ.h | 62 --- Frameworks/PostgresKit/Source/FLXPostgresTimeTZ.m | 84 ---- .../Source/FLXPostgresTypeDateTimeHandler.h | 55 --- .../Source/FLXPostgresTypeDateTimeHandler.m | 213 --------- .../PostgresKit/Source/FLXPostgresTypeHandler.h | 38 -- .../PostgresKit/Source/FLXPostgresTypeHandler.m | 48 -- .../Source/FLXPostgresTypeHandlerProtocol.h | 78 ---- .../Source/FLXPostgresTypeNumberHandler.h | 56 --- .../Source/FLXPostgresTypeNumberHandler.m | 206 --------- .../Source/FLXPostgresTypeStringHandler.h | 56 --- .../Source/FLXPostgresTypeStringHandler.m | 163 ------- Frameworks/PostgresKit/Source/FLXPostgresTypes.h | 119 ----- Frameworks/PostgresKit/Source/PGConstants.h | 67 +++ Frameworks/PostgresKit/Source/PGConstants.m | 67 +++ .../PostgresKit/Source/PGPostgresConnection.h | 101 +++++ .../PostgresKit/Source/PGPostgresConnection.m | 483 +++++++++++++++++++++ .../Source/PGPostgresConnectionDelegate.h | 65 +++ .../Source/PGPostgresConnectionEncoding.h | 39 ++ .../Source/PGPostgresConnectionEncoding.m | 197 +++++++++ .../Source/PGPostgresConnectionParameters.h | 56 +++ .../Source/PGPostgresConnectionParameters.m | 220 ++++++++++ .../Source/PGPostgresConnectionQueryExecution.h | 38 ++ .../Source/PGPostgresConnectionQueryExecution.m | 314 ++++++++++++++ .../Source/PGPostgresConnectionQueryPreparation.h | 30 ++ .../Source/PGPostgresConnectionQueryPreparation.m | 108 +++++ .../Source/PGPostgresConnectionTypeHandling.h | 34 ++ .../Source/PGPostgresConnectionTypeHandling.m | 107 +++++ .../PostgresKit/Source/PGPostgresConnectionUtils.h | 33 ++ .../PostgresKit/Source/PGPostgresConnectionUtils.m | 133 ++++++ Frameworks/PostgresKit/Source/PGPostgresError.h | 74 ++++ Frameworks/PostgresKit/Source/PGPostgresError.m | 129 ++++++ .../PostgresKit/Source/PGPostgresException.h | 28 ++ .../PostgresKit/Source/PGPostgresException.m | 64 +++ .../PostgresKit/Source/PGPostgresKitPrivateAPI.h | 46 ++ Frameworks/PostgresKit/Source/PGPostgresResult.h | 84 ++++ Frameworks/PostgresKit/Source/PGPostgresResult.m | 308 +++++++++++++ .../PostgresKit/Source/PGPostgresStatement.h | 44 ++ .../PostgresKit/Source/PGPostgresTimeInterval.h | 85 ++++ .../PostgresKit/Source/PGPostgresTimeInterval.m | 76 ++++ Frameworks/PostgresKit/Source/PGPostgresTimeTZ.h | 62 +++ Frameworks/PostgresKit/Source/PGPostgresTimeTZ.m | 84 ++++ .../Source/PGPostgresTypeDateTimeHandler.h | 55 +++ .../Source/PGPostgresTypeDateTimeHandler.m | 213 +++++++++ .../PostgresKit/Source/PGPostgresTypeHandler.h | 38 ++ .../PostgresKit/Source/PGPostgresTypeHandler.m | 48 ++ .../Source/PGPostgresTypeHandlerProtocol.h | 78 ++++ .../Source/PGPostgresTypeNumberHandler.h | 56 +++ .../Source/PGPostgresTypeNumberHandler.m | 206 +++++++++ .../Source/PGPostgresTypeStringHandler.h | 56 +++ .../Source/PGPostgresTypeStringHandler.m | 163 +++++++ Frameworks/PostgresKit/Source/PGPostgresTypes.h | 119 +++++ Frameworks/PostgresKit/Source/PGostgresStatement.m | 81 ++++ .../PostgresKit/Source/PostgresKit-Prefix.pch | 4 +- Frameworks/PostgresKit/Source/PostgresKit.h | 16 +- 83 files changed, 4467 insertions(+), 4459 deletions(-) delete mode 100644 Frameworks/PostgresKit/Source/FLXConstants.h delete mode 100644 Frameworks/PostgresKit/Source/FLXConstants.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresConnection.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresConnection.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresConnectionDelegate.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresConnectionEncoding.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresConnectionEncoding.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresConnectionParameters.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresConnectionParameters.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresConnectionQueryExecution.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresConnectionQueryExecution.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresConnectionQueryPreparation.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresConnectionQueryPreparation.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresConnectionTypeHandling.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresConnectionTypeHandling.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresConnectionUtils.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresConnectionUtils.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresError.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresError.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresException.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresException.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresKitPrivateAPI.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresResult.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresResult.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresStatement.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresStatement.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresTimeInterval.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresTimeInterval.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresTimeTZ.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresTimeTZ.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresTypeHandlerProtocol.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.h delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m delete mode 100644 Frameworks/PostgresKit/Source/FLXPostgresTypes.h create mode 100644 Frameworks/PostgresKit/Source/PGConstants.h create mode 100644 Frameworks/PostgresKit/Source/PGConstants.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresConnection.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresConnection.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresConnectionDelegate.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresConnectionEncoding.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresConnectionEncoding.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresConnectionParameters.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresConnectionParameters.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresConnectionQueryExecution.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresConnectionQueryExecution.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresConnectionQueryPreparation.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresConnectionQueryPreparation.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresConnectionTypeHandling.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresConnectionTypeHandling.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresConnectionUtils.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresConnectionUtils.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresError.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresError.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresException.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresException.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresKitPrivateAPI.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresResult.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresResult.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresStatement.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresTimeInterval.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresTimeInterval.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresTimeTZ.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresTimeTZ.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresTypeDateTimeHandler.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresTypeDateTimeHandler.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresTypeHandler.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresTypeHandler.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresTypeHandlerProtocol.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresTypeNumberHandler.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresTypeNumberHandler.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresTypeStringHandler.h create mode 100644 Frameworks/PostgresKit/Source/PGPostgresTypeStringHandler.m create mode 100644 Frameworks/PostgresKit/Source/PGPostgresTypes.h create mode 100644 Frameworks/PostgresKit/Source/PGostgresStatement.m (limited to 'Frameworks/PostgresKit') diff --git a/Frameworks/PostgresKit/PostgresKit.xcodeproj/project.pbxproj b/Frameworks/PostgresKit/PostgresKit.xcodeproj/project.pbxproj index 24ff9f9f..da627b47 100644 --- a/Frameworks/PostgresKit/PostgresKit.xcodeproj/project.pbxproj +++ b/Frameworks/PostgresKit/PostgresKit.xcodeproj/project.pbxproj @@ -7,53 +7,53 @@ objects = { /* Begin PBXBuildFile section */ - 170465CE15C2960F00DC5BE5 /* FLXPostgresTypeHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 170465CC15C2960F00DC5BE5 /* FLXPostgresTypeHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 170465CF15C2960F00DC5BE5 /* FLXPostgresTypeHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 170465CD15C2960F00DC5BE5 /* FLXPostgresTypeHandler.m */; }; + 170465CE15C2960F00DC5BE5 /* PGPostgresTypeHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 170465CC15C2960F00DC5BE5 /* PGPostgresTypeHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 170465CF15C2960F00DC5BE5 /* PGPostgresTypeHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 170465CD15C2960F00DC5BE5 /* PGPostgresTypeHandler.m */; }; 1724C9B815F9ED8600AB2291 /* libpqtypes.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1724C9B715F9ED8600AB2291 /* libpqtypes.a */; }; - 1724CC9215FB4CC200AB2291 /* FLXPostgresTimeTZ.h in Headers */ = {isa = PBXBuildFile; fileRef = 1724CC9015FB4CC200AB2291 /* FLXPostgresTimeTZ.h */; }; - 1724CC9315FB4CC200AB2291 /* FLXPostgresTimeTZ.m in Sources */ = {isa = PBXBuildFile; fileRef = 1724CC9115FB4CC200AB2291 /* FLXPostgresTimeTZ.m */; }; + 1724CC9215FB4CC200AB2291 /* PGPostgresTimeTZ.h in Headers */ = {isa = PBXBuildFile; fileRef = 1724CC9015FB4CC200AB2291 /* PGPostgresTimeTZ.h */; }; + 1724CC9315FB4CC200AB2291 /* PGPostgresTimeTZ.m in Sources */ = {isa = PBXBuildFile; fileRef = 1724CC9115FB4CC200AB2291 /* PGPostgresTimeTZ.m */; }; 1724CD1515FB69EC00AB2291 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 17E595F114F3058F0054EE08 /* Foundation.framework */; }; 1724CD1815FB6A0500AB2291 /* PostgresKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* PostgresKit.framework */; }; - 1724CD5915FB8A3300AB2291 /* FLXPostgresTimeInterval.h in Headers */ = {isa = PBXBuildFile; fileRef = 1724CD5715FB8A3300AB2291 /* FLXPostgresTimeInterval.h */; }; - 1724CD5A15FB8A3300AB2291 /* FLXPostgresTimeInterval.m in Sources */ = {isa = PBXBuildFile; fileRef = 1724CD5815FB8A3300AB2291 /* FLXPostgresTimeInterval.m */; }; - 1731F02B15EE09E000D973EB /* FLXPostgresConnectionParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 1731F02915EE09E000D973EB /* FLXPostgresConnectionParameters.h */; }; - 1731F02C15EE09E000D973EB /* FLXPostgresConnectionParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 1731F02A15EE09E000D973EB /* FLXPostgresConnectionParameters.m */; }; - 1731F10815F1A52B00D973EB /* FLXPostgresTypeDateTimeHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 1731F10615F1A52B00D973EB /* FLXPostgresTypeDateTimeHandler.h */; }; - 1731F10915F1A52B00D973EB /* FLXPostgresTypeDateTimeHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 1731F10715F1A52B00D973EB /* FLXPostgresTypeDateTimeHandler.m */; }; - 1731F52E15F48BA500D973EB /* FLXPostgresError.h in Headers */ = {isa = PBXBuildFile; fileRef = 1731F52C15F48BA500D973EB /* FLXPostgresError.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 1731F52F15F48BA500D973EB /* FLXPostgresError.m in Sources */ = {isa = PBXBuildFile; fileRef = 1731F52D15F48BA500D973EB /* FLXPostgresError.m */; }; - 173D4E5A15BAB1DD0007F267 /* FLXPostgresTypeNumberHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4E5615BAB1DD0007F267 /* FLXPostgresTypeNumberHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 173D4E5B15BAB1DD0007F267 /* FLXPostgresTypeNumberHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 173D4E5715BAB1DD0007F267 /* FLXPostgresTypeNumberHandler.m */; }; - 173D4E5C15BAB1DD0007F267 /* FLXPostgresTypeStringHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4E5815BAB1DD0007F267 /* FLXPostgresTypeStringHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 173D4E5D15BAB1DD0007F267 /* FLXPostgresTypeStringHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 173D4E5915BAB1DD0007F267 /* FLXPostgresTypeStringHandler.m */; }; - 173D4EA115BAB2A80007F267 /* FLXPostgresConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4E9515BAB2A80007F267 /* FLXPostgresConnection.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 173D4EA215BAB2A80007F267 /* FLXPostgresConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 173D4E9615BAB2A80007F267 /* FLXPostgresConnection.m */; }; - 173D4EA315BAB2A80007F267 /* FLXPostgresConnectionUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4E9715BAB2A80007F267 /* FLXPostgresConnectionUtils.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 173D4EA415BAB2A80007F267 /* FLXPostgresConnectionUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 173D4E9815BAB2A80007F267 /* FLXPostgresConnectionUtils.m */; }; - 173D4EA515BAB2A80007F267 /* FLXPostgresException.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4E9915BAB2A80007F267 /* FLXPostgresException.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 173D4EA615BAB2A80007F267 /* FLXPostgresException.m in Sources */ = {isa = PBXBuildFile; fileRef = 173D4E9A15BAB2A80007F267 /* FLXPostgresException.m */; }; - 173D4EA715BAB2A80007F267 /* FLXPostgresResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4E9B15BAB2A80007F267 /* FLXPostgresResult.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 173D4EA815BAB2A80007F267 /* FLXPostgresResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 173D4E9C15BAB2A80007F267 /* FLXPostgresResult.m */; }; - 173D4EA915BAB2A80007F267 /* FLXPostgresStatement.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4E9D15BAB2A80007F267 /* FLXPostgresStatement.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 173D4EAA15BAB2A80007F267 /* FLXPostgresStatement.m in Sources */ = {isa = PBXBuildFile; fileRef = 173D4E9E15BAB2A80007F267 /* FLXPostgresStatement.m */; }; + 1724CD5915FB8A3300AB2291 /* PGPostgresTimeInterval.h in Headers */ = {isa = PBXBuildFile; fileRef = 1724CD5715FB8A3300AB2291 /* PGPostgresTimeInterval.h */; }; + 1724CD5A15FB8A3300AB2291 /* PGPostgresTimeInterval.m in Sources */ = {isa = PBXBuildFile; fileRef = 1724CD5815FB8A3300AB2291 /* PGPostgresTimeInterval.m */; }; + 1731F02B15EE09E000D973EB /* PGPostgresConnectionParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 1731F02915EE09E000D973EB /* PGPostgresConnectionParameters.h */; }; + 1731F02C15EE09E000D973EB /* PGPostgresConnectionParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 1731F02A15EE09E000D973EB /* PGPostgresConnectionParameters.m */; }; + 1731F10815F1A52B00D973EB /* PGPostgresTypeDateTimeHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 1731F10615F1A52B00D973EB /* PGPostgresTypeDateTimeHandler.h */; }; + 1731F10915F1A52B00D973EB /* PGPostgresTypeDateTimeHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 1731F10715F1A52B00D973EB /* PGPostgresTypeDateTimeHandler.m */; }; + 1731F52E15F48BA500D973EB /* PGPostgresError.h in Headers */ = {isa = PBXBuildFile; fileRef = 1731F52C15F48BA500D973EB /* PGPostgresError.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 1731F52F15F48BA500D973EB /* PGPostgresError.m in Sources */ = {isa = PBXBuildFile; fileRef = 1731F52D15F48BA500D973EB /* PGPostgresError.m */; }; + 173D4E5A15BAB1DD0007F267 /* PGPostgresTypeNumberHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4E5615BAB1DD0007F267 /* PGPostgresTypeNumberHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 173D4E5B15BAB1DD0007F267 /* PGPostgresTypeNumberHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 173D4E5715BAB1DD0007F267 /* PGPostgresTypeNumberHandler.m */; }; + 173D4E5C15BAB1DD0007F267 /* PGPostgresTypeStringHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4E5815BAB1DD0007F267 /* PGPostgresTypeStringHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 173D4E5D15BAB1DD0007F267 /* PGPostgresTypeStringHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 173D4E5915BAB1DD0007F267 /* PGPostgresTypeStringHandler.m */; }; + 173D4EA115BAB2A80007F267 /* PGPostgresConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4E9515BAB2A80007F267 /* PGPostgresConnection.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 173D4EA215BAB2A80007F267 /* PGPostgresConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 173D4E9615BAB2A80007F267 /* PGPostgresConnection.m */; }; + 173D4EA315BAB2A80007F267 /* PGPostgresConnectionUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4E9715BAB2A80007F267 /* PGPostgresConnectionUtils.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 173D4EA415BAB2A80007F267 /* PGPostgresConnectionUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 173D4E9815BAB2A80007F267 /* PGPostgresConnectionUtils.m */; }; + 173D4EA515BAB2A80007F267 /* PGPostgresException.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4E9915BAB2A80007F267 /* PGPostgresException.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 173D4EA615BAB2A80007F267 /* PGPostgresException.m in Sources */ = {isa = PBXBuildFile; fileRef = 173D4E9A15BAB2A80007F267 /* PGPostgresException.m */; }; + 173D4EA715BAB2A80007F267 /* PGPostgresResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4E9B15BAB2A80007F267 /* PGPostgresResult.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 173D4EA815BAB2A80007F267 /* PGPostgresResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 173D4E9C15BAB2A80007F267 /* PGPostgresResult.m */; }; + 173D4EA915BAB2A80007F267 /* PGPostgresStatement.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4E9D15BAB2A80007F267 /* PGPostgresStatement.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 173D4EAA15BAB2A80007F267 /* PGostgresStatement.m in Sources */ = {isa = PBXBuildFile; fileRef = 173D4E9E15BAB2A80007F267 /* PGostgresStatement.m */; }; 173D4EAB15BAB2A80007F267 /* PostgresKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4E9F15BAB2A80007F267 /* PostgresKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 173D4EE215BACA700007F267 /* libpq.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 173D4EE115BACA700007F267 /* libpq.a */; }; - 173D4F4515BAD22B0007F267 /* FLXPostgresTypeHandlerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4EA015BAB2A80007F267 /* FLXPostgresTypeHandlerProtocol.h */; settings = {ATTRIBUTES = (); }; }; - 173D4F5715BAD3030007F267 /* FLXPostgresTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4F5615BAD3030007F267 /* FLXPostgresTypes.h */; settings = {ATTRIBUTES = (); }; }; + 173D4F4515BAD22B0007F267 /* PGPostgresTypeHandlerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4EA015BAB2A80007F267 /* PGPostgresTypeHandlerProtocol.h */; settings = {ATTRIBUTES = (); }; }; + 173D4F5715BAD3030007F267 /* PGPostgresTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D4F5615BAD3030007F267 /* PGPostgresTypes.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 = (); }; }; - 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 */; }; - 177AC5F115C50F6E00A3658D /* FLXPostgresConnectionTypeHandling.m in Sources */ = {isa = PBXBuildFile; fileRef = 177AC5EF15C50F6E00A3658D /* FLXPostgresConnectionTypeHandling.m */; }; - 177AC66915C53CB000A3658D /* FLXPostgresConnectionQueryExecution.h in Headers */ = {isa = PBXBuildFile; fileRef = 177AC66715C53CB000A3658D /* FLXPostgresConnectionQueryExecution.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 177AC66A15C53CB000A3658D /* FLXPostgresConnectionQueryExecution.m in Sources */ = {isa = PBXBuildFile; fileRef = 177AC66815C53CB000A3658D /* FLXPostgresConnectionQueryExecution.m */; }; - 177AC67F15C53FA400A3658D /* FLXPostgresKitPrivateAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 177AC67D15C53FA400A3658D /* FLXPostgresKitPrivateAPI.h */; }; - 177AC6B015C5460C00A3658D /* FLXPostgresConnectionQueryPreparation.h in Headers */ = {isa = PBXBuildFile; fileRef = 177AC6AE15C5460C00A3658D /* FLXPostgresConnectionQueryPreparation.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 177AC6B115C5460C00A3658D /* FLXPostgresConnectionQueryPreparation.m in Sources */ = {isa = PBXBuildFile; fileRef = 177AC6AF15C5460C00A3658D /* FLXPostgresConnectionQueryPreparation.m */; }; - 177C9BAB15CD37E000128642 /* FLXPostgresConnectionEncoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 177C9BA915CD37E000128642 /* FLXPostgresConnectionEncoding.h */; }; - 177C9BAC15CD37E000128642 /* FLXPostgresConnectionEncoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 177C9BAA15CD37E000128642 /* FLXPostgresConnectionEncoding.m */; }; + 173D508C15BBD98D0007F267 /* PGConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D508B15BBD98D0007F267 /* PGConstants.h */; settings = {ATTRIBUTES = (); }; }; + 173D508F15BBD9BF0007F267 /* PGConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 173D508E15BBD9BF0007F267 /* PGConstants.m */; }; + 173D513515BBE50D0007F267 /* PGPostgresConnectionDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 173D513415BBE50D0007F267 /* PGPostgresConnectionDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 177AC5F015C50F6E00A3658D /* PGPostgresConnectionTypeHandling.h in Headers */ = {isa = PBXBuildFile; fileRef = 177AC5EE15C50F6E00A3658D /* PGPostgresConnectionTypeHandling.h */; }; + 177AC5F115C50F6E00A3658D /* PGPostgresConnectionTypeHandling.m in Sources */ = {isa = PBXBuildFile; fileRef = 177AC5EF15C50F6E00A3658D /* PGPostgresConnectionTypeHandling.m */; }; + 177AC66915C53CB000A3658D /* PGPostgresConnectionQueryExecution.h in Headers */ = {isa = PBXBuildFile; fileRef = 177AC66715C53CB000A3658D /* PGPostgresConnectionQueryExecution.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 177AC66A15C53CB000A3658D /* PGPostgresConnectionQueryExecution.m in Sources */ = {isa = PBXBuildFile; fileRef = 177AC66815C53CB000A3658D /* PGPostgresConnectionQueryExecution.m */; }; + 177AC67F15C53FA400A3658D /* PGPostgresKitPrivateAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 177AC67D15C53FA400A3658D /* PGPostgresKitPrivateAPI.h */; }; + 177AC6B015C5460C00A3658D /* PGPostgresConnectionQueryPreparation.h in Headers */ = {isa = PBXBuildFile; fileRef = 177AC6AE15C5460C00A3658D /* PGPostgresConnectionQueryPreparation.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 177AC6B115C5460C00A3658D /* PGPostgresConnectionQueryPreparation.m in Sources */ = {isa = PBXBuildFile; fileRef = 177AC6AF15C5460C00A3658D /* PGPostgresConnectionQueryPreparation.m */; }; + 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 */; }; /* End PBXBuildFile section */ @@ -68,57 +68,57 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 170465CC15C2960F00DC5BE5 /* FLXPostgresTypeHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresTypeHandler.h; sourceTree = ""; }; - 170465CD15C2960F00DC5BE5 /* FLXPostgresTypeHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresTypeHandler.m; sourceTree = ""; }; + 170465CC15C2960F00DC5BE5 /* PGPostgresTypeHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresTypeHandler.h; sourceTree = ""; }; + 170465CD15C2960F00DC5BE5 /* PGPostgresTypeHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresTypeHandler.m; sourceTree = ""; }; 1724C9B715F9ED8600AB2291 /* libpqtypes.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libpqtypes.a; sourceTree = ""; }; 1724CA3B15F9EE7300AB2291 /* libpqtypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = libpqtypes.h; sourceTree = ""; }; - 1724CC9015FB4CC200AB2291 /* FLXPostgresTimeTZ.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresTimeTZ.h; sourceTree = ""; }; - 1724CC9115FB4CC200AB2291 /* FLXPostgresTimeTZ.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresTimeTZ.m; sourceTree = ""; }; + 1724CC9015FB4CC200AB2291 /* PGPostgresTimeTZ.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresTimeTZ.h; sourceTree = ""; }; + 1724CC9115FB4CC200AB2291 /* PGPostgresTimeTZ.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresTimeTZ.m; sourceTree = ""; }; 1724CD0415FB68E800AB2291 /* Tests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; 1724CD0515FB68E800AB2291 /* Tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Tests-Info.plist"; path = "Resources/Tests-Info.plist"; sourceTree = ""; }; - 1724CD5715FB8A3300AB2291 /* FLXPostgresTimeInterval.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresTimeInterval.h; sourceTree = ""; }; - 1724CD5815FB8A3300AB2291 /* FLXPostgresTimeInterval.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresTimeInterval.m; sourceTree = ""; }; - 1731F02915EE09E000D973EB /* FLXPostgresConnectionParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresConnectionParameters.h; sourceTree = ""; }; - 1731F02A15EE09E000D973EB /* FLXPostgresConnectionParameters.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresConnectionParameters.m; sourceTree = ""; }; - 1731F10615F1A52B00D973EB /* FLXPostgresTypeDateTimeHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresTypeDateTimeHandler.h; sourceTree = ""; }; - 1731F10715F1A52B00D973EB /* FLXPostgresTypeDateTimeHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresTypeDateTimeHandler.m; sourceTree = ""; }; - 1731F52C15F48BA500D973EB /* FLXPostgresError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresError.h; sourceTree = ""; }; - 1731F52D15F48BA500D973EB /* FLXPostgresError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresError.m; sourceTree = ""; }; + 1724CD5715FB8A3300AB2291 /* PGPostgresTimeInterval.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresTimeInterval.h; sourceTree = ""; }; + 1724CD5815FB8A3300AB2291 /* PGPostgresTimeInterval.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresTimeInterval.m; sourceTree = ""; }; + 1731F02915EE09E000D973EB /* PGPostgresConnectionParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresConnectionParameters.h; sourceTree = ""; }; + 1731F02A15EE09E000D973EB /* PGPostgresConnectionParameters.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresConnectionParameters.m; sourceTree = ""; }; + 1731F10615F1A52B00D973EB /* PGPostgresTypeDateTimeHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresTypeDateTimeHandler.h; sourceTree = ""; }; + 1731F10715F1A52B00D973EB /* PGPostgresTypeDateTimeHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresTypeDateTimeHandler.m; sourceTree = ""; }; + 1731F52C15F48BA500D973EB /* PGPostgresError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresError.h; sourceTree = ""; }; + 1731F52D15F48BA500D973EB /* PGPostgresError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresError.m; sourceTree = ""; }; 173D4E2F15BAB13C0007F267 /* PostgresKit-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "PostgresKit-Prefix.pch"; path = "Source/PostgresKit-Prefix.pch"; sourceTree = ""; }; - 173D4E5615BAB1DD0007F267 /* FLXPostgresTypeNumberHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresTypeNumberHandler.h; sourceTree = ""; }; - 173D4E5715BAB1DD0007F267 /* FLXPostgresTypeNumberHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresTypeNumberHandler.m; sourceTree = ""; }; - 173D4E5815BAB1DD0007F267 /* FLXPostgresTypeStringHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresTypeStringHandler.h; sourceTree = ""; }; - 173D4E5915BAB1DD0007F267 /* FLXPostgresTypeStringHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresTypeStringHandler.m; sourceTree = ""; }; - 173D4E9515BAB2A80007F267 /* FLXPostgresConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresConnection.h; sourceTree = ""; }; - 173D4E9615BAB2A80007F267 /* FLXPostgresConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresConnection.m; sourceTree = ""; }; - 173D4E9715BAB2A80007F267 /* FLXPostgresConnectionUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresConnectionUtils.h; sourceTree = ""; }; - 173D4E9815BAB2A80007F267 /* FLXPostgresConnectionUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresConnectionUtils.m; sourceTree = ""; }; - 173D4E9915BAB2A80007F267 /* FLXPostgresException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresException.h; sourceTree = ""; }; - 173D4E9A15BAB2A80007F267 /* FLXPostgresException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresException.m; sourceTree = ""; }; - 173D4E9B15BAB2A80007F267 /* FLXPostgresResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresResult.h; sourceTree = ""; }; - 173D4E9C15BAB2A80007F267 /* FLXPostgresResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresResult.m; sourceTree = ""; }; - 173D4E9D15BAB2A80007F267 /* FLXPostgresStatement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresStatement.h; sourceTree = ""; }; - 173D4E9E15BAB2A80007F267 /* FLXPostgresStatement.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresStatement.m; sourceTree = ""; }; + 173D4E5615BAB1DD0007F267 /* PGPostgresTypeNumberHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresTypeNumberHandler.h; sourceTree = ""; }; + 173D4E5715BAB1DD0007F267 /* PGPostgresTypeNumberHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresTypeNumberHandler.m; sourceTree = ""; }; + 173D4E5815BAB1DD0007F267 /* PGPostgresTypeStringHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresTypeStringHandler.h; sourceTree = ""; }; + 173D4E5915BAB1DD0007F267 /* PGPostgresTypeStringHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresTypeStringHandler.m; sourceTree = ""; }; + 173D4E9515BAB2A80007F267 /* PGPostgresConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresConnection.h; sourceTree = ""; }; + 173D4E9615BAB2A80007F267 /* PGPostgresConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresConnection.m; sourceTree = ""; }; + 173D4E9715BAB2A80007F267 /* PGPostgresConnectionUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresConnectionUtils.h; sourceTree = ""; }; + 173D4E9815BAB2A80007F267 /* PGPostgresConnectionUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresConnectionUtils.m; sourceTree = ""; }; + 173D4E9915BAB2A80007F267 /* PGPostgresException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresException.h; sourceTree = ""; }; + 173D4E9A15BAB2A80007F267 /* PGPostgresException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresException.m; sourceTree = ""; }; + 173D4E9B15BAB2A80007F267 /* PGPostgresResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresResult.h; sourceTree = ""; }; + 173D4E9C15BAB2A80007F267 /* PGPostgresResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresResult.m; sourceTree = ""; }; + 173D4E9D15BAB2A80007F267 /* PGPostgresStatement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresStatement.h; sourceTree = ""; }; + 173D4E9E15BAB2A80007F267 /* PGostgresStatement.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGostgresStatement.m; sourceTree = ""; }; 173D4E9F15BAB2A80007F267 /* PostgresKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PostgresKit.h; sourceTree = ""; }; - 173D4EA015BAB2A80007F267 /* FLXPostgresTypeHandlerProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresTypeHandlerProtocol.h; sourceTree = ""; }; + 173D4EA015BAB2A80007F267 /* PGPostgresTypeHandlerProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresTypeHandlerProtocol.h; sourceTree = ""; }; 173D4EE115BACA700007F267 /* libpq.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libpq.a; sourceTree = ""; }; 173D4EE315BACA900007F267 /* libpq-fe.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "libpq-fe.h"; sourceTree = ""; }; 173D4EE415BACA900007F267 /* postgres_ext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = postgres_ext.h; sourceTree = ""; }; - 173D4F5615BAD3030007F267 /* FLXPostgresTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresTypes.h; sourceTree = ""; }; + 173D4F5615BAD3030007F267 /* PGPostgresTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresTypes.h; sourceTree = ""; }; 173D506915BB93470007F267 /* libssl.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libssl.dylib; path = usr/lib/libssl.dylib; sourceTree = SDKROOT; }; 173D506F15BB93E40007F267 /* libcrypto.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcrypto.dylib; path = usr/lib/libcrypto.dylib; sourceTree = SDKROOT; }; - 173D508B15BBD98D0007F267 /* FLXConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXConstants.h; sourceTree = ""; }; - 173D508E15BBD9BF0007F267 /* FLXConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXConstants.m; sourceTree = ""; }; - 173D513415BBE50D0007F267 /* FLXPostgresConnectionDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresConnectionDelegate.h; sourceTree = ""; }; - 177AC5EE15C50F6E00A3658D /* FLXPostgresConnectionTypeHandling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresConnectionTypeHandling.h; sourceTree = ""; }; - 177AC5EF15C50F6E00A3658D /* FLXPostgresConnectionTypeHandling.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresConnectionTypeHandling.m; sourceTree = ""; }; - 177AC66715C53CB000A3658D /* FLXPostgresConnectionQueryExecution.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresConnectionQueryExecution.h; sourceTree = ""; }; - 177AC66815C53CB000A3658D /* FLXPostgresConnectionQueryExecution.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresConnectionQueryExecution.m; sourceTree = ""; }; - 177AC67D15C53FA400A3658D /* FLXPostgresKitPrivateAPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresKitPrivateAPI.h; sourceTree = ""; }; - 177AC6AE15C5460C00A3658D /* FLXPostgresConnectionQueryPreparation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresConnectionQueryPreparation.h; sourceTree = ""; }; - 177AC6AF15C5460C00A3658D /* FLXPostgresConnectionQueryPreparation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresConnectionQueryPreparation.m; sourceTree = ""; }; - 177C9BA915CD37E000128642 /* FLXPostgresConnectionEncoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLXPostgresConnectionEncoding.h; sourceTree = ""; }; - 177C9BAA15CD37E000128642 /* FLXPostgresConnectionEncoding.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLXPostgresConnectionEncoding.m; sourceTree = ""; }; + 173D508B15BBD98D0007F267 /* PGConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGConstants.h; sourceTree = ""; }; + 173D508E15BBD9BF0007F267 /* PGConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGConstants.m; sourceTree = ""; }; + 173D513415BBE50D0007F267 /* PGPostgresConnectionDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresConnectionDelegate.h; sourceTree = ""; }; + 177AC5EE15C50F6E00A3658D /* PGPostgresConnectionTypeHandling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresConnectionTypeHandling.h; sourceTree = ""; }; + 177AC5EF15C50F6E00A3658D /* PGPostgresConnectionTypeHandling.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresConnectionTypeHandling.m; sourceTree = ""; }; + 177AC66715C53CB000A3658D /* PGPostgresConnectionQueryExecution.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresConnectionQueryExecution.h; sourceTree = ""; }; + 177AC66815C53CB000A3658D /* PGPostgresConnectionQueryExecution.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresConnectionQueryExecution.m; sourceTree = ""; }; + 177AC67D15C53FA400A3658D /* PGPostgresKitPrivateAPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresKitPrivateAPI.h; sourceTree = ""; }; + 177AC6AE15C5460C00A3658D /* PGPostgresConnectionQueryPreparation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresConnectionQueryPreparation.h; sourceTree = ""; }; + 177AC6AF15C5460C00A3658D /* PGPostgresConnectionQueryPreparation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresConnectionQueryPreparation.m; sourceTree = ""; }; + 177C9BA915CD37E000128642 /* PGPostgresConnectionEncoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPostgresConnectionEncoding.h; sourceTree = ""; }; + 177C9BAA15CD37E000128642 /* PGPostgresConnectionEncoding.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPostgresConnectionEncoding.m; sourceTree = ""; }; 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 = ""; }; 8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Resources/Info.plist; sourceTree = ""; }; @@ -165,6 +165,7 @@ 17F5B77C15C9D092006DA689 /* README */, 173D4E2F15BAB13C0007F267 /* PostgresKit-Prefix.pch */, 173D4E2115BAB0FE0007F267 /* Source */, + 171D582B1612E00D00F84472 /* Tests */, 089C1665FE841158C02AAC07 /* Resources */, 173D4EDE15BACA090007F267 /* Libs */, 0867D69AFE84028FC02AAC07 /* Frameworks */, @@ -192,6 +193,13 @@ name = Resources; sourceTree = ""; }; + 171D582B1612E00D00F84472 /* Tests */ = { + isa = PBXGroup; + children = ( + ); + name = Tests; + sourceTree = ""; + }; 1724CA3715F9EDC900AB2291 /* libpq */ = { isa = PBXGroup; children = ( @@ -229,10 +237,10 @@ 1724CC8715FB4BF400AB2291 /* Domain */ = { isa = PBXGroup; children = ( - 1724CC9015FB4CC200AB2291 /* FLXPostgresTimeTZ.h */, - 1724CC9115FB4CC200AB2291 /* FLXPostgresTimeTZ.m */, - 1724CD5715FB8A3300AB2291 /* FLXPostgresTimeInterval.h */, - 1724CD5815FB8A3300AB2291 /* FLXPostgresTimeInterval.m */, + 1724CC9015FB4CC200AB2291 /* PGPostgresTimeTZ.h */, + 1724CC9115FB4CC200AB2291 /* PGPostgresTimeTZ.m */, + 1724CD5715FB8A3300AB2291 /* PGPostgresTimeInterval.h */, + 1724CD5815FB8A3300AB2291 /* PGPostgresTimeInterval.m */, ); name = Domain; sourceTree = ""; @@ -240,10 +248,10 @@ 1731F50415F369E400D973EB /* Query */ = { isa = PBXGroup; children = ( - 177AC66715C53CB000A3658D /* FLXPostgresConnectionQueryExecution.h */, - 177AC66815C53CB000A3658D /* FLXPostgresConnectionQueryExecution.m */, - 177AC6AE15C5460C00A3658D /* FLXPostgresConnectionQueryPreparation.h */, - 177AC6AF15C5460C00A3658D /* FLXPostgresConnectionQueryPreparation.m */, + 177AC66715C53CB000A3658D /* PGPostgresConnectionQueryExecution.h */, + 177AC66815C53CB000A3658D /* PGPostgresConnectionQueryExecution.m */, + 177AC6AE15C5460C00A3658D /* PGPostgresConnectionQueryPreparation.h */, + 177AC6AF15C5460C00A3658D /* PGPostgresConnectionQueryPreparation.m */, ); name = Query; sourceTree = ""; @@ -251,8 +259,8 @@ 1731F50515F369FE00D973EB /* Encoding */ = { isa = PBXGroup; children = ( - 177C9BA915CD37E000128642 /* FLXPostgresConnectionEncoding.h */, - 177C9BAA15CD37E000128642 /* FLXPostgresConnectionEncoding.m */, + 177C9BA915CD37E000128642 /* PGPostgresConnectionEncoding.h */, + 177C9BAA15CD37E000128642 /* PGPostgresConnectionEncoding.m */, ); name = Encoding; sourceTree = ""; @@ -260,12 +268,12 @@ 1731F50615F36A3E00D973EB /* Other */ = { isa = PBXGroup; children = ( - 173D4E9715BAB2A80007F267 /* FLXPostgresConnectionUtils.h */, - 173D4E9815BAB2A80007F267 /* FLXPostgresConnectionUtils.m */, - 1731F02915EE09E000D973EB /* FLXPostgresConnectionParameters.h */, - 1731F02A15EE09E000D973EB /* FLXPostgresConnectionParameters.m */, - 177AC5EE15C50F6E00A3658D /* FLXPostgresConnectionTypeHandling.h */, - 177AC5EF15C50F6E00A3658D /* FLXPostgresConnectionTypeHandling.m */, + 173D4E9715BAB2A80007F267 /* PGPostgresConnectionUtils.h */, + 173D4E9815BAB2A80007F267 /* PGPostgresConnectionUtils.m */, + 1731F02915EE09E000D973EB /* PGPostgresConnectionParameters.h */, + 1731F02A15EE09E000D973EB /* PGPostgresConnectionParameters.m */, + 177AC5EE15C50F6E00A3658D /* PGPostgresConnectionTypeHandling.h */, + 177AC5EF15C50F6E00A3658D /* PGPostgresConnectionTypeHandling.m */, ); name = Other; sourceTree = ""; @@ -273,14 +281,14 @@ 1731F52B15F48B4400D973EB /* Domain */ = { isa = PBXGroup; children = ( - 1731F52C15F48BA500D973EB /* FLXPostgresError.h */, - 1731F52D15F48BA500D973EB /* FLXPostgresError.m */, - 173D4E9B15BAB2A80007F267 /* FLXPostgresResult.h */, - 173D4E9C15BAB2A80007F267 /* FLXPostgresResult.m */, - 173D4E9D15BAB2A80007F267 /* FLXPostgresStatement.h */, - 173D4E9E15BAB2A80007F267 /* FLXPostgresStatement.m */, - 173D4E9915BAB2A80007F267 /* FLXPostgresException.h */, - 173D4E9A15BAB2A80007F267 /* FLXPostgresException.m */, + 1731F52C15F48BA500D973EB /* PGPostgresError.h */, + 1731F52D15F48BA500D973EB /* PGPostgresError.m */, + 173D4E9B15BAB2A80007F267 /* PGPostgresResult.h */, + 173D4E9C15BAB2A80007F267 /* PGPostgresResult.m */, + 173D4E9D15BAB2A80007F267 /* PGPostgresStatement.h */, + 173D4E9E15BAB2A80007F267 /* PGostgresStatement.m */, + 173D4E9915BAB2A80007F267 /* PGPostgresException.h */, + 173D4E9A15BAB2A80007F267 /* PGPostgresException.m */, ); name = Domain; sourceTree = ""; @@ -289,7 +297,7 @@ isa = PBXGroup; children = ( 173D4E9F15BAB2A80007F267 /* PostgresKit.h */, - 177AC67D15C53FA400A3658D /* FLXPostgresKitPrivateAPI.h */, + 177AC67D15C53FA400A3658D /* PGPostgresKitPrivateAPI.h */, 1731F52B15F48B4400D973EB /* Domain */, 173D513315BBE4230007F267 /* Connection */, 173D508D15BBD99B0007F267 /* Constants */, @@ -301,8 +309,8 @@ 173D4E5015BAB17A0007F267 /* Types */ = { isa = PBXGroup; children = ( - 173D4F5615BAD3030007F267 /* FLXPostgresTypes.h */, - 173D4EA015BAB2A80007F267 /* FLXPostgresTypeHandlerProtocol.h */, + 173D4F5615BAD3030007F267 /* PGPostgresTypes.h */, + 173D4EA015BAB2A80007F267 /* PGPostgresTypeHandlerProtocol.h */, 1724CC8715FB4BF400AB2291 /* Domain */, 17F5B62215C7D1DA006DA689 /* Handlers */, ); @@ -338,8 +346,8 @@ 173D508D15BBD99B0007F267 /* Constants */ = { isa = PBXGroup; children = ( - 173D508B15BBD98D0007F267 /* FLXConstants.h */, - 173D508E15BBD9BF0007F267 /* FLXConstants.m */, + 173D508B15BBD98D0007F267 /* PGConstants.h */, + 173D508E15BBD9BF0007F267 /* PGConstants.m */, ); name = Constants; sourceTree = ""; @@ -347,9 +355,9 @@ 173D513315BBE4230007F267 /* Connection */ = { isa = PBXGroup; children = ( - 173D4E9515BAB2A80007F267 /* FLXPostgresConnection.h */, - 173D4E9615BAB2A80007F267 /* FLXPostgresConnection.m */, - 173D513415BBE50D0007F267 /* FLXPostgresConnectionDelegate.h */, + 173D4E9515BAB2A80007F267 /* PGPostgresConnection.h */, + 173D4E9615BAB2A80007F267 /* PGPostgresConnection.m */, + 173D513415BBE50D0007F267 /* PGPostgresConnectionDelegate.h */, 1731F50515F369FE00D973EB /* Encoding */, 1731F50415F369E400D973EB /* Query */, 1731F50615F36A3E00D973EB /* Other */, @@ -360,14 +368,14 @@ 17F5B62215C7D1DA006DA689 /* Handlers */ = { isa = PBXGroup; children = ( - 170465CC15C2960F00DC5BE5 /* FLXPostgresTypeHandler.h */, - 170465CD15C2960F00DC5BE5 /* FLXPostgresTypeHandler.m */, - 173D4E5815BAB1DD0007F267 /* FLXPostgresTypeStringHandler.h */, - 173D4E5915BAB1DD0007F267 /* FLXPostgresTypeStringHandler.m */, - 173D4E5615BAB1DD0007F267 /* FLXPostgresTypeNumberHandler.h */, - 173D4E5715BAB1DD0007F267 /* FLXPostgresTypeNumberHandler.m */, - 1731F10615F1A52B00D973EB /* FLXPostgresTypeDateTimeHandler.h */, - 1731F10715F1A52B00D973EB /* FLXPostgresTypeDateTimeHandler.m */, + 170465CC15C2960F00DC5BE5 /* PGPostgresTypeHandler.h */, + 170465CD15C2960F00DC5BE5 /* PGPostgresTypeHandler.m */, + 173D4E5815BAB1DD0007F267 /* PGPostgresTypeStringHandler.h */, + 173D4E5915BAB1DD0007F267 /* PGPostgresTypeStringHandler.m */, + 173D4E5615BAB1DD0007F267 /* PGPostgresTypeNumberHandler.h */, + 173D4E5715BAB1DD0007F267 /* PGPostgresTypeNumberHandler.m */, + 1731F10615F1A52B00D973EB /* PGPostgresTypeDateTimeHandler.h */, + 1731F10715F1A52B00D973EB /* PGPostgresTypeDateTimeHandler.m */, ); name = Handlers; sourceTree = ""; @@ -379,29 +387,29 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 173D4E5A15BAB1DD0007F267 /* FLXPostgresTypeNumberHandler.h in Headers */, - 173D4E5C15BAB1DD0007F267 /* FLXPostgresTypeStringHandler.h in Headers */, - 173D4EA115BAB2A80007F267 /* FLXPostgresConnection.h in Headers */, - 173D4EA315BAB2A80007F267 /* FLXPostgresConnectionUtils.h in Headers */, - 173D4EA515BAB2A80007F267 /* FLXPostgresException.h in Headers */, - 173D4EA715BAB2A80007F267 /* FLXPostgresResult.h in Headers */, - 173D4EA915BAB2A80007F267 /* FLXPostgresStatement.h in Headers */, + 173D4E5A15BAB1DD0007F267 /* PGPostgresTypeNumberHandler.h in Headers */, + 173D4E5C15BAB1DD0007F267 /* PGPostgresTypeStringHandler.h in Headers */, + 173D4EA115BAB2A80007F267 /* PGPostgresConnection.h in Headers */, + 173D4EA315BAB2A80007F267 /* PGPostgresConnectionUtils.h in Headers */, + 173D4EA515BAB2A80007F267 /* PGPostgresException.h in Headers */, + 173D4EA715BAB2A80007F267 /* PGPostgresResult.h in Headers */, + 173D4EA915BAB2A80007F267 /* PGPostgresStatement.h in Headers */, 173D4EAB15BAB2A80007F267 /* PostgresKit.h in Headers */, - 173D4F4515BAD22B0007F267 /* FLXPostgresTypeHandlerProtocol.h in Headers */, - 173D4F5715BAD3030007F267 /* FLXPostgresTypes.h in Headers */, - 173D508C15BBD98D0007F267 /* FLXConstants.h in Headers */, - 173D513515BBE50D0007F267 /* FLXPostgresConnectionDelegate.h in Headers */, - 170465CE15C2960F00DC5BE5 /* FLXPostgresTypeHandler.h in Headers */, - 177AC5F015C50F6E00A3658D /* FLXPostgresConnectionTypeHandling.h in Headers */, - 177AC66915C53CB000A3658D /* FLXPostgresConnectionQueryExecution.h in Headers */, - 177AC67F15C53FA400A3658D /* FLXPostgresKitPrivateAPI.h in Headers */, - 177AC6B015C5460C00A3658D /* FLXPostgresConnectionQueryPreparation.h in Headers */, - 177C9BAB15CD37E000128642 /* FLXPostgresConnectionEncoding.h in Headers */, - 1731F02B15EE09E000D973EB /* FLXPostgresConnectionParameters.h in Headers */, - 1731F10815F1A52B00D973EB /* FLXPostgresTypeDateTimeHandler.h in Headers */, - 1731F52E15F48BA500D973EB /* FLXPostgresError.h in Headers */, - 1724CC9215FB4CC200AB2291 /* FLXPostgresTimeTZ.h in Headers */, - 1724CD5915FB8A3300AB2291 /* FLXPostgresTimeInterval.h in Headers */, + 173D4F4515BAD22B0007F267 /* PGPostgresTypeHandlerProtocol.h in Headers */, + 173D4F5715BAD3030007F267 /* PGPostgresTypes.h in Headers */, + 173D508C15BBD98D0007F267 /* PGConstants.h in Headers */, + 173D513515BBE50D0007F267 /* PGPostgresConnectionDelegate.h in Headers */, + 170465CE15C2960F00DC5BE5 /* PGPostgresTypeHandler.h in Headers */, + 177AC5F015C50F6E00A3658D /* PGPostgresConnectionTypeHandling.h in Headers */, + 177AC66915C53CB000A3658D /* PGPostgresConnectionQueryExecution.h in Headers */, + 177AC67F15C53FA400A3658D /* PGPostgresKitPrivateAPI.h in Headers */, + 177AC6B015C5460C00A3658D /* PGPostgresConnectionQueryPreparation.h in Headers */, + 177C9BAB15CD37E000128642 /* PGPostgresConnectionEncoding.h in Headers */, + 1731F02B15EE09E000D973EB /* PGPostgresConnectionParameters.h in Headers */, + 1731F10815F1A52B00D973EB /* PGPostgresTypeDateTimeHandler.h in Headers */, + 1731F52E15F48BA500D973EB /* PGPostgresError.h in Headers */, + 1724CC9215FB4CC200AB2291 /* PGPostgresTimeTZ.h in Headers */, + 1724CD5915FB8A3300AB2291 /* PGPostgresTimeInterval.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -498,24 +506,24 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 173D4E5B15BAB1DD0007F267 /* FLXPostgresTypeNumberHandler.m in Sources */, - 173D4E5D15BAB1DD0007F267 /* FLXPostgresTypeStringHandler.m in Sources */, - 173D4EA215BAB2A80007F267 /* FLXPostgresConnection.m in Sources */, - 173D4EA415BAB2A80007F267 /* FLXPostgresConnectionUtils.m in Sources */, - 173D4EA615BAB2A80007F267 /* FLXPostgresException.m in Sources */, - 173D4EA815BAB2A80007F267 /* FLXPostgresResult.m in Sources */, - 173D4EAA15BAB2A80007F267 /* FLXPostgresStatement.m in Sources */, - 173D508F15BBD9BF0007F267 /* FLXConstants.m in Sources */, - 170465CF15C2960F00DC5BE5 /* FLXPostgresTypeHandler.m in Sources */, - 177AC5F115C50F6E00A3658D /* FLXPostgresConnectionTypeHandling.m in Sources */, - 177AC66A15C53CB000A3658D /* FLXPostgresConnectionQueryExecution.m in Sources */, - 177AC6B115C5460C00A3658D /* FLXPostgresConnectionQueryPreparation.m in Sources */, - 177C9BAC15CD37E000128642 /* FLXPostgresConnectionEncoding.m in Sources */, - 1731F02C15EE09E000D973EB /* FLXPostgresConnectionParameters.m in Sources */, - 1731F10915F1A52B00D973EB /* FLXPostgresTypeDateTimeHandler.m in Sources */, - 1731F52F15F48BA500D973EB /* FLXPostgresError.m in Sources */, - 1724CC9315FB4CC200AB2291 /* FLXPostgresTimeTZ.m in Sources */, - 1724CD5A15FB8A3300AB2291 /* FLXPostgresTimeInterval.m in Sources */, + 173D4E5B15BAB1DD0007F267 /* PGPostgresTypeNumberHandler.m in Sources */, + 173D4E5D15BAB1DD0007F267 /* PGPostgresTypeStringHandler.m in Sources */, + 173D4EA215BAB2A80007F267 /* PGPostgresConnection.m in Sources */, + 173D4EA415BAB2A80007F267 /* PGPostgresConnectionUtils.m in Sources */, + 173D4EA615BAB2A80007F267 /* PGPostgresException.m in Sources */, + 173D4EA815BAB2A80007F267 /* PGPostgresResult.m in Sources */, + 173D4EAA15BAB2A80007F267 /* PGostgresStatement.m in Sources */, + 173D508F15BBD9BF0007F267 /* PGConstants.m in Sources */, + 170465CF15C2960F00DC5BE5 /* PGPostgresTypeHandler.m in Sources */, + 177AC5F115C50F6E00A3658D /* PGPostgresConnectionTypeHandling.m in Sources */, + 177AC66A15C53CB000A3658D /* PGPostgresConnectionQueryExecution.m in Sources */, + 177AC6B115C5460C00A3658D /* PGPostgresConnectionQueryPreparation.m in Sources */, + 177C9BAC15CD37E000128642 /* PGPostgresConnectionEncoding.m in Sources */, + 1731F02C15EE09E000D973EB /* PGPostgresConnectionParameters.m in Sources */, + 1731F10915F1A52B00D973EB /* PGPostgresTypeDateTimeHandler.m in Sources */, + 1731F52F15F48BA500D973EB /* PGPostgresError.m in Sources */, + 1724CC9315FB4CC200AB2291 /* PGPostgresTimeTZ.m in Sources */, + 1724CD5A15FB8A3300AB2291 /* PGPostgresTimeInterval.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Frameworks/PostgresKit/Source/FLXConstants.h b/Frameworks/PostgresKit/Source/FLXConstants.h deleted file mode 100644 index 01e71919..00000000 --- a/Frameworks/PostgresKit/Source/FLXConstants.h +++ /dev/null @@ -1,67 +0,0 @@ -// -// $Id$ -// -// FLXConstants.h -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -// Connection defaults -extern const NSUInteger FLXPostgresConnectionDefaultTimeout; -extern const NSUInteger FLXPostgresConnectionDefaultServerPort; -extern const NSUInteger FLXPostgresConnectionDefaultKeepAlive; - -extern NSString *FLXPostgresConnectionDefaultEncoding; -extern NSString *FLXPostgresConnectionErrorDomain; -extern NSStringEncoding FLXPostgresConnectionDefaultStringEncoding; - -// Server parameters -extern NSString *FLXPostgresParameterServerEncoding; -extern NSString *FLXPostgresParameterClientEncoding; -extern NSString *FLXPostgresParameterSuperUser; -extern NSString *FLXPostgresParameterTimeZone; -extern NSString *FLXPostgresParameterIntegerDateTimes; - -// Result 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; -extern const char *FLXPostgresResultValueNumeric; -extern const char *FLXPostgresResultValueBool; -extern const char *FLXPostgresResultValueInt2; -extern const char *FLXPostgresResultValueInt4; -extern const char *FLXPostgresResultValueInt8; -extern const char *FLXPostgresResultValueFloat4; -extern const char *FLXPostgresResultValueFloat8; - -// Connection parameters -extern const char *FLXPostgresKitApplicationName; -extern const char *FLXPostgresApplicationParam; -extern const char *FLXPostgresUserParam; -extern const char *FLXPostgresHostParam; -extern const char *FLXPostgresPasswordParam; -extern const char *FLXPostgresPortParam; -extern const char *FLXPostgresDatabaseParam; -extern const char *FLXPostgresClientEncodingParam; -extern const char *FLXPostgresKeepAliveParam; -extern const char *FLXPostgresKeepAliveIntervalParam; diff --git a/Frameworks/PostgresKit/Source/FLXConstants.m b/Frameworks/PostgresKit/Source/FLXConstants.m deleted file mode 100644 index 16344a50..00000000 --- a/Frameworks/PostgresKit/Source/FLXConstants.m +++ /dev/null @@ -1,67 +0,0 @@ -// -// $Id$ -// -// FLXConstants.m -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -// Connection defaults -const NSUInteger FLXPostgresConnectionDefaultTimeout = 30; -const NSUInteger FLXPostgresConnectionDefaultServerPort = 5432; -const NSUInteger FLXPostgresConnectionDefaultKeepAlive = 60; - -NSString *FLXPostgresConnectionDefaultEncoding = @"UNICODE"; -NSString *FLXPostgresConnectionErrorDomain = @"FLXPostgresConnectionError"; -NSStringEncoding FLXPostgresConnectionDefaultStringEncoding = NSUTF8StringEncoding; - -// Server parameters -NSString *FLXPostgresParameterServerEncoding = @"server_encoding"; -NSString *FLXPostgresParameterClientEncoding = @"client_encoding"; -NSString *FLXPostgresParameterSuperUser = @"is_superuser"; -NSString *FLXPostgresParameterTimeZone = @"TimeZone"; -NSString *FLXPostgresParameterIntegerDateTimes = @"integer_datetimes"; - -// Result value specifiers -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"; -const char *FLXPostgresResultValueNumeric = "%numeric"; -const char *FLXPostgresResultValueBool = "%bool"; -const char *FLXPostgresResultValueInt2 = "%int2"; -const char *FLXPostgresResultValueInt4 = "%int4"; -const char *FLXPostgresResultValueInt8 = "%int8"; -const char *FLXPostgresResultValueFloat4 = "%float4"; -const char *FLXPostgresResultValueFloat8 = "%float8"; - -// Connection parameters -const char *FLXPostgresKitApplicationName = "PostgresKit"; -const char *FLXPostgresApplicationParam = "application_name"; -const char *FLXPostgresUserParam = "user"; -const char *FLXPostgresHostParam = "host"; -const char *FLXPostgresPasswordParam = "password"; -const char *FLXPostgresPortParam = "port"; -const char *FLXPostgresDatabaseParam = "dbname"; -const char *FLXPostgresClientEncodingParam = "client_encoding"; -const char *FLXPostgresKeepAliveParam = "keepalives"; -const char *FLXPostgresKeepAliveIntervalParam = "keepalives_interval"; diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnection.h b/Frameworks/PostgresKit/Source/FLXPostgresConnection.h deleted file mode 100644 index 87ac46d3..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnection.h +++ /dev/null @@ -1,101 +0,0 @@ -// -// $Id$ -// -// FLXPostgresConnection.h -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresConnectionDelegate.h" - -@class FLXPostgresError; -@class FLXPostgresResult; -@class FLXPostgresStatement; -@class FLXPostgresConnectionParameters; - -@interface FLXPostgresConnection : NSObject -{ - void *_connection; - - NSString *_host; - NSString *_user; - NSString *_database; - NSString *_password; - NSString *_socketPath; - NSString *_encoding; - NSString *_connectionError; - NSString *_applicationName; - - const char **_connectionParamNames; - const char **_connectionParamValues; - - NSStringEncoding _stringEncoding; - - NSUInteger _port; - NSUInteger _timeout; - NSUInteger _keepAliveInterval; - - BOOL _useSocket; - BOOL _useKeepAlive; - BOOL _lastQueryWasCancelled; - BOOL _delegateSupportsWillExecute; - - NSMutableDictionary *_typeMap; - - FLXPostgresError *_lastError; - FLXPostgresConnectionParameters *_parameters; - - NSObject *_delegate; -} - -@property (readwrite, assign) NSObject *delegate; - -@property (readwrite, retain) NSString *host; -@property (readwrite, retain) NSString *user; -@property (readwrite, retain) NSString *database; -@property (readwrite, retain) NSString *password; -@property (readwrite, retain) NSString *socketPath; -@property (readwrite, retain) NSString *applicationName; - -@property (readonly) NSString *encoding; -@property (readonly) NSString *connectionError; -@property (readonly) FLXPostgresError *lastError; -@property (readonly) NSStringEncoding stringEncoding; -@property (readonly) FLXPostgresConnectionParameters *parameters; - -@property (readwrite, assign) BOOL useSocket; -@property (readwrite, assign) BOOL useKeepAlive; -@property (readwrite, assign) BOOL lastQueryWasCancelled; - -@property (readwrite, assign) NSUInteger timeout; -@property (readwrite, assign) NSUInteger port; -@property (readwrite, assign) NSUInteger keepAliveInterval; - -- (id)initWithDelegate:(NSObject *)delegate; - -- (BOOL)connect; -- (void)disconnect; -- (BOOL)isConnected; -- (BOOL)reset; - -- (NSUInteger)clientVersion; -- (NSUInteger)serverVersion; -- (NSUInteger)serverProcessId; - -- (BOOL)cancelCurrentQuery:(NSError **)error; - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnection.m b/Frameworks/PostgresKit/Source/FLXPostgresConnection.m deleted file mode 100644 index a649a982..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnection.m +++ /dev/null @@ -1,483 +0,0 @@ -// -// $Id$ -// -// FLXPostgresConnection.m -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresConnection.h" -#import "FLXPostgresConnectionParameters.h" -#import "FLXPostgresConnectionTypeHandling.h" -#import "FLXPostgresKitPrivateAPI.h" -#import "FLXPostgresTypeHandlerProtocol.h" -#import "FLXPostgresTypeNumberHandler.h" -#import "FLXPostgresTypeStringHandler.h" -#import "FLXPostgresException.h" -#import "FLXPostgresStatement.h" -#import "FLXPostgresResult.h" - -#import -#import - -@interface FLXPostgresConnection () - -- (void)_loadDatabaseParameters; -- (void)_createConnectionParameters; -- (void)_pollConnection:(NSNumber *)isReset; - -// libpq callback -static void _FLXPostgresConnectionNoticeProcessor(void *arg, const char *message); - -@end - -@implementation FLXPostgresConnection - -@synthesize port = _port; -@synthesize host = _host; -@synthesize user = _user; -@synthesize database = _database; -@synthesize password = _password; -@synthesize useSocket = _useSocket; -@synthesize socketPath = _socketPath; -@synthesize delegate = _delegate; -@synthesize timeout = _timeout; -@synthesize useKeepAlive = _useKeepAlive; -@synthesize keepAliveInterval = _keepAliveInterval; -@synthesize lastQueryWasCancelled = _lastQueryWasCancelled; -@synthesize lastError = _lastError; -@synthesize encoding = _encoding; -@synthesize connectionError = _connectionError; -@synthesize stringEncoding = _stringEncoding; -@synthesize parameters = _parameters; -@synthesize applicationName = _applicationName; - -#pragma mark - -#pragma mark Initialisation - -- (id)init -{ - return [self initWithDelegate:nil]; -} - -/** - * Initialise a new connection with the supplied delegate. - * - * @param delegate The delegate this connection should use. - * - * @return The new connection instance. - */ -- (id)initWithDelegate:(NSObject *)delegate -{ - if ((self = [super init])) { - - _delegate = delegate; - - _port = FLXPostgresConnectionDefaultServerPort; - _timeout = FLXPostgresConnectionDefaultTimeout; - - _useKeepAlive = YES; - _keepAliveInterval = FLXPostgresConnectionDefaultKeepAlive; - - _lastError = nil; - _connection = nil; - _connectionError = nil; - _lastQueryWasCancelled = NO; - - _stringEncoding = FLXPostgresConnectionDefaultStringEncoding; - _encoding = [NSString stringWithString:FLXPostgresConnectionDefaultEncoding]; - - _delegateSupportsWillExecute = [_delegate respondsToSelector:@selector(connection:willExecute:withValues:)]; - - _typeMap = [[NSMutableDictionary alloc] init]; - - [self registerTypeHandlers]; - } - - return self; -} - -#pragma mark - -#pragma mark Accessors - -- (PGconn *)postgresConnection -{ - return _connection; -} - -#pragma mark - -#pragma mark Connection Handling - -/** - * Does this connection have an underlying connection established with the server. - * - * @return A BOOL indicating the result of the query. - */ -- (BOOL)isConnected -{ - if (!_connection) return NO; - - return PQstatus(_connection) == CONNECTION_OK; -} - -/** - * Attempts to disconnect the underlying connection with the server. - */ -- (void)disconnect -{ - if (!_connection) return; - - [self cancelCurrentQuery:nil]; - - PQfinish(_connection); - - _connection = nil; - - if (_delegate && [_delegate respondsToSelector:@selector(connectionDisconnected:)]) { - [_delegate connectionDisconnected:self]; - } -} - -/** - * Initiates the underlying connection to the server asynchronously. - * - * Note, that if no user, host or database is set when connect is called, then libpq's defaults are used. - * For no host, this means a socket connection to /tmp is attempted. - * - * @return A BOOL indicating the success of requesting the connection. Note, that this does not indicate - * that a successful connection has been made, only that it has successfullly been requested. - */ -- (BOOL)connect -{ - if ([self isConnected]) { - [FLXPostgresException raise:FLXPostgresConnectionErrorDomain reason:@"Attempt to initiate a connection that is already active"]; - - return NO; - } - - [self _createConnectionParameters]; - - // Perform the connection - _connection = PQconnectStartParams(_connectionParamNames, _connectionParamValues, 0); - - if (!_connection || PQstatus(_connection) == CONNECTION_BAD) { - - if (_connectionError) [_connectionError release]; - - _connectionError = [[NSString alloc] initWithUTF8String:PQerrorMessage(_connection)]; - - PQfinish(_connection); - - _connection = nil; - - return NO; - } - - [self performSelectorInBackground:@selector(_pollConnection:) withObject:nil]; - - return YES; -} - -/** - * Attempts the reset the underlying connection. - * - * @note A return value of NO means that the connection is not currently - * connected or the request to reset it failed. YES means the reset request was successful, - * not that the connection re-establishment has succeeded. Wait for the - * delegate connection reset method to be called and check -isConnected. - * - * @return A BOOL indicating the success of the call. - */ -- (BOOL)reset -{ - if (![self isConnected]) return NO; - - if (!PQresetStart(_connection)) return NO; - - [self performSelectorInBackground:@selector(_pollConnection:) withObject:[NSNumber numberWithBool:YES]]; - - return YES; -} - -/** - * Returns the PostgreSQL client library (libpq) version being used. - * - * @return The library version (e.g. version 9.1 is 90100). - */ -- (NSUInteger)clientVersion -{ - return PQlibVersion(); -} - -/** - * Returns the version of the server we're connected to. - * - * @return The server version (e.g. version 9.1 is 90100). Zero is returned if there's no connection. - */ -- (NSUInteger)serverVersion -{ - if (![self isConnected]) return 0; - - return PQserverVersion(_connection); -} - -/** - * Returns the ID of the process handling this connection on the remote host. - * - * @return The process ID or -1 if no connection is available. - */ -- (NSUInteger)serverProcessId -{ - if (![self isConnected]) return -1; - - return PQbackendPID(_connection); -} - -/** - * Attempts to cancel the query currently executing on this connection. - * - * @param error Populated if query was unabled to be cancelled. - * - * @return A BOOL indicating the success of the request - */ -- (BOOL)cancelCurrentQuery:(NSError **)error -{ - if (![self isConnected]) return NO; - - PGcancel *cancel = PQgetCancel(_connection); - - if (!cancel) return NO; - - char errorBuf[256]; - - int result = PQcancel(cancel, errorBuf, 256); - - PQfreeCancel(cancel); - - if (!result) { - if (error != NULL) { - *error = [NSError errorWithDomain:FLXPostgresConnectionErrorDomain - code:0 - userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithUTF8String:errorBuf] forKey:NSLocalizedDescriptionKey]]; - } - - return NO; - } - - _lastQueryWasCancelled = YES; - - return YES; -} - -#pragma mark - -#pragma mark Private API - -/** - * Polls the connection that was previously requested via -connect and waits for meaninful status. - * - * @note This method should be called on a background thread as it will block waiting for the connection. - */ -- (void)_pollConnection:(NSNumber *)isReset -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - BOOL reset = [isReset boolValue]; - - int sock = PQsocket(_connection); - - if (sock == -1) { - [pool release]; - return; - } - - struct pollfd fdinfo[1]; - - fdinfo[0].fd = sock; - fdinfo[0].events = POLLIN|POLLOUT; - - PostgresPollingStatusType status; - - do - { - status = reset ? PQresetPoll(_connection) : PQconnectPoll(_connection); - - if (status == PGRES_POLLING_READING || status == PGRES_POLLING_WRITING) { - if (poll(fdinfo, 1, -1) < 0) break; - } - } - while (status != PGRES_POLLING_OK && status != PGRES_POLLING_FAILED); - - if (status == PGRES_POLLING_OK && [self isConnected]) { - - // Increase error verbosity - PQsetErrorVerbosity(_connection, PQERRORS_VERBOSE); - - // Set notice processor - PQsetNoticeProcessor(_connection, _FLXPostgresConnectionNoticeProcessor, self); - - NSInteger success = reset ? PQclearTypes(_connection) : PQinitTypes(_connection); - - // Register type extensions - if (!success) { - NSLog(@"PostgresKit: Error: Failed to initialise (or clear) type extensions. Connection might return unexpected results!"); - } - - [self _loadDatabaseParameters]; - - if (reset) { - if (_delegate && [_delegate respondsToSelector:@selector(connectionReset:)]) { - [_delegate performSelectorOnMainThread:@selector(connectionReset:) withObject:self waitUntilDone:NO]; - } - } - else{ - if (_delegate && [_delegate respondsToSelector:@selector(connectionEstablished:)]) { - [_delegate performSelectorOnMainThread:@selector(connectionEstablished:) withObject:self waitUntilDone:NO]; - } - } - } - - [pool release]; -} - -/** - * Loads the database parameters. - */ -- (void)_loadDatabaseParameters -{ - if (_parameters) [_parameters release]; - - _parameters = [[FLXPostgresConnectionParameters alloc] initWithConnection:self]; - - BOOL success = [_parameters loadParameters]; - - if (!success) NSLog(@"PostgresKit: Warning: Failed to load database parameters."); -} - -/** - * libpq notice processor function. Simply passes the message onto the connection delegate. - * - * @param arg The calling connection. - * @param message The message that was sent. - */ -static void _FLXPostgresConnectionNoticeProcessor(void *arg, const char *message) -{ - FLXPostgresConnection *connection = (FLXPostgresConnection *)arg; - - if ([connection isKindOfClass:[FLXPostgresConnection class]]) { - - if ([connection delegate] && [[connection delegate] respondsToSelector:@selector(connection:notice:)]) { - [[connection delegate] connection:connection notice:[NSString stringWithUTF8String:message]]; - } - } -} - -/** - * Creates the parameter arrays required to establish a connection. - */ -- (void)_createConnectionParameters -{ - BOOL hasUser = NO; - BOOL hasHost = NO; - BOOL hasPassword = NO; - BOOL hasDatabase = NO; - - if (_connectionParamNames) free(_connectionParamNames); - if (_connectionParamValues) free(_connectionParamValues); - - int paramCount = 5; - - if (_user && [_user length]) paramCount++, hasUser = YES; - if (_host && [_host length]) paramCount++, hasHost = YES; - if (_password && [_password length]) paramCount++, hasPassword = YES; - if (_database && [_database length]) paramCount++, hasDatabase = YES; - - _connectionParamNames = malloc(paramCount * sizeof(*_connectionParamNames)); - _connectionParamValues = malloc(paramCount * sizeof(*_connectionParamValues)); - - _connectionParamNames[0] = FLXPostgresApplicationParam; - _connectionParamValues[0] = !_applicationName ? [_applicationName UTF8String] : FLXPostgresKitApplicationName; - - _connectionParamNames[1] = FLXPostgresPortParam; - _connectionParamValues[1] = [[[NSNumber numberWithUnsignedInteger:_port] stringValue] UTF8String]; - - _connectionParamNames[2] = FLXPostgresClientEncodingParam; - _connectionParamValues[2] = [_encoding UTF8String]; - - _connectionParamNames[3] = FLXPostgresKeepAliveParam; - _connectionParamValues[3] = _useKeepAlive ? "1" : "0"; - - _connectionParamNames[4] = FLXPostgresKeepAliveIntervalParam; - _connectionParamValues[4] = [[[NSNumber numberWithUnsignedInteger:_keepAliveInterval] stringValue] UTF8String]; - - NSUInteger i = 5; - - if (hasUser) { - _connectionParamNames[i] = FLXPostgresUserParam; - _connectionParamValues[i] = [_user UTF8String]; - - i++; - } - - if (hasHost) { - _connectionParamNames[i] = FLXPostgresHostParam; - _connectionParamValues[i] = [_host UTF8String]; - - i++; - } - - if (hasPassword) { - _connectionParamNames[i] = FLXPostgresPasswordParam; - _connectionParamValues[i] = [_password UTF8String]; - - i++; - } - - if (hasDatabase) { - _connectionParamNames[i] = FLXPostgresDatabaseParam; - _connectionParamValues[i] = [_database UTF8String]; - - i++; - } - - _connectionParamNames[i] = '\0'; - _connectionParamValues[i] = '\0'; -} - -#pragma mark - - -- (void)dealloc -{ - [_typeMap release]; - - [self disconnect]; - - [self setHost:nil]; - [self setUser:nil]; - [self setDatabase:nil]; - - if (_connectionParamNames) free(_connectionParamNames); - if (_connectionParamValues) free(_connectionParamValues); - - if (_lastError) [_lastError release], _lastError = nil; - if (_parameters) [_parameters release], _parameters = nil; - if (_connectionError) [_connectionError release], _connectionError = nil; - if (_applicationName) [_applicationName release], _applicationName = nil; - - [super dealloc]; -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnectionDelegate.h b/Frameworks/PostgresKit/Source/FLXPostgresConnectionDelegate.h deleted file mode 100644 index d8fd3ac6..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnectionDelegate.h +++ /dev/null @@ -1,65 +0,0 @@ -// -// $Id$ -// -// FLXPostgresConnectionDelegate.h -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -@class FLXPostgresConnection; - -@protocol FLXPostgresConnectionDelegate - -/** - * Called whenever the supplied connection has been successfully established and is ready to use. - * - * @param connection The connection instance. - */ -- (void)connectionEstablished:(FLXPostgresConnection *)connection; - -/** - * Called whenever the supplied connection has been successfully reset and is ready to use. - * - * @param connection The connection instance. - */ -- (void)connectionReset:(FLXPostgresConnection *)connection; - -/** - * Called whenever a connection is disconnected. - * - * @param connection The connection instance. - */ -- (void)connectionDisconnected:(FLXPostgresConnection *)connection; - -/** - * Called whenever a message is received from the PostgreSQL server. - * - * @param connection The connection instance. - * @param notice The notice message received. - */ -- (void)connection:(FLXPostgresConnection *)connection notice:(NSString *)notice; - -/** - * Called just before a query is about to be executed. - * - * @param connection The connection executing the query. - * @param query The query about the be executed. - * @param values The values of the query. - */ -- (void)connection:(FLXPostgresConnection *)connection willExecute:(NSObject *)query withValues:(NSArray *)values; - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnectionEncoding.h b/Frameworks/PostgresKit/Source/FLXPostgresConnectionEncoding.h deleted file mode 100644 index c6686465..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnectionEncoding.h +++ /dev/null @@ -1,39 +0,0 @@ -// $Id$ -// -// FLXPostgresConnectionEncoding.h -// PostgresKit -// -// Created by Stuart Connolly (stuconnolly.com) on August 4, 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 "FLXPostgresConnection.h" - -@interface FLXPostgresConnection (FLXPostgresConnectionEncoding) - -- (BOOL)setEncoding:(NSString *)encoding; - -+ (NSStringEncoding)stringEncodingForPostgreSQLCharset:(const char *)charset; -+ (NSString *)postgreSQLCharsetForStringEncoding:(NSStringEncoding)stringEncoding; - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnectionEncoding.m b/Frameworks/PostgresKit/Source/FLXPostgresConnectionEncoding.m deleted file mode 100644 index a58de60b..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnectionEncoding.m +++ /dev/null @@ -1,197 +0,0 @@ -// -// $Id$ -// -// FLXPostgresConnectionEncoding.m -// PostgresKit -// -// Created by Stuart Connolly (stuconnolly.com) on August 4, 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 "FLXPostgresConnectionEncoding.h" -#import "FLXPostgresKitPrivateAPI.h" - -@implementation FLXPostgresConnection (FLXPostgresConnectionEncoding) - -/** - * Set the current connection's encoding. - * - * @param encoding The name of the encoding to use. - * - * @return A BOOL indicating the success of the operation. NO means there was either no connection or the - * encoding name wasn't recognised by the server. - */ -- (BOOL)setEncoding:(NSString *)encoding -{ - if (![self isConnected]) return NO; - - if ([_encoding isEqualToString:encoding]) return YES; - - if (PQsetClientEncoding(_connection, [encoding UTF8String]) != 0) return NO; - - [_encoding release], _encoding = [[NSString alloc] initWithString:encoding]; - - _stringEncoding = [FLXPostgresConnection stringEncodingForPostgreSQLCharset:[encoding UTF8String]]; - - return YES; -} - -/** - * Translates the supplied encoding name to it's corresponding string encoding identifier. - * - * @param charset The character set as a char array. - * - * @return The string encoding identifier. - */ -+ (NSStringEncoding)stringEncodingForPostgreSQLCharset:(const char *)charset -{ - if (!strcmp(charset, "UNICODE") || !strcmp(charset, "MULE_INTERNAL")) { - return NSUTF8StringEncoding; - } - else if (!strcmp(charset, "LATIN1")) { - return NSISOLatin1StringEncoding; - } - else if (!strcmp(charset, "LATIN2")) { - return NSISOLatin2StringEncoding; - } - else if (!strcmp(charset, "LATIN3")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin3); - } - else if (!strcmp(charset, "LATIN4")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin4); - } - else if (!strcmp(charset, "LATIN5")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin5); - } - else if (!strcmp(charset, "LATIN6")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin6); - } - else if (!strcmp(charset, "LATIN7")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin7); - } - else if (!strcmp(charset, "LATIN8")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin8); - } - else if (!strcmp(charset, "LATIN9")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin9); - } - else if (!strcmp(charset, "LATIN10")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin10); - } - else if (!strcmp(charset, "SQL_ASCII")) { - return NSASCIIStringEncoding; - } - else if (!strcmp(charset, "EUC_JP")) { - return NSJapaneseEUCStringEncoding; - } - else if (!strcmp(charset, "EUC_CN")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingEUC_CN); - } - else if (!strcmp(charset, "EUC_KR")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingEUC_KR); - } - else if (!strcmp(charset, "JOHAB")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsKoreanJohab); - } - else if (!strcmp(charset, "EUC_TW")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingEUC_TW); - } - else if (!strcmp(charset, "ISO_8859_5")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatinCyrillic); - } - else if (!strcmp(charset, "ISO_8859_6")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatinArabic); - } - else if (!strcmp(charset, "ISO_8859_7")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatinGreek); - } - else if (!strcmp(charset, "ISO_8859_8")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatinHebrew); - } - else if (!strcmp(charset, "KOI8")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingKOI8_R); - } - else if (!strcmp(charset, "ALT")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingDOSRussian); - } - else if (!strcmp(charset, "WIN")) { - return NSWindowsCP1251StringEncoding; - } - else if (!strcmp(charset, "WIN1256")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsArabic); - } - else if (!strcmp(charset, "TCVN")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsVietnamese); - } - else if (!strcmp(charset, "WIN874")) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingDOSThai); - } - - NSLog(@"PostgresKit: Warning: Unable to process unknown PostgreSQL encoding '%s'; falling back to UTF8.", charset); - - return FLXPostgresConnectionDefaultStringEncoding; -} - -/** - * Translates the supplied encoding identifier to it's corresponding encoding name. - * - * @param stringEncoding The string encoding to translate - * - * @return The encoding name as a string or nil if there's no mapping. - */ -+ (NSString *)postgreSQLCharsetForStringEncoding:(NSStringEncoding)stringEncoding -{ - switch (stringEncoding) - { - case NSASCIIStringEncoding: - return @"SQL_ASCII"; - - case NSJapaneseEUCStringEncoding: - return @"EUC_JP"; - - case NSUTF8StringEncoding: - case NSNonLossyASCIIStringEncoding: - return @"UNICODE"; - - case NSISOLatin1StringEncoding: - case NSWindowsCP1252StringEncoding: - return @"LATIN1"; - - case NSISOLatin2StringEncoding: - case NSWindowsCP1250StringEncoding: - return @"LATIN2"; - - case NSWindowsCP1251StringEncoding: - return @"WIN"; - - case NSWindowsCP1253StringEncoding: - return @"ISO_8859_7"; - - case NSWindowsCP1254StringEncoding: - return @"LATIN5"; - } - - return nil; -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnectionParameters.h b/Frameworks/PostgresKit/Source/FLXPostgresConnectionParameters.h deleted file mode 100644 index 84864a1a..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnectionParameters.h +++ /dev/null @@ -1,56 +0,0 @@ -// -// $Id$ -// -// FLXPostgresConnectionParameters.h -// PostgresKit -// -// Created by Stuart Connolly (stuconnolly.com) on August 29, 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 - -@class FLXPostgresConnection; - -@interface FLXPostgresConnectionParameters : NSObject -{ - FLXPostgresConnection *_connection; - - NSMutableArray *_parameterNames; - NSMutableDictionary *_parameters; - - pthread_mutex_t _readLock; -} - -/** - * @property connection The database connection to use. - */ -@property (readwrite, assign) FLXPostgresConnection *connection; - -- (id)initWithConnection:(FLXPostgresConnection *)connection; - -- (BOOL)loadParameters; - -- (id)valueForParameter:(NSString *)parameter; - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnectionParameters.m b/Frameworks/PostgresKit/Source/FLXPostgresConnectionParameters.m deleted file mode 100644 index b5c3d9db..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnectionParameters.m +++ /dev/null @@ -1,220 +0,0 @@ -// -// $Id$ -// -// FLXPostgresConnectionParameters.m -// PostgresKit -// -// Created by Stuart Connolly (stuconnolly.com) on August 29, 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 "FLXPostgresConnectionParameters.h" -#import "FLXPostgresKitPrivateAPI.h" -#import "FLXPostgresConnection.h" - -@interface FLXPostgresConnectionParameters () - -- (void)_loadParameters:(id)object; -- (BOOL)_isBooleanParameterValue:(NSString *)value; -- (BOOL)_booleanForParameterValue:(NSString *)value; - -@end - -@implementation FLXPostgresConnectionParameters - -@synthesize connection = _connection; - -#pragma mark - - -- (id)init -{ - return [self initWithConnection:nil]; -} - -/** - * Initialise a parameters instance with the supplied connection. - * - * @param connection The connection to use. - * - * @return The initialised instance. - */ -- (id)initWithConnection:(FLXPostgresConnection *)connection -{ - if ((self = [super init])) { - _connection = connection; - - pthread_mutex_init(&_readLock, NULL); - } - - return self; -} - -#pragma mark - -#pragma mark Public API - -/** - * Loads the database parameters. - * - * @return A BOOL indicating the success of the load. - */ -- (BOOL)loadParameters -{ - pthread_mutex_lock(&_readLock); - - if (!_connection || ![_connection isConnected]) { - pthread_mutex_unlock(&_readLock); - - return NO; - } - - if (!_parameterNames) { - _parameterNames = [[NSMutableArray alloc] init]; - - [_parameterNames addObject:FLXPostgresParameterServerEncoding]; - [_parameterNames addObject:FLXPostgresParameterClientEncoding]; - [_parameterNames addObject:FLXPostgresParameterSuperUser]; - [_parameterNames addObject:FLXPostgresParameterTimeZone]; - [_parameterNames addObject:FLXPostgresParameterIntegerDateTimes]; - } - - pthread_mutex_unlock(&_readLock); - - [self performSelectorInBackground:@selector(_loadParameters:) withObject:_parameterNames]; - - return YES; -} - -/** - * Gets the object for the supplied parameter. - * - * @param parameter The name of the parameter to lookup. - * - * @return The parameter value or nil if parameters haven't been loaded or it can't be found. - */ -- (id)valueForParameter:(NSString *)parameter -{ - pthread_mutex_lock(&_readLock); - - if (!_parameters || ![_parameters count]) { - pthread_mutex_unlock(&_readLock); - - return nil; - } - - id value = [_parameters objectForKey:parameter]; - - pthread_mutex_unlock(&_readLock); - - return value; -} - -#pragma mark - -#pragma mark Private API - -/** - * Loads the values of the supplied array of parameters by query the current connection. - * - * @param object The parameters to load. - */ -- (void)_loadParameters:(id)object -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - pthread_mutex_lock(&_readLock); - - NSArray *parameters = (NSArray *)object; - - if (!_parameters) { - _parameters = [[NSMutableDictionary alloc] initWithCapacity:[parameters count]]; - } - - for (NSString *parameter in parameters) - { - const char *value = PQparameterStatus([_connection postgresConnection], [parameter UTF8String]); - - if (!value) continue; - - NSString *stringValue = [NSString stringWithUTF8String:value]; - - id paramObject = [self _isBooleanParameterValue:stringValue] ? (id)[NSNumber numberWithBool:[self _booleanForParameterValue:stringValue]] : stringValue; - - [_parameters setObject:paramObject forKey:parameter]; - } - - pthread_mutex_unlock(&_readLock); - - [pool release]; -} - -/** - * Determines whether or not the supplied value is a boolean value. - * - * @param value The value to look at. - * - * @return A BOOL indicating if the value is a boolean type. - */ -- (BOOL)_isBooleanParameterValue:(NSString *)value -{ - value = [value uppercaseString]; - - return - [value isEqualToString:@"ON"] || - [value isEqualToString:@"YES"] || - [value isEqualToString:@"TRUE"] || - [value isEqualToString:@"OFF"] || - [value isEqualToString:@"NO"] || - [value isEqualToString:@"FALSE"]; -} - -/** - * Determines the boolean value for the supplied boolean string representation. - * - * @param value The value to look at. - * - * @return A BOOL indicating the value of the string representation. - */ -- (BOOL)_booleanForParameterValue:(NSString *)value -{ - value = [value uppercaseString]; - - return - [value isEqualToString:@"ON"] || - [value isEqualToString:@"YES"] || - [value isEqualToString:@"TRUE"]; -} - -#pragma mark - - -- (void)dealloc -{ - _connection = nil; - - pthread_mutex_destroy(&_readLock); - - if (_parameters) [_parameters release], _parameters = nil; - if (_parameterNames) [_parameterNames release], _parameterNames = nil; - - [super dealloc]; -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnectionQueryExecution.h b/Frameworks/PostgresKit/Source/FLXPostgresConnectionQueryExecution.h deleted file mode 100644 index b1c8aed0..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnectionQueryExecution.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// $Id$ -// -// FLXPostgresConnectionQueryExecution.h -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresConnection.h" - -@interface FLXPostgresConnection (FLXPostgresConnectionQueryExecution) - -// Synchronous interface -- (FLXPostgresResult *)execute:(NSString *)query; -- (FLXPostgresResult *)executeWithFormat:(NSString *)query, ...; -- (FLXPostgresResult *)executePrepared:(FLXPostgresStatement *)statement; -- (FLXPostgresResult *)execute:(NSString *)query values:(NSArray *)values; -- (FLXPostgresResult *)execute:(NSString *)query value:(NSObject *)value; -- (FLXPostgresResult *)executePrepared:(FLXPostgresStatement *)statement values:(NSArray *)values; -- (FLXPostgresResult *)executePrepared:(FLXPostgresStatement *)statement value:(NSObject *)value; - -// Asynchronous interface - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnectionQueryExecution.m b/Frameworks/PostgresKit/Source/FLXPostgresConnectionQueryExecution.m deleted file mode 100644 index a41471a3..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnectionQueryExecution.m +++ /dev/null @@ -1,314 +0,0 @@ -// -// $Id$ -// -// FLXPostgresConnectionQueryExecution.h -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresConnectionQueryExecution.h" -#import "FLXPostgresKitPrivateAPI.h" -#import "FLXPostgresConnectionTypeHandling.h" -#import "FLXPostgresConnectionDelegate.h" -#import "FLXPostgresTypeHandlerProtocol.h" -#import "FLXPostgresConnection.h" -#import "FLXPostgresException.h" -#import "FLXPostgresResult.h" -#import "FLXPostgresStatement.h" -#import "FLXPostgresError.h" - -// Constants -static int FLXPostgresResultsAsBinary = 1; - -// Internal query structure -typedef struct -{ - int paramNum; - const void **paramValues; - FLXPostgresOid* paramTypes; - int *paramLengths; - int *paramFormats; -} -FLXQueryParamData; - -@interface FLXPostgresConnection () - -- (FLXPostgresResult *)_execute:(NSObject *)query values:(NSArray *)values; -- (BOOL)_queryDidError:(PGresult *)result; -- (FLXQueryParamData *)_createParameterDataStructureWithCount:(int)paramNum; -- (void)_destroyParamDataStructure:(FLXQueryParamData *)paramData; - -@end - -@implementation FLXPostgresConnection (FLXPostgresConnectionQueryExecution) - -#pragma mark - -#pragma mark Synchronous Interface - -- (FLXPostgresResult *)execute:(NSString *)query -{ - return [self _execute:query values:nil]; -} - -- (FLXPostgresResult *)execute:(NSString *)query value:(NSObject *)value -{ - return [self _execute:query values:[NSArray arrayWithObject:value]]; -} - -- (FLXPostgresResult *)executePrepared:(FLXPostgresStatement *)statement value:(NSObject *)value -{ - return [self _execute:statement values:[NSArray arrayWithObject:value]]; -} - -- (FLXPostgresResult *)executePrepared:(FLXPostgresStatement *)statement -{ - return [self _execute:statement values:nil]; -} - -- (FLXPostgresResult *)executePrepared:(FLXPostgresStatement *)statement values:(NSArray *)values -{ - return [self _execute:statement values:values]; -} - -- (FLXPostgresResult *)execute:(NSString *)query values:(NSArray *)values -{ - return [self _execute:query values:values]; -} - -- (FLXPostgresResult *)executeWithFormat:(NSString *)query, ... -{ - va_list argumentList; - va_start(argumentList, query); - - NSMutableString *string = [[NSMutableString alloc] init]; - - CFStringAppendFormatAndArguments((CFMutableStringRef)string, (CFDictionaryRef)nil, (CFStringRef)query, argumentList); - - va_end(argumentList); - - FLXPostgresResult *result = [self _execute:string values:nil]; - - [string release]; - - return result; -} - -#pragma mark - -#pragma mark Asynchronous Interface - -#pragma mark - -#pragma mark Private API - -- (FLXPostgresResult *)_execute:(NSObject *)query values:(NSArray *)values -{ - _lastQueryWasCancelled = NO; - - if (![self isConnected] || !query || ![query isKindOfClass:[NSString class]] || [query isKindOfClass:[FLXPostgresStatement class]]) return nil; - - // Notify the delegate - if (_delegate && _delegateSupportsWillExecute) { - [_delegate connection:self willExecute:query withValues:values]; - } - - FLXQueryParamData *paramData = [self _createParameterDataStructureWithCount:values ? (int)[values count] : 0]; - - if (!paramData) return nil; - - // Fill the data structures - for (int i = 0; i < paramData->paramNum; i++) - { - id nativeObject = [values objectAtIndex:i]; - - // Deterime if bound value is an NSNull - if ([nativeObject isKindOfClass:[NSNull class]]) { - paramData->paramValues[i] = NULL; - paramData->paramTypes[i] = 0; - paramData->paramLengths[i] = 0; - paramData->paramFormats[i] = 0; - - continue; - } - - // Obtain correct handler for this class - id typeHandler = [self typeHandlerForClass:[nativeObject class]]; - - if (!typeHandler) { - [self _destroyParamDataStructure:paramData]; - - // TODO: get rid of exceptions - [FLXPostgresException raise:FLXPostgresConnectionErrorDomain reason:[NSString stringWithFormat:@"Parameter $%u unsupported class %@", (i + 1), NSStringFromClass([nativeObject class])]]; - return nil; - } - - NSData *data = nil; // Sending parameters as binary is not implemented yet - FLXPostgresOid type = 0; - - if (!data) { - [self _destroyParamDataStructure:paramData]; - - // TODO: get rid of exceptions - [FLXPostgresException raise:FLXPostgresConnectionErrorDomain reason:[NSString stringWithFormat:@"Parameter $%u cannot be converted into a bound value", (i + 1)]]; - return nil; - } - - // Check length of data - if ([data length] > INT_MAX) { - [self _destroyParamDataStructure:paramData]; - - // TODO: get rid of exceptions - [FLXPostgresException raise:FLXPostgresConnectionErrorDomain reason:[NSString stringWithFormat:@"Bound value $%u exceeds maximum size", (i + 1)]]; - return nil; - } - - // Assign data - paramData->paramTypes[i] = type; - - // NOTE: if data length is zero, we encode as text instead, as NSData returns 0 for - // empty data, and it gets encoded as a NULL. - if ([data length] == 0) { - paramData->paramValues[i] = ""; - paramData->paramFormats[i] = 0; - paramData->paramLengths[i] = 0; - } - else { - // Send as binary data - paramData->paramValues[i] = [data bytes]; - paramData->paramLengths[i] = (int)[data length]; - paramData->paramFormats[i] = 1; - } - } - - // Execute the command - return data in binary - PGresult *result = nil; - - if ([query isKindOfClass:[NSString class]]) { - - result = PQexecParams(_connection, - [(NSString *)query UTF8String], - paramData->paramNum, - paramData->paramTypes, - (const char **)paramData->paramValues, - (const int *)paramData->paramLengths, - (const int *)paramData->paramFormats, - FLXPostgresResultsAsBinary); - } - else if ([query isKindOfClass:[FLXPostgresStatement class]]) { - FLXPostgresStatement *statement = (FLXPostgresStatement *)query; - - // Statement has not been prepared yet, so prepare it with the given parameter types - if (![statement name]) { - BOOL prepareResult = [self _prepare:statement num:paramData->paramNum types:paramData->paramTypes]; - - if (!prepareResult || ![statement name]) return nil; - } - - result = PQexecPrepared(_connection, - [statement UTF8Name], - paramData->paramNum, - (const char **)paramData->paramValues, - (const int *)paramData->paramLengths, - (const int *)paramData->paramFormats, - FLXPostgresResultsAsBinary); - } - - [self _destroyParamDataStructure:paramData]; - - if (!result || [self _queryDidError:result]) return nil; - - return [[[FLXPostgresResult alloc] initWithResult:result connection:self] autorelease]; -} - -/** - * Determines whether or not the supplied result indicates an error occurred. - * - * @param result The result to examine. - * - * @return A BOOL indicating if an error occurred. - */ -- (BOOL)_queryDidError:(PGresult *)result -{ - ExecStatusType status = PQresultStatus(result); - - if (status == PGRES_BAD_RESPONSE || status == PGRES_FATAL_ERROR) { - if (_lastError) [_lastError release], _lastError = nil; - - _lastError = [[FLXPostgresError alloc] initWithResult:result]; - - PQclear(result); - - return YES; - } - - return NO; -} - -/** - * Creates the internal query parameter data structure. - * - * @note This method will throw an exception if it can't allocated the required memory. - * - * @param paramNum The number of parameters the structure should accommodate. - * - * @return The data structure or nil if an exception occurred. - */ -- (FLXQueryParamData *)_createParameterDataStructureWithCount:(int)paramNum -{ - FLXQueryParamData *paramData = malloc(sizeof(FLXQueryParamData)); - - paramData->paramNum = paramNum; - paramData->paramValues = NULL; - paramData->paramTypes = NULL; - paramData->paramLengths = NULL; - paramData->paramFormats = NULL; - - if (paramData->paramNum) { - paramData->paramValues = malloc(sizeof(void *) * paramData->paramNum); - paramData->paramTypes = malloc(sizeof(FLXPostgresOid) * paramData->paramNum); - paramData->paramLengths = malloc(sizeof(int) * paramData->paramNum); - paramData->paramFormats = malloc(sizeof(int) * paramData->paramNum); - - if (!paramData->paramValues || !paramData->paramLengths || !paramData->paramFormats) { - [self _destroyParamDataStructure:paramData]; - - // Probably justifies throwing an exception if we can't allocate any memory! - [FLXPostgresException raise:FLXPostgresConnectionErrorDomain reason:@"Memory allocation error"]; - - return nil; - } - } - - return paramData; -} - -/** - * Frees the memory associated with the supplied parameter data structure. - * - * @param paramData The parameter data to destroy. - */ -- (void)_destroyParamDataStructure:(FLXQueryParamData *)paramData -{ - if (!paramData) return; - - if (paramData->paramValues) free(paramData->paramValues); - if (paramData->paramTypes) free(paramData->paramTypes); - if (paramData->paramLengths) free(paramData->paramLengths); - if (paramData->paramFormats) free(paramData->paramFormats); - - free(paramData); -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnectionQueryPreparation.h b/Frameworks/PostgresKit/Source/FLXPostgresConnectionQueryPreparation.h deleted file mode 100644 index 915b8c90..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnectionQueryPreparation.h +++ /dev/null @@ -1,30 +0,0 @@ -// -// $Id$ -// -// FLXPostgresConnectionQueryPreparation.h -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresConnection.h" - -@interface FLXPostgresConnection (FLXPostgresConnectionQueryPreparation) - -- (FLXPostgresStatement *)prepare:(NSString *)query; -- (FLXPostgresStatement *)prepareWithFormat:(NSString *)query, ...; - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnectionQueryPreparation.m b/Frameworks/PostgresKit/Source/FLXPostgresConnectionQueryPreparation.m deleted file mode 100644 index b2f80702..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnectionQueryPreparation.m +++ /dev/null @@ -1,108 +0,0 @@ -// -// $Id$ -// -// FLXPostgresConnectionQueryPreparation.m -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresConnectionQueryPreparation.h" -#import "FLXPostgresConnectionTypeHandling.h" -#import "FLXPostgresKitPrivateAPI.h" -#import "FLXPostgresStatement.h" -#import "FLXPostgresException.h" - -@implementation FLXPostgresConnection (FLXPostgresConnectionQueryPreparation) - -/** - * Creates a prepared statment from the supplied query. - * - * @param query The query to create the statement from. - * - * @return The prepared statement instance. - */ -- (FLXPostgresStatement *)prepare:(NSString *)query -{ - if (!query || ![query length]) return nil; - - return [[[FLXPostgresStatement alloc] initWithStatement:query] autorelease]; -} - -/** - * Creates a prepared statment from the supplied query format and values. - * - * @param query The query to create the statement from. - * @param ... Any values to insert into the query (optional). - * - * @return The prepared statement instance. - */ -- (FLXPostgresStatement *)prepareWithFormat:(NSString *)query, ... -{ - if (!query || ![query length]) return nil; - - va_list args; - va_start(args, query); - - NSMutableString *string = [[NSMutableString alloc] initWithFormat:query arguments:args]; - - va_end(args); - - FLXPostgresStatement *statement = [self prepare:string]; - - [string release]; - - return statement; -} - -#pragma mark - -#pragma mark Private API - -/** - * Actually prepares the supplied statement against the database. - * - * @param statement The statement to prepare. - * @param paranNum The number of parameters the statement contains. - * @param paramTypes Any of Postgres parameter types. - * - * @return A BOOL indicating succes. Returns NO if there's no statement, statement name or current connection. - */ -- (BOOL)_prepare:(FLXPostgresStatement *)statement num:(NSInteger)paramNum types:(FLXPostgresOid *)paramTypes -{ - if (!statement || ![statement name] || ![self isConnected]) return NO; - - NSString *name = [[NSProcessInfo processInfo] globallyUniqueString]; - - PGresult *result = PQprepare(_connection, [name UTF8String], [statement UTF8Statement], (int)paramNum, paramTypes); - - if (!result) return NO; - - ExecStatusType resultStatus = PQresultStatus(result); - - if (resultStatus == PGRES_BAD_RESPONSE || resultStatus == PGRES_FATAL_ERROR) { - PQclear(result); - - return NO; - } - - PQclear(result); - - [statement setName:name]; - - return YES; -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnectionTypeHandling.h b/Frameworks/PostgresKit/Source/FLXPostgresConnectionTypeHandling.h deleted file mode 100644 index 6567cd0b..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnectionTypeHandling.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// $Id$ -// -// FLXPostgresConnectionTypeHandling.h -// PostgresKit -// -// Created by Stuart Connolly (stuconnolly.com) on July 29, 2012. -// Copyright (c) 2012 Stuart Connolly. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresConnection.h" -#import "FLXPostgresTypeHandlerProtocol.h" - -@interface FLXPostgresConnection (FLXPostgresConnectionTypeHandling) - -- (void)registerTypeHandlers; - -- (id )typeHandlerForClass:(Class)class; -- (id )typeHandlerForRemoteType:(FLXPostgresOid)type; - -- (void)registerTypeHandler:(Class)handlerClass; - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnectionTypeHandling.m b/Frameworks/PostgresKit/Source/FLXPostgresConnectionTypeHandling.m deleted file mode 100644 index 483519cf..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnectionTypeHandling.m +++ /dev/null @@ -1,107 +0,0 @@ -// -// $Id$ -// -// FLXPostgresConnectionTypeHandling.m -// PostgresKit -// -// Created by Stuart Connolly (stuconnolly.com) on July 29, 2012. -// Copyright (c) 2012 Stuart Connolly. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresConnectionTypeHandling.h" -#import "FLXPostgresTypeStringHandler.h" -#import "FLXPostgresTypeNumberHandler.h" -#import "FLXPostgresTypeDateTimeHandler.h" -#import "FLXPostgresException.h" - -@implementation FLXPostgresConnection (FLXPostgresConnectionTypeHandling) - -/** - * Register all of our data type handlers for this connection. - */ -- (void)registerTypeHandlers -{ - if (_typeMap) { - [_typeMap release]; - - _typeMap = [[NSMutableDictionary alloc] init]; - } - - [self registerTypeHandler:[FLXPostgresTypeStringHandler class]]; - [self registerTypeHandler:[FLXPostgresTypeNumberHandler class]]; - [self registerTypeHandler:[FLXPostgresTypeDateTimeHandler class]]; -} - -/** - * Get the data type handler for the supplied class. - * - * @param class The class to get the handler for. - * - * @return The handler or nil if there's none associated with the class. - */ -- (id )typeHandlerForClass:(Class)class -{ - return [_typeMap objectForKey:NSStringFromClass(class)]; -} - -/** - * Get the data type handler for the supplied PostgreSQL type. - * - * @param type The PostgreSQL type to get the handler for. - * - * @return The handler or nil if there's none associated with the type. - */ -- (id )typeHandlerForRemoteType:(FLXPostgresOid)type -{ - return [_typeMap objectForKey:[NSNumber numberWithUnsignedInteger:type]]; -} - -/** - * Register the supplied type handler class. - * - * @param handlerClass The handler class to register. - */ -- (void)registerTypeHandler:(Class)handlerClass -{ - if (![handlerClass conformsToProtocol:@protocol(FLXPostgresTypeHandlerProtocol)]) { - [FLXPostgresException raise:FLXPostgresConnectionErrorDomain - reason:@"Class '%@' does not conform to protocol '%@'", NSStringFromClass(handlerClass), NSStringFromProtocol(@protocol(FLXPostgresTypeHandlerProtocol))]; - } - - // Create an instance of this class - id handler = [[[handlerClass alloc] initWithConnection:self] autorelease]; - - // Add to the type map - for native class - [_typeMap setObject:handler forKey:NSStringFromClass([handler nativeClass])]; - - NSArray *aliases = [handler classAliases]; - - if (aliases) { - for (NSString *alias in aliases) - { - [_typeMap setObject:handler forKey:alias]; - } - } - - FLXPostgresOid *remoteTypes = [handler remoteTypes]; - - for (NSUInteger i = 0; remoteTypes[i]; i++) - { - NSNumber *key = [NSNumber numberWithUnsignedInteger:remoteTypes[i]]; - - [_typeMap setObject:handler forKey:key]; - } -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnectionUtils.h b/Frameworks/PostgresKit/Source/FLXPostgresConnectionUtils.h deleted file mode 100644 index 60eacfea..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnectionUtils.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// $Id$ -// -// FLXPostgresConnectionUtils.h -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresConnection.h" - -@interface FLXPostgresConnection (FLXPostgresConnectionUtils) - -- (NSArray *)schemas; -- (NSArray *)databases; -- (NSArray *)tablesInSchema:(NSString *)schema; -- (NSArray *)columnNamesForTable:(NSString *)table inSchema:(NSString *)schema; -- (NSString *)primaryKeyForTable:(NSString *)table inSchema:(NSString *)schema; - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnectionUtils.m b/Frameworks/PostgresKit/Source/FLXPostgresConnectionUtils.m deleted file mode 100644 index 73235766..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnectionUtils.m +++ /dev/null @@ -1,133 +0,0 @@ -// -// $Id$ -// -// FLXPostgresConnectionUtils.m -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresConnectionQueryPreparation.h" -#import "FLXPostgresConnectionQueryExecution.h" -#import "FLXPostgresResult.h" - -@interface FLXPostgresConnection () - -- (NSArray *)_executeAndReturnResult:(NSString *)query; - -@end - -@implementation FLXPostgresConnection (FLXPostgresConnectionUtils) - -/** - * Returns an array of all databases. - * - * @return An array of strings or nil if no connection is present. - */ -- (NSArray *)databases -{ - return [self isConnected] ? [self _executeAndReturnResult:@"SELECT DISTINCT \"catalog_name\" FROM \"information_schema\".\"schemata\""] : nil; -} - -/** - * Returns an array of all schemas. - * - * @return An array of strings or nil if no connection is present. - */ -- (NSArray *)schemas -{ - return [self isConnected] ? [self _executeAndReturnResult:[NSString stringWithFormat:@"SELECT \"schema_name\" FROM \"information_schema\".\"schemata\" WHERE \"catalog_name\" = '%@'", [self database]]] : nil; -} - -/** - * Returns an array of tables in the supplied schema. - * - * @param schem The schema to get tables for. - * - * @return An array of strings or nil if not connected or parameters are not valid. - */ -- (NSArray * )tablesInSchema:(NSString *)schema -{ - if (![self isConnected] || !schema || ![schema length]) return nil; - - return [self _executeAndReturnResult:[NSString stringWithFormat:@"SELECT \"table_name\" FROM \"information_schema\".\"tables\" WHERE \"table_catalog\" = '%@' AND \"table_schema\" = '%@' AND \"table_type\" = 'BASE TABLE'",[self database], schema]]; -} - -/** - * Get the primary key column name on the supplied table in the supplied schema. - * - * @param table The table to get the primary key for. - * @param schema The schem the table belongs to. - * - * @return The column name as a string or nil not connected or parameters are not valid. - */ -- (NSString *)primaryKeyForTable:(NSString *)table inSchema:(NSString *)schema -{ - if (![self isConnected] || !table || ![table length] || !schema || ![schema length]) return nil; - - NSString *join = @"\"information_schema\".\"table_constraints\" t INNER JOIN \"information_schema\".\"key_column_usage\" k ON t.\"constraint_name\" = k.\"constraint_name\""; - NSString *where = [NSString stringWithFormat:@"t.\"constraint_type\" = 'PRIMARY KEY' AND t.\"table_catalog\" = '%@' AND t.\"table_schema\" = '%@' AND t.\"table_name\" = '%@'", [self database], schema, table]; - - FLXPostgresResult *result = [self executeWithFormat:@"SELECT k.\"column_name\" FROM %@ WHERE %@", join, where]; - - return [result numberOfRows] == 0 ? nil : [[result rowAsArray] objectAtIndex:0]; -} - -/** - * Returns an array of column names for the supplied table and schema. - * - * @param table The table to get column names from. - * @param schema The schem the table belongs to. - * - * @return An array of strings or nil if not connected or parameters are not valid. - */ -- (NSArray *)columnNamesForTable:(NSString *)table inSchema:(NSString *)schema -{ - if (![self isConnected] || !table || ![table length] || !schema || ![schema length]) return nil; - - return [self _executeAndReturnResult:[NSString stringWithFormat:@"SELECT \"column_name\" FROM \"information_schema\".\"columns\" WHERE \"table_catalog\" = '%@' AND \"table_schema\" = '%@' AND \"table_name\" = '%@'", [self database], schema, table]]; -} - -#pragma mark - -#pragma mark Private API - -/** - * Executes the supplied query and returns the result. - * - * @param query The query to execute. - * - * @return The result as an array. - */ -- (NSArray *)_executeAndReturnResult:(NSString *)query -{ - FLXPostgresResult *result = [self execute:query]; - - if (!result || ![result numberOfRows]) return nil; - - NSArray *row = nil; - NSMutableArray *data = [NSMutableArray arrayWithCapacity:(NSUInteger)[result numberOfRows]]; - - while ((row = [result rowAsArray])) - { - if (![row count]) continue; - - [data addObject:[row objectAtIndex:0]]; - } - - return data; -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresError.h b/Frameworks/PostgresKit/Source/FLXPostgresError.h deleted file mode 100644 index f3ee9c60..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresError.h +++ /dev/null @@ -1,74 +0,0 @@ -// -// $Id$ -// -// FLXPostgresError.h -// PostgresKit -// -// Created by Stuart Connolly (stuconnolly.com) on September 3, 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. - -@interface FLXPostgresError : NSObject -{ - NSString *_errorSeverity; - NSString *_errorStateCode; - NSString *_errorPrimaryMessage; - NSString *_errorDetailMessage; - NSString *_errorMessageHint; - - NSUInteger _errorStatementPosition; -} - -/** - * @property errorSeverity The severity of the error. - */ -@property (readonly) NSString *errorSeverity; - -/** - * @property errorStateCode The errors state code. - */ -@property (readonly) NSString *errorStateCode; - -/** - * @property errorPrimaryMessage The primary error message. - */ -@property (readonly) NSString *errorPrimaryMessage; - -/** - * @property errorDetailMessage The detailed error message. - */ -@property (readonly) NSString *errorDetailMessage; - -/** - * @property errorMessageHint The error message hint. - */ -@property (readonly) NSString *errorMessageHint; - -/** - * @property errorStatementPosition The position within the executed statement that caused the error. - */ -@property (readonly) NSUInteger errorStatementPosition; - -- (id)initWithResult:(const void *)result; - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresError.m b/Frameworks/PostgresKit/Source/FLXPostgresError.m deleted file mode 100644 index 31024a92..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresError.m +++ /dev/null @@ -1,129 +0,0 @@ -// -// $Id$ -// -// FLXPostgresError.m -// PostgresKit -// -// Created by Stuart Connolly (stuconnolly.com) on September 3, 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 "FLXPostgresError.h" -#import "FLXPostgresException.h" - -@interface FLXPostgresError () - -- (void)_extractErrorDetailsFromResult:(const PGresult *)result; -- (NSString *)_extractErrorField:(int)field fromResult:(const PGresult *)result; - -@end - -@implementation FLXPostgresError - -@synthesize errorSeverity = _errorSeverity; -@synthesize errorStateCode = _errorStateCode; -@synthesize errorPrimaryMessage = _errorPrimaryMessage; -@synthesize errorDetailMessage = _errorDetailMessage; -@synthesize errorMessageHint = _errorMessageHint; -@synthesize errorStatementPosition = _errorStatementPosition; - -#pragma mark - - -- (id)init -{ - [FLXPostgresException raise:NSInternalInconsistencyException - reason:@"%@ shouldn't be init'd directly; use initWithResult: instead.", [self className]]; - - return nil; -} - -- (id)initWithResult:(const void *)result -{ - if ((self = [super init])) { - - _errorSeverity = nil; - _errorStateCode = nil; - _errorPrimaryMessage = nil; - _errorDetailMessage = nil; - _errorMessageHint = nil; - _errorStatementPosition = -1; - - if (result) [self _extractErrorDetailsFromResult:(const PGresult *)result]; - } - - return self; -} - -- (NSString *)description -{ - return [NSString stringWithFormat:@"<%@: Sev %@ (%@): %@>", [self className], _errorSeverity, _errorStateCode, _errorPrimaryMessage]; -} - -#pragma mark - -#pragma mark Private API - -/** - * Extracts all the error information from the supplied result. - * - * @param result The Postgres result to extract the information from. - */ -- (void)_extractErrorDetailsFromResult:(const PGresult *)result -{ - // Note that we don't expose all the fields that are available. - // The ones we don't mostly include information internal to Postgres - // that generally isn't useful to end users. - _errorSeverity = [self _extractErrorField:PG_DIAG_SEVERITY fromResult:result]; - _errorStateCode = [self _extractErrorField:PG_DIAG_SQLSTATE fromResult:result]; - _errorPrimaryMessage = [self _extractErrorField:PG_DIAG_MESSAGE_PRIMARY fromResult:result]; - _errorDetailMessage = [self _extractErrorField:PG_DIAG_MESSAGE_DETAIL fromResult:result]; - _errorMessageHint = [self _extractErrorField:PG_DIAG_MESSAGE_HINT fromResult:result]; - _errorStatementPosition = [[self _extractErrorField:PG_DIAG_STATEMENT_POSITION fromResult:result] integerValue]; -} - -/** - * Extracts the supplied error field from the supplied Postgres result. - * - * @param field The error field to extract. - * @param result The Postgres result to extract the field from. - * - * @return A string representing the error value. The caller is responsible for freeing the associated memory. - */ -- (NSString *)_extractErrorField:(int)field fromResult:(const PGresult *)result -{ - return [[[NSString alloc] initWithUTF8String:PQresultErrorField(result, field)] autorelease]; -} - -#pragma mark - - -- (void)dealloc -{ - if (_errorSeverity) [_errorSeverity release], _errorSeverity = nil; - if (_errorStateCode) [_errorStateCode release], _errorStateCode = nil; - if (_errorPrimaryMessage) [_errorPrimaryMessage release], _errorPrimaryMessage = nil; - if (_errorDetailMessage) [_errorDetailMessage release], _errorDetailMessage = nil; - if (_errorMessageHint) [_errorMessageHint release], _errorMessageHint = nil; - - [super dealloc]; -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresException.h b/Frameworks/PostgresKit/Source/FLXPostgresException.h deleted file mode 100644 index 54b781c4..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresException.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// $Id$ -// -// FLXPostgresException.h -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -@interface FLXPostgresException : NSException - -+ (void)raise:(NSString *)name connection:(void *)connection; -+ (void)raise:(NSString *)name reason:(NSString *)reason, ...; - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresException.m b/Frameworks/PostgresKit/Source/FLXPostgresException.m deleted file mode 100644 index 266ac1a7..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresException.m +++ /dev/null @@ -1,64 +0,0 @@ -// -// $Id$ -// -// FLXPostgresException.m -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresException.h" - -@implementation FLXPostgresException - -/** - * Raise a new exception with the supplied details. - * - * @param name The name of the exception to raise. - * @param connection The connection associated with the exception being raised. - */ -+ (void)raise:(NSString *)name connection:(void *)connection -{ - const char *errorMessage = "Unknown error"; - - if (connection) errorMessage = PQerrorMessage(connection); - - errorMessage = strlen(errorMessage) ? errorMessage : "Unknown error"; - - [[[[FLXPostgresException alloc] initWithName:name reason:[NSString stringWithUTF8String:errorMessage] userInfo:nil] autorelease] raise]; -} - -/** - * Raise a new exception with the supplied details. - * - * @param name The name of the exception to raise. - * @param reason The reason for the exception being raised. - */ -+ (void)raise:(NSString *)name reason:(NSString *)reason, ... -{ - va_list args; - va_start(args, reason); - - NSString *reasonMessage = [[NSString alloc] initWithFormat:reason arguments:args]; - - va_end(args); - - [[[[FLXPostgresException alloc] initWithName:name reason:reasonMessage userInfo:nil] autorelease] raise]; - - [reasonMessage release]; -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresKitPrivateAPI.h b/Frameworks/PostgresKit/Source/FLXPostgresKitPrivateAPI.h deleted file mode 100644 index 1a564b91..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresKitPrivateAPI.h +++ /dev/null @@ -1,46 +0,0 @@ -// -// $Id$ -// -// FLXPostgresConnectionKitAPI.h -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresConnection.h" -#import "FLXPostgresTimeInterval.h" - -@interface FLXPostgresConnection () - -- (PGconn *)postgresConnection; - -@end - -@interface FLXPostgresConnection (FLXPostgresConnectionQueryPreparationPrivateAPI) - -- (BOOL)_prepare:(FLXPostgresStatement *)statement num:(NSInteger)paramNum types:(FLXPostgresOid *)paramTypes; - -@end - -@interface FLXPostgresTimeInterval () - -+ (id)intervalWithPGInterval:(PGinterval *)interval; -- (id)initWithInterval:(PGinterval *)interval; - -@end - - - diff --git a/Frameworks/PostgresKit/Source/FLXPostgresResult.h b/Frameworks/PostgresKit/Source/FLXPostgresResult.h deleted file mode 100644 index 6f10c3e5..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresResult.h +++ /dev/null @@ -1,84 +0,0 @@ -// -// $Id$ -// -// FLXPostgresResult.h -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -@class FLXPostgresConnection; - -// Result set row types -typedef enum -{ - FLXPostgresResultRowAsArray = 1, - FLXPostgresResultRowAsDictionary = 2 -} -FLXPostgresResultRowType; - -@interface FLXPostgresResult : NSObject -{ - void *_result; - void **_typeHandlers; - - unsigned long long _row; - unsigned long long _numberOfRows; - - NSUInteger _numberOfFields; - - NSString **_fields; - - NSStringEncoding _stringEncoding; - FLXPostgresResultRowType _defaultRowType; - - FLXPostgresConnection *_connection; -} - -/** - * @property numberOfFields The number of fields this result has. - */ -@property (readonly) NSUInteger numberOfFields; - -/** - * @property numberOfRows The number or rows this result has. - */ -@property (readonly) unsigned long long numberOfRows; - -/** - * @property stringEncoding The ecoding that was in use when this result was created. - */ -@property (readonly) NSStringEncoding stringEncoding; - -/** - * @property defaultRowType The row type that should be used when calling -row. - */ -@property (readwrite, assign) FLXPostgresResultRowType defaultRowType; - -- (id)initWithResult:(void *)result connection:(FLXPostgresConnection *)connection; - -- (NSUInteger)numberOfFields; - -- (void)seekToRow:(unsigned long long)row; - -- (NSArray *)fields; - -- (id)row; -- (NSArray *)rowAsArray; -- (NSDictionary *)rowAsDictionary; -- (id)rowAsType:(FLXPostgresResultRowType)type; - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresResult.m b/Frameworks/PostgresKit/Source/FLXPostgresResult.m deleted file mode 100644 index f2844faa..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresResult.m +++ /dev/null @@ -1,308 +0,0 @@ -// -// $Id$ -// -// FLXPostgresResult.m -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresResult.h" -#import "FLXPostgresException.h" -#import "FLXPostgresConnection.h" -#import "FLXPostgresConnectionTypeHandling.h" - -@interface FLXPostgresResult () - -- (void)_populateFields; -- (id)_objectForRow:(NSUInteger)row column:(NSUInteger)column; -- (id )_typeHandlerForColumn:(NSUInteger)column withType:(FLXPostgresOid)type; - -@end - -@implementation FLXPostgresResult - -@synthesize numberOfRows = _numberOfRows; -@synthesize numberOfFields = _numberOfFields; -@synthesize stringEncoding = _stringEncoding; -@synthesize defaultRowType = _defaultRowType; - -#pragma mark - -#pragma mark Initialisation - -/** - * Prevent normal initialisation. - * - * @return nil - */ -- (id)init -{ - [FLXPostgresException raise:NSInternalInconsistencyException reason:@"%@ shouldn't be init'd directly; use initWithResult:connection: instead.", [self className]]; - - return nil; -} - -/** - * Initialises a result with the supplied details. - * - * @param result The underlying PostgreSQL result this wrapper represents. - * @param connection The connection the result came from. - * - * @return The result wrapper. - */ -- (id)initWithResult:(void *)result connection:(FLXPostgresConnection *)connection -{ - if ((self = [super init])) { - - _row = 0; - _result = result; - _numberOfRows = PQntuples(_result); - _numberOfFields = PQnfields(_result); - _connection = [connection retain]; - - _stringEncoding = [_connection stringEncoding]; - _defaultRowType = FLXPostgresResultRowAsDictionary; - - _typeHandlers = (void **)calloc(sizeof(void *), _numberOfFields); - - unsigned long long affectedRows = (unsigned long long)[[NSString stringWithUTF8String:PQcmdTuples(_result)] longLongValue]; - - _numberOfRows = PQresultStatus(_result) == PGRES_TUPLES_OK ? _numberOfRows : affectedRows; - - [self _populateFields]; - } - - return self; -} - -#pragma mark - -#pragma mark Public API - -/** - * This result's fields as an array. - * - * @return The array of fields. - */ -- (NSArray *)fields -{ - return [NSArray arrayWithObjects:_fields count:_numberOfFields]; -} - -/** - * Sets the current row marker to the supplied row. - * - * @param row The row to seek to. - */ -- (void)seekToRow:(unsigned long long)row -{ - if (row >= _numberOfRows) row = _numberOfRows - 1; - - _row = row; -} - -#pragma mark - -#pragma mark Data Retrieval - -/** - * Return the current row in the type of the currently set default (defaults to dictionary). - * - * @return The row of data. - */ -- (id)row -{ - return [self rowAsType:_defaultRowType]; -} - -/** - * Return the current row as an array. - * - * @return The array of data. - */ -- (NSArray *)rowAsArray -{ - return [self rowAsType:FLXPostgresResultRowAsArray]; -} - -/** - * Return the current row as dictionary with keys as field names and values as the data. - * - * @return The row as a dictionary. - */ -- (NSDictionary *)rowAsDictionary -{ - return [self rowAsType:FLXPostgresResultRowAsDictionary]; -} - -/** - * Return the current row in the format specified by the supplied type. - * - * @return The data row as either an array or dictionary. - */ -- (id)rowAsType:(FLXPostgresResultRowType)type -{ - if (_row >= _numberOfRows) return nil; - - id data = (type == FLXPostgresResultRowAsArray) ? [NSMutableArray arrayWithCapacity:_numberOfFields] : [NSMutableDictionary dictionaryWithCapacity:_numberOfFields]; - - for (NSUInteger i = 0; i < _numberOfFields; i++) - { - id object = [self _objectForRow:(int)_row column:i]; - - if (type == FLXPostgresResultRowAsArray) { - [(NSMutableArray *)data addObject:object]; - } - else { - [(NSMutableDictionary *)data setObject:object forKey:_fields[i]]; - } - } - - _row++; - - return data; -} - -#pragma mark - -#pragma mark Fast enumeration implementation - -- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len -{ - if (state->state >= _numberOfRows) return 0; - - if (state->state != _row) [self seekToRow:state->state]; - - // Determine how many objects to return - 128, len, or all items remaining - NSUInteger itemsToReturn = 128; - - if (len < 128) itemsToReturn = len; - - if (_numberOfRows - state->state < itemsToReturn) { - itemsToReturn = (unsigned long)_numberOfRows - state->state; - } - - for (NSUInteger i = 0; i < itemsToReturn; i++) - { - stackbuf[i] = [self rowAsType:_defaultRowType]; - } - - state->state += itemsToReturn; - state->itemsPtr = stackbuf; - state->mutationsPtr = (unsigned long *)self; - - return itemsToReturn; -} - -#pragma mark - -#pragma mark Private API - -/** - * Populates the internal field names array. - */ -- (void)_populateFields -{ - _fields = malloc(sizeof(NSString *) * _numberOfFields); - - for (NSUInteger i = 0; i < _numberOfFields; i++) - { - const char *bytes = PQfname(_result, (int)i); - - if (!bytes) continue; - - _fields[i] = [[NSString alloc] initWithBytes:bytes length:strlen(bytes) encoding:_stringEncoding]; - } -} - -/** - * Get the native object at the supplied row and column. - * - * @param row The row index to get the data from. - * @param column The column index to get the data from. - * - * @return The native object or nil if out of this result's range. - */ -- (id)_objectForRow:(NSUInteger)row column:(NSUInteger)column -{ - if (row >= _numberOfRows || column >= _numberOfFields) return [NSNull null]; - - // Check for null - if (PQgetisnull(_result, (int)row, (int)column)) return [NSNull null]; - - FLXPostgresOid type = PQftype(_result, (int)column); - - // Get handler for this type - id handler = [self _typeHandlerForColumn:column withType:type]; - - if (!handler) { - NSLog(@"PostgresKit: Warning: No type handler found for type %d, return NSData.", type); - - const void *bytes = PQgetvalue(_result, (int)row, (int)column); - NSUInteger length = PQgetlength(_result, (int)row, (int)column); - - 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 object; -} - -/** - * Get the data type handler for the supplied column index. - * - * @param column The column index to get the handler for. - * - * @return The type handler or nil if out of this result's range. - */ -- (id )_typeHandlerForColumn:(NSUInteger)column withType:(FLXPostgresOid)type -{ - if (column >= _numberOfFields) return nil; - - id handler = _typeHandlers[column]; - - if (!handler) { - handler = [_connection typeHandlerForRemoteType:type]; - - _typeHandlers[column] = handler; - } - - return handler; -} - -#pragma mark - - --(void)dealloc -{ - PQclear(_result); - - for (NSUInteger i = 0; i < _numberOfFields; i++) [_fields[i] release]; - - free(_fields); - free(_typeHandlers); - - if (_connection) [_connection release], _connection = nil; - - [super dealloc]; -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresStatement.h b/Frameworks/PostgresKit/Source/FLXPostgresStatement.h deleted file mode 100644 index fafbb8dc..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresStatement.h +++ /dev/null @@ -1,44 +0,0 @@ -// -// $Id$ -// -// FLXPostgresStatement.h -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -@interface FLXPostgresStatement : NSObject -{ - NSString *_statement; - NSString *_name; -} - -/** - * @property statement The query statement. - */ -@property (readwrite, retain) NSString *statement; - -/** - * @property name The name of this statement. - */ -@property (readwrite, retain) NSString *name; - -- (id)initWithStatement:(NSString *)queryStatement; - -- (const char *)UTF8Name; -- (const char *)UTF8Statement; - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresStatement.m b/Frameworks/PostgresKit/Source/FLXPostgresStatement.m deleted file mode 100644 index a1505ccd..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresStatement.m +++ /dev/null @@ -1,81 +0,0 @@ -// -// $Id$ -// -// FLXPostgresStatement.m -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresStatement.h" - -@implementation FLXPostgresStatement - -@synthesize name = _name; -@synthesize statement = _statement; - -#pragma mark - -#pragma mark Initialisation - -- (id)initWithStatement:(NSString *)queryStatement -{ - if ((self = [super init])) { - [self setStatement:queryStatement]; - [self setName:nil]; - } - - return self; -} - -#pragma mark - -#pragma mark Public API - -/** - * Returns a null terminated C string of the statement's name. - * - * @return The statement name. - */ -- (const char *)UTF8Name -{ - return [[self name] UTF8String]; -} - -/** - * Returns a null terminated C string of the statement. - * - * @return The prepared statement. - */ -- (const char *)UTF8Statement -{ - return [[self statement] UTF8String]; -} - -- (NSString *)description -{ - return [self name] ? [NSString stringWithFormat:@"<%@ %@>", [self className], [self name]] : [NSString stringWithFormat:@"<%@>", [self className]]; -} - -#pragma mark - - -- (void)dealloc -{ - if (_name) [_name release], _name = nil; - if (_statement) [_statement release], _statement = nil; - - [super dealloc]; -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTimeInterval.h b/Frameworks/PostgresKit/Source/FLXPostgresTimeInterval.h deleted file mode 100644 index 74f14c41..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresTimeInterval.h +++ /dev/null @@ -1,85 +0,0 @@ -// -// $Id$ -// -// FLXPostgresTimeInterval.h -// PostgresKit -// -// Created by Stuart Connolly (stuconnolly.com) on September 9, 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. - -/** - * @class FLXPostgresTimeInterval FLXPostgresTimeInterval.h - * - * @author Stuart Connolly http://stuconnolly.com - * - * Simple wrapper around libpqtypes' PQinterval structure. - */ -@interface FLXPostgresTimeInterval : NSObject -{ - NSUInteger _microseconds; - NSUInteger _seconds; - NSUInteger _minutes; - NSUInteger _hours; - NSUInteger _days; - NSUInteger _months; - NSUInteger _years; -} - -/** - * @property microseconds The number of microseconds. - */ -@property (readonly) NSUInteger microseconds; - -/** - * @property seconds The number of seconds. - */ -@property (readonly) NSUInteger seconds; - -/** - * @property minutes The number of minutes. - */ -@property (readonly) NSUInteger minutes; - -/** - * @property hours The number of hours. - */ -@property (readonly) NSUInteger hours; - -/** - * @property days The number of days. - */ -@property (readonly) NSUInteger days; - -/** - * @property months The number of months. - */ -@property (readonly) NSUInteger months; - -/** - * @property years The number of years. - */ -@property (readonly) NSUInteger years; - - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTimeInterval.m b/Frameworks/PostgresKit/Source/FLXPostgresTimeInterval.m deleted file mode 100644 index 5acd7581..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresTimeInterval.m +++ /dev/null @@ -1,76 +0,0 @@ -// -// $Id$ -// -// FLXPostgresTimeInterval.m -// PostgresKit -// -// Created by Stuart Connolly (stuconnolly.com) on September 9, 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 "FLXPostgresTimeInterval.h" -#import "FLXPostgresKitPrivateAPI.h" - -@implementation FLXPostgresTimeInterval - -@synthesize microseconds = _microseconds; -@synthesize seconds = _seconds; -@synthesize minutes = _minutes; -@synthesize hours = _hours; -@synthesize days = _days; -@synthesize months = _months; -@synthesize years = _years; - -#pragma mark - - -+ (id)intervalWithPGInterval:(PGinterval *)interval -{ - return [[[FLXPostgresTimeInterval alloc] initWithInterval:interval] autorelease]; -} - -- (id)initWithInterval:(PGinterval *)interval -{ - if ((self = [super init])) { - if (interval) { - _microseconds = interval->usecs; - _seconds = interval->secs; - _minutes = interval->mins; - _hours = interval->hours; - _days = interval->days; - _months = interval->mons; - _years = interval->years; - } - } - - return self; -} - -#pragma mark - - -- (NSString *)description -{ - return [NSString stringWithFormat:@"%d years, %d months, %d days, %d hours, %d minutes, %d seconds and %d microseconds", - _years, _months, _days, _hours, _minutes, _seconds, _microseconds]; -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTimeTZ.h b/Frameworks/PostgresKit/Source/FLXPostgresTimeTZ.h deleted file mode 100644 index dd58f57f..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresTimeTZ.h +++ /dev/null @@ -1,62 +0,0 @@ -// -// $Id$ -// -// FLXPostgresTimeTZ.h -// PostgresKit -// -// Created by Stuart Connolly (stuconnolly.com) on September 8, 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. - -/** - * @class FLXPostgresTimeTZ FLXPostgresTimeTZ.h - * - * @author Stuart Connolly http://stuconnolly.com - * - * Simple wrapper to represet a time or timestamp with an associated time zone. - */ -@interface FLXPostgresTimeTZ : NSObject -{ - BOOL _hasDate; - - NSDate *_date; - NSTimeZone *_timeZone; -} - -@property (readwrite, assign) BOOL hasDate; - -/** - * @property date The date instance that holds the time. - */ -@property (readonly) NSDate *date; - -/** - * @property timeZone The time zone of the associated time. - */ -@property (readonly) NSTimeZone *timeZone; - -+ (FLXPostgresTimeTZ *)timeWithDate:(NSDate *)date timeZoneGMTOffset:(NSUInteger)offset; - -- (id)initWithDate:(NSDate *)date timeZoneGMTOffset:(NSUInteger)offset; - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTimeTZ.m b/Frameworks/PostgresKit/Source/FLXPostgresTimeTZ.m deleted file mode 100644 index 692ef200..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresTimeTZ.m +++ /dev/null @@ -1,84 +0,0 @@ -// -// $Id$ -// -// FLXPostgresTimeTZ.m -// PostgresKit -// -// Created by Stuart Connolly (stuconnolly.com) on September 8, 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 "FLXPostgresTimeTZ.h" - -@implementation FLXPostgresTimeTZ - -@synthesize hasDate = _hasDate; -@synthesize date = _date; -@synthesize timeZone = _timeZone; - -- (id)init -{ - return [self initWithDate:[NSDate date] timeZoneGMTOffset:[[NSTimeZone systemTimeZone] secondsFromGMT]]; -} - -+ (FLXPostgresTimeTZ *)timeWithDate:(NSDate *)date timeZoneGMTOffset:(NSUInteger)offset -{ - return [[[FLXPostgresTimeTZ alloc] initWithDate:date timeZoneGMTOffset:offset] autorelease]; -} - -/** - * Initialise a FLXPostgresTimeTZ with the supplied date and GMT offset. - * - * @param date The date to use. - * @param offset The GMT offset in seconds that the associated time zone is. - * - * @return The initialised instance. - */ -- (id)initWithDate:(NSDate *)date timeZoneGMTOffset:(NSUInteger)offset -{ - if ((self = [super init])) { - _date = date; - _hasDate = NO; - _timeZone = [NSTimeZone timeZoneForSecondsFromGMT:offset]; - } - - return self; -} - -#pragma mark - - -- (NSString *)description -{ - NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; - - [formatter setDateStyle:_hasDate ? NSDateFormatterMediumStyle : NSDateFormatterNoStyle]; - [formatter setTimeStyle:NSDateFormatterMediumStyle]; - - NSString *output = [formatter stringFromDate:_date]; - - [formatter release]; - - return [NSString stringWithFormat:@"%@ %@", output, [_timeZone abbreviation]]; -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.h b/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.h deleted file mode 100644 index 2aa084c2..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.h +++ /dev/null @@ -1,55 +0,0 @@ -// -// $Id$ -// -// FLXPostgresTypeDateTimeHandler.h -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresTypeHandler.h" - -@interface FLXPostgresTypeDateTimeHandler : FLXPostgresTypeHandler -{ - NSUInteger _row; - NSUInteger _column; - - const PGresult *_result; - - FLXPostgresOid _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) FLXPostgresOid 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/FLXPostgresTypeDateTimeHandler.m b/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m deleted file mode 100644 index 1a5081db..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m +++ /dev/null @@ -1,213 +0,0 @@ -// -// $Id$ -// -// FLXPostgresTypeDateTimeHandler.m -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresTypeDateTimeHandler.h" -#import "FLXPostgresTypeNumberHandler.h" -#import "FLXPostgresConnectionParameters.h" -#import "FLXPostgresConnection.h" -#import "FLXPostgresConnectionTypeHandling.h" -#import "FLXPostgresTimeTZ.h" -#import "FLXPostgresTimeInterval.h" -#import "FLXPostgresKitPrivateAPI.h" - -static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] = -{ - FLXPostgresOidDate, - FLXPostgresOidTime, - FLXPostgresOidTimeTZ, - FLXPostgresOidAbsTime, - FLXPostgresOidTimestamp, - FLXPostgresOidTimestampTZ, - FLXPostgresOidInterval, - 0 -}; - -@interface FLXPostgresTypeDateTimeHandler () - -- (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; - -#pragma mark - -#pragma mark Protocol Implementation - -- (FLXPostgresOid *)remoteTypes -{ - return FLXPostgresTypeDateTimeTypes; -} - -- (Class)nativeClass -{ - return [NSDate class]; -} - -- (NSArray *)classAliases -{ - return nil; -} - -- (id)objectFromResult -{ - if (!_result || !_type) return [NSNull null]; - - switch (_type) - { - case FLXPostgresOidDate: - return [self _dateFromResult]; - case FLXPostgresOidTime: - case FLXPostgresOidTimeTZ: - case FLXPostgresOidAbsTime: - return [self _timeFromResult]; - case FLXPostgresOidTimestamp: - case FLXPostgresOidTimestampTZ: - return [self _timestmpFromResult]; - case FLXPostgresOidInterval: - return [self _timeIntervalFromResult]; - } - - return [NSNull null]; -} - -#pragma mark - -#pragma mark Private API - -/** - * Returns an NSDate created from a date value. - * - * @return The NSDate representation. - */ -- (id)_dateFromResult -{ - PGdate date; - - if (!PQgetf(_result, (int)_row, FLXPostgresResultValueDate, (int)_column, &date)) return [NSNull null]; - - NSDateComponents *components = [[NSDateComponents alloc] init]; - - [components setDay:date.mday]; - [components setMonth:date.mon + 1]; // Months are indexed from 0 - [components setYear:date.year]; - - return [self _dateFromComponents:components]; -} - -/** - * Converts a time interval value to a FLXPostgresTimeInterval instance. - * - * @return The FLXPostgresTimeInterval representation. - */ -- (id)_timeIntervalFromResult -{ - PGinterval interval; - - if (!PQgetf(_result, (int)_row, FLXPostgresResultValueInterval, (int)_column, &interval)) return [NSNull null]; - - return [FLXPostgresTimeInterval intervalWithPGInterval:&interval]; -} - -/** - * Returns a native object created from a time value. - * - * @note The date part should be ignored as it's set to a default value. - * - * @return The object representation. - */ -- (id)_timeFromResult -{ - PGtime pgTime; - - BOOL hasTimeZone = _type == FLXPostgresOidTimeTZ; - - if (!PQgetf(_result, (int)_row, hasTimeZone ? FLXPostgresResultValueTimeTZ : FLXPostgresResultValueTime, (int)_column, &pgTime)) return [NSNull null]; - - NSDateComponents *components = [[NSDateComponents alloc] init]; - - // Default date values; should be ignored - [components setDay:1]; - [components setMonth:1]; - [components setYear:2000]; - - [components setHour:pgTime.hour]; - [components setMinute:pgTime.min]; - [components setSecond:pgTime.sec]; - - NSDate *date = [self _dateFromComponents:components]; - - return hasTimeZone ? (id)[FLXPostgresTimeTZ timeWithDate:date timeZoneGMTOffset:pgTime.gmtoff] : date; -} - -/** - * Returns a native object created from a timestamp value. - * - * @return The object representation. - */ -- (id)_timestmpFromResult -{ - PGtimestamp timestamp; - - BOOL hasTimeZone = _type == FLXPostgresOidTimestampTZ; - - if (!PQgetf(_result, (int)_row, hasTimeZone ? FLXPostgresResultValueTimestmpTZ : FLXPostgresResultValueTimestamp, (int)_column, ×tamp)) return [NSNull null]; - - FLXPostgresTimeTZ *timestampTZ = nil; - NSDate *date = [NSDate dateWithTimeIntervalSince1970:timestamp.epoch]; - - if (hasTimeZone) { - timestampTZ = [FLXPostgresTimeTZ timeWithDate:date timeZoneGMTOffset:timestamp.time.gmtoff]; - - [timestampTZ setHasDate:YES]; - } - - return hasTimeZone ? (id)timestampTZ : date; -} - -/** - * Returns an NSDate created from the supplied components. - * - * @param The components to create the date from. - * - * @return The NSDate created. - */ -- (NSDate *)_dateFromComponents:(NSDateComponents *)components -{ - NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; - - NSDate *date = [gregorian dateFromComponents:components]; - - [gregorian release]; - - return date; -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.h b/Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.h deleted file mode 100644 index 3bfdac39..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// $Id$ -// -// FLXPostgresTypeHandler.h -// PostgresKit -// -// Created by Stuart Connolly (stuconnolly.com) on July 27, 2012. -// Copyright (c) 2012 Stuart Connolly. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresTypeHandlerProtocol.h" - -@class FLXPostgresConnection; - -@interface FLXPostgresTypeHandler : NSObject -{ - FLXPostgresConnection *_connection; -} - -/** - * @property connection The connection this type handler is associated with. - */ -@property (readonly) FLXPostgresConnection *connection; - -- (id)initWithConnection:(FLXPostgresConnection *)connection; - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.m b/Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.m deleted file mode 100644 index 2f232307..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresTypeHandler.m +++ /dev/null @@ -1,48 +0,0 @@ -// -// $Id$ -// -// FLXPostgresTypeHandler.h -// PostgresKit -// -// Created by Stuart Connolly (stuconnolly.com) on July 27, 2012. -// Copyright (c) 2012 Stuart Connolly. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresTypeHandler.h" - -@implementation FLXPostgresTypeHandler - -@synthesize connection = _connection; - -#pragma mark - - -- (id)initWithConnection:(FLXPostgresConnection *)connection -{ - if ((self = [super init])) { - _connection = [connection retain]; - } - - return self; -} - -#pragma mark - - -- (void)dealloc -{ - if (_connection) [_connection release], _connection = nil; - - [super dealloc]; -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeHandlerProtocol.h b/Frameworks/PostgresKit/Source/FLXPostgresTypeHandlerProtocol.h deleted file mode 100644 index c750ba3d..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresTypeHandlerProtocol.h +++ /dev/null @@ -1,78 +0,0 @@ -// -// $Id$ -// -// FLXPostgresTypeHandlerProtocol.h -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -@class FLXPostgresConnection; - -/** - * @protocol FLXPostgresTypeHandlerProtocol - */ -@protocol FLXPostgresTypeHandlerProtocol - -/** - * @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) FLXPostgresOid type; - -/** - * @property The result the handler is being asked to operate on. - */ -@property (readwrite, assign) const PGresult *result; - -/** - * The remote type values handled by this class (terminated by 0). - * - * @return The remote types as an array of FLXPostgresOid's. - */ -- (FLXPostgresOid *)remoteTypes; - -/** - * What is the native class this class handles. - * - * @return The native class. - */ -- (Class)nativeClass; - -/** - * Any aliases that the native class is known by. - * - * @return An of aliases as strings or nil if none. - */ -- (NSArray *)classAliases; - -/** - * Convert the value at the specified row and column in the supplied result to a native object. - * - * @return An object represenation of the data. - */ -- (id)objectFromResult; - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.h b/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.h deleted file mode 100644 index 73cc9d1e..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.h +++ /dev/null @@ -1,56 +0,0 @@ -// -// $Id$ -// -// FLXPostgresTypeNumberHandler.h -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresTypeHandler.h" - -@interface FLXPostgresTypeNumberHandler : FLXPostgresTypeHandler -{ - NSUInteger _row; - NSUInteger _column; - - const PGresult *_result; - - FLXPostgresOid _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) FLXPostgresOid 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/FLXPostgresTypeNumberHandler.m b/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m deleted file mode 100644 index a8fbc631..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m +++ /dev/null @@ -1,206 +0,0 @@ -// -// $Id$ -// -// FLXPostgresTypeNumberHandler.m -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresTypeNumberHandler.h" - -static FLXPostgresOid FLXPostgresTypeNumberTypes[] = -{ - FLXPostgresOidInt8, - FLXPostgresOidInt2, - FLXPostgresOidInt4, - FLXPostgresOidFloat4, - FLXPostgresOidFloat8, - FLXPostgresOidBool, - FLXPostgresOidOid, - FLXPostgresOidMoney, - FLXPostgresOidNumeric, - 0 -}; - -@interface FLXPostgresTypeNumberHandler () - -- (id)_integerObjectFromResult; -- (id)_floatObjectFromResult; -- (id)_booleanObjectFromResult; -- (id)_numericFromResult; - -@end - -@implementation FLXPostgresTypeNumberHandler - -@synthesize row = _row; -@synthesize type = _type; -@synthesize column = _column; -@synthesize result = _result; - -#pragma mark - -#pragma mark Protocol Implementation - -- (FLXPostgresOid *)remoteTypes -{ - return FLXPostgresTypeNumberTypes; -} - -- (Class)nativeClass -{ - return [NSNumber class]; -} - -- (NSArray *)classAliases -{ - return nil; -} - -- (id)objectFromResult -{ - if (!_result || !_type) return [NSNull null]; - - switch (_type) - { - case FLXPostgresOidInt8: - case FLXPostgresOidInt2: - case FLXPostgresOidInt4: - return [self _integerObjectFromResult]; - case FLXPostgresOidFloat4: - case FLXPostgresOidFloat8: - return [self _floatObjectFromResult]; - case FLXPostgresOidBool: - return [self _booleanObjectFromResult]; - case FLXPostgresOidNumeric: - return [self _numericFromResult]; - } - - return [NSNull null]; -} - -#pragma mark - -#pragma mark Integer - -/** - * Converts an integer value to an NSNumber instance. - * - * @return An NSNumber representation of the the value. - */ -- (id)_integerObjectFromResult -{ - NSUInteger length = PQgetlength(_result, (int)_row, (int)_column); - - if (!length) return [NSNull null]; - - PGint2 int2; - PGint4 int4; - PGint8 int8; - - switch (length) - { - case 2: - if (!PQgetf(_result, _row, FLXPostgresResultValueInt2, &int2)) return [NSNull null]; - - return [NSNumber numberWithShort:int2]; - case 4: - if (!PQgetf(_result, _row, FLXPostgresResultValueInt4, &int4)) return [NSNull null]; - - return [NSNumber numberWithInteger:int4]; - case 8: - if (!PQgetf(_result, _row, FLXPostgresResultValueInt8, &int8)) return [NSNull null]; - - return [NSNumber numberWithLongLong:int8]; - } - - return [NSNull null]; -} - -#pragma mark - -#pragma mark Floating Point - -/** - * Converts a float value to an NSNumber instance. - * - * @return An NSNumber representation of the the value. - */ -- (id)_floatObjectFromResult -{ - NSUInteger length = PQgetlength(_result, (int)_row, (int)_column); - - if (!length) return [NSNull null]; - - PGfloat4 float4; - PGfloat8 float8; - - switch (length) - { - case 4: - if (!PQgetf(_result, _row, FLXPostgresResultValueFloat4, &float4)) return [NSNull null]; - - return [NSNumber numberWithFloat:float4]; - case 8: - if (!PQgetf(_result, _row, FLXPostgresResultValueFloat8, &float8)) return [NSNull null]; - - return [NSNumber numberWithDouble:float8]; - } - - return [NSNull null]; -} - -#pragma mark - -#pragma mark Boolean - -/** - * Converts a boolean value to an NSNumber instance. - * - * @return An NSNumber representation of the the value. - */ -- (id)_booleanObjectFromResult -{ - PGbool b; - - if (!PQgetf(_result, _row, FLXPostgresResultValueBool, &b)) return [NSNull null]; - - return [NSNumber numberWithInt:b]; -} - -#pragma mark - -#pragma mark Numeric - -/** - * Converts a numeric value to a native NSNumber instance. - * - * @return An NSNumber representation of the the value. - */ -- (id)_numericFromResult -{ - PGnumeric numeric; - - if (!PQgetf(_result, (int)_row, FLXPostgresResultValueNumeric, (int)_column, &numeric)) return [NSNull null]; - - NSString *stringValue = [[NSString alloc] initWithUTF8String:numeric]; - - double value = [stringValue doubleValue]; - - if (value == HUGE_VAL || value == -HUGE_VAL) return [NSNull null]; - - [stringValue release]; - - return [NSNumber numberWithDouble:value]; -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.h b/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.h deleted file mode 100644 index 9b0e8d8b..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.h +++ /dev/null @@ -1,56 +0,0 @@ -// -// $Id$ -// -// FLXPostgresTypeStringHandler.h -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresTypeHandler.h" - -@interface FLXPostgresTypeStringHandler : FLXPostgresTypeHandler -{ - NSUInteger _row; - NSUInteger _column; - - const PGresult *_result; - - FLXPostgresOid _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) FLXPostgresOid 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/FLXPostgresTypeStringHandler.m b/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m deleted file mode 100644 index 725153a7..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m +++ /dev/null @@ -1,163 +0,0 @@ -// -// $Id$ -// -// FLXPostgresTypeStringHandler.m -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "FLXPostgresTypeStringHandler.h" -#import "FLXPostgresConnection.h" - -#import - -static FLXPostgresOid FLXPostgresTypeStringTypes[] = -{ - FLXPostgresOidText, - FLXPostgresOidChar, - FLXPostgresOidName, - FLXPostgresOidVarChar, - FLXPostgresOidXML, - FLXPostgresOidUUID, - FLXPostgresOidBit, - FLXPostgresOidVarBit, - FLXPostgresOidInetAddr, - FLXPostgresOidCidrAddr, - FLXPostgresOidMacAddr, - FLXPostgresOidUnknown, - 0 -}; - -@interface FLXPostgresTypeStringHandler () - -- (id)_stringFromResult; -- (id)_macAddressFromResult; -- (id)_inetAddressFromResult; - -@end - -@implementation FLXPostgresTypeStringHandler - -@synthesize row = _row; -@synthesize type = _type; -@synthesize column = _column; -@synthesize result = _result; - -#pragma mark - -#pragma mark Protocol Implementation - -- (FLXPostgresOid *)remoteTypes -{ - return FLXPostgresTypeStringTypes; -} - -- (Class)nativeClass -{ - return [NSString class]; -} - -- (NSArray *)classAliases -{ - return [NSArray arrayWithObject:@"NSCFString"]; -} - -- (id)objectFromResult -{ - if (!_result || !_type) return [NSNull null]; - - switch (_type) - { - case FLXPostgresOidText: - case FLXPostgresOidChar: - case FLXPostgresOidName: - case FLXPostgresOidVarChar: - case FLXPostgresOidXML: - case FLXPostgresOidUUID: - case FLXPostgresOidBit: - case FLXPostgresOidVarBit: - case FLXPostgresOidUnknown: - return [self _stringFromResult]; - case FLXPostgresOidMacAddr: - return [self _macAddressFromResult]; - case FLXPostgresOidInetAddr: - case FLXPostgresOidCidrAddr: - return [self _inetAddressFromResult]; - } - - return [NSNull null]; -} - -#pragma mark - -#pragma mark Private API - -/** - * Converts a char value to a string. - * - * @return A string representation of the value. - */ -- (id)_stringFromResult -{ - const void *bytes = PQgetvalue(_result, (int)_row, (int)_column); - NSUInteger length = PQgetlength(_result, (int)_row, (int)_column); - - if (!bytes || !length) return [NSNull null]; - - return [[[NSString alloc] initWithBytes:bytes length:length encoding:[_connection stringEncoding]] autorelease]; -} - -/** - * Converts a MAC address value to a string. - * - * @return A string representation of the MAC address. - */ -- (id)_macAddressFromResult -{ - PGmacaddr address; - - if (!PQgetf(_result, (int)_row, FLXPostgresResultValueMacAddr, (int)_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]; -} - -/** - * Converts a network address value to a string. - * - * @return A string representation of the network address. - */ -- (id)_inetAddressFromResult -{ - PGinet inet; - - if (!PQgetf(_result, (int)_row, _type == FLXPostgresOidInetAddr ? FLXPostgresResultValueInet : FLXPostgresResultValueCidr, (int)_column, &inet)) return [NSNull null]; - - char ip[80]; - struct sockaddr *sa = (struct sockaddr *)inet.sa_buf; - - int success = getnameinfo(sa, inet.sa_buf_len, ip, sizeof(ip), NULL, 0, NI_NUMERICHOST); - - if (success != 0) { - const char *error = gai_strerror(success); - - NSLog(@"PostgresKit: Error: Failed to convert IP address to string representation (%s)", error); - - return [NSNull null]; - } - - return [NSString stringWithUTF8String:ip]; -} - -@end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypes.h b/Frameworks/PostgresKit/Source/FLXPostgresTypes.h deleted file mode 100644 index 9f923552..00000000 --- a/Frameworks/PostgresKit/Source/FLXPostgresTypes.h +++ /dev/null @@ -1,119 +0,0 @@ -// -// $Id$ -// -// FLXPostgresTypes.h -// PostgresKit -// -// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com -// -// Forked by the Sequel Pro Team on July 22, 2012. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -#import "postgres_ext.h" - -// Generic PostgreSQL object ID -typedef Oid FLXPostgresOid; - -// See PostgreSQL source: include/catalog/pg_type.h - -enum -{ - // BOOL - FLXPostgresOidBool = 16, // NumberHandler => NSNumber - FLXPostgresOidByteData = 17, // Currently not supported - - // Text - FLXPostgresOidName = 19, // StringHandler => NSString - - // Integers - FLXPostgresOidInt8 = 20, // NumberHandler => NSNumber - FLXPostgresOidInt2 = 21, // NumberHandler => NSNumber - FLXPostgresOidInt4 = 23, // NumberHandler => NSNumber - - // Text - FLXPostgresOidText = 25, // StringHandler => NSString - - // OID - FLXPostgresOidOid = 26, // NumberHandler => NSNumber - - // XML - FLXPostgresOidXML = 142, // StringHandler => NSString - - // Geometric - FLXPostgresOidPoint = 600, // Currently not supported - FLXPostgresOidLSeg = 601, // Currently not supported - FLXPostgresOidPath = 602, // Currently not supported - FLXPostgresOidBox = 603, // Currently not supported - FLXPostgresOidPolygon = 604, // Currently not supported - - // Network - FLXPostgresOidCidrAddr = 650, // StringHandler => NSString - - // Float - FLXPostgresOidFloat4 = 700, // NumberHandler => NSNumber - FLXPostgresOidFloat8 = 701, // NumberHandler => NSNumber - - // ABS Time - FLXPostgresOidAbsTime = 702, // DateHandler => NSDate - - // What! - FLXPostgresOidUnknown = 705, // StringHandler => NSString - - // Geometric - FLXPostgresOidCircle = 718, // Currently not supported - - // Monetary - FLXPostgresOidMoney = 790, // NumberHandler => NSNumber - - // Network - FLXPostgresOidMacAddr = 829, // StringHandler => NSString - FLXPostgresOidInetAddr = 869, // StringHandler => NSString - - // Arrays - FLXPostgresOidArrayBool = 1000, // Currently not supported - FLXPostgresOidArrayData = 1001, // Currently not supported - FLXPostgresOidArrayChar = 1002, // Currently not supported - FLXPostgresOidArrayName = 1003, // Currently not supported - FLXPostgresOidArrayInt2 = 1005, // Currently not supported - FLXPostgresOidArrayInt4 = 1007, // Currently not supported - FLXPostgresOidArrayText = 1009, // Currently not supported - FLXPostgresOidArrayVarchar = 1015, // Currently not supported - FLXPostgresOidArrayInt8 = 1016, // Currently not supported - FLXPostgresOidArrayFloat4 = 1021, // Currently not supported - FLXPostgresOidArrayFloat8 = 1022, // Currently not supported - FLXPostgresOidArrayMacAddr = 1040, // Currently not supported - FLXPostgresOidArrayIPAddr = 1041, // Currently not supported - - // Text - FLXPostgresOidChar = 1042, // StringHandler => NSString - FLXPostgresOidVarChar = 1043, // StringHandler => NSString - - // Date/time - FLXPostgresOidDate = 1082, // DateHandler => NSDate - FLXPostgresOidTime = 1083, // DateHandler => NSDate - FLXPostgresOidTimestamp = 1114, // DateHandler => NSDate - FLXPostgresOidTimestampTZ = 1184, // DateHandler => FLXPostgresTimeTZ - FLXPostgresOidInterval = 1186, // DateHandler => FLXPostgresTimeInterval - FLXPostgresOidTimeTZ = 1266, // DateHandler => FLXPostgresTimeTZ - - // Bit strings - FLXPostgresOidBit = 1560, // StringHandler => NSString - FLXPostgresOidVarBit = 1562, // StringHandler => NSString - - // Numeric - FLXPostgresOidNumeric = 1700, // NumberHandler => NSNumber - - // UUID - FLXPostgresOidUUID = 2950 // StringHandler => NSString -}; diff --git a/Frameworks/PostgresKit/Source/PGConstants.h b/Frameworks/PostgresKit/Source/PGConstants.h new file mode 100644 index 00000000..d8ac3641 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGConstants.h @@ -0,0 +1,67 @@ +// +// $Id: PGConstants.h 3866 2012-09-26 01:30:28Z stuart02 $ +// +// PGConstants.h +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +// Connection defaults +extern const NSUInteger PGPostgresConnectionDefaultTimeout; +extern const NSUInteger PGPostgresConnectionDefaultServerPort; +extern const NSUInteger PGPostgresConnectionDefaultKeepAlive; + +extern NSString *PGPostgresConnectionDefaultEncoding; +extern NSString *PGPostgresConnectionErrorDomain; +extern NSStringEncoding PGPostgresConnectionDefaultStringEncoding; + +// Server parameters +extern NSString *PGPostgresParameterServerEncoding; +extern NSString *PGPostgresParameterClientEncoding; +extern NSString *PGPostgresParameterSuperUser; +extern NSString *PGPostgresParameterTimeZone; +extern NSString *PGPostgresParameterIntegerDateTimes; + +// Result value specifiers +extern const char *PGPostgresResultValueMacAddr; +extern const char *PGPostgresResultValueInet; +extern const char *PGPostgresResultValueCidr; +extern const char *PGPostgresResultValueDate; +extern const char *PGPostgresResultValueTime; +extern const char *PGPostgresResultValueTimeTZ; +extern const char *PGPostgresResultValueTimestamp; +extern const char *PGPostgresResultValueTimestmpTZ; +extern const char *PGPostgresResultValueInterval; +extern const char *PGPostgresResultValueNumeric; +extern const char *PGPostgresResultValueBool; +extern const char *PGPostgresResultValueInt2; +extern const char *PGPostgresResultValueInt4; +extern const char *PGPostgresResultValueInt8; +extern const char *PGPostgresResultValueFloat4; +extern const char *PGPostgresResultValueFloat8; + +// Connection parameters +extern const char *PGPostgresKitApplicationName; +extern const char *PGPostgresApplicationParam; +extern const char *PGPostgresUserParam; +extern const char *PGPostgresHostParam; +extern const char *PGPostgresPasswordParam; +extern const char *PGPostgresPortParam; +extern const char *PGPostgresDatabaseParam; +extern const char *PGPostgresClientEncodingParam; +extern const char *PGPostgresKeepAliveParam; +extern const char *PGPostgresKeepAliveIntervalParam; diff --git a/Frameworks/PostgresKit/Source/PGConstants.m b/Frameworks/PostgresKit/Source/PGConstants.m new file mode 100644 index 00000000..169dd85c --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGConstants.m @@ -0,0 +1,67 @@ +// +// $Id: PGConstants.m 3866 2012-09-26 01:30:28Z stuart02 $ +// +// PGConstants.m +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +// Connection defaults +const NSUInteger PGPostgresConnectionDefaultTimeout = 30; +const NSUInteger PGPostgresConnectionDefaultServerPort = 5432; +const NSUInteger PGPostgresConnectionDefaultKeepAlive = 60; + +NSString *PGPostgresConnectionDefaultEncoding = @"UNICODE"; +NSString *PGPostgresConnectionErrorDomain = @"PGPostgresConnectionError"; +NSStringEncoding PGPostgresConnectionDefaultStringEncoding = NSUTF8StringEncoding; + +// Server parameters +NSString *PGPostgresParameterServerEncoding = @"server_encoding"; +NSString *PGPostgresParameterClientEncoding = @"client_encoding"; +NSString *PGPostgresParameterSuperUser = @"is_superuser"; +NSString *PGPostgresParameterTimeZone = @"TimeZone"; +NSString *PGPostgresParameterIntegerDateTimes = @"integer_datetimes"; + +// Result value specifiers +const char *PGPostgresResultValueMacAddr = "%macaddr"; +const char *PGPostgresResultValueInet = "%inet"; +const char *PGPostgresResultValueCidr = "%cidr"; +const char *PGPostgresResultValueDate = "%date"; +const char *PGPostgresResultValueTime = "%time"; +const char *PGPostgresResultValueTimeTZ = "%timetz"; +const char *PGPostgresResultValueTimestamp = "%timestamp"; +const char *PGPostgresResultValueTimestmpTZ = "%timestamptz"; +const char *PGPostgresResultValueInterval = "%interval"; +const char *PGPostgresResultValueNumeric = "%numeric"; +const char *PGPostgresResultValueBool = "%bool"; +const char *PGPostgresResultValueInt2 = "%int2"; +const char *PGPostgresResultValueInt4 = "%int4"; +const char *PGPostgresResultValueInt8 = "%int8"; +const char *PGPostgresResultValueFloat4 = "%float4"; +const char *PGPostgresResultValueFloat8 = "%float8"; + +// Connection parameters +const char *PGPostgresKitApplicationName = "PostgresKit"; +const char *PGPostgresApplicationParam = "application_name"; +const char *PGPostgresUserParam = "user"; +const char *PGPostgresHostParam = "host"; +const char *PGPostgresPasswordParam = "password"; +const char *PGPostgresPortParam = "port"; +const char *PGPostgresDatabaseParam = "dbname"; +const char *PGPostgresClientEncodingParam = "client_encoding"; +const char *PGPostgresKeepAliveParam = "keepalives"; +const char *PGPostgresKeepAliveIntervalParam = "keepalives_interval"; diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnection.h b/Frameworks/PostgresKit/Source/PGPostgresConnection.h new file mode 100644 index 00000000..bf1f51d0 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresConnection.h @@ -0,0 +1,101 @@ +// +// $Id: PGPostgresConnection.h 3845 2012-09-11 09:35:40Z stuart02 $ +// +// PGPostgresConnection.h +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresConnectionDelegate.h" + +@class PGPostgresError; +@class PGPostgresResult; +@class PGPostgresStatement; +@class PGPostgresConnectionParameters; + +@interface PGPostgresConnection : NSObject +{ + void *_connection; + + NSString *_host; + NSString *_user; + NSString *_database; + NSString *_password; + NSString *_socketPath; + NSString *_encoding; + NSString *_connectionError; + NSString *_applicationName; + + const char **_connectionParamNames; + const char **_connectionParamValues; + + NSStringEncoding _stringEncoding; + + NSUInteger _port; + NSUInteger _timeout; + NSUInteger _keepAliveInterval; + + BOOL _useSocket; + BOOL _useKeepAlive; + BOOL _lastQueryWasCancelled; + BOOL _delegateSupportsWillExecute; + + NSMutableDictionary *_typeMap; + + PGPostgresError *_lastError; + PGPostgresConnectionParameters *_parameters; + + NSObject *_delegate; +} + +@property (readwrite, assign) NSObject *delegate; + +@property (readwrite, retain) NSString *host; +@property (readwrite, retain) NSString *user; +@property (readwrite, retain) NSString *database; +@property (readwrite, retain) NSString *password; +@property (readwrite, retain) NSString *socketPath; +@property (readwrite, retain) NSString *applicationName; + +@property (readonly) NSString *encoding; +@property (readonly) NSString *connectionError; +@property (readonly) PGPostgresError *lastError; +@property (readonly) NSStringEncoding stringEncoding; +@property (readonly) PGPostgresConnectionParameters *parameters; + +@property (readwrite, assign) BOOL useSocket; +@property (readwrite, assign) BOOL useKeepAlive; +@property (readwrite, assign) BOOL lastQueryWasCancelled; + +@property (readwrite, assign) NSUInteger timeout; +@property (readwrite, assign) NSUInteger port; +@property (readwrite, assign) NSUInteger keepAliveInterval; + +- (id)initWithDelegate:(NSObject *)delegate; + +- (BOOL)connect; +- (void)disconnect; +- (BOOL)isConnected; +- (BOOL)reset; + +- (NSUInteger)clientVersion; +- (NSUInteger)serverVersion; +- (NSUInteger)serverProcessId; + +- (BOOL)cancelCurrentQuery:(NSError **)error; + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnection.m b/Frameworks/PostgresKit/Source/PGPostgresConnection.m new file mode 100644 index 00000000..8fcf8ae0 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresConnection.m @@ -0,0 +1,483 @@ +// +// $Id: PGPostgresConnection.m 3848 2012-09-12 12:19:31Z stuart02 $ +// +// PGPostgresConnection.m +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresConnection.h" +#import "PGPostgresConnectionParameters.h" +#import "PGPostgresConnectionTypeHandling.h" +#import "PGPostgresKitPrivateAPI.h" +#import "PGPostgresTypeHandlerProtocol.h" +#import "PGPostgresTypeNumberHandler.h" +#import "PGPostgresTypeStringHandler.h" +#import "PGPostgresException.h" +#import "PGPostgresStatement.h" +#import "PGPostgresResult.h" + +#import +#import + +@interface PGPostgresConnection () + +- (void)_loadDatabaseParameters; +- (void)_createConnectionParameters; +- (void)_pollConnection:(NSNumber *)isReset; + +// libpq callback +static void _PGPostgresConnectionNoticeProcessor(void *arg, const char *message); + +@end + +@implementation PGPostgresConnection + +@synthesize port = _port; +@synthesize host = _host; +@synthesize user = _user; +@synthesize database = _database; +@synthesize password = _password; +@synthesize useSocket = _useSocket; +@synthesize socketPath = _socketPath; +@synthesize delegate = _delegate; +@synthesize timeout = _timeout; +@synthesize useKeepAlive = _useKeepAlive; +@synthesize keepAliveInterval = _keepAliveInterval; +@synthesize lastQueryWasCancelled = _lastQueryWasCancelled; +@synthesize lastError = _lastError; +@synthesize encoding = _encoding; +@synthesize connectionError = _connectionError; +@synthesize stringEncoding = _stringEncoding; +@synthesize parameters = _parameters; +@synthesize applicationName = _applicationName; + +#pragma mark - +#pragma mark Initialisation + +- (id)init +{ + return [self initWithDelegate:nil]; +} + +/** + * Initialise a new connection with the supplied delegate. + * + * @param delegate The delegate this connection should use. + * + * @return The new connection instance. + */ +- (id)initWithDelegate:(NSObject *)delegate +{ + if ((self = [super init])) { + + _delegate = delegate; + + _port = PGPostgresConnectionDefaultServerPort; + _timeout = PGPostgresConnectionDefaultTimeout; + + _useKeepAlive = YES; + _keepAliveInterval = PGPostgresConnectionDefaultKeepAlive; + + _lastError = nil; + _connection = nil; + _connectionError = nil; + _lastQueryWasCancelled = NO; + + _stringEncoding = PGPostgresConnectionDefaultStringEncoding; + _encoding = [NSString stringWithString:PGPostgresConnectionDefaultEncoding]; + + _delegateSupportsWillExecute = [_delegate respondsToSelector:@selector(connection:willExecute:withValues:)]; + + _typeMap = [[NSMutableDictionary alloc] init]; + + [self registerTypeHandlers]; + } + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (PGconn *)postgresConnection +{ + return _connection; +} + +#pragma mark - +#pragma mark Connection Handling + +/** + * Does this connection have an underlying connection established with the server. + * + * @return A BOOL indicating the result of the query. + */ +- (BOOL)isConnected +{ + if (!_connection) return NO; + + return PQstatus(_connection) == CONNECTION_OK; +} + +/** + * Attempts to disconnect the underlying connection with the server. + */ +- (void)disconnect +{ + if (!_connection) return; + + [self cancelCurrentQuery:nil]; + + PQfinish(_connection); + + _connection = nil; + + if (_delegate && [_delegate respondsToSelector:@selector(connectionDisconnected:)]) { + [_delegate connectionDisconnected:self]; + } +} + +/** + * Initiates the underlying connection to the server asynchronously. + * + * Note, that if no user, host or database is set when connect is called, then libpq's defaults are used. + * For no host, this means a socket connection to /tmp is attempted. + * + * @return A BOOL indicating the success of requesting the connection. Note, that this does not indicate + * that a successful connection has been made, only that it has successfullly been requested. + */ +- (BOOL)connect +{ + if ([self isConnected]) { + [PGPostgresException raise:PGPostgresConnectionErrorDomain reason:@"Attempt to initiate a connection that is already active"]; + + return NO; + } + + [self _createConnectionParameters]; + + // Perform the connection + _connection = PQconnectStartParams(_connectionParamNames, _connectionParamValues, 0); + + if (!_connection || PQstatus(_connection) == CONNECTION_BAD) { + + if (_connectionError) [_connectionError release]; + + _connectionError = [[NSString alloc] initWithUTF8String:PQerrorMessage(_connection)]; + + PQfinish(_connection); + + _connection = nil; + + return NO; + } + + [self performSelectorInBackground:@selector(_pollConnection:) withObject:nil]; + + return YES; +} + +/** + * Attempts the reset the underlying connection. + * + * @note A return value of NO means that the connection is not currently + * connected or the request to reset it failed. YES means the reset request was successful, + * not that the connection re-establishment has succeeded. Wait for the + * delegate connection reset method to be called and check -isConnected. + * + * @return A BOOL indicating the success of the call. + */ +- (BOOL)reset +{ + if (![self isConnected]) return NO; + + if (!PQresetStart(_connection)) return NO; + + [self performSelectorInBackground:@selector(_pollConnection:) withObject:[NSNumber numberWithBool:YES]]; + + return YES; +} + +/** + * Returns the PostgreSQL client library (libpq) version being used. + * + * @return The library version (e.g. version 9.1 is 90100). + */ +- (NSUInteger)clientVersion +{ + return PQlibVersion(); +} + +/** + * Returns the version of the server we're connected to. + * + * @return The server version (e.g. version 9.1 is 90100). Zero is returned if there's no connection. + */ +- (NSUInteger)serverVersion +{ + if (![self isConnected]) return 0; + + return PQserverVersion(_connection); +} + +/** + * Returns the ID of the process handling this connection on the remote host. + * + * @return The process ID or -1 if no connection is available. + */ +- (NSUInteger)serverProcessId +{ + if (![self isConnected]) return -1; + + return PQbackendPID(_connection); +} + +/** + * Attempts to cancel the query currently executing on this connection. + * + * @param error Populated if query was unabled to be cancelled. + * + * @return A BOOL indicating the success of the request + */ +- (BOOL)cancelCurrentQuery:(NSError **)error +{ + if (![self isConnected]) return NO; + + PGcancel *cancel = PQgetCancel(_connection); + + if (!cancel) return NO; + + char errorBuf[256]; + + int result = PQcancel(cancel, errorBuf, 256); + + PQfreeCancel(cancel); + + if (!result) { + if (error != NULL) { + *error = [NSError errorWithDomain:PGPostgresConnectionErrorDomain + code:0 + userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithUTF8String:errorBuf] forKey:NSLocalizedDescriptionKey]]; + } + + return NO; + } + + _lastQueryWasCancelled = YES; + + return YES; +} + +#pragma mark - +#pragma mark Private API + +/** + * Polls the connection that was previously requested via -connect and waits for meaninful status. + * + * @note This method should be called on a background thread as it will block waiting for the connection. + */ +- (void)_pollConnection:(NSNumber *)isReset +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + BOOL reset = [isReset boolValue]; + + int sock = PQsocket(_connection); + + if (sock == -1) { + [pool release]; + return; + } + + struct pollfd fdinfo[1]; + + fdinfo[0].fd = sock; + fdinfo[0].events = POLLIN|POLLOUT; + + PostgresPollingStatusType status; + + do + { + status = reset ? PQresetPoll(_connection) : PQconnectPoll(_connection); + + if (status == PGRES_POLLING_READING || status == PGRES_POLLING_WRITING) { + if (poll(fdinfo, 1, -1) < 0) break; + } + } + while (status != PGRES_POLLING_OK && status != PGRES_POLLING_FAILED); + + if (status == PGRES_POLLING_OK && [self isConnected]) { + + // Increase error verbosity + PQsetErrorVerbosity(_connection, PQERRORS_VERBOSE); + + // Set notice processor + PQsetNoticeProcessor(_connection, _PGPostgresConnectionNoticeProcessor, self); + + NSInteger success = reset ? PQclearTypes(_connection) : PQinitTypes(_connection); + + // Register type extensions + if (!success) { + NSLog(@"PostgresKit: Error: Failed to initialise (or clear) type extensions. Connection might return unexpected results!"); + } + + [self _loadDatabaseParameters]; + + if (reset) { + if (_delegate && [_delegate respondsToSelector:@selector(connectionReset:)]) { + [_delegate performSelectorOnMainThread:@selector(connectionReset:) withObject:self waitUntilDone:NO]; + } + } + else{ + if (_delegate && [_delegate respondsToSelector:@selector(connectionEstablished:)]) { + [_delegate performSelectorOnMainThread:@selector(connectionEstablished:) withObject:self waitUntilDone:NO]; + } + } + } + + [pool release]; +} + +/** + * Loads the database parameters. + */ +- (void)_loadDatabaseParameters +{ + if (_parameters) [_parameters release]; + + _parameters = [[PGPostgresConnectionParameters alloc] initWithConnection:self]; + + BOOL success = [_parameters loadParameters]; + + if (!success) NSLog(@"PostgresKit: Warning: Failed to load database parameters."); +} + +/** + * libpq notice processor function. Simply passes the message onto the connection delegate. + * + * @param arg The calling connection. + * @param message The message that was sent. + */ +static void _PGPostgresConnectionNoticeProcessor(void *arg, const char *message) +{ + PGPostgresConnection *connection = (PGPostgresConnection *)arg; + + if ([connection isKindOfClass:[PGPostgresConnection class]]) { + + if ([connection delegate] && [[connection delegate] respondsToSelector:@selector(connection:notice:)]) { + [[connection delegate] connection:connection notice:[NSString stringWithUTF8String:message]]; + } + } +} + +/** + * Creates the parameter arrays required to establish a connection. + */ +- (void)_createConnectionParameters +{ + BOOL hasUser = NO; + BOOL hasHost = NO; + BOOL hasPassword = NO; + BOOL hasDatabase = NO; + + if (_connectionParamNames) free(_connectionParamNames); + if (_connectionParamValues) free(_connectionParamValues); + + int paramCount = 5; + + if (_user && [_user length]) paramCount++, hasUser = YES; + if (_host && [_host length]) paramCount++, hasHost = YES; + if (_password && [_password length]) paramCount++, hasPassword = YES; + if (_database && [_database length]) paramCount++, hasDatabase = YES; + + _connectionParamNames = malloc(paramCount * sizeof(*_connectionParamNames)); + _connectionParamValues = malloc(paramCount * sizeof(*_connectionParamValues)); + + _connectionParamNames[0] = PGPostgresApplicationParam; + _connectionParamValues[0] = !_applicationName ? [_applicationName UTF8String] : PGPostgresKitApplicationName; + + _connectionParamNames[1] = PGPostgresPortParam; + _connectionParamValues[1] = [[[NSNumber numberWithUnsignedInteger:_port] stringValue] UTF8String]; + + _connectionParamNames[2] = PGPostgresClientEncodingParam; + _connectionParamValues[2] = [_encoding UTF8String]; + + _connectionParamNames[3] = PGPostgresKeepAliveParam; + _connectionParamValues[3] = _useKeepAlive ? "1" : "0"; + + _connectionParamNames[4] = PGPostgresKeepAliveIntervalParam; + _connectionParamValues[4] = [[[NSNumber numberWithUnsignedInteger:_keepAliveInterval] stringValue] UTF8String]; + + NSUInteger i = 5; + + if (hasUser) { + _connectionParamNames[i] = PGPostgresUserParam; + _connectionParamValues[i] = [_user UTF8String]; + + i++; + } + + if (hasHost) { + _connectionParamNames[i] = PGPostgresHostParam; + _connectionParamValues[i] = [_host UTF8String]; + + i++; + } + + if (hasPassword) { + _connectionParamNames[i] = PGPostgresPasswordParam; + _connectionParamValues[i] = [_password UTF8String]; + + i++; + } + + if (hasDatabase) { + _connectionParamNames[i] = PGPostgresDatabaseParam; + _connectionParamValues[i] = [_database UTF8String]; + + i++; + } + + _connectionParamNames[i] = '\0'; + _connectionParamValues[i] = '\0'; +} + +#pragma mark - + +- (void)dealloc +{ + [_typeMap release]; + + [self disconnect]; + + [self setHost:nil]; + [self setUser:nil]; + [self setDatabase:nil]; + + if (_connectionParamNames) free(_connectionParamNames); + if (_connectionParamValues) free(_connectionParamValues); + + if (_lastError) [_lastError release], _lastError = nil; + if (_parameters) [_parameters release], _parameters = nil; + if (_connectionError) [_connectionError release], _connectionError = nil; + if (_applicationName) [_applicationName release], _applicationName = nil; + + [super dealloc]; +} + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnectionDelegate.h b/Frameworks/PostgresKit/Source/PGPostgresConnectionDelegate.h new file mode 100644 index 00000000..05390aa3 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresConnectionDelegate.h @@ -0,0 +1,65 @@ +// +// $Id: PGPostgresConnectionDelegate.h 3841 2012-09-10 08:52:00Z stuart02 $ +// +// PGPostgresConnectionDelegate.h +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +@class PGPostgresConnection; + +@protocol PGPostgresConnectionDelegate + +/** + * Called whenever the supplied connection has been successfully established and is ready to use. + * + * @param connection The connection instance. + */ +- (void)connectionEstablished:(PGPostgresConnection *)connection; + +/** + * Called whenever the supplied connection has been successfully reset and is ready to use. + * + * @param connection The connection instance. + */ +- (void)connectionReset:(PGPostgresConnection *)connection; + +/** + * Called whenever a connection is disconnected. + * + * @param connection The connection instance. + */ +- (void)connectionDisconnected:(PGPostgresConnection *)connection; + +/** + * Called whenever a message is received from the PostgreSQL server. + * + * @param connection The connection instance. + * @param notice The notice message received. + */ +- (void)connection:(PGPostgresConnection *)connection notice:(NSString *)notice; + +/** + * Called just before a query is about to be executed. + * + * @param connection The connection executing the query. + * @param query The query about the be executed. + * @param values The values of the query. + */ +- (void)connection:(PGPostgresConnection *)connection willExecute:(NSObject *)query withValues:(NSArray *)values; + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnectionEncoding.h b/Frameworks/PostgresKit/Source/PGPostgresConnectionEncoding.h new file mode 100644 index 00000000..fee143a8 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresConnectionEncoding.h @@ -0,0 +1,39 @@ +// $Id: PGPostgresConnectionEncoding.h 3793 2012-09-03 10:22:17Z stuart02 $ +// +// PGPostgresConnectionEncoding.h +// PostgresKit +// +// Created by Stuart Connolly (stuconnolly.com) on August 4, 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 "PGPostgresConnection.h" + +@interface PGPostgresConnection (PGPostgresConnectionEncoding) + +- (BOOL)setEncoding:(NSString *)encoding; + ++ (NSStringEncoding)stringEncodingForPostgreSQLCharset:(const char *)charset; ++ (NSString *)postgreSQLCharsetForStringEncoding:(NSStringEncoding)stringEncoding; + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnectionEncoding.m b/Frameworks/PostgresKit/Source/PGPostgresConnectionEncoding.m new file mode 100644 index 00000000..b8422f78 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresConnectionEncoding.m @@ -0,0 +1,197 @@ +// +// $Id: PGPostgresConnectionEncoding.m 3825 2012-09-09 00:43:58Z stuart02 $ +// +// PGPostgresConnectionEncoding.m +// PostgresKit +// +// Created by Stuart Connolly (stuconnolly.com) on August 4, 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 "PGPostgresConnectionEncoding.h" +#import "PGPostgresKitPrivateAPI.h" + +@implementation PGPostgresConnection (PGPostgresConnectionEncoding) + +/** + * Set the current connection's encoding. + * + * @param encoding The name of the encoding to use. + * + * @return A BOOL indicating the success of the operation. NO means there was either no connection or the + * encoding name wasn't recognised by the server. + */ +- (BOOL)setEncoding:(NSString *)encoding +{ + if (![self isConnected]) return NO; + + if ([_encoding isEqualToString:encoding]) return YES; + + if (PQsetClientEncoding(_connection, [encoding UTF8String]) != 0) return NO; + + [_encoding release], _encoding = [[NSString alloc] initWithString:encoding]; + + _stringEncoding = [PGPostgresConnection stringEncodingForPostgreSQLCharset:[encoding UTF8String]]; + + return YES; +} + +/** + * Translates the supplied encoding name to it's corresponding string encoding identifier. + * + * @param charset The character set as a char array. + * + * @return The string encoding identifier. + */ ++ (NSStringEncoding)stringEncodingForPostgreSQLCharset:(const char *)charset +{ + if (!strcmp(charset, "UNICODE") || !strcmp(charset, "MULE_INTERNAL")) { + return NSUTF8StringEncoding; + } + else if (!strcmp(charset, "LATIN1")) { + return NSISOLatin1StringEncoding; + } + else if (!strcmp(charset, "LATIN2")) { + return NSISOLatin2StringEncoding; + } + else if (!strcmp(charset, "LATIN3")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin3); + } + else if (!strcmp(charset, "LATIN4")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin4); + } + else if (!strcmp(charset, "LATIN5")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin5); + } + else if (!strcmp(charset, "LATIN6")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin6); + } + else if (!strcmp(charset, "LATIN7")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin7); + } + else if (!strcmp(charset, "LATIN8")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin8); + } + else if (!strcmp(charset, "LATIN9")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin9); + } + else if (!strcmp(charset, "LATIN10")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin10); + } + else if (!strcmp(charset, "SQL_ASCII")) { + return NSASCIIStringEncoding; + } + else if (!strcmp(charset, "EUC_JP")) { + return NSJapaneseEUCStringEncoding; + } + else if (!strcmp(charset, "EUC_CN")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingEUC_CN); + } + else if (!strcmp(charset, "EUC_KR")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingEUC_KR); + } + else if (!strcmp(charset, "JOHAB")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsKoreanJohab); + } + else if (!strcmp(charset, "EUC_TW")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingEUC_TW); + } + else if (!strcmp(charset, "ISO_8859_5")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatinCyrillic); + } + else if (!strcmp(charset, "ISO_8859_6")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatinArabic); + } + else if (!strcmp(charset, "ISO_8859_7")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatinGreek); + } + else if (!strcmp(charset, "ISO_8859_8")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatinHebrew); + } + else if (!strcmp(charset, "KOI8")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingKOI8_R); + } + else if (!strcmp(charset, "ALT")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingDOSRussian); + } + else if (!strcmp(charset, "WIN")) { + return NSWindowsCP1251StringEncoding; + } + else if (!strcmp(charset, "WIN1256")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsArabic); + } + else if (!strcmp(charset, "TCVN")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsVietnamese); + } + else if (!strcmp(charset, "WIN874")) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingDOSThai); + } + + NSLog(@"PostgresKit: Warning: Unable to process unknown PostgreSQL encoding '%s'; falling back to UTF8.", charset); + + return PGPostgresConnectionDefaultStringEncoding; +} + +/** + * Translates the supplied encoding identifier to it's corresponding encoding name. + * + * @param stringEncoding The string encoding to translate + * + * @return The encoding name as a string or nil if there's no mapping. + */ ++ (NSString *)postgreSQLCharsetForStringEncoding:(NSStringEncoding)stringEncoding +{ + switch (stringEncoding) + { + case NSASCIIStringEncoding: + return @"SQL_ASCII"; + + case NSJapaneseEUCStringEncoding: + return @"EUC_JP"; + + case NSUTF8StringEncoding: + case NSNonLossyASCIIStringEncoding: + return @"UNICODE"; + + case NSISOLatin1StringEncoding: + case NSWindowsCP1252StringEncoding: + return @"LATIN1"; + + case NSISOLatin2StringEncoding: + case NSWindowsCP1250StringEncoding: + return @"LATIN2"; + + case NSWindowsCP1251StringEncoding: + return @"WIN"; + + case NSWindowsCP1253StringEncoding: + return @"ISO_8859_7"; + + case NSWindowsCP1254StringEncoding: + return @"LATIN5"; + } + + return nil; +} + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnectionParameters.h b/Frameworks/PostgresKit/Source/PGPostgresConnectionParameters.h new file mode 100644 index 00000000..f81140aa --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresConnectionParameters.h @@ -0,0 +1,56 @@ +// +// $Id: PGPostgresConnectionParameters.h 3793 2012-09-03 10:22:17Z stuart02 $ +// +// PGPostgresConnectionParameters.h +// PostgresKit +// +// Created by Stuart Connolly (stuconnolly.com) on August 29, 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 + +@class PGPostgresConnection; + +@interface PGPostgresConnectionParameters : NSObject +{ + PGPostgresConnection *_connection; + + NSMutableArray *_parameterNames; + NSMutableDictionary *_parameters; + + pthread_mutex_t _readLock; +} + +/** + * @property connection The database connection to use. + */ +@property (readwrite, assign) PGPostgresConnection *connection; + +- (id)initWithConnection:(PGPostgresConnection *)connection; + +- (BOOL)loadParameters; + +- (id)valueForParameter:(NSString *)parameter; + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnectionParameters.m b/Frameworks/PostgresKit/Source/PGPostgresConnectionParameters.m new file mode 100644 index 00000000..e179f110 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresConnectionParameters.m @@ -0,0 +1,220 @@ +// +// $Id: PGPostgresConnectionParameters.m 3848 2012-09-12 12:19:31Z stuart02 $ +// +// PGPostgresConnectionParameters.m +// PostgresKit +// +// Created by Stuart Connolly (stuconnolly.com) on August 29, 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 "PGPostgresConnectionParameters.h" +#import "PGPostgresKitPrivateAPI.h" +#import "PGPostgresConnection.h" + +@interface PGPostgresConnectionParameters () + +- (void)_loadParameters:(id)object; +- (BOOL)_isBooleanParameterValue:(NSString *)value; +- (BOOL)_booleanForParameterValue:(NSString *)value; + +@end + +@implementation PGPostgresConnectionParameters + +@synthesize connection = _connection; + +#pragma mark - + +- (id)init +{ + return [self initWithConnection:nil]; +} + +/** + * Initialise a parameters instance with the supplied connection. + * + * @param connection The connection to use. + * + * @return The initialised instance. + */ +- (id)initWithConnection:(PGPostgresConnection *)connection +{ + if ((self = [super init])) { + _connection = connection; + + pthread_mutex_init(&_readLock, NULL); + } + + return self; +} + +#pragma mark - +#pragma mark Public API + +/** + * Loads the database parameters. + * + * @return A BOOL indicating the success of the load. + */ +- (BOOL)loadParameters +{ + pthread_mutex_lock(&_readLock); + + if (!_connection || ![_connection isConnected]) { + pthread_mutex_unlock(&_readLock); + + return NO; + } + + if (!_parameterNames) { + _parameterNames = [[NSMutableArray alloc] init]; + + [_parameterNames addObject:PGPostgresParameterServerEncoding]; + [_parameterNames addObject:PGPostgresParameterClientEncoding]; + [_parameterNames addObject:PGPostgresParameterSuperUser]; + [_parameterNames addObject:PGPostgresParameterTimeZone]; + [_parameterNames addObject:PGPostgresParameterIntegerDateTimes]; + } + + pthread_mutex_unlock(&_readLock); + + [self performSelectorInBackground:@selector(_loadParameters:) withObject:_parameterNames]; + + return YES; +} + +/** + * Gets the object for the supplied parameter. + * + * @param parameter The name of the parameter to lookup. + * + * @return The parameter value or nil if parameters haven't been loaded or it can't be found. + */ +- (id)valueForParameter:(NSString *)parameter +{ + pthread_mutex_lock(&_readLock); + + if (!_parameters || ![_parameters count]) { + pthread_mutex_unlock(&_readLock); + + return nil; + } + + id value = [_parameters objectForKey:parameter]; + + pthread_mutex_unlock(&_readLock); + + return value; +} + +#pragma mark - +#pragma mark Private API + +/** + * Loads the values of the supplied array of parameters by query the current connection. + * + * @param object The parameters to load. + */ +- (void)_loadParameters:(id)object +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + pthread_mutex_lock(&_readLock); + + NSArray *parameters = (NSArray *)object; + + if (!_parameters) { + _parameters = [[NSMutableDictionary alloc] initWithCapacity:[parameters count]]; + } + + for (NSString *parameter in parameters) + { + const char *value = PQparameterStatus([_connection postgresConnection], [parameter UTF8String]); + + if (!value) continue; + + NSString *stringValue = [NSString stringWithUTF8String:value]; + + id paramObject = [self _isBooleanParameterValue:stringValue] ? (id)[NSNumber numberWithBool:[self _booleanForParameterValue:stringValue]] : stringValue; + + [_parameters setObject:paramObject forKey:parameter]; + } + + pthread_mutex_unlock(&_readLock); + + [pool release]; +} + +/** + * Determines whether or not the supplied value is a boolean value. + * + * @param value The value to look at. + * + * @return A BOOL indicating if the value is a boolean type. + */ +- (BOOL)_isBooleanParameterValue:(NSString *)value +{ + value = [value uppercaseString]; + + return + [value isEqualToString:@"ON"] || + [value isEqualToString:@"YES"] || + [value isEqualToString:@"TRUE"] || + [value isEqualToString:@"OFF"] || + [value isEqualToString:@"NO"] || + [value isEqualToString:@"FALSE"]; +} + +/** + * Determines the boolean value for the supplied boolean string representation. + * + * @param value The value to look at. + * + * @return A BOOL indicating the value of the string representation. + */ +- (BOOL)_booleanForParameterValue:(NSString *)value +{ + value = [value uppercaseString]; + + return + [value isEqualToString:@"ON"] || + [value isEqualToString:@"YES"] || + [value isEqualToString:@"TRUE"]; +} + +#pragma mark - + +- (void)dealloc +{ + _connection = nil; + + pthread_mutex_destroy(&_readLock); + + if (_parameters) [_parameters release], _parameters = nil; + if (_parameterNames) [_parameterNames release], _parameterNames = nil; + + [super dealloc]; +} + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnectionQueryExecution.h b/Frameworks/PostgresKit/Source/PGPostgresConnectionQueryExecution.h new file mode 100644 index 00000000..2fbfb74d --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresConnectionQueryExecution.h @@ -0,0 +1,38 @@ +// +// $Id: PGPostgresConnectionQueryExecution.h 3793 2012-09-03 10:22:17Z stuart02 $ +// +// PGPostgresConnectionQueryExecution.h +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresConnection.h" + +@interface PGPostgresConnection (PGPostgresConnectionQueryExecution) + +// Synchronous interface +- (PGPostgresResult *)execute:(NSString *)query; +- (PGPostgresResult *)executeWithFormat:(NSString *)query, ...; +- (PGPostgresResult *)executePrepared:(PGPostgresStatement *)statement; +- (PGPostgresResult *)execute:(NSString *)query values:(NSArray *)values; +- (PGPostgresResult *)execute:(NSString *)query value:(NSObject *)value; +- (PGPostgresResult *)executePrepared:(PGPostgresStatement *)statement values:(NSArray *)values; +- (PGPostgresResult *)executePrepared:(PGPostgresStatement *)statement value:(NSObject *)value; + +// Asynchronous interface + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnectionQueryExecution.m b/Frameworks/PostgresKit/Source/PGPostgresConnectionQueryExecution.m new file mode 100644 index 00000000..4dec74a6 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresConnectionQueryExecution.m @@ -0,0 +1,314 @@ +// +// $Id: PGPostgresConnectionQueryExecution.m 3841 2012-09-10 08:52:00Z stuart02 $ +// +// PGPostgresConnectionQueryExecution.h +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresConnectionQueryExecution.h" +#import "PGPostgresKitPrivateAPI.h" +#import "PGPostgresConnectionTypeHandling.h" +#import "PGPostgresConnectionDelegate.h" +#import "PGPostgresTypeHandlerProtocol.h" +#import "PGPostgresConnection.h" +#import "PGPostgresException.h" +#import "PGPostgresResult.h" +#import "PGPostgresStatement.h" +#import "PGPostgresError.h" + +// Constants +static int PGPostgresResultsAsBinary = 1; + +// Internal query structure +typedef struct +{ + int paramNum; + const void **paramValues; + PGPostgresOid* paramTypes; + int *paramLengths; + int *paramFormats; +} +PGQueryParamData; + +@interface PGPostgresConnection () + +- (PGPostgresResult *)_execute:(NSObject *)query values:(NSArray *)values; +- (BOOL)_queryDidError:(PGresult *)result; +- (PGQueryParamData *)_createParameterDataStructureWithCount:(int)paramNum; +- (void)_destroyParamDataStructure:(PGQueryParamData *)paramData; + +@end + +@implementation PGPostgresConnection (PGPostgresConnectionQueryExecution) + +#pragma mark - +#pragma mark Synchronous Interface + +- (PGPostgresResult *)execute:(NSString *)query +{ + return [self _execute:query values:nil]; +} + +- (PGPostgresResult *)execute:(NSString *)query value:(NSObject *)value +{ + return [self _execute:query values:[NSArray arrayWithObject:value]]; +} + +- (PGPostgresResult *)executePrepared:(PGPostgresStatement *)statement value:(NSObject *)value +{ + return [self _execute:statement values:[NSArray arrayWithObject:value]]; +} + +- (PGPostgresResult *)executePrepared:(PGPostgresStatement *)statement +{ + return [self _execute:statement values:nil]; +} + +- (PGPostgresResult *)executePrepared:(PGPostgresStatement *)statement values:(NSArray *)values +{ + return [self _execute:statement values:values]; +} + +- (PGPostgresResult *)execute:(NSString *)query values:(NSArray *)values +{ + return [self _execute:query values:values]; +} + +- (PGPostgresResult *)executeWithFormat:(NSString *)query, ... +{ + va_list argumentList; + va_start(argumentList, query); + + NSMutableString *string = [[NSMutableString alloc] init]; + + CFStringAppendFormatAndArguments((CFMutableStringRef)string, (CFDictionaryRef)nil, (CFStringRef)query, argumentList); + + va_end(argumentList); + + PGPostgresResult *result = [self _execute:string values:nil]; + + [string release]; + + return result; +} + +#pragma mark - +#pragma mark Asynchronous Interface + +#pragma mark - +#pragma mark Private API + +- (PGPostgresResult *)_execute:(NSObject *)query values:(NSArray *)values +{ + _lastQueryWasCancelled = NO; + + if (![self isConnected] || !query || ![query isKindOfClass:[NSString class]] || [query isKindOfClass:[PGPostgresStatement class]]) return nil; + + // Notify the delegate + if (_delegate && _delegateSupportsWillExecute) { + [_delegate connection:self willExecute:query withValues:values]; + } + + PGQueryParamData *paramData = [self _createParameterDataStructureWithCount:values ? (int)[values count] : 0]; + + if (!paramData) return nil; + + // Fill the data structures + for (int i = 0; i < paramData->paramNum; i++) + { + id nativeObject = [values objectAtIndex:i]; + + // Deterime if bound value is an NSNull + if ([nativeObject isKindOfClass:[NSNull class]]) { + paramData->paramValues[i] = NULL; + paramData->paramTypes[i] = 0; + paramData->paramLengths[i] = 0; + paramData->paramFormats[i] = 0; + + continue; + } + + // Obtain correct handler for this class + id typeHandler = [self typeHandlerForClass:[nativeObject class]]; + + if (!typeHandler) { + [self _destroyParamDataStructure:paramData]; + + // TODO: get rid of exceptions + [PGPostgresException raise:PGPostgresConnectionErrorDomain reason:[NSString stringWithFormat:@"Parameter $%u unsupported class %@", (i + 1), NSStringFromClass([nativeObject class])]]; + return nil; + } + + NSData *data = nil; // Sending parameters as binary is not implemented yet + PGPostgresOid type = 0; + + if (!data) { + [self _destroyParamDataStructure:paramData]; + + // TODO: get rid of exceptions + [PGPostgresException raise:PGPostgresConnectionErrorDomain reason:[NSString stringWithFormat:@"Parameter $%u cannot be converted into a bound value", (i + 1)]]; + return nil; + } + + // Check length of data + if ([data length] > INT_MAX) { + [self _destroyParamDataStructure:paramData]; + + // TODO: get rid of exceptions + [PGPostgresException raise:PGPostgresConnectionErrorDomain reason:[NSString stringWithFormat:@"Bound value $%u exceeds maximum size", (i + 1)]]; + return nil; + } + + // Assign data + paramData->paramTypes[i] = type; + + // NOTE: if data length is zero, we encode as text instead, as NSData returns 0 for + // empty data, and it gets encoded as a NULL. + if ([data length] == 0) { + paramData->paramValues[i] = ""; + paramData->paramFormats[i] = 0; + paramData->paramLengths[i] = 0; + } + else { + // Send as binary data + paramData->paramValues[i] = [data bytes]; + paramData->paramLengths[i] = (int)[data length]; + paramData->paramFormats[i] = 1; + } + } + + // Execute the command - return data in binary + PGresult *result = nil; + + if ([query isKindOfClass:[NSString class]]) { + + result = PQexecParams(_connection, + [(NSString *)query UTF8String], + paramData->paramNum, + paramData->paramTypes, + (const char **)paramData->paramValues, + (const int *)paramData->paramLengths, + (const int *)paramData->paramFormats, + PGPostgresResultsAsBinary); + } + else if ([query isKindOfClass:[PGPostgresStatement class]]) { + PGPostgresStatement *statement = (PGPostgresStatement *)query; + + // Statement has not been prepared yet, so prepare it with the given parameter types + if (![statement name]) { + BOOL prepareResult = [self _prepare:statement num:paramData->paramNum types:paramData->paramTypes]; + + if (!prepareResult || ![statement name]) return nil; + } + + result = PQexecPrepared(_connection, + [statement UTF8Name], + paramData->paramNum, + (const char **)paramData->paramValues, + (const int *)paramData->paramLengths, + (const int *)paramData->paramFormats, + PGPostgresResultsAsBinary); + } + + [self _destroyParamDataStructure:paramData]; + + if (!result || [self _queryDidError:result]) return nil; + + return [[[PGPostgresResult alloc] initWithResult:result connection:self] autorelease]; +} + +/** + * Determines whether or not the supplied result indicates an error occurred. + * + * @param result The result to examine. + * + * @return A BOOL indicating if an error occurred. + */ +- (BOOL)_queryDidError:(PGresult *)result +{ + ExecStatusType status = PQresultStatus(result); + + if (status == PGRES_BAD_RESPONSE || status == PGRES_FATAL_ERROR) { + if (_lastError) [_lastError release], _lastError = nil; + + _lastError = [[PGPostgresError alloc] initWithResult:result]; + + PQclear(result); + + return YES; + } + + return NO; +} + +/** + * Creates the internal query parameter data structure. + * + * @note This method will throw an exception if it can't allocated the required memory. + * + * @param paramNum The number of parameters the structure should accommodate. + * + * @return The data structure or nil if an exception occurred. + */ +- (PGQueryParamData *)_createParameterDataStructureWithCount:(int)paramNum +{ + PGQueryParamData *paramData = malloc(sizeof(PGQueryParamData)); + + paramData->paramNum = paramNum; + paramData->paramValues = NULL; + paramData->paramTypes = NULL; + paramData->paramLengths = NULL; + paramData->paramFormats = NULL; + + if (paramData->paramNum) { + paramData->paramValues = malloc(sizeof(void *) * paramData->paramNum); + paramData->paramTypes = malloc(sizeof(PGPostgresOid) * paramData->paramNum); + paramData->paramLengths = malloc(sizeof(int) * paramData->paramNum); + paramData->paramFormats = malloc(sizeof(int) * paramData->paramNum); + + if (!paramData->paramValues || !paramData->paramLengths || !paramData->paramFormats) { + [self _destroyParamDataStructure:paramData]; + + // Probably justifies throwing an exception if we can't allocate any memory! + [PGPostgresException raise:PGPostgresConnectionErrorDomain reason:@"Memory allocation error"]; + + return nil; + } + } + + return paramData; +} + +/** + * Frees the memory associated with the supplied parameter data structure. + * + * @param paramData The parameter data to destroy. + */ +- (void)_destroyParamDataStructure:(PGQueryParamData *)paramData +{ + if (!paramData) return; + + if (paramData->paramValues) free(paramData->paramValues); + if (paramData->paramTypes) free(paramData->paramTypes); + if (paramData->paramLengths) free(paramData->paramLengths); + if (paramData->paramFormats) free(paramData->paramFormats); + + free(paramData); +} + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnectionQueryPreparation.h b/Frameworks/PostgresKit/Source/PGPostgresConnectionQueryPreparation.h new file mode 100644 index 00000000..81cba455 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresConnectionQueryPreparation.h @@ -0,0 +1,30 @@ +// +// $Id: PGPostgresConnectionQueryPreparation.h 3806 2012-09-07 09:57:31Z stuart02 $ +// +// PGPostgresConnectionQueryPreparation.h +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresConnection.h" + +@interface PGPostgresConnection (PGPostgresConnectionQueryPreparation) + +- (PGPostgresStatement *)prepare:(NSString *)query; +- (PGPostgresStatement *)prepareWithFormat:(NSString *)query, ...; + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnectionQueryPreparation.m b/Frameworks/PostgresKit/Source/PGPostgresConnectionQueryPreparation.m new file mode 100644 index 00000000..f773da42 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresConnectionQueryPreparation.m @@ -0,0 +1,108 @@ +// +// $Id: PGPostgresConnectionQueryPreparation.m 3848 2012-09-12 12:19:31Z stuart02 $ +// +// PGPostgresConnectionQueryPreparation.m +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresConnectionQueryPreparation.h" +#import "PGPostgresConnectionTypeHandling.h" +#import "PGPostgresKitPrivateAPI.h" +#import "PGPostgresStatement.h" +#import "PGPostgresException.h" + +@implementation PGPostgresConnection (PGPostgresConnectionQueryPreparation) + +/** + * Creates a prepared statment from the supplied query. + * + * @param query The query to create the statement from. + * + * @return The prepared statement instance. + */ +- (PGPostgresStatement *)prepare:(NSString *)query +{ + if (!query || ![query length]) return nil; + + return [[[PGPostgresStatement alloc] initWithStatement:query] autorelease]; +} + +/** + * Creates a prepared statment from the supplied query format and values. + * + * @param query The query to create the statement from. + * @param ... Any values to insert into the query (optional). + * + * @return The prepared statement instance. + */ +- (PGPostgresStatement *)prepareWithFormat:(NSString *)query, ... +{ + if (!query || ![query length]) return nil; + + va_list args; + va_start(args, query); + + NSMutableString *string = [[NSMutableString alloc] initWithFormat:query arguments:args]; + + va_end(args); + + PGPostgresStatement *statement = [self prepare:string]; + + [string release]; + + return statement; +} + +#pragma mark - +#pragma mark Private API + +/** + * Actually prepares the supplied statement against the database. + * + * @param statement The statement to prepare. + * @param paranNum The number of parameters the statement contains. + * @param paramTypes Any of Postgres parameter types. + * + * @return A BOOL indicating succes. Returns NO if there's no statement, statement name or current connection. + */ +- (BOOL)_prepare:(PGPostgresStatement *)statement num:(NSInteger)paramNum types:(PGPostgresOid *)paramTypes +{ + if (!statement || ![statement name] || ![self isConnected]) return NO; + + NSString *name = [[NSProcessInfo processInfo] globallyUniqueString]; + + PGresult *result = PQprepare(_connection, [name UTF8String], [statement UTF8Statement], (int)paramNum, paramTypes); + + if (!result) return NO; + + ExecStatusType resultStatus = PQresultStatus(result); + + if (resultStatus == PGRES_BAD_RESPONSE || resultStatus == PGRES_FATAL_ERROR) { + PQclear(result); + + return NO; + } + + PQclear(result); + + [statement setName:name]; + + return YES; +} + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnectionTypeHandling.h b/Frameworks/PostgresKit/Source/PGPostgresConnectionTypeHandling.h new file mode 100644 index 00000000..11514df7 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresConnectionTypeHandling.h @@ -0,0 +1,34 @@ +// +// $Id: PGPostgresConnectionTypeHandling.h 3817 2012-09-08 08:57:46Z stuart02 $ +// +// PGPostgresConnectionTypeHandling.h +// PostgresKit +// +// Created by Stuart Connolly (stuconnolly.com) on July 29, 2012. +// Copyright (c) 2012 Stuart Connolly. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresConnection.h" +#import "PGPostgresTypeHandlerProtocol.h" + +@interface PGPostgresConnection (PGPostgresConnectionTypeHandling) + +- (void)registerTypeHandlers; + +- (id )typeHandlerForClass:(Class)class; +- (id )typeHandlerForRemoteType:(PGPostgresOid)type; + +- (void)registerTypeHandler:(Class)handlerClass; + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnectionTypeHandling.m b/Frameworks/PostgresKit/Source/PGPostgresConnectionTypeHandling.m new file mode 100644 index 00000000..ddd6e745 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresConnectionTypeHandling.m @@ -0,0 +1,107 @@ +// +// $Id: PGPostgresConnectionTypeHandling.m 3803 2012-09-06 11:00:21Z stuart02 $ +// +// PGPostgresConnectionTypeHandling.m +// PostgresKit +// +// Created by Stuart Connolly (stuconnolly.com) on July 29, 2012. +// Copyright (c) 2012 Stuart Connolly. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresConnectionTypeHandling.h" +#import "PGPostgresTypeStringHandler.h" +#import "PGPostgresTypeNumberHandler.h" +#import "PGPostgresTypeDateTimeHandler.h" +#import "PGPostgresException.h" + +@implementation PGPostgresConnection (PGPostgresConnectionTypeHandling) + +/** + * Register all of our data type handlers for this connection. + */ +- (void)registerTypeHandlers +{ + if (_typeMap) { + [_typeMap release]; + + _typeMap = [[NSMutableDictionary alloc] init]; + } + + [self registerTypeHandler:[PGPostgresTypeStringHandler class]]; + [self registerTypeHandler:[PGPostgresTypeNumberHandler class]]; + [self registerTypeHandler:[PGPostgresTypeDateTimeHandler class]]; +} + +/** + * Get the data type handler for the supplied class. + * + * @param class The class to get the handler for. + * + * @return The handler or nil if there's none associated with the class. + */ +- (id )typeHandlerForClass:(Class)class +{ + return [_typeMap objectForKey:NSStringFromClass(class)]; +} + +/** + * Get the data type handler for the supplied PostgreSQL type. + * + * @param type The PostgreSQL type to get the handler for. + * + * @return The handler or nil if there's none associated with the type. + */ +- (id )typeHandlerForRemoteType:(PGPostgresOid)type +{ + return [_typeMap objectForKey:[NSNumber numberWithUnsignedInteger:type]]; +} + +/** + * Register the supplied type handler class. + * + * @param handlerClass The handler class to register. + */ +- (void)registerTypeHandler:(Class)handlerClass +{ + if (![handlerClass conformsToProtocol:@protocol(PGPostgresTypeHandlerProtocol)]) { + [PGPostgresException raise:PGPostgresConnectionErrorDomain + reason:@"Class '%@' does not conform to protocol '%@'", NSStringFromClass(handlerClass), NSStringFromProtocol(@protocol(PGPostgresTypeHandlerProtocol))]; + } + + // Create an instance of this class + id handler = [[[handlerClass alloc] initWithConnection:self] autorelease]; + + // Add to the type map - for native class + [_typeMap setObject:handler forKey:NSStringFromClass([handler nativeClass])]; + + NSArray *aliases = [handler classAliases]; + + if (aliases) { + for (NSString *alias in aliases) + { + [_typeMap setObject:handler forKey:alias]; + } + } + + PGPostgresOid *remoteTypes = [handler remoteTypes]; + + for (NSUInteger i = 0; remoteTypes[i]; i++) + { + NSNumber *key = [NSNumber numberWithUnsignedInteger:remoteTypes[i]]; + + [_typeMap setObject:handler forKey:key]; + } +} + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnectionUtils.h b/Frameworks/PostgresKit/Source/PGPostgresConnectionUtils.h new file mode 100644 index 00000000..ae9c3201 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresConnectionUtils.h @@ -0,0 +1,33 @@ +// +// $Id: PGPostgresConnectionUtils.h 3793 2012-09-03 10:22:17Z stuart02 $ +// +// PGPostgresConnectionUtils.h +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresConnection.h" + +@interface PGPostgresConnection (PGPostgresConnectionUtils) + +- (NSArray *)schemas; +- (NSArray *)databases; +- (NSArray *)tablesInSchema:(NSString *)schema; +- (NSArray *)columnNamesForTable:(NSString *)table inSchema:(NSString *)schema; +- (NSString *)primaryKeyForTable:(NSString *)table inSchema:(NSString *)schema; + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnectionUtils.m b/Frameworks/PostgresKit/Source/PGPostgresConnectionUtils.m new file mode 100644 index 00000000..30ad94a7 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresConnectionUtils.m @@ -0,0 +1,133 @@ +// +// $Id: PGPostgresConnectionUtils.m 3806 2012-09-07 09:57:31Z stuart02 $ +// +// PGPostgresConnectionUtils.m +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresConnectionQueryPreparation.h" +#import "PGPostgresConnectionQueryExecution.h" +#import "PGPostgresResult.h" + +@interface PGPostgresConnection () + +- (NSArray *)_executeAndReturnResult:(NSString *)query; + +@end + +@implementation PGPostgresConnection (PGPostgresConnectionUtils) + +/** + * Returns an array of all databases. + * + * @return An array of strings or nil if no connection is present. + */ +- (NSArray *)databases +{ + return [self isConnected] ? [self _executeAndReturnResult:@"SELECT DISTINCT \"catalog_name\" FROM \"information_schema\".\"schemata\""] : nil; +} + +/** + * Returns an array of all schemas. + * + * @return An array of strings or nil if no connection is present. + */ +- (NSArray *)schemas +{ + return [self isConnected] ? [self _executeAndReturnResult:[NSString stringWithFormat:@"SELECT \"schema_name\" FROM \"information_schema\".\"schemata\" WHERE \"catalog_name\" = '%@'", [self database]]] : nil; +} + +/** + * Returns an array of tables in the supplied schema. + * + * @param schem The schema to get tables for. + * + * @return An array of strings or nil if not connected or parameters are not valid. + */ +- (NSArray * )tablesInSchema:(NSString *)schema +{ + if (![self isConnected] || !schema || ![schema length]) return nil; + + return [self _executeAndReturnResult:[NSString stringWithFormat:@"SELECT \"table_name\" FROM \"information_schema\".\"tables\" WHERE \"table_catalog\" = '%@' AND \"table_schema\" = '%@' AND \"table_type\" = 'BASE TABLE'",[self database], schema]]; +} + +/** + * Get the primary key column name on the supplied table in the supplied schema. + * + * @param table The table to get the primary key for. + * @param schema The schem the table belongs to. + * + * @return The column name as a string or nil not connected or parameters are not valid. + */ +- (NSString *)primaryKeyForTable:(NSString *)table inSchema:(NSString *)schema +{ + if (![self isConnected] || !table || ![table length] || !schema || ![schema length]) return nil; + + NSString *join = @"\"information_schema\".\"table_constraints\" t INNER JOIN \"information_schema\".\"key_column_usage\" k ON t.\"constraint_name\" = k.\"constraint_name\""; + NSString *where = [NSString stringWithFormat:@"t.\"constraint_type\" = 'PRIMARY KEY' AND t.\"table_catalog\" = '%@' AND t.\"table_schema\" = '%@' AND t.\"table_name\" = '%@'", [self database], schema, table]; + + PGPostgresResult *result = [self executeWithFormat:@"SELECT k.\"column_name\" FROM %@ WHERE %@", join, where]; + + return [result numberOfRows] == 0 ? nil : [[result rowAsArray] objectAtIndex:0]; +} + +/** + * Returns an array of column names for the supplied table and schema. + * + * @param table The table to get column names from. + * @param schema The schem the table belongs to. + * + * @return An array of strings or nil if not connected or parameters are not valid. + */ +- (NSArray *)columnNamesForTable:(NSString *)table inSchema:(NSString *)schema +{ + if (![self isConnected] || !table || ![table length] || !schema || ![schema length]) return nil; + + return [self _executeAndReturnResult:[NSString stringWithFormat:@"SELECT \"column_name\" FROM \"information_schema\".\"columns\" WHERE \"table_catalog\" = '%@' AND \"table_schema\" = '%@' AND \"table_name\" = '%@'", [self database], schema, table]]; +} + +#pragma mark - +#pragma mark Private API + +/** + * Executes the supplied query and returns the result. + * + * @param query The query to execute. + * + * @return The result as an array. + */ +- (NSArray *)_executeAndReturnResult:(NSString *)query +{ + PGPostgresResult *result = [self execute:query]; + + if (!result || ![result numberOfRows]) return nil; + + NSArray *row = nil; + NSMutableArray *data = [NSMutableArray arrayWithCapacity:(NSUInteger)[result numberOfRows]]; + + while ((row = [result rowAsArray])) + { + if (![row count]) continue; + + [data addObject:[row objectAtIndex:0]]; + } + + return data; +} + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresError.h b/Frameworks/PostgresKit/Source/PGPostgresError.h new file mode 100644 index 00000000..df41574d --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresError.h @@ -0,0 +1,74 @@ +// +// $Id: PGPostgresError.h 3800 2012-09-06 09:26:47Z stuart02 $ +// +// PGPostgresError.h +// PostgresKit +// +// Created by Stuart Connolly (stuconnolly.com) on September 3, 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. + +@interface PGPostgresError : NSObject +{ + NSString *_errorSeverity; + NSString *_errorStateCode; + NSString *_errorPrimaryMessage; + NSString *_errorDetailMessage; + NSString *_errorMessageHint; + + NSUInteger _errorStatementPosition; +} + +/** + * @property errorSeverity The severity of the error. + */ +@property (readonly) NSString *errorSeverity; + +/** + * @property errorStateCode The errors state code. + */ +@property (readonly) NSString *errorStateCode; + +/** + * @property errorPrimaryMessage The primary error message. + */ +@property (readonly) NSString *errorPrimaryMessage; + +/** + * @property errorDetailMessage The detailed error message. + */ +@property (readonly) NSString *errorDetailMessage; + +/** + * @property errorMessageHint The error message hint. + */ +@property (readonly) NSString *errorMessageHint; + +/** + * @property errorStatementPosition The position within the executed statement that caused the error. + */ +@property (readonly) NSUInteger errorStatementPosition; + +- (id)initWithResult:(const void *)result; + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresError.m b/Frameworks/PostgresKit/Source/PGPostgresError.m new file mode 100644 index 00000000..bbf40fa1 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresError.m @@ -0,0 +1,129 @@ +// +// $Id: PGPostgresError.m 3837 2012-09-09 12:25:03Z stuart02 $ +// +// PGPostgresError.m +// PostgresKit +// +// Created by Stuart Connolly (stuconnolly.com) on September 3, 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 "PGPostgresError.h" +#import "PGPostgresException.h" + +@interface PGPostgresError () + +- (void)_extractErrorDetailsFromResult:(const PGresult *)result; +- (NSString *)_extractErrorField:(int)field fromResult:(const PGresult *)result; + +@end + +@implementation PGPostgresError + +@synthesize errorSeverity = _errorSeverity; +@synthesize errorStateCode = _errorStateCode; +@synthesize errorPrimaryMessage = _errorPrimaryMessage; +@synthesize errorDetailMessage = _errorDetailMessage; +@synthesize errorMessageHint = _errorMessageHint; +@synthesize errorStatementPosition = _errorStatementPosition; + +#pragma mark - + +- (id)init +{ + [PGPostgresException raise:NSInternalInconsistencyException + reason:@"%@ shouldn't be init'd directly; use initWithResult: instead.", [self className]]; + + return nil; +} + +- (id)initWithResult:(const void *)result +{ + if ((self = [super init])) { + + _errorSeverity = nil; + _errorStateCode = nil; + _errorPrimaryMessage = nil; + _errorDetailMessage = nil; + _errorMessageHint = nil; + _errorStatementPosition = -1; + + if (result) [self _extractErrorDetailsFromResult:(const PGresult *)result]; + } + + return self; +} + +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@: Sev %@ (%@): %@>", [self className], _errorSeverity, _errorStateCode, _errorPrimaryMessage]; +} + +#pragma mark - +#pragma mark Private API + +/** + * Extracts all the error information from the supplied result. + * + * @param result The Postgres result to extract the information from. + */ +- (void)_extractErrorDetailsFromResult:(const PGresult *)result +{ + // Note that we don't expose all the fields that are available. + // The ones we don't mostly include information internal to Postgres + // that generally isn't useful to end users. + _errorSeverity = [self _extractErrorField:PG_DIAG_SEVERITY fromResult:result]; + _errorStateCode = [self _extractErrorField:PG_DIAG_SQLSTATE fromResult:result]; + _errorPrimaryMessage = [self _extractErrorField:PG_DIAG_MESSAGE_PRIMARY fromResult:result]; + _errorDetailMessage = [self _extractErrorField:PG_DIAG_MESSAGE_DETAIL fromResult:result]; + _errorMessageHint = [self _extractErrorField:PG_DIAG_MESSAGE_HINT fromResult:result]; + _errorStatementPosition = [[self _extractErrorField:PG_DIAG_STATEMENT_POSITION fromResult:result] integerValue]; +} + +/** + * Extracts the supplied error field from the supplied Postgres result. + * + * @param field The error field to extract. + * @param result The Postgres result to extract the field from. + * + * @return A string representing the error value. The caller is responsible for freeing the associated memory. + */ +- (NSString *)_extractErrorField:(int)field fromResult:(const PGresult *)result +{ + return [[[NSString alloc] initWithUTF8String:PQresultErrorField(result, field)] autorelease]; +} + +#pragma mark - + +- (void)dealloc +{ + if (_errorSeverity) [_errorSeverity release], _errorSeverity = nil; + if (_errorStateCode) [_errorStateCode release], _errorStateCode = nil; + if (_errorPrimaryMessage) [_errorPrimaryMessage release], _errorPrimaryMessage = nil; + if (_errorDetailMessage) [_errorDetailMessage release], _errorDetailMessage = nil; + if (_errorMessageHint) [_errorMessageHint release], _errorMessageHint = nil; + + [super dealloc]; +} + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresException.h b/Frameworks/PostgresKit/Source/PGPostgresException.h new file mode 100644 index 00000000..1e586dad --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresException.h @@ -0,0 +1,28 @@ +// +// $Id: PGPostgresException.h 3793 2012-09-03 10:22:17Z stuart02 $ +// +// PGPostgresException.h +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +@interface PGPostgresException : NSException + ++ (void)raise:(NSString *)name connection:(void *)connection; ++ (void)raise:(NSString *)name reason:(NSString *)reason, ...; + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresException.m b/Frameworks/PostgresKit/Source/PGPostgresException.m new file mode 100644 index 00000000..95a7ab9b --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresException.m @@ -0,0 +1,64 @@ +// +// $Id: PGPostgresException.m 3793 2012-09-03 10:22:17Z stuart02 $ +// +// PGPostgresException.m +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresException.h" + +@implementation PGPostgresException + +/** + * Raise a new exception with the supplied details. + * + * @param name The name of the exception to raise. + * @param connection The connection associated with the exception being raised. + */ ++ (void)raise:(NSString *)name connection:(void *)connection +{ + const char *errorMessage = "Unknown error"; + + if (connection) errorMessage = PQerrorMessage(connection); + + errorMessage = strlen(errorMessage) ? errorMessage : "Unknown error"; + + [[[[PGPostgresException alloc] initWithName:name reason:[NSString stringWithUTF8String:errorMessage] userInfo:nil] autorelease] raise]; +} + +/** + * Raise a new exception with the supplied details. + * + * @param name The name of the exception to raise. + * @param reason The reason for the exception being raised. + */ ++ (void)raise:(NSString *)name reason:(NSString *)reason, ... +{ + va_list args; + va_start(args, reason); + + NSString *reasonMessage = [[NSString alloc] initWithFormat:reason arguments:args]; + + va_end(args); + + [[[[PGPostgresException alloc] initWithName:name reason:reasonMessage userInfo:nil] autorelease] raise]; + + [reasonMessage release]; +} + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresKitPrivateAPI.h b/Frameworks/PostgresKit/Source/PGPostgresKitPrivateAPI.h new file mode 100644 index 00000000..6004039d --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresKitPrivateAPI.h @@ -0,0 +1,46 @@ +// +// $Id: PGPostgresKitPrivateAPI.h 3828 2012-09-09 01:10:06Z stuart02 $ +// +// PGPostgresConnectionKitAPI.h +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresConnection.h" +#import "PGPostgresTimeInterval.h" + +@interface PGPostgresConnection () + +- (PGconn *)postgresConnection; + +@end + +@interface PGPostgresConnection (PGPostgresConnectionQueryPreparationPrivateAPI) + +- (BOOL)_prepare:(PGPostgresStatement *)statement num:(NSInteger)paramNum types:(PGPostgresOid *)paramTypes; + +@end + +@interface PGPostgresTimeInterval () + ++ (id)intervalWithPGInterval:(PGinterval *)interval; +- (id)initWithInterval:(PGinterval *)interval; + +@end + + + diff --git a/Frameworks/PostgresKit/Source/PGPostgresResult.h b/Frameworks/PostgresKit/Source/PGPostgresResult.h new file mode 100644 index 00000000..2bd1ba96 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresResult.h @@ -0,0 +1,84 @@ +// +// $Id: PGPostgresResult.h 3860 2012-09-24 11:36:57Z stuart02 $ +// +// PGPostgresResult.h +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +@class PGPostgresConnection; + +// Result set row types +typedef enum +{ + PGPostgresResultRowAsArray = 1, + PGPostgresResultRowAsDictionary = 2 +} +PGPostgresResultRowType; + +@interface PGPostgresResult : NSObject +{ + void *_result; + void **_typeHandlers; + + unsigned long long _row; + unsigned long long _numberOfRows; + + NSUInteger _numberOfFields; + + NSString **_fields; + + NSStringEncoding _stringEncoding; + PGPostgresResultRowType _defaultRowType; + + PGPostgresConnection *_connection; +} + +/** + * @property numberOfFields The number of fields this result has. + */ +@property (readonly) NSUInteger numberOfFields; + +/** + * @property numberOfRows The number or rows this result has. + */ +@property (readonly) unsigned long long numberOfRows; + +/** + * @property stringEncoding The ecoding that was in use when this result was created. + */ +@property (readonly) NSStringEncoding stringEncoding; + +/** + * @property defaultRowType The row type that should be used when calling -row. + */ +@property (readwrite, assign) PGPostgresResultRowType defaultRowType; + +- (id)initWithResult:(void *)result connection:(PGPostgresConnection *)connection; + +- (NSUInteger)numberOfFields; + +- (void)seekToRow:(unsigned long long)row; + +- (NSArray *)fields; + +- (id)row; +- (NSArray *)rowAsArray; +- (NSDictionary *)rowAsDictionary; +- (id)rowAsType:(PGPostgresResultRowType)type; + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresResult.m b/Frameworks/PostgresKit/Source/PGPostgresResult.m new file mode 100644 index 00000000..892e8a53 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresResult.m @@ -0,0 +1,308 @@ +// +// $Id: PGPostgresResult.m 3862 2012-09-24 12:58:47Z stuart02 $ +// +// PGPostgresResult.m +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresResult.h" +#import "PGPostgresException.h" +#import "PGPostgresConnection.h" +#import "PGPostgresConnectionTypeHandling.h" + +@interface PGPostgresResult () + +- (void)_populateFields; +- (id)_objectForRow:(NSUInteger)row column:(NSUInteger)column; +- (id )_typeHandlerForColumn:(NSUInteger)column withType:(PGPostgresOid)type; + +@end + +@implementation PGPostgresResult + +@synthesize numberOfRows = _numberOfRows; +@synthesize numberOfFields = _numberOfFields; +@synthesize stringEncoding = _stringEncoding; +@synthesize defaultRowType = _defaultRowType; + +#pragma mark - +#pragma mark Initialisation + +/** + * Prevent normal initialisation. + * + * @return nil + */ +- (id)init +{ + [PGPostgresException raise:NSInternalInconsistencyException reason:@"%@ shouldn't be init'd directly; use initWithResult:connection: instead.", [self className]]; + + return nil; +} + +/** + * Initialises a result with the supplied details. + * + * @param result The underlying PostgreSQL result this wrapper represents. + * @param connection The connection the result came from. + * + * @return The result wrapper. + */ +- (id)initWithResult:(void *)result connection:(PGPostgresConnection *)connection +{ + if ((self = [super init])) { + + _row = 0; + _result = result; + _numberOfRows = PQntuples(_result); + _numberOfFields = PQnfields(_result); + _connection = [connection retain]; + + _stringEncoding = [_connection stringEncoding]; + _defaultRowType = PGPostgresResultRowAsDictionary; + + _typeHandlers = (void **)calloc(sizeof(void *), _numberOfFields); + + unsigned long long affectedRows = (unsigned long long)[[NSString stringWithUTF8String:PQcmdTuples(_result)] longLongValue]; + + _numberOfRows = PQresultStatus(_result) == PGRES_TUPLES_OK ? _numberOfRows : affectedRows; + + [self _populateFields]; + } + + return self; +} + +#pragma mark - +#pragma mark Public API + +/** + * This result's fields as an array. + * + * @return The array of fields. + */ +- (NSArray *)fields +{ + return [NSArray arrayWithObjects:_fields count:_numberOfFields]; +} + +/** + * Sets the current row marker to the supplied row. + * + * @param row The row to seek to. + */ +- (void)seekToRow:(unsigned long long)row +{ + if (row >= _numberOfRows) row = _numberOfRows - 1; + + _row = row; +} + +#pragma mark - +#pragma mark Data Retrieval + +/** + * Return the current row in the type of the currently set default (defaults to dictionary). + * + * @return The row of data. + */ +- (id)row +{ + return [self rowAsType:_defaultRowType]; +} + +/** + * Return the current row as an array. + * + * @return The array of data. + */ +- (NSArray *)rowAsArray +{ + return [self rowAsType:PGPostgresResultRowAsArray]; +} + +/** + * Return the current row as dictionary with keys as field names and values as the data. + * + * @return The row as a dictionary. + */ +- (NSDictionary *)rowAsDictionary +{ + return [self rowAsType:PGPostgresResultRowAsDictionary]; +} + +/** + * Return the current row in the format specified by the supplied type. + * + * @return The data row as either an array or dictionary. + */ +- (id)rowAsType:(PGPostgresResultRowType)type +{ + if (_row >= _numberOfRows) return nil; + + id data = (type == PGPostgresResultRowAsArray) ? [NSMutableArray arrayWithCapacity:_numberOfFields] : [NSMutableDictionary dictionaryWithCapacity:_numberOfFields]; + + for (NSUInteger i = 0; i < _numberOfFields; i++) + { + id object = [self _objectForRow:(int)_row column:i]; + + if (type == PGPostgresResultRowAsArray) { + [(NSMutableArray *)data addObject:object]; + } + else { + [(NSMutableDictionary *)data setObject:object forKey:_fields[i]]; + } + } + + _row++; + + return data; +} + +#pragma mark - +#pragma mark Fast enumeration implementation + +- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len +{ + if (state->state >= _numberOfRows) return 0; + + if (state->state != _row) [self seekToRow:state->state]; + + // Determine how many objects to return - 128, len, or all items remaining + NSUInteger itemsToReturn = 128; + + if (len < 128) itemsToReturn = len; + + if (_numberOfRows - state->state < itemsToReturn) { + itemsToReturn = (unsigned long)_numberOfRows - state->state; + } + + for (NSUInteger i = 0; i < itemsToReturn; i++) + { + stackbuf[i] = [self rowAsType:_defaultRowType]; + } + + state->state += itemsToReturn; + state->itemsPtr = stackbuf; + state->mutationsPtr = (unsigned long *)self; + + return itemsToReturn; +} + +#pragma mark - +#pragma mark Private API + +/** + * Populates the internal field names array. + */ +- (void)_populateFields +{ + _fields = malloc(sizeof(NSString *) * _numberOfFields); + + for (NSUInteger i = 0; i < _numberOfFields; i++) + { + const char *bytes = PQfname(_result, (int)i); + + if (!bytes) continue; + + _fields[i] = [[NSString alloc] initWithBytes:bytes length:strlen(bytes) encoding:_stringEncoding]; + } +} + +/** + * Get the native object at the supplied row and column. + * + * @param row The row index to get the data from. + * @param column The column index to get the data from. + * + * @return The native object or nil if out of this result's range. + */ +- (id)_objectForRow:(NSUInteger)row column:(NSUInteger)column +{ + if (row >= _numberOfRows || column >= _numberOfFields) return [NSNull null]; + + // Check for null + if (PQgetisnull(_result, (int)row, (int)column)) return [NSNull null]; + + PGPostgresOid type = PQftype(_result, (int)column); + + // Get handler for this type + id handler = [self _typeHandlerForColumn:column withType:type]; + + if (!handler) { + NSLog(@"PostgresKit: Warning: No type handler found for type %d, return NSData.", type); + + const void *bytes = PQgetvalue(_result, (int)row, (int)column); + NSUInteger length = PQgetlength(_result, (int)row, (int)column); + + 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 object; +} + +/** + * Get the data type handler for the supplied column index. + * + * @param column The column index to get the handler for. + * + * @return The type handler or nil if out of this result's range. + */ +- (id )_typeHandlerForColumn:(NSUInteger)column withType:(PGPostgresOid)type +{ + if (column >= _numberOfFields) return nil; + + id handler = _typeHandlers[column]; + + if (!handler) { + handler = [_connection typeHandlerForRemoteType:type]; + + _typeHandlers[column] = handler; + } + + return handler; +} + +#pragma mark - + +-(void)dealloc +{ + PQclear(_result); + + for (NSUInteger i = 0; i < _numberOfFields; i++) [_fields[i] release]; + + free(_fields); + free(_typeHandlers); + + if (_connection) [_connection release], _connection = nil; + + [super dealloc]; +} + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresStatement.h b/Frameworks/PostgresKit/Source/PGPostgresStatement.h new file mode 100644 index 00000000..70a6d7dd --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresStatement.h @@ -0,0 +1,44 @@ +// +// $Id: PGPostgresStatement.h 3793 2012-09-03 10:22:17Z stuart02 $ +// +// PGPostgresStatement.h +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +@interface PGPostgresStatement : NSObject +{ + NSString *_statement; + NSString *_name; +} + +/** + * @property statement The query statement. + */ +@property (readwrite, retain) NSString *statement; + +/** + * @property name The name of this statement. + */ +@property (readwrite, retain) NSString *name; + +- (id)initWithStatement:(NSString *)queryStatement; + +- (const char *)UTF8Name; +- (const char *)UTF8Statement; + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresTimeInterval.h b/Frameworks/PostgresKit/Source/PGPostgresTimeInterval.h new file mode 100644 index 00000000..5e08e2b3 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresTimeInterval.h @@ -0,0 +1,85 @@ +// +// $Id: PGPostgresTimeInterval.h 3827 2012-09-09 00:51:43Z stuart02 $ +// +// PGPostgresTimeInterval.h +// PostgresKit +// +// Created by Stuart Connolly (stuconnolly.com) on September 9, 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. + +/** + * @class PGPostgresTimeInterval PGPostgresTimeInterval.h + * + * @author Stuart Connolly http://stuconnolly.com + * + * Simple wrapper around libpqtypes' PQinterval structure. + */ +@interface PGPostgresTimeInterval : NSObject +{ + NSUInteger _microseconds; + NSUInteger _seconds; + NSUInteger _minutes; + NSUInteger _hours; + NSUInteger _days; + NSUInteger _months; + NSUInteger _years; +} + +/** + * @property microseconds The number of microseconds. + */ +@property (readonly) NSUInteger microseconds; + +/** + * @property seconds The number of seconds. + */ +@property (readonly) NSUInteger seconds; + +/** + * @property minutes The number of minutes. + */ +@property (readonly) NSUInteger minutes; + +/** + * @property hours The number of hours. + */ +@property (readonly) NSUInteger hours; + +/** + * @property days The number of days. + */ +@property (readonly) NSUInteger days; + +/** + * @property months The number of months. + */ +@property (readonly) NSUInteger months; + +/** + * @property years The number of years. + */ +@property (readonly) NSUInteger years; + + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresTimeInterval.m b/Frameworks/PostgresKit/Source/PGPostgresTimeInterval.m new file mode 100644 index 00000000..5c40ea52 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresTimeInterval.m @@ -0,0 +1,76 @@ +// +// $Id: PGPostgresTimeInterval.m 3828 2012-09-09 01:10:06Z stuart02 $ +// +// PGPostgresTimeInterval.m +// PostgresKit +// +// Created by Stuart Connolly (stuconnolly.com) on September 9, 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 "PGPostgresTimeInterval.h" +#import "PGPostgresKitPrivateAPI.h" + +@implementation PGPostgresTimeInterval + +@synthesize microseconds = _microseconds; +@synthesize seconds = _seconds; +@synthesize minutes = _minutes; +@synthesize hours = _hours; +@synthesize days = _days; +@synthesize months = _months; +@synthesize years = _years; + +#pragma mark - + ++ (id)intervalWithPGInterval:(PGinterval *)interval +{ + return [[[PGPostgresTimeInterval alloc] initWithInterval:interval] autorelease]; +} + +- (id)initWithInterval:(PGinterval *)interval +{ + if ((self = [super init])) { + if (interval) { + _microseconds = interval->usecs; + _seconds = interval->secs; + _minutes = interval->mins; + _hours = interval->hours; + _days = interval->days; + _months = interval->mons; + _years = interval->years; + } + } + + return self; +} + +#pragma mark - + +- (NSString *)description +{ + return [NSString stringWithFormat:@"%d years, %d months, %d days, %d hours, %d minutes, %d seconds and %d microseconds", + _years, _months, _days, _hours, _minutes, _seconds, _microseconds]; +} + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresTimeTZ.h b/Frameworks/PostgresKit/Source/PGPostgresTimeTZ.h new file mode 100644 index 00000000..075ffbb0 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresTimeTZ.h @@ -0,0 +1,62 @@ +// +// $Id: PGPostgresTimeTZ.h 3827 2012-09-09 00:51:43Z stuart02 $ +// +// PGPostgresTimeTZ.h +// PostgresKit +// +// Created by Stuart Connolly (stuconnolly.com) on September 8, 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. + +/** + * @class PGPostgresTimeTZ PGPostgresTimeTZ.h + * + * @author Stuart Connolly http://stuconnolly.com + * + * Simple wrapper to represet a time or timestamp with an associated time zone. + */ +@interface PGPostgresTimeTZ : NSObject +{ + BOOL _hasDate; + + NSDate *_date; + NSTimeZone *_timeZone; +} + +@property (readwrite, assign) BOOL hasDate; + +/** + * @property date The date instance that holds the time. + */ +@property (readonly) NSDate *date; + +/** + * @property timeZone The time zone of the associated time. + */ +@property (readonly) NSTimeZone *timeZone; + ++ (PGPostgresTimeTZ *)timeWithDate:(NSDate *)date timeZoneGMTOffset:(NSUInteger)offset; + +- (id)initWithDate:(NSDate *)date timeZoneGMTOffset:(NSUInteger)offset; + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresTimeTZ.m b/Frameworks/PostgresKit/Source/PGPostgresTimeTZ.m new file mode 100644 index 00000000..d2d91898 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresTimeTZ.m @@ -0,0 +1,84 @@ +// +// $Id: PGPostgresTimeTZ.m 3827 2012-09-09 00:51:43Z stuart02 $ +// +// PGPostgresTimeTZ.m +// PostgresKit +// +// Created by Stuart Connolly (stuconnolly.com) on September 8, 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 "PGPostgresTimeTZ.h" + +@implementation PGPostgresTimeTZ + +@synthesize hasDate = _hasDate; +@synthesize date = _date; +@synthesize timeZone = _timeZone; + +- (id)init +{ + return [self initWithDate:[NSDate date] timeZoneGMTOffset:[[NSTimeZone systemTimeZone] secondsFromGMT]]; +} + ++ (PGPostgresTimeTZ *)timeWithDate:(NSDate *)date timeZoneGMTOffset:(NSUInteger)offset +{ + return [[[PGPostgresTimeTZ alloc] initWithDate:date timeZoneGMTOffset:offset] autorelease]; +} + +/** + * Initialise a PGPostgresTimeTZ with the supplied date and GMT offset. + * + * @param date The date to use. + * @param offset The GMT offset in seconds that the associated time zone is. + * + * @return The initialised instance. + */ +- (id)initWithDate:(NSDate *)date timeZoneGMTOffset:(NSUInteger)offset +{ + if ((self = [super init])) { + _date = date; + _hasDate = NO; + _timeZone = [NSTimeZone timeZoneForSecondsFromGMT:offset]; + } + + return self; +} + +#pragma mark - + +- (NSString *)description +{ + NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; + + [formatter setDateStyle:_hasDate ? NSDateFormatterMediumStyle : NSDateFormatterNoStyle]; + [formatter setTimeStyle:NSDateFormatterMediumStyle]; + + NSString *output = [formatter stringFromDate:_date]; + + [formatter release]; + + return [NSString stringWithFormat:@"%@ %@", output, [_timeZone abbreviation]]; +} + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresTypeDateTimeHandler.h b/Frameworks/PostgresKit/Source/PGPostgresTypeDateTimeHandler.h new file mode 100644 index 00000000..6b9bf2f7 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresTypeDateTimeHandler.h @@ -0,0 +1,55 @@ +// +// $Id: PGPostgresTypeDateTimeHandler.h 3850 2012-09-13 09:05:50Z stuart02 $ +// +// PGPostgresTypeDateTimeHandler.h +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresTypeHandler.h" + +@interface PGPostgresTypeDateTimeHandler : PGPostgresTypeHandler +{ + 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/PGPostgresTypeDateTimeHandler.m b/Frameworks/PostgresKit/Source/PGPostgresTypeDateTimeHandler.m new file mode 100644 index 00000000..eb206587 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresTypeDateTimeHandler.m @@ -0,0 +1,213 @@ +// +// $Id: PGPostgresTypeDateTimeHandler.m 3866 2012-09-26 01:30:28Z stuart02 $ +// +// PGPostgresTypeDateTimeHandler.m +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresTypeDateTimeHandler.h" +#import "PGPostgresTypeNumberHandler.h" +#import "PGPostgresConnectionParameters.h" +#import "PGPostgresConnection.h" +#import "PGPostgresConnectionTypeHandling.h" +#import "PGPostgresTimeTZ.h" +#import "PGPostgresTimeInterval.h" +#import "PGPostgresKitPrivateAPI.h" + +static PGPostgresOid PGPostgresTypeDateTimeTypes[] = +{ + PGPostgresOidDate, + PGPostgresOidTime, + PGPostgresOidTimeTZ, + PGPostgresOidAbsTime, + PGPostgresOidTimestamp, + PGPostgresOidTimestampTZ, + PGPostgresOidInterval, + 0 +}; + +@interface PGPostgresTypeDateTimeHandler () + +- (id)_timeFromResult; +- (id)_timestmpFromResult; +- (id)_timeIntervalFromResult; + +- (NSDate *)_dateFromResult; +- (NSDate *)_dateFromComponents:(NSDateComponents *)components; + +@end + +@implementation PGPostgresTypeDateTimeHandler + +@synthesize row = _row; +@synthesize type = _type; +@synthesize column = _column; +@synthesize result = _result; + +#pragma mark - +#pragma mark Protocol Implementation + +- (PGPostgresOid *)remoteTypes +{ + return PGPostgresTypeDateTimeTypes; +} + +- (Class)nativeClass +{ + return [NSDate class]; +} + +- (NSArray *)classAliases +{ + return nil; +} + +- (id)objectFromResult +{ + if (!_result || !_type) return [NSNull null]; + + switch (_type) + { + case PGPostgresOidDate: + return [self _dateFromResult]; + case PGPostgresOidTime: + case PGPostgresOidTimeTZ: + case PGPostgresOidAbsTime: + return [self _timeFromResult]; + case PGPostgresOidTimestamp: + case PGPostgresOidTimestampTZ: + return [self _timestmpFromResult]; + case PGPostgresOidInterval: + return [self _timeIntervalFromResult]; + } + + return [NSNull null]; +} + +#pragma mark - +#pragma mark Private API + +/** + * Returns an NSDate created from a date value. + * + * @return The NSDate representation. + */ +- (id)_dateFromResult +{ + PGdate date; + + if (!PQgetf(_result, (int)_row, PGPostgresResultValueDate, (int)_column, &date)) return [NSNull null]; + + NSDateComponents *components = [[NSDateComponents alloc] init]; + + [components setDay:date.mday]; + [components setMonth:date.mon + 1]; // Months are indexed from 0 + [components setYear:date.year]; + + return [self _dateFromComponents:components]; +} + +/** + * Converts a time interval value to a PGPostgresTimeInterval instance. + * + * @return The PGPostgresTimeInterval representation. + */ +- (id)_timeIntervalFromResult +{ + PGinterval interval; + + if (!PQgetf(_result, (int)_row, PGPostgresResultValueInterval, (int)_column, &interval)) return [NSNull null]; + + return [PGPostgresTimeInterval intervalWithPGInterval:&interval]; +} + +/** + * Returns a native object created from a time value. + * + * @note The date part should be ignored as it's set to a default value. + * + * @return The object representation. + */ +- (id)_timeFromResult +{ + PGtime pgTime; + + BOOL hasTimeZone = _type == PGPostgresOidTimeTZ; + + if (!PQgetf(_result, (int)_row, hasTimeZone ? PGPostgresResultValueTimeTZ : PGPostgresResultValueTime, (int)_column, &pgTime)) return [NSNull null]; + + NSDateComponents *components = [[NSDateComponents alloc] init]; + + // Default date values; should be ignored + [components setDay:1]; + [components setMonth:1]; + [components setYear:2000]; + + [components setHour:pgTime.hour]; + [components setMinute:pgTime.min]; + [components setSecond:pgTime.sec]; + + NSDate *date = [self _dateFromComponents:components]; + + return hasTimeZone ? (id)[PGPostgresTimeTZ timeWithDate:date timeZoneGMTOffset:pgTime.gmtoff] : date; +} + +/** + * Returns a native object created from a timestamp value. + * + * @return The object representation. + */ +- (id)_timestmpFromResult +{ + PGtimestamp timestamp; + + BOOL hasTimeZone = _type == PGPostgresOidTimestampTZ; + + if (!PQgetf(_result, (int)_row, hasTimeZone ? PGPostgresResultValueTimestmpTZ : PGPostgresResultValueTimestamp, (int)_column, ×tamp)) return [NSNull null]; + + PGPostgresTimeTZ *timestampTZ = nil; + NSDate *date = [NSDate dateWithTimeIntervalSince1970:timestamp.epoch]; + + if (hasTimeZone) { + timestampTZ = [PGPostgresTimeTZ timeWithDate:date timeZoneGMTOffset:timestamp.time.gmtoff]; + + [timestampTZ setHasDate:YES]; + } + + return hasTimeZone ? (id)timestampTZ : date; +} + +/** + * Returns an NSDate created from the supplied components. + * + * @param The components to create the date from. + * + * @return The NSDate created. + */ +- (NSDate *)_dateFromComponents:(NSDateComponents *)components +{ + NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; + + NSDate *date = [gregorian dateFromComponents:components]; + + [gregorian release]; + + return date; +} + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresTypeHandler.h b/Frameworks/PostgresKit/Source/PGPostgresTypeHandler.h new file mode 100644 index 00000000..5fe9c567 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresTypeHandler.h @@ -0,0 +1,38 @@ +// +// $Id: PGPostgresTypeHandler.h 3848 2012-09-12 12:19:31Z stuart02 $ +// +// PGPostgresTypeHandler.h +// PostgresKit +// +// Created by Stuart Connolly (stuconnolly.com) on July 27, 2012. +// Copyright (c) 2012 Stuart Connolly. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresTypeHandlerProtocol.h" + +@class PGPostgresConnection; + +@interface PGPostgresTypeHandler : NSObject +{ + PGPostgresConnection *_connection; +} + +/** + * @property connection The connection this type handler is associated with. + */ +@property (readonly) PGPostgresConnection *connection; + +- (id)initWithConnection:(PGPostgresConnection *)connection; + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresTypeHandler.m b/Frameworks/PostgresKit/Source/PGPostgresTypeHandler.m new file mode 100644 index 00000000..49cdd01a --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresTypeHandler.m @@ -0,0 +1,48 @@ +// +// $Id: PGPostgresTypeHandler.m 3848 2012-09-12 12:19:31Z stuart02 $ +// +// PGPostgresTypeHandler.h +// PostgresKit +// +// Created by Stuart Connolly (stuconnolly.com) on July 27, 2012. +// Copyright (c) 2012 Stuart Connolly. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresTypeHandler.h" + +@implementation PGPostgresTypeHandler + +@synthesize connection = _connection; + +#pragma mark - + +- (id)initWithConnection:(PGPostgresConnection *)connection +{ + if ((self = [super init])) { + _connection = [connection retain]; + } + + return self; +} + +#pragma mark - + +- (void)dealloc +{ + if (_connection) [_connection release], _connection = nil; + + [super dealloc]; +} + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresTypeHandlerProtocol.h b/Frameworks/PostgresKit/Source/PGPostgresTypeHandlerProtocol.h new file mode 100644 index 00000000..5c8dab83 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresTypeHandlerProtocol.h @@ -0,0 +1,78 @@ +// +// $Id: PGPostgresTypeHandlerProtocol.h 3850 2012-09-13 09:05:50Z stuart02 $ +// +// PGPostgresTypeHandlerProtocol.h +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +@class PGPostgresConnection; + +/** + * @protocol PGPostgresTypeHandlerProtocol + */ +@protocol PGPostgresTypeHandlerProtocol + +/** + * @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; + +/** + * The remote type values handled by this class (terminated by 0). + * + * @return The remote types as an array of PGPostgresOid's. + */ +- (PGPostgresOid *)remoteTypes; + +/** + * What is the native class this class handles. + * + * @return The native class. + */ +- (Class)nativeClass; + +/** + * Any aliases that the native class is known by. + * + * @return An of aliases as strings or nil if none. + */ +- (NSArray *)classAliases; + +/** + * Convert the value at the specified row and column in the supplied result to a native object. + * + * @return An object represenation of the data. + */ +- (id)objectFromResult; + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresTypeNumberHandler.h b/Frameworks/PostgresKit/Source/PGPostgresTypeNumberHandler.h new file mode 100644 index 00000000..c454bb92 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresTypeNumberHandler.h @@ -0,0 +1,56 @@ +// +// $Id: PGPostgresTypeNumberHandler.h 3850 2012-09-13 09:05:50Z stuart02 $ +// +// PGPostgresTypeNumberHandler.h +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresTypeHandler.h" + +@interface PGPostgresTypeNumberHandler : PGPostgresTypeHandler +{ + 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/PGPostgresTypeNumberHandler.m b/Frameworks/PostgresKit/Source/PGPostgresTypeNumberHandler.m new file mode 100644 index 00000000..106fce21 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresTypeNumberHandler.m @@ -0,0 +1,206 @@ +// +// $Id: PGPostgresTypeNumberHandler.m 3867 2012-09-26 02:45:14Z stuart02 $ +// +// PGPostgresTypeNumberHandler.m +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresTypeNumberHandler.h" + +static PGPostgresOid PGPostgresTypeNumberTypes[] = +{ + PGPostgresOidInt8, + PGPostgresOidInt2, + PGPostgresOidInt4, + PGPostgresOidFloat4, + PGPostgresOidFloat8, + PGPostgresOidBool, + PGPostgresOidOid, + PGPostgresOidMoney, + PGPostgresOidNumeric, + 0 +}; + +@interface PGPostgresTypeNumberHandler () + +- (id)_integerObjectFromResult; +- (id)_floatObjectFromResult; +- (id)_booleanObjectFromResult; +- (id)_numericFromResult; + +@end + +@implementation PGPostgresTypeNumberHandler + +@synthesize row = _row; +@synthesize type = _type; +@synthesize column = _column; +@synthesize result = _result; + +#pragma mark - +#pragma mark Protocol Implementation + +- (PGPostgresOid *)remoteTypes +{ + return PGPostgresTypeNumberTypes; +} + +- (Class)nativeClass +{ + return [NSNumber class]; +} + +- (NSArray *)classAliases +{ + return nil; +} + +- (id)objectFromResult +{ + if (!_result || !_type) return [NSNull null]; + + switch (_type) + { + case PGPostgresOidInt8: + case PGPostgresOidInt2: + case PGPostgresOidInt4: + return [self _integerObjectFromResult]; + case PGPostgresOidFloat4: + case PGPostgresOidFloat8: + return [self _floatObjectFromResult]; + case PGPostgresOidBool: + return [self _booleanObjectFromResult]; + case PGPostgresOidNumeric: + return [self _numericFromResult]; + } + + return [NSNull null]; +} + +#pragma mark - +#pragma mark Integer + +/** + * Converts an integer value to an NSNumber instance. + * + * @return An NSNumber representation of the the value. + */ +- (id)_integerObjectFromResult +{ + NSUInteger length = PQgetlength(_result, (int)_row, (int)_column); + + if (!length) return [NSNull null]; + + PGint2 int2; + PGint4 int4; + PGint8 int8; + + switch (length) + { + case 2: + if (!PQgetf(_result, _row, PGPostgresResultValueInt2, &int2)) return [NSNull null]; + + return [NSNumber numberWithShort:int2]; + case 4: + if (!PQgetf(_result, _row, PGPostgresResultValueInt4, &int4)) return [NSNull null]; + + return [NSNumber numberWithInteger:int4]; + case 8: + if (!PQgetf(_result, _row, PGPostgresResultValueInt8, &int8)) return [NSNull null]; + + return [NSNumber numberWithLongLong:int8]; + } + + return [NSNull null]; +} + +#pragma mark - +#pragma mark Floating Point + +/** + * Converts a float value to an NSNumber instance. + * + * @return An NSNumber representation of the the value. + */ +- (id)_floatObjectFromResult +{ + NSUInteger length = PQgetlength(_result, (int)_row, (int)_column); + + if (!length) return [NSNull null]; + + PGfloat4 float4; + PGfloat8 float8; + + switch (length) + { + case 4: + if (!PQgetf(_result, _row, PGPostgresResultValueFloat4, &float4)) return [NSNull null]; + + return [NSNumber numberWithFloat:float4]; + case 8: + if (!PQgetf(_result, _row, PGPostgresResultValueFloat8, &float8)) return [NSNull null]; + + return [NSNumber numberWithDouble:float8]; + } + + return [NSNull null]; +} + +#pragma mark - +#pragma mark Boolean + +/** + * Converts a boolean value to an NSNumber instance. + * + * @return An NSNumber representation of the the value. + */ +- (id)_booleanObjectFromResult +{ + PGbool b; + + if (!PQgetf(_result, _row, PGPostgresResultValueBool, &b)) return [NSNull null]; + + return [NSNumber numberWithInt:b]; +} + +#pragma mark - +#pragma mark Numeric + +/** + * Converts a numeric value to a native NSNumber instance. + * + * @return An NSNumber representation of the the value. + */ +- (id)_numericFromResult +{ + PGnumeric numeric; + + if (!PQgetf(_result, (int)_row, PGPostgresResultValueNumeric, (int)_column, &numeric)) return [NSNull null]; + + NSString *stringValue = [[NSString alloc] initWithUTF8String:numeric]; + + double value = [stringValue doubleValue]; + + if (value == HUGE_VAL || value == -HUGE_VAL) return [NSNull null]; + + [stringValue release]; + + return [NSNumber numberWithDouble:value]; +} + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresTypeStringHandler.h b/Frameworks/PostgresKit/Source/PGPostgresTypeStringHandler.h new file mode 100644 index 00000000..e5edd7c7 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresTypeStringHandler.h @@ -0,0 +1,56 @@ +// +// $Id: PGPostgresTypeStringHandler.h 3850 2012-09-13 09:05:50Z stuart02 $ +// +// PGPostgresTypeStringHandler.h +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresTypeHandler.h" + +@interface PGPostgresTypeStringHandler : PGPostgresTypeHandler +{ + 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/PGPostgresTypeStringHandler.m b/Frameworks/PostgresKit/Source/PGPostgresTypeStringHandler.m new file mode 100644 index 00000000..f638eb4e --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresTypeStringHandler.m @@ -0,0 +1,163 @@ +// +// $Id: PGPostgresTypeStringHandler.m 3866 2012-09-26 01:30:28Z stuart02 $ +// +// PGPostgresTypeStringHandler.m +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresTypeStringHandler.h" +#import "PGPostgresConnection.h" + +#import + +static PGPostgresOid PGPostgresTypeStringTypes[] = +{ + PGPostgresOidText, + PGPostgresOidChar, + PGPostgresOidName, + PGPostgresOidVarChar, + PGPostgresOidXML, + PGPostgresOidUUID, + PGPostgresOidBit, + PGPostgresOidVarBit, + PGPostgresOidInetAddr, + PGPostgresOidCidrAddr, + PGPostgresOidMacAddr, + PGPostgresOidUnknown, + 0 +}; + +@interface PGPostgresTypeStringHandler () + +- (id)_stringFromResult; +- (id)_macAddressFromResult; +- (id)_inetAddressFromResult; + +@end + +@implementation PGPostgresTypeStringHandler + +@synthesize row = _row; +@synthesize type = _type; +@synthesize column = _column; +@synthesize result = _result; + +#pragma mark - +#pragma mark Protocol Implementation + +- (PGPostgresOid *)remoteTypes +{ + return PGPostgresTypeStringTypes; +} + +- (Class)nativeClass +{ + return [NSString class]; +} + +- (NSArray *)classAliases +{ + return [NSArray arrayWithObject:@"NSCFString"]; +} + +- (id)objectFromResult +{ + if (!_result || !_type) return [NSNull null]; + + switch (_type) + { + case PGPostgresOidText: + case PGPostgresOidChar: + case PGPostgresOidName: + case PGPostgresOidVarChar: + case PGPostgresOidXML: + case PGPostgresOidUUID: + case PGPostgresOidBit: + case PGPostgresOidVarBit: + case PGPostgresOidUnknown: + return [self _stringFromResult]; + case PGPostgresOidMacAddr: + return [self _macAddressFromResult]; + case PGPostgresOidInetAddr: + case PGPostgresOidCidrAddr: + return [self _inetAddressFromResult]; + } + + return [NSNull null]; +} + +#pragma mark - +#pragma mark Private API + +/** + * Converts a char value to a string. + * + * @return A string representation of the value. + */ +- (id)_stringFromResult +{ + const void *bytes = PQgetvalue(_result, (int)_row, (int)_column); + NSUInteger length = PQgetlength(_result, (int)_row, (int)_column); + + if (!bytes || !length) return [NSNull null]; + + return [[[NSString alloc] initWithBytes:bytes length:length encoding:[_connection stringEncoding]] autorelease]; +} + +/** + * Converts a MAC address value to a string. + * + * @return A string representation of the MAC address. + */ +- (id)_macAddressFromResult +{ + PGmacaddr address; + + if (!PQgetf(_result, (int)_row, PGPostgresResultValueMacAddr, (int)_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]; +} + +/** + * Converts a network address value to a string. + * + * @return A string representation of the network address. + */ +- (id)_inetAddressFromResult +{ + PGinet inet; + + if (!PQgetf(_result, (int)_row, _type == PGPostgresOidInetAddr ? PGPostgresResultValueInet : PGPostgresResultValueCidr, (int)_column, &inet)) return [NSNull null]; + + char ip[80]; + struct sockaddr *sa = (struct sockaddr *)inet.sa_buf; + + int success = getnameinfo(sa, inet.sa_buf_len, ip, sizeof(ip), NULL, 0, NI_NUMERICHOST); + + if (success != 0) { + const char *error = gai_strerror(success); + + NSLog(@"PostgresKit: Error: Failed to convert IP address to string representation (%s)", error); + + return [NSNull null]; + } + + return [NSString stringWithUTF8String:ip]; +} + +@end diff --git a/Frameworks/PostgresKit/Source/PGPostgresTypes.h b/Frameworks/PostgresKit/Source/PGPostgresTypes.h new file mode 100644 index 00000000..993e824d --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGPostgresTypes.h @@ -0,0 +1,119 @@ +// +// $Id: PGPostgresTypes.h 3861 2012-09-24 12:23:27Z stuart02 $ +// +// PGPostgresTypes.h +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "postgres_ext.h" + +// Generic PostgreSQL object ID +typedef Oid PGPostgresOid; + +// See PostgreSQL source: include/catalog/pg_type.h + +enum +{ + // BOOL + PGPostgresOidBool = 16, // NumberHandler => NSNumber + PGPostgresOidByteData = 17, // Currently not supported + + // Text + PGPostgresOidName = 19, // StringHandler => NSString + + // Integers + PGPostgresOidInt8 = 20, // NumberHandler => NSNumber + PGPostgresOidInt2 = 21, // NumberHandler => NSNumber + PGPostgresOidInt4 = 23, // NumberHandler => NSNumber + + // Text + PGPostgresOidText = 25, // StringHandler => NSString + + // OID + PGPostgresOidOid = 26, // NumberHandler => NSNumber + + // XML + PGPostgresOidXML = 142, // StringHandler => NSString + + // Geometric + PGPostgresOidPoint = 600, // Currently not supported + PGPostgresOidLSeg = 601, // Currently not supported + PGPostgresOidPath = 602, // Currently not supported + PGPostgresOidBox = 603, // Currently not supported + PGPostgresOidPolygon = 604, // Currently not supported + + // Network + PGPostgresOidCidrAddr = 650, // StringHandler => NSString + + // Float + PGPostgresOidFloat4 = 700, // NumberHandler => NSNumber + PGPostgresOidFloat8 = 701, // NumberHandler => NSNumber + + // ABS Time + PGPostgresOidAbsTime = 702, // DateHandler => NSDate + + // What! + PGPostgresOidUnknown = 705, // StringHandler => NSString + + // Geometric + PGPostgresOidCircle = 718, // Currently not supported + + // Monetary + PGPostgresOidMoney = 790, // NumberHandler => NSNumber + + // Network + PGPostgresOidMacAddr = 829, // StringHandler => NSString + PGPostgresOidInetAddr = 869, // StringHandler => NSString + + // Arrays + PGPostgresOidArrayBool = 1000, // Currently not supported + PGPostgresOidArrayData = 1001, // Currently not supported + PGPostgresOidArrayChar = 1002, // Currently not supported + PGPostgresOidArrayName = 1003, // Currently not supported + PGPostgresOidArrayInt2 = 1005, // Currently not supported + PGPostgresOidArrayInt4 = 1007, // Currently not supported + PGPostgresOidArrayText = 1009, // Currently not supported + PGPostgresOidArrayVarchar = 1015, // Currently not supported + PGPostgresOidArrayInt8 = 1016, // Currently not supported + PGPostgresOidArrayFloat4 = 1021, // Currently not supported + PGPostgresOidArrayFloat8 = 1022, // Currently not supported + PGPostgresOidArrayMacAddr = 1040, // Currently not supported + PGPostgresOidArrayIPAddr = 1041, // Currently not supported + + // Text + PGPostgresOidChar = 1042, // StringHandler => NSString + PGPostgresOidVarChar = 1043, // StringHandler => NSString + + // Date/time + PGPostgresOidDate = 1082, // DateHandler => NSDate + PGPostgresOidTime = 1083, // DateHandler => NSDate + PGPostgresOidTimestamp = 1114, // DateHandler => NSDate + PGPostgresOidTimestampTZ = 1184, // DateHandler => PGPostgresTimeTZ + PGPostgresOidInterval = 1186, // DateHandler => PGPostgresTimeInterval + PGPostgresOidTimeTZ = 1266, // DateHandler => PGPostgresTimeTZ + + // Bit strings + PGPostgresOidBit = 1560, // StringHandler => NSString + PGPostgresOidVarBit = 1562, // StringHandler => NSString + + // Numeric + PGPostgresOidNumeric = 1700, // NumberHandler => NSNumber + + // UUID + PGPostgresOidUUID = 2950 // StringHandler => NSString +}; diff --git a/Frameworks/PostgresKit/Source/PGostgresStatement.m b/Frameworks/PostgresKit/Source/PGostgresStatement.m new file mode 100644 index 00000000..5e0d1959 --- /dev/null +++ b/Frameworks/PostgresKit/Source/PGostgresStatement.m @@ -0,0 +1,81 @@ +// +// $Id: PGPostgresStatement.m 3793 2012-09-03 10:22:17Z stuart02 $ +// +// PGPostgresStatement.m +// PostgresKit +// +// Copyright (c) 2008-2009 David Thorpe, djt@mutablelogic.com +// +// Forked by the Sequel Pro Team on July 22, 2012. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#import "PGPostgresStatement.h" + +@implementation PGPostgresStatement + +@synthesize name = _name; +@synthesize statement = _statement; + +#pragma mark - +#pragma mark Initialisation + +- (id)initWithStatement:(NSString *)queryStatement +{ + if ((self = [super init])) { + [self setStatement:queryStatement]; + [self setName:nil]; + } + + return self; +} + +#pragma mark - +#pragma mark Public API + +/** + * Returns a null terminated C string of the statement's name. + * + * @return The statement name. + */ +- (const char *)UTF8Name +{ + return [[self name] UTF8String]; +} + +/** + * Returns a null terminated C string of the statement. + * + * @return The prepared statement. + */ +- (const char *)UTF8Statement +{ + return [[self statement] UTF8String]; +} + +- (NSString *)description +{ + return [self name] ? [NSString stringWithFormat:@"<%@ %@>", [self className], [self name]] : [NSString stringWithFormat:@"<%@>", [self className]]; +} + +#pragma mark - + +- (void)dealloc +{ + if (_name) [_name release], _name = nil; + if (_statement) [_statement release], _statement = nil; + + [super dealloc]; +} + +@end diff --git a/Frameworks/PostgresKit/Source/PostgresKit-Prefix.pch b/Frameworks/PostgresKit/Source/PostgresKit-Prefix.pch index 093e3126..ac7904dd 100644 --- a/Frameworks/PostgresKit/Source/PostgresKit-Prefix.pch +++ b/Frameworks/PostgresKit/Source/PostgresKit-Prefix.pch @@ -30,8 +30,8 @@ #import "libpqtypes.h" // Framework constants - #import "FLXConstants.h" + #import "PGConstants.h" // Global types - #import "FLXPostgresTypes.h" + #import "PGPostgresTypes.h" #endif diff --git a/Frameworks/PostgresKit/Source/PostgresKit.h b/Frameworks/PostgresKit/Source/PostgresKit.h index 40c86169..4189fffe 100644 --- a/Frameworks/PostgresKit/Source/PostgresKit.h +++ b/Frameworks/PostgresKit/Source/PostgresKit.h @@ -18,11 +18,11 @@ // License for the specific language governing permissions and limitations under // the License. -#import "FLXPostgresError.h" -#import "FLXPostgresResult.h" -#import "FLXPostgresStatement.h" -#import "FLXPostgresException.h" -#import "FLXPostgresConnection.h" -#import "FLXPostgresConnectionUtils.h" -#import "FLXPostgresConnectionQueryExecution.h" -#import "FLXPostgresConnectionQueryPreparation.h" +#import "PGPostgresError.h" +#import "PGPostgresResult.h" +#import "PGPostgresStatement.h" +#import "PGPostgresException.h" +#import "PGPostgresConnection.h" +#import "PGPostgresConnectionUtils.h" +#import "PGPostgresConnectionQueryExecution.h" +#import "PGPostgresConnectionQueryPreparation.h" -- cgit v1.2.3