From 57c65943c542a634532685cf28bb3c0d75c59c77 Mon Sep 17 00:00:00 2001 From: helge Date: Mon, 11 Apr 2005 18:46:37 +0000 Subject: [PATCH] more cleanups git-svn-id: http://svn.opengroupware.org/SOPE/trunk@722 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-gdl1/MySQL4/EOAttribute+SQLite.h | 1 - sope-gdl1/MySQL4/MySQL4Adaptor.h | 12 ++- sope-gdl1/MySQL4/MySQL4Channel.m | 52 +++++++++- sope-gdl1/MySQL4/MySQL4Context.m | 12 ++- sope-gdl1/MySQL4/NSString+SQLite.h | 8 +- sope-gdl1/MySQL4/NSString+SQLite.m | 134 +++++++++++++------------- 6 files changed, 139 insertions(+), 80 deletions(-) diff --git a/sope-gdl1/MySQL4/EOAttribute+SQLite.h b/sope-gdl1/MySQL4/EOAttribute+SQLite.h index ea08505d..30262b04 100644 --- a/sope-gdl1/MySQL4/EOAttribute+SQLite.h +++ b/sope-gdl1/MySQL4/EOAttribute+SQLite.h @@ -27,7 +27,6 @@ #define ___MySQL4_EOAttribute_H___ #import -#include @class NSString; diff --git a/sope-gdl1/MySQL4/MySQL4Adaptor.h b/sope-gdl1/MySQL4/MySQL4Adaptor.h index 764c11a0..3e64fc94 100644 --- a/sope-gdl1/MySQL4/MySQL4Adaptor.h +++ b/sope-gdl1/MySQL4/MySQL4Adaptor.h @@ -30,9 +30,12 @@ The MySQL4 adaptor. The connection dictionary of this adaptor understands these keys: + hostName + port + options + userName + password databaseName - - The adaptor is based on libsqlite. */ #import @@ -49,7 +52,12 @@ // connection management +- (NSString *)serverName; +- (NSString *)loginName; +- (NSString *)loginPassword; - (NSString *)databaseName; +- (NSString *)port; +- (NSString *)options; - (NSString *)newKeyExpression; // sequence for primary key generation diff --git a/sope-gdl1/MySQL4/MySQL4Channel.m b/sope-gdl1/MySQL4/MySQL4Channel.m index fdb1ea13..c4a7b340 100644 --- a/sope-gdl1/MySQL4/MySQL4Channel.m +++ b/sope-gdl1/MySQL4/MySQL4Channel.m @@ -137,6 +137,9 @@ 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 .. @@ -146,6 +149,7 @@ static int openConnectionCount = 0; sqlite3_close(self->_connection); return NO; } +#endif if (isDebuggingEnabled) NSLog(@"MySQL4 connection established 0x%08X", self->_connection); @@ -171,12 +175,20 @@ 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 #if 0 NSLog(@"---------- %s: %@ close channel count[%d]", __PRETTY_FUNCTION__, self, openConnectionCount); @@ -204,12 +216,19 @@ static int openConnectionCount = 0; const char *em; int rc; +#if 1 +# warning IMPLEMENT ME +#else rc = sqlite3_step(self->statement); +#endif #if 0 NSLog(@"STEP: %i (row=%i, done=%i, mis=%i)", rc, SQLITE_ROW, SQLITE_DONE, SQLITE_MISUSE); #endif +#if 1 +# warning IMPLEMENT ME +#else if (rc == SQLITE_ROW) { self->hasPendingRow = YES; self->isDone = NO; @@ -232,6 +251,7 @@ static int openConnectionCount = 0; if ((em = sqlite3_errmsg(self->_connection)) != NULL) r = [r stringByAppendingFormat:@": %s", em]; +#endif return [MySQL4Exception exceptionWithName:@"FetchFailed" reason:r userInfo:nil]; @@ -239,7 +259,11 @@ 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; @@ -275,7 +299,11 @@ static int openConnectionCount = 0; if (!self->hasPendingRow) /* no rows available */ return nil; +#if 1 +# warning IMPLEMENT ME +#else fieldCount = sqlite3_column_count(self->statement); +#endif /* old code below */ @@ -287,9 +315,13 @@ static int openConnectionCount = 0; NSString *columnName = nil; NSString *attrName = nil; +#if 1 +# warning IMPLEMENT ME +#else columnName = [NSString stringWithCString: sqlite3_column_name(self->statement, cnt)]; - attrName = [columnName _sqlite3ModelMakeInstanceVarName]; +#endif + attrName = [columnName _mySQL4ModelMakeInstanceVarName]; if ([[usedNames objectForKey:attrName] boolValue]) { int cnt2 = 0; @@ -317,6 +349,9 @@ static int openConnectionCount = 0; [attribute setName:attrName]; [attribute setColumnName:columnName]; +#if 1 +# warning IMPLEMENT ME +#else switch (sqlite3_column_type(self->statement, cnt)) { case SQLITE_INTEGER: [attribute setExternalType:@"INTEGER"]; @@ -348,7 +383,7 @@ static int openConnectionCount = 0; __PRETTY_FUNCTION__, cnt); break; } - +#endif [result addObject:attribute]; [attribute release]; } @@ -436,6 +471,9 @@ static int openConnectionCount = 0; continue; } +#if 1 +# warning IMPLEMENT ME +#else switch (sqlite3_column_type(self->statement, cnt)) { case SQLITE_INTEGER: value = [[valueClass alloc] @@ -475,7 +513,7 @@ static int openConnectionCount = 0; continue; } } - +#endif if (value != nil) { [row setObject:value forKey:attrName]; [value release]; @@ -551,6 +589,9 @@ static int openConnectionCount = 0; self->hasPendingRow = NO; s = [sql UTF8String]; +#if 1 +# warning IMPLEMENT ME +#else rc = sqlite3_prepare(self->_connection, s, strlen(s), (void *)&(self->statement), &tails); @@ -565,6 +606,7 @@ static int openConnectionCount = 0; return [MySQL4Exception exceptionWithName:@"ExecutionFailed" reason:r userInfo:nil]; } +#endif /* step to first row */ @@ -580,7 +622,11 @@ 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; } } diff --git a/sope-gdl1/MySQL4/MySQL4Context.m b/sope-gdl1/MySQL4/MySQL4Context.m index 73a41a71..eaf58fc3 100644 --- a/sope-gdl1/MySQL4/MySQL4Context.m +++ b/sope-gdl1/MySQL4/MySQL4Context.m @@ -27,6 +27,12 @@ #include "MySQL4Channel.h" #include "common.h" +/* + Note: MySQL doesn't know 'BEGIN TRANSACTION'. It prefers 'START TRANSACTION' + which was added in 4.0.11, which is why we use just 'BEGIN' (available + since 3.23.17) +*/ + @implementation MySQL4Context - (void)channelDidInit:_channel { @@ -42,7 +48,7 @@ result = [[[channels lastObject] nonretainedObjectValue] - evaluateExpression:@"BEGIN TRANSACTION"]; + evaluateExpression:@"BEGIN"]; return result; } @@ -52,7 +58,7 @@ result = [[[channels lastObject] nonretainedObjectValue] - evaluateExpression:@"COMMIT TRANSACTION"]; + evaluateExpression:@"COMMIT"]; return result; } @@ -62,7 +68,7 @@ result = [[[channels lastObject] nonretainedObjectValue] - evaluateExpression:@"ROLLBACK TRANSACTION"]; + evaluateExpression:@"ROLLBACK"]; return result; } diff --git a/sope-gdl1/MySQL4/NSString+SQLite.h b/sope-gdl1/MySQL4/NSString+SQLite.h index 10d6e49e..e0779274 100644 --- a/sope-gdl1/MySQL4/NSString+SQLite.h +++ b/sope-gdl1/MySQL4/NSString+SQLite.h @@ -30,10 +30,10 @@ @interface NSString(MySQL4MiscStrings) -- (NSString *)_sqlite3ModelMakeInstanceVarName; -- (NSString *)_sqlite3ModelMakeClassName; -- (NSString *)_sqlite3StringWithCapitalizedFirstChar; -- (NSString *)_sqlite3StripEndSpaces; +- (NSString *)_mySQL4ModelMakeInstanceVarName; +- (NSString *)_mySQL4ModelMakeClassName; +- (NSString *)_mySQL4StringWithCapitalizedFirstChar; +- (NSString *)_mySQL4StripEndSpaces; @end diff --git a/sope-gdl1/MySQL4/NSString+SQLite.m b/sope-gdl1/MySQL4/NSString+SQLite.m index 584d9a38..dbaab708 100644 --- a/sope-gdl1/MySQL4/NSString+SQLite.m +++ b/sope-gdl1/MySQL4/NSString+SQLite.m @@ -22,7 +22,6 @@ If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id: NSString+MySQL4.m,v 1.1 2004/06/14 14:27:44 helge Exp $ #if LIB_FOUNDATION_BOEHM_GC # include @@ -34,55 +33,54 @@ @implementation NSString(MySQL4MiscStrings) -- (NSString *)_sqlite3ModelMakeInstanceVarName { +- (NSString *)_mySQL4ModelMakeInstanceVarName { + unsigned clen = 0; + char *s = NULL; + int cnt, cnt2; + if ([self length] == 0) return @""; - else { - unsigned clen = 0; - char *s = NULL; - int cnt, cnt2; - clen = [self cStringLength]; - s = malloc(clen + 10); + clen = [self cStringLength]; + s = malloc(clen + 10); - [self getCString:s maxLength:clen]; + [self getCString:s maxLength:clen]; - for (cnt = cnt2 = 0; cnt < clen; cnt++, cnt2++) { - if ((s[cnt] == '_') && (s[cnt + 1] != '\0')) { - s[cnt2] = toupper(s[cnt + 1]); - cnt++; - } - else if ((s[cnt] == '2') && (s[cnt + 1] != '\0')) { - s[cnt2] = s[cnt]; - cnt++; - cnt2++; - s[cnt2] = toupper(s[cnt]); - } - else - s[cnt2] = tolower(s[cnt]); + for (cnt = cnt2 = 0; cnt < clen; cnt++, cnt2++) { + if ((s[cnt] == '_') && (s[cnt + 1] != '\0')) { + s[cnt2] = toupper(s[cnt + 1]); + cnt++; } - s[cnt2] = '\0'; - - return [[[NSString alloc] - initWithCStringNoCopy:s length:strlen(s) freeWhenDone:YES] - autorelease]; + else if ((s[cnt] == '2') && (s[cnt + 1] != '\0')) { + s[cnt2] = s[cnt]; + cnt++; + cnt2++; + s[cnt2] = toupper(s[cnt]); + } + else + s[cnt2] = tolower(s[cnt]); } + s[cnt2] = '\0'; + + return [[[NSString alloc] + initWithCStringNoCopy:s length:strlen(s) freeWhenDone:YES] + autorelease]; } -- (NSString *)_sqlite3ModelMakeClassName { +- (NSString *)_mySQL4ModelMakeClassName { + unsigned clen = 0; + char *s = NULL; + int cnt, cnt2; + if ([self length] == 0) return @""; - else { - unsigned clen = 0; - char *s = NULL; - int cnt, cnt2; - clen = [self cStringLength]; - s = malloc(clen + 10); + clen = [self cStringLength]; + s = malloc(clen + 10); - [self getCString:s maxLength:clen]; + [self getCString:s maxLength:clen]; - for (cnt = cnt2 = 0; cnt < clen; cnt++, cnt2++) { + for (cnt = cnt2 = 0; cnt < clen; cnt++, cnt2++) { if ((s[cnt] == '_') && (s[cnt + 1] != '\0')) { s[cnt2] = toupper(s[cnt + 1]); cnt++; @@ -95,46 +93,49 @@ } else s[cnt2] = tolower(s[cnt]); - } - s[cnt2] = '\0'; + } + s[cnt2] = '\0'; - s[0] = toupper(s[0]); + s[0] = toupper(s[0]); - return [[[NSString alloc] + return [[[NSString alloc] initWithCStringNoCopy:s length:strlen(s) freeWhenDone:YES] autorelease]; - } } -- (NSString *)_sqlite3StringWithCapitalizedFirstChar { - NSCharacterSet *upperSet = [NSCharacterSet uppercaseLetterCharacterSet]; +- (NSString *)_mySQL4StringWithCapitalizedFirstChar { + NSCharacterSet *upperSet; + NSMutableString *str; if ([self length] == 0) return @""; - else if ([upperSet characterIsMember:[self characterAtIndex:0]]) + + upperSet = [NSCharacterSet uppercaseLetterCharacterSet]; + if ([upperSet characterIsMember:[self characterAtIndex:0]]) return [[self copy] autorelease]; - else { - NSMutableString *str = [NSMutableString stringWithCapacity:[self length]]; - - [str appendString:[[self substringToIndex:1] uppercaseString]]; - [str appendString:[self substringFromIndex:1]]; - - return [[str copy] autorelease]; - } + + str = [NSMutableString stringWithCapacity:[self length]]; + [str appendString:[[self substringToIndex:1] uppercaseString]]; + [str appendString:[self substringFromIndex:1]]; + return [[str copy] autorelease]; } -- (NSString *)_sqlite3StripEndSpaces { - if ([self length] > 0) { - NSCharacterSet *spaceSet = [NSCharacterSet whitespaceCharacterSet]; - NSMutableString *str = [NSMutableString stringWithCapacity:[self length]]; - IMP charAtIndex; - NSRange range; - - charAtIndex = [self methodForSelector:@selector(characterAtIndex:)]; - range.length = 0; +- (NSString *)_mySQL4StripEndSpaces { + NSCharacterSet *spaceSet; + NSMutableString *str; + IMP charAtIndex; + NSRange range; + + if ([self length] == 0) + return [[self copy] autorelease]; + + spaceSet = [NSCharacterSet whitespaceCharacterSet]; + str = [NSMutableString stringWithCapacity:[self length]]; + charAtIndex = [self methodForSelector:@selector(characterAtIndex:)]; + range.length = 0; - for (range.location = ([self length] - 1); + for (range.location = ([self length] - 1); range.location >= 0; range.location++, range.length++) { unichar c; @@ -143,15 +144,14 @@ range.location); if (![spaceSet characterIsMember:c]) break; - } + } - if (range.length > 0) { + if (range.length > 0) { [str appendString:self]; [str deleteCharactersInRange:range]; - return AUTORELEASE([str copy]); - } + return [[str copy] autorelease]; } - return AUTORELEASE([self copy]); + return [[self copy] autorelease]; } @end -- 2.39.5