From 9a5449256ba205e8a8a02415450fe5503647523c Mon Sep 17 00:00:00 2001 From: helge Date: Mon, 11 Apr 2005 20:03:45 +0000 Subject: [PATCH] connect work git-svn-id: http://svn.opengroupware.org/SOPE/trunk@725 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-gdl1/MySQL4/MySQL4Channel.h | 1 - sope-gdl1/MySQL4/MySQL4Channel.m | 83 +++++++++++++++----------------- 2 files changed, 39 insertions(+), 45 deletions(-) diff --git a/sope-gdl1/MySQL4/MySQL4Channel.h b/sope-gdl1/MySQL4/MySQL4Channel.h index b4793e63..5ef914e1 100644 --- a/sope-gdl1/MySQL4/MySQL4Channel.h +++ b/sope-gdl1/MySQL4/MySQL4Channel.h @@ -37,7 +37,6 @@ void *_connection; // valid during -evaluateExpression: - void *statement; BOOL hasPendingRow; BOOL isDone; diff --git a/sope-gdl1/MySQL4/MySQL4Channel.m b/sope-gdl1/MySQL4/MySQL4Channel.m index c3d9df0b..db1d80e8 100644 --- a/sope-gdl1/MySQL4/MySQL4Channel.m +++ b/sope-gdl1/MySQL4/MySQL4Channel.m @@ -33,6 +33,7 @@ #include "MySQL4Values.h" #include "EOAttribute+MySQL4.h" #include "common.h" +#include #ifndef MIN # define MIN(x, y) ((x > y) ? y : x) @@ -109,16 +110,17 @@ static int openConnectionCount = 0; [[NSUserDefaults standardUserDefaults] integerForKey:@"MySQL4MaxOpenConnectionCount"]; if (MaxOpenConnectionCount == 0) - MaxOpenConnectionCount = 15; + MaxOpenConnectionCount = 150; return MaxOpenConnectionCount; } - (BOOL)openChannel { const unsigned char *cDBName; MySQL4Adaptor *adaptor; - int rc; + NSString *host, *socket; + void *rc; - if (self->_connection) { + if (self->_connection != NULL) { NSLog(@"%s: Connection already open !!!", __PRETTY_FUNCTION__); return NO; } @@ -127,7 +129,7 @@ static int openConnectionCount = 0; if (![super openChannel]) return NO; - + if (openConnectionCount > [self maxOpenConnectionCount]) { [MySQL4CouldNotOpenChannelException raise:@"NoMoreConnections" @@ -137,19 +139,36 @@ static int openConnectionCount = 0; cDBName = [[adaptor databaseName] UTF8String]; -#if 1 -# warning IMPLEMENT ME -#else - rc = sqlite3_open(cDBName, (void *)&(self->_connection)); - if (rc != SQLITE_OK) { - // could not login .. - // Note: connection *is* set! (might be required to deallocate) + if ((self->_connection = mysql_init(NULL)) == NULL) { + NSLog(@"ERROR(%s): could not allocate MySQL4 connection!"); + return NO; + } + + // TODO: could change options using mysql_options() + + host = [adaptor serverName]; + if ([host hasPrefix:@"/"]) { /* treat hostname as Unix socket path */ + socket = host; + host = nil; + } + else + socket = nil; + + rc = mysql_real_connect(self->_connection, + [host UTF8String], + [[adaptor loginName] UTF8String], + [[adaptor loginPassword] UTF8String], + cDBName, + [[adaptor port] intValue], + [socket cString], + 0); + if (rc == NULL) { NSLog(@"WARNING: could not open MySQL4 connection to database '%@': %s", - [adaptor databaseName], sqlite3_errmsg(self->_connection)); - sqlite3_close(self->_connection); + [adaptor databaseName], mysql_error(self->_connection)); + mysql_close(self->_connection); + self->_connection = NULL; return NO; } -#endif if (isDebuggingEnabled) NSLog(@"MySQL4 connection established 0x%08X", self->_connection); @@ -174,21 +193,8 @@ static int openConnectionCount = 0; } - (void)primaryCloseChannel { - if (self->statement != NULL) { -#if 1 -# warning IMPLEMENT ME -#else - sqlite3_finalize(self->statement); -#endif - self->statement = NULL; - } - if (self->_connection != NULL) { -#if 1 -# warning IMPLEMENT ME -#else - sqlite3_close(self->_connection); -#endif + mysql_close(self->_connection); #if 0 NSLog(@"---------- %s: %@ close channel count[%d]", __PRETTY_FUNCTION__, self, openConnectionCount); @@ -258,14 +264,6 @@ static int openConnectionCount = 0; } - (void)cancelFetch { - if (self->statement != NULL) { -#if 1 -# warning IMPLEMENT ME -#else - sqlite3_finalize(self->statement); -#endif - self->statement = NULL; - } self->isDone = NO; self->hasPendingRow = NO; [super cancelFetch]; @@ -422,12 +420,14 @@ static int openConnectionCount = 0; NSException *error; unsigned attrCount = [_attributes count]; unsigned cnt; - + +#if 0 if (self->statement == NULL) { NSLog(@"ERROR: no fetch in progress?"); [self cancelFetch]; return nil; } +#endif if (!self->hasPendingRow && !self->isDone) { if ((error = [self _makeMySQL4Step]) != nil) { @@ -567,12 +567,14 @@ static int openConnectionCount = 0; reason:@"MySQL4 connection is not open" userInfo:nil]; } +#if 0 if (self->statement != NULL) { return [MySQL4Exception exceptionWithName:@"CommandInProgressException" reason:@"an evaluation is in progress" userInfo:nil]; return NO; } +#endif if ([self isFetchInProgress]) { NSLog(@"WARNING: a fetch is still in progress: %@", self); @@ -612,7 +614,6 @@ static int openConnectionCount = 0; if ([sql hasPrefix:@"SELECT"] || [sql hasPrefix:@"select"]) { self->isFetchInProgress = YES; - NSAssert(self->statement, @"missing statement"); } else { if ((error = [self _makeMySQL4Step]) != nil) { @@ -622,12 +623,6 @@ static int openConnectionCount = 0; self->isFetchInProgress = self->hasPendingRow; if (!self->isFetchInProgress) { -#if 1 -# warning IMPLEMENT ME -#else - sqlite3_finalize(self->statement); -#endif - self->statement = NULL; } } -- 2.39.5