diff options
author | stuconnolly <stuart02@gmail.com> | 2012-09-11 09:35:40 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2012-09-11 09:35:40 +0000 |
commit | ab9c87af48c8831a5bbd4b924e9200df92a78e0e (patch) | |
tree | 8de310cb838d579f12091820b061a2bfb24ac0ce /Frameworks | |
parent | 7dd33a85a537c410cd3b31d661731b1f8d1e7d59 (diff) | |
download | sequelpro-ab9c87af48c8831a5bbd4b924e9200df92a78e0e.tar.gz sequelpro-ab9c87af48c8831a5bbd4b924e9200df92a78e0e.tar.bz2 sequelpro-ab9c87af48c8831a5bbd4b924e9200df92a78e0e.zip |
Add the ability for the client application to set the PostgreSQL application name when connecting.
Diffstat (limited to 'Frameworks')
-rw-r--r-- | Frameworks/PostgresKit/Source/FLXConstants.h | 20 | ||||
-rw-r--r-- | Frameworks/PostgresKit/Source/FLXConstants.m | 23 | ||||
-rw-r--r-- | Frameworks/PostgresKit/Source/FLXPostgresConnection.h | 2 | ||||
-rw-r--r-- | Frameworks/PostgresKit/Source/FLXPostgresConnection.m | 21 |
4 files changed, 44 insertions, 22 deletions
diff --git a/Frameworks/PostgresKit/Source/FLXConstants.h b/Frameworks/PostgresKit/Source/FLXConstants.h index b3aeaed9..b14ba5c1 100644 --- a/Frameworks/PostgresKit/Source/FLXConstants.h +++ b/Frameworks/PostgresKit/Source/FLXConstants.h @@ -20,7 +20,11 @@ // License for the specific language governing permissions and limitations under // the License. -// Defaults +// Connection defaults +extern const NSUInteger FLXPostgresConnectionDefaultTimeout; +extern const NSUInteger FLXPostgresConnectionDefaultServerPort; +extern const NSUInteger FLXPostgresConnectionDefaultKeepAlive; + extern NSString *FLXPostgresConnectionDefaultEncoding; extern NSString *FLXPostgresConnectionErrorDomain; extern NSStringEncoding FLXPostgresConnectionDefaultStringEncoding; @@ -32,7 +36,7 @@ extern NSString *FLXPostgresParameterSuperUser; extern NSString *FLXPostgresParameterTimeZone; extern NSString *FLXPostgresParameterIntegerDateTimes; -// Value specifiers +// Result value specifiers extern const char *FLXPostgresResultValueMacAddr; extern const char *FLXPostgresResultValueInet; extern const char *FLXPostgresResultValueCidr; @@ -42,3 +46,15 @@ extern const char *FLXPostgresResultValueTimeTZ; extern const char *FLXPostgresResultValueTimestamp; extern const char *FLXPostgresResultValueTimestmpTZ; extern const char *FLXPostgresResultValueInterval; + +// 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 index 14771072..4f82bef8 100644 --- a/Frameworks/PostgresKit/Source/FLXConstants.m +++ b/Frameworks/PostgresKit/Source/FLXConstants.m @@ -20,16 +20,23 @@ // License for the specific language governing permissions and limitations under // the License. -NSString *FLXPostgresConnectionDefaultEncoding = @"UNICODE"; -NSString *FLXPostgresConnectionErrorDomain = @"FLXPostgresConnectionError"; +// 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"; @@ -39,3 +46,15 @@ const char *FLXPostgresResultValueTimeTZ = "%timetz"; const char *FLXPostgresResultValueTimestamp = "%timestamp"; const char *FLXPostgresResultValueTimestmpTZ = "%timestamptz"; const char *FLXPostgresResultValueInterval = "%interval"; + +// 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 index 5ff6f06b..87ac46d3 100644 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnection.h +++ b/Frameworks/PostgresKit/Source/FLXPostgresConnection.h @@ -38,6 +38,7 @@ NSString *_socketPath; NSString *_encoding; NSString *_connectionError; + NSString *_applicationName; const char **_connectionParamNames; const char **_connectionParamValues; @@ -68,6 +69,7 @@ @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; diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnection.m b/Frameworks/PostgresKit/Source/FLXPostgresConnection.m index e5b889f5..e5253fa8 100644 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnection.m +++ b/Frameworks/PostgresKit/Source/FLXPostgresConnection.m @@ -34,23 +34,6 @@ #import <pthread.h> #import <poll.h> -// Connection default constants -static NSUInteger FLXPostgresConnectionDefaultTimeout = 30; -static NSUInteger FLXPostgresConnectionDefaultServerPort = 5432; -static NSUInteger FLXPostgresConnectionDefaultKeepAlive = 60; - -// libpq connection parameters -static const char *FLXPostgresApplicationName = "PostgresKit"; -static const char *FLXPostgresApplicationParam = "application_name"; -static const char *FLXPostgresUserParam = "user"; -static const char *FLXPostgresHostParam = "host"; -static const char *FLXPostgresPasswordParam = "password"; -static const char *FLXPostgresPortParam = "port"; -static const char *FLXPostgresDatabaseParam = "dbname"; -static const char *FLXPostgresClientEncodingParam = "client_encoding"; -static const char *FLXPostgresKeepAliveParam = "keepalives"; -static const char *FLXPostgresKeepAliveIntervalParam = "keepalives_interval"; - @interface FLXPostgresConnection () - (void)_loadDatabaseParameters; @@ -81,6 +64,7 @@ static void _FLXPostgresConnectionNoticeProcessor(void *arg, const char *message @synthesize connectionError = _connectionError; @synthesize stringEncoding = _stringEncoding; @synthesize parameters = _parameters; +@synthesize applicationName = _applicationName; #pragma mark - #pragma mark Initialisation @@ -425,7 +409,7 @@ static void _FLXPostgresConnectionNoticeProcessor(void *arg, const char *message _connectionParamValues = malloc(paramCount * sizeof(*_connectionParamValues)); _connectionParamNames[0] = FLXPostgresApplicationParam; - _connectionParamValues[0] = FLXPostgresApplicationName; + _connectionParamValues[0] = !_applicationName ? [_applicationName UTF8String] : FLXPostgresKitApplicationName; _connectionParamNames[1] = FLXPostgresPortParam; _connectionParamValues[1] = [[[NSNumber numberWithUnsignedInteger:_port] stringValue] UTF8String]; @@ -491,6 +475,7 @@ static void _FLXPostgresConnectionNoticeProcessor(void *arg, const char *message 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]; } |