Update of /cvsroot/pgsqlformac/pgCocoaDB In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11899 Modified Files: ChangeLog Connection.h Connection.m ExplorerModel.h ExplorerModel.m ExplorerNode.h ExplorerNode.m Schema.h Schema.m Log Message: Fix for PGconn not being thread safe. Migrate to new PQconnectdb API. Index: ChangeLog =================================================================== RCS file: /cvsroot/pgsqlformac/pgCocoaDB/ChangeLog,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** ChangeLog 30 Aug 2006 21:26:54 -0000 1.19 --- ChangeLog 1 Sep 2006 00:53:35 -0000 1.20 *************** *** 1,2 **** --- 1,8 ---- + 2006-08-30 16:26 ntiffin + + * ChangeLog, ExplorerModel.m, Schema.h, Schema.m, + UnitTest/pgCocoaDBSchemaTest.m: Fix constraints, columns, + triggers. + 2006-08-30 10:48 ntiffin Index: Schema.m =================================================================== RCS file: /cvsroot/pgsqlformac/pgCocoaDB/Schema.m,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Schema.m 30 Aug 2006 21:26:54 -0000 1.21 --- Schema.m 1 Sep 2006 00:53:35 -0000 1.22 *************** *** 16,20 **** @implementation Schema ! - initWithConnection:(Connection *) theConnection { NSString *sql; --- 16,20 ---- @implementation Schema ! - initWithConnectionString:(NSString *) theConnectionString { NSString *sql; *************** *** 23,29 **** [super init]; ! [connection release]; ! connection = theConnection; ! [connection retain]; publicSchemaName = [[NSString alloc] initWithString: @"public"]; pgCatalogSchemaName = [[NSString alloc] initWithString: @"pg_catalog"]; --- 23,30 ---- [super init]; ! ! connection = [[Connection alloc] init]; ! [connection connectUsingString:theConnectionString]; ! publicSchemaName = [[NSString alloc] initWithString: @"public"]; pgCatalogSchemaName = [[NSString alloc] initWithString: @"pg_catalog"]; *************** *** 65,68 **** --- 66,73 ---- return pgVersionFound; } + - (Connection *)connection; + { + return connection; + } Index: Schema.h =================================================================== RCS file: /cvsroot/pgsqlformac/pgCocoaDB/Schema.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Schema.h 30 Aug 2006 21:26:54 -0000 1.13 --- Schema.h 1 Sep 2006 00:53:35 -0000 1.14 *************** *** 15,19 **** @interface Schema : NSObject { ! Connection *connection; NSString *publicSchemaName; // is "public" NSString *pgCatalogSchemaName; // is "pg_catalog" --- 15,19 ---- @interface Schema : NSObject { ! Connection * connection; NSString *publicSchemaName; // is "public" NSString *pgCatalogSchemaName; // is "pg_catalog" *************** *** 22,26 **** } ! - initWithConnection:(Connection *) theConnection; - (NSString *)publicSchemaName; --- 22,26 ---- } ! - initWithConnectionString:(NSString *) theConnection; - (NSString *)publicSchemaName; *************** *** 28,31 **** --- 28,32 ---- - (NSString *)informationSchemaName; - (NSString *)pgVersionFound; + - (Connection *)connection; // generate SQL Index: Connection.m =================================================================== RCS file: /cvsroot/pgsqlformac/pgCocoaDB/Connection.m,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Connection.m 30 Aug 2006 15:48:49 -0000 1.15 --- Connection.m 1 Sep 2006 00:53:35 -0000 1.16 *************** *** 36,39 **** --- 36,45 ---- tty = nil; dbName = [[NSString alloc] initWithString:@"template1"]; + userName = nil; + password = nil; + sslMode = nil; + service = nil; + krbsrvName = nil; + connectionString = nil; errorDescription = nil; *************** *** 55,58 **** --- 61,68 ---- [userName release]; [password release]; + [sslMode release]; + [service release]; + [krbsrvName release]; + [connectionString release]; [dbs release]; [errorDescription release]; *************** *** 62,73 **** } - (BOOL)connect ! { [self disconnect]; ! ! // connect to the server (attempt) // TODO should use PQconnectdb() ! pgconn = (PGconn *)PQsetdbLogin([host cString], [port cString], ! [options cString], NULL, ! [dbName cString], [userName cString], [password cString]); if (PQoptions(pgconn)) { --- 72,87 ---- } + - (BOOL)connect ! { [self disconnect]; ! ! if (connectionString == nil) ! { ! connectionString = [self makeConnectionString]; ! [connectionString retain]; ! } ! NSAssert( (connectionString != nil), @"Attempted to connect to PostgreSQL with empty connectionString."); ! pgconn = (PGconn *)PQconnectdb([connectionString cString]); if (PQoptions(pgconn)) { *************** *** 81,85 **** [self setErrorDescription:[NSString stringWithFormat:@"%s", PQerrorMessage(pgconn)]]; [self appendSQLLog:[NSMutableString stringWithFormat:@"Connection to database %@ Failed.\n", dbName]]; ! PQfinish(pgconn); pgconn = nil; --- 95,99 ---- [self setErrorDescription:[NSString stringWithFormat:@"%s", PQerrorMessage(pgconn)]]; [self appendSQLLog:[NSMutableString stringWithFormat:@"Connection to database %@ Failed.\n", dbName]]; ! PQfinish(pgconn); pgconn = nil; *************** *** 100,104 **** // set up notification PQsetNoticeProcessor(pgconn, handle_pq_notice, self); ! [self setSQLLog:[NSMutableString stringWithFormat:@"Connected to database %@ on %@.\n", dbName, [[NSCalendarDate calendarDate] description]]]; connected = YES; --- 114,118 ---- // set up notification PQsetNoticeProcessor(pgconn, handle_pq_notice, self); ! [self setSQLLog:[NSMutableString stringWithFormat:@"Connected to database %@ on %@.\n", dbName, [[NSCalendarDate calendarDate] description]]]; connected = YES; *************** *** 106,109 **** --- 120,129 ---- } + - (BOOL)connectUsingString:(NSString *)aConnectionString + { + [self setConnectionString:aConnectionString]; + return [self connect]; + } + - (BOOL)connectToHost:(NSString *)toHost onPort:(NSString *)onPort *************** *** 118,121 **** --- 138,142 ---- [self setDbName:userDB]; + [self setConnectionString:nil]; return [self connect]; } *************** *** 159,162 **** --- 180,184 ---- host = [newHost copy]; } + [self setConnectionString:nil]; } *************** *** 173,176 **** --- 195,199 ---- port = [newPort copy]; } + [self setConnectionString:nil]; } *************** *** 187,190 **** --- 210,214 ---- options = [newOptions copy]; } + [self setConnectionString:nil]; } *************** *** 201,204 **** --- 225,229 ---- tty = [newTty copy]; } + [self setConnectionString:nil]; } *************** *** 215,218 **** --- 240,244 ---- dbName = [newDbName copy]; } + [self setConnectionString:nil]; } *************** *** 229,232 **** --- 255,259 ---- userName = [value copy]; } + [self setConnectionString:nil]; } *************** *** 243,248 **** --- 270,333 ---- password = [value copy]; } + [self setConnectionString:nil]; + } + + - (NSString *)connectionString + { + return connectionString; + } + + - (void)setConnectionString:(NSString *)value + { + if (connectionString != value) + { + [connectionString release]; + connectionString = [value copy]; + } + } + + - (NSString *)sslMode + { + return sslMode; + } + + - (void)setSslMode:(NSString *)value + { + if (sslMode != value) + { + [sslMode release]; + sslMode = [value copy]; + } + } + + - (NSString *)service; + { + return service; + } + + - (void)setService:(NSString *)value; + { + if (service != value) + { + [service release]; + service = [value copy]; + } + } + + - (NSString *)krbsrvName; + { + return krbsrvName; + } + + - (void)setKrbsrvName:(NSString *)value; + { + if (krbsrvName != value) + { + [krbsrvName release]; + krbsrvName = [value copy]; + } } + - (Databases *)databases { *************** *** 533,535 **** --- 618,669 ---- } + -(NSMutableString *)makeConnectionString + { + NSMutableString *connStr = [[[NSMutableString alloc] init] autorelease]; + + if (connectionString) + { + [connStr appendString:connectionString]; + return connStr; + } + if (host) + { + [connStr appendFormat:@" host='%@' ", host]; + } + if (port) + { + [connStr appendFormat:@" port='%@' ", port]; + } + if (options) + { + [connStr appendFormat:@" options='%@' ", options]; + } + if (dbName) + { + [connStr appendFormat:@" dbname='%@' ", dbName]; + } + if (userName) + { + [connStr appendFormat:@" user='%@' ", userName]; + } + if (password) + { + [connStr appendFormat:@" password='%@' ", password]; + } + if (sslMode) + { + [connStr appendFormat:@" sslmode='%@' ", sslMode]; + } + if (service) + { + [connStr appendFormat:@" service='%@' ", service]; + } + if (krbsrvName) + { + [connStr appendFormat:@" krbsrvname='%@' ", krbsrvName]; + } + return connStr; + } + + @end Index: Connection.h =================================================================== RCS file: /cvsroot/pgsqlformac/pgCocoaDB/Connection.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Connection.h 30 Aug 2006 15:48:49 -0000 1.8 --- Connection.h 1 Sep 2006 00:53:35 -0000 1.9 *************** *** 20,27 **** NSString *port; NSString *options; ! NSString *tty; NSString *dbName; NSString *userName; NSString *password; Databases *dbs; --- 20,32 ---- NSString *port; NSString *options; ! NSString *tty; // ignored now NSString *dbName; NSString *userName; NSString *password; + NSString *sslMode; // allow, prefer, require + NSString *service; // service name + NSString *krbsrvName; + + NSMutableString *connectionString; Databases *dbs; *************** *** 34,37 **** --- 39,43 ---- - (BOOL)connect; + - (BOOL)connectUsingString:(NSString *)aConnectionString; - (BOOL)connectToHost:(NSString *)toHost onPort:(NSString *)onPort *************** *** 64,70 **** --- 70,88 ---- - (void)setPassword:(NSString *)value; + - (NSString *)sslMode; + - (void)setSslMode:(NSString *)value; + + - (NSString *)service; + - (void)setService:(NSString *)value; + + - (NSString *)krbsrvName; + - (void)setKrbsrvName:(NSString *)value; + - (NSString *)errorDescription; - (void)setErrorDescription:(NSString *)ed; + - (NSString *)connectionString; + - (void)setConnectionString:(NSString *)ed; + - (NSMutableString *)sqlLog; - (void)setSQLLog:(NSString *)value; *************** *** 83,86 **** --- 101,105 ---- - (int)cancelQuery; + - (NSMutableString *)makeConnectionString; @end Index: ExplorerNode.m =================================================================== RCS file: /cvsroot/pgsqlformac/pgCocoaDB/ExplorerNode.m,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ExplorerNode.m 12 Aug 2006 16:38:16 -0000 1.6 --- ExplorerNode.m 1 Sep 2006 00:53:35 -0000 1.7 *************** *** 81,84 **** --- 81,88 ---- } + -(NSColor *) nameColor + { + return nameColor; + } -(UInt32)oid; *************** *** 95,99 **** -(void)setNameColor:(NSColor *)s { ! ; //TODO } --- 99,105 ---- -(void)setNameColor:(NSColor *)s { ! [s retain]; ! [nameColor release]; ! nameColor = s; } Index: ExplorerModel.h =================================================================== RCS file: /cvsroot/pgsqlformac/pgCocoaDB/ExplorerModel.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ExplorerModel.h 30 Aug 2006 15:48:49 -0000 1.5 --- ExplorerModel.h 1 Sep 2006 00:53:35 -0000 1.6 *************** *** 18,22 **** { ExplorerNode * rootNode; ! Connection * connection; Schema * schema; bool showInformationSchema; --- 18,23 ---- { ExplorerNode * rootNode; ! NSString * connectionString; ! //Connection *connection; Schema * schema; bool showInformationSchema; *************** *** 30,34 **** } ! - (id)initWithConnection:(Connection *) aConnection; - (void)buildSchema:(id)anObject; --- 31,35 ---- } ! - (id)initWithConnectionString:(NSString *)theConnection; - (void)buildSchema:(id)anObject; Index: ExplorerModel.m =================================================================== RCS file: /cvsroot/pgsqlformac/pgCocoaDB/ExplorerModel.m,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ExplorerModel.m 30 Aug 2006 21:26:54 -0000 1.14 --- ExplorerModel.m 1 Sep 2006 00:53:35 -0000 1.15 *************** *** 309,320 **** ! - (id)initWithConnection:(Connection *) theConnection { [super init]; ExplorerNode * newNode; ! // TODO clone this connection so we can multi-thread ! connection = theConnection; ! schema = [[Schema alloc] initWithConnection:connection]; explorerThreadStatusLock = [[NSLock alloc] init]; --- 309,318 ---- ! - (id)initWithConnectionString:(NSString *) theConnection { [super init]; ExplorerNode * newNode; ! connectionString = theConnection; explorerThreadStatusLock = [[NSLock alloc] init]; *************** *** 344,348 **** } ! - (void)buildSchema:(id)anOutlineView { --- 342,346 ---- } ! // May be run in a separate thread. - (void)buildSchema:(id)anOutlineView { *************** *** 352,357 **** RecordSet * results; ExplorerNode * realRootNode; ! ! if ((connection == nil) || (schema == nil)) { NSLog(@"Attempted to build Schema without proper init."); --- 350,357 ---- RecordSet * results; ExplorerNode * realRootNode; ! ! schema = [[Schema alloc] initWithConnectionString:connectionString]; ! ! if (schema == nil) { NSLog(@"Attempted to build Schema without proper init."); *************** *** 364,368 **** // set database level realRootNode = [[ExplorerNode alloc] init]; ! [realRootNode setName: [connection currentDatabase]]; [realRootNode setBaseTable: @""]; [realRootNode setExplorerType:@"Database"]; --- 364,368 ---- // set database level realRootNode = [[ExplorerNode alloc] init]; ! [realRootNode setName: [[schema connection] currentDatabase]]; [realRootNode setBaseTable: @""]; [realRootNode setExplorerType:@"Database"]; *************** *** 460,463 **** --- 460,465 ---- [self setExplorerThreadStatus:3]; [(NSOutlineView *)anOutlineView reloadData]; + [schema release]; + schema = nil; [pool release]; return; Index: ExplorerNode.h =================================================================== RCS file: /cvsroot/pgsqlformac/pgCocoaDB/ExplorerNode.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ExplorerNode.h 30 Aug 2006 15:48:49 -0000 1.4 --- ExplorerNode.h 1 Sep 2006 00:53:35 -0000 1.5 *************** *** 23,26 **** --- 23,27 ---- // for display as a tool tip NSString *baseSchema; + NSColor *nameColor; } |