From 669d45c54dc297d3a553f93f9ff62b4705f43427 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Thu, 6 Sep 2012 09:35:29 +0000 Subject: Add a new connection error property. --- Frameworks/PostgresKit/Source/FLXPostgresConnection.h | 2 ++ Frameworks/PostgresKit/Source/FLXPostgresConnection.m | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'Frameworks') diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnection.h b/Frameworks/PostgresKit/Source/FLXPostgresConnection.h index 51a6f9e5..6b96d624 100644 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnection.h +++ b/Frameworks/PostgresKit/Source/FLXPostgresConnection.h @@ -38,6 +38,7 @@ NSString *_password; NSString *_socketPath; NSString *_encoding; + NSString *_connectionError; const char **_connectionParamNames; const char **_connectionParamValues; @@ -70,6 +71,7 @@ @property (readwrite, retain) NSString *socketPath; @property (readonly) NSString *encoding; +@property (readonly) NSString *connectionError; @property (readonly) FLXPostgresError *lastError; @property (readonly) NSStringEncoding stringEncoding; @property (readonly) FLXPostgresConnectionParameters *parameters; diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnection.m b/Frameworks/PostgresKit/Source/FLXPostgresConnection.m index 8e0fba79..d9060a5f 100644 --- a/Frameworks/PostgresKit/Source/FLXPostgresConnection.m +++ b/Frameworks/PostgresKit/Source/FLXPostgresConnection.m @@ -77,6 +77,7 @@ static void _FLXPostgresConnectionNoticeProcessor(void *arg, const char *message @synthesize lastQueryWasCancelled = _lastQueryWasCancelled; @synthesize lastError = _lastError; @synthesize encoding = _encoding; +@synthesize connectionError = _connectionError; @synthesize stringEncoding = _stringEncoding; @synthesize parameters = _parameters; @@ -109,6 +110,7 @@ static void _FLXPostgresConnectionNoticeProcessor(void *arg, const char *message _lastError = nil; _connection = nil; + _connectionError = nil; _lastQueryWasCancelled = NO; _stringEncoding = FLXPostgresConnectionDefaultStringEncoding; @@ -189,6 +191,10 @@ static void _FLXPostgresConnectionNoticeProcessor(void *arg, const char *message if (!_connection || PQstatus(_connection) == CONNECTION_BAD) { + if (_connectionError) [_connectionError release]; + + _connectionError = [[NSString alloc] initWithUTF8String:PQerrorMessage(_connection)]; + // TODO: implement reconnection attempt return NO; } @@ -303,7 +309,7 @@ static void _FLXPostgresConnectionNoticeProcessor(void *arg, const char *message BOOL connected = NO; while (!connected && !failed) - { + { switch (PQconnectPoll(_connection)) { case PGRES_POLLING_READING: @@ -455,6 +461,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; [super dealloc]; } -- cgit v1.2.3