From: helge Date: Mon, 21 Feb 2005 00:29:22 +0000 (+0000) Subject: fixed fetch issue X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31264fcb585b2a030a64263c29a0951d3c66dbcf;p=sope fixed fetch issue git-svn-id: http://svn.opengroupware.org/SOPE/trunk@580 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-gdl1/PostgreSQL/GNUmakefile b/sope-gdl1/PostgreSQL/GNUmakefile index 7796736c..719d026b 100644 --- a/sope-gdl1/PostgreSQL/GNUmakefile +++ b/sope-gdl1/PostgreSQL/GNUmakefile @@ -65,4 +65,4 @@ gdltest_OBJC_FILES = gdltest.m include $(GNUSTEP_MAKEFILES)/bundle.make #include $(GNUSTEP_MAKEFILES)/tool.make -include GNUmakefile.postamble --include fhs.make +include fhs.make diff --git a/sope-gdl1/PostgreSQL/GNUmakefile.preamble b/sope-gdl1/PostgreSQL/GNUmakefile.preamble index 3794dd8d..5a9c5729 100644 --- a/sope-gdl1/PostgreSQL/GNUmakefile.preamble +++ b/sope-gdl1/PostgreSQL/GNUmakefile.preamble @@ -22,8 +22,6 @@ # If not, write to the Free Software Foundation, # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# $Id: GNUmakefile.preamble 1 2004-08-20 10:38:46Z znek $ - PostgreSQL_BUNDLE_LIBS += -lpq PostgreSQL_BUNDLE_LIBS += -lGDLAccess -lEOControl diff --git a/sope-gdl1/SQLite3/ChangeLog b/sope-gdl1/SQLite3/ChangeLog index 636294bf..d8136958 100644 --- a/sope-gdl1/SQLite3/ChangeLog +++ b/sope-gdl1/SQLite3/ChangeLog @@ -1,3 +1,15 @@ +2005-02-21 Helge Hess + + * v4.5.11 + + * SQLiteChannel.m: fixed an issue with fetching empty tables + + * SQLiteChannel.m: properly generate the trailing ';' for SQL + expressions + + * SQLiteAdaptor.m: added special url=>condict handling (the whole URL + path is taken as the database name) + 2005-02-20 Helge Hess * SQLiteChannel.m: implemented -describeResults (v4.5.10) diff --git a/sope-gdl1/SQLite3/SQLiteAdaptor.m b/sope-gdl1/SQLite3/SQLiteAdaptor.m index 8dc8bcc2..fee187dd 100644 --- a/sope-gdl1/SQLite3/SQLiteAdaptor.m +++ b/sope-gdl1/SQLite3/SQLiteAdaptor.m @@ -1,7 +1,7 @@ /* SQLiteAdaptor.m - Copyright (C) 2003 SKYRIX Software AG + Copyright (C) 2003-2005 SKYRIX Software AG Author: Helge Hess (helge.hess@skyrix.com) @@ -22,7 +22,6 @@ If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id: SQLiteAdaptor.m,v 1.1 2004/06/14 14:27:44 helge Exp $ #import "common.h" #import "SQLiteAdaptor.h" @@ -33,6 +32,27 @@ @implementation SQLiteAdaptor +- (NSDictionary *)connectionDictionaryForNSURL:(NSURL *)_url { + /* + "Database URLs" + + We use the schema: + SQLite3://localhost/dbpath/foldername + */ + NSMutableDictionary *md; + NSString *p; + + if ((p = [_url path]) == nil) + return nil; + + p = [p stringByDeletingLastPathComponent]; + if ([p length] == 0) p = [_url path]; + + md = [NSMutableDictionary dictionaryWithCapacity:8]; + [md setObject:p forKey:@"databaseName"]; + return md; +} + - (id)initWithName:(NSString *)_name { if ((self = [super initWithName:_name])) { } diff --git a/sope-gdl1/SQLite3/SQLiteChannel.h b/sope-gdl1/SQLite3/SQLiteChannel.h index 29323b22..030956fc 100644 --- a/sope-gdl1/SQLite3/SQLiteChannel.h +++ b/sope-gdl1/SQLite3/SQLiteChannel.h @@ -39,6 +39,7 @@ // valid during -evaluateExpression: void *statement; BOOL hasPendingRow; + BOOL isDone; void *results; #if 0 diff --git a/sope-gdl1/SQLite3/SQLiteChannel.m b/sope-gdl1/SQLite3/SQLiteChannel.m index 3f056008..5f459647 100644 --- a/sope-gdl1/SQLite3/SQLiteChannel.m +++ b/sope-gdl1/SQLite3/SQLiteChannel.m @@ -114,6 +114,7 @@ static int openConnectionCount = 0; } - (BOOL)openChannel { + const unsigned char *cDBName; SQLiteAdaptor *adaptor; int rc; @@ -123,7 +124,7 @@ static int openConnectionCount = 0; } adaptor = (SQLiteAdaptor *)[adaptorContext adaptor]; - + if (![super openChannel]) return NO; @@ -133,9 +134,10 @@ static int openConnectionCount = 0; format:@"cannot open a additional connection !"]; return NO; } + + cDBName = [[adaptor databaseName] UTF8String]; - rc = sqlite3_open([[adaptor databaseName] UTF8String], - (void *)&(self->_connection)); + rc = sqlite3_open(cDBName, (void *)&(self->_connection)); if (rc != SQLITE_OK) { // could not login .. // Note: connection *is* set! (might be required to deallocate) @@ -161,8 +163,8 @@ static int openConnectionCount = 0; #endif if (isDebuggingEnabled) { - NSLog(@"SQLite channel 0x%08X opened (connection=0x%08X)", - (unsigned)self, self->_connection); + NSLog(@"SQLite channel 0x%08X opened (connection=0x%08X,%s)", + (unsigned)self, self->_connection, cDBName); } return YES; } @@ -199,27 +201,37 @@ static int openConnectionCount = 0; - (NSException *)_makeSQLiteStep { NSString *r; + const char *em; int rc; rc = sqlite3_step(self->statement); +#if 0 + NSLog(@"STEP: %i (row=%i, done=%i, mis=%i)", rc, + SQLITE_ROW, SQLITE_DONE, SQLITE_MISUSE); +#endif if (rc == SQLITE_ROW) { self->hasPendingRow = YES; + self->isDone = NO; return nil /* no error */; } if (rc == SQLITE_DONE) { self->hasPendingRow = NO; + self->isDone = YES; return nil /* no error */; } if (rc == SQLITE_ERROR) r = [NSString stringWithUTF8String:sqlite3_errmsg(self->_connection)]; else if (rc == SQLITE_MISUSE) - r = @"Somehow the SQLite method was called in an incorrect way."; + r = @"The SQLite step function was called in an incorrect way"; else if (rc == SQLITE_BUSY) r = @"The SQLite is busy."; else r = [NSString stringWithFormat:@"Unexpected SQLite error: %i", rc]; + + if ((em = sqlite3_errmsg(self->_connection)) != NULL) + r = [r stringByAppendingFormat:@": %s", em]; return [SQLiteException exceptionWithName:@"FetchFailed" reason:r userInfo:nil]; @@ -230,6 +242,8 @@ static int openConnectionCount = 0; sqlite3_finalize(self->statement); self->statement = NULL; } + self->isDone = NO; + self->hasPendingRow = NO; [super cancelFetch]; } @@ -380,14 +394,14 @@ static int openConnectionCount = 0; return nil; } - if (!self->hasPendingRow) { + if (!self->hasPendingRow && !self->isDone) { if ((error = [self _makeSQLiteStep]) != nil) { [self cancelFetch]; [error raise]; // raise error, TODO: make exception-less method return nil; } } - if (!self->hasPendingRow) { /* step was fine, but we are at the end */ + if (self->isDone) { /* step was fine, but we are at the end */ [self cancelFetch]; return nil; } @@ -476,7 +490,6 @@ static int openConnectionCount = 0; - (NSException *)evaluateExpressionX:(NSString *)_expression { NSMutableString *sql; NSException *error; - char *zErrMsg = NULL; BOOL result; const char *s; const char *tails = NULL; @@ -491,6 +504,7 @@ static int openConnectionCount = 0; } sql = [[_expression mutableCopy] autorelease]; + [sql appendString:@";"]; /* ask delegate */ @@ -533,17 +547,23 @@ static int openConnectionCount = 0; /* reset environment */ self->isFetchInProgress = NO; + self->isDone = NO; + self->hasPendingRow = NO; s = [sql UTF8String]; rc = sqlite3_prepare(self->_connection, s, strlen(s), (void *)&(self->statement), &tails); if (rc != SQLITE_OK) { + NSString *r; + [self cancelFetch]; // TODO: improve error + + r = [NSString stringWithFormat:@"could not parse SQL statement: %s", + sqlite3_errmsg(self->_connection)]; return [SQLiteException exceptionWithName:@"ExecutionFailed" - reason:@"could not parse SQL statement" - userInfo:nil]; + reason:r userInfo:nil]; } /* step to first row */ @@ -565,14 +585,6 @@ static int openConnectionCount = 0; } } - /* check whether there are pending errors */ - - if (zErrMsg != NULL) { - NSLog(@"WARNING(%s): %@ pending error message: '%s'", - __PRETTY_FUNCTION__, self, zErrMsg); - free(zErrMsg); - } - /* only on empty results? */ if (delegateRespondsTo.didEvaluateExpression) [delegate adaptorChannel:self didEvaluateExpression:sql]; diff --git a/sope-gdl1/SQLite3/Version b/sope-gdl1/SQLite3/Version index c7825e07..6f0aa782 100644 --- a/sope-gdl1/SQLite3/Version +++ b/sope-gdl1/SQLite3/Version @@ -1,3 +1,3 @@ # Version file -SUBMINOR_VERSION:=10 +SUBMINOR_VERSION:=11