From: helge Date: Tue, 12 Apr 2005 13:51:38 +0000 (+0000) Subject: added query call X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0fc7cb9c0dae5397516b14599665106f4d29181;p=sope added query call git-svn-id: http://svn.opengroupware.org/SOPE/trunk@729 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-gdl1/MySQL4/ChangeLog b/sope-gdl1/MySQL4/ChangeLog index a85905be..0728516d 100644 --- a/sope-gdl1/MySQL4/ChangeLog +++ b/sope-gdl1/MySQL4/ChangeLog @@ -1,3 +1,7 @@ +2005-04-12 Helge Hess + + * MySQL4Channel.m: implemented query (v4.5.2) + 2005-04-11 Helge Hess * started MySQL4 adaptor based on SQLite one (v4.5.1) diff --git a/sope-gdl1/MySQL4/MySQL4Channel.h b/sope-gdl1/MySQL4/MySQL4Channel.h index 5ef914e1..93b8d0eb 100644 --- a/sope-gdl1/MySQL4/MySQL4Channel.h +++ b/sope-gdl1/MySQL4/MySQL4Channel.h @@ -27,7 +27,6 @@ #define ___MySQL4_Channel_H___ #import -#include @class NSArray, NSString, NSMutableDictionary; diff --git a/sope-gdl1/MySQL4/MySQL4Channel.m b/sope-gdl1/MySQL4/MySQL4Channel.m index a61889ee..96fd9476 100644 --- a/sope-gdl1/MySQL4/MySQL4Channel.m +++ b/sope-gdl1/MySQL4/MySQL4Channel.m @@ -272,6 +272,11 @@ static int openConnectionCount = 0; } - (void)cancelFetch { + if (self->results != NULL) { + mysql_free_result(self->results); + self->results = NULL; + } + self->isDone = NO; self->hasPendingRow = NO; [super cancelFetch]; @@ -598,43 +603,36 @@ static int openConnectionCount = 0; self->isDone = NO; self->hasPendingRow = NO; - s = [sql UTF8String]; -#if 1 -# warning IMPLEMENT ME -#else - rc = sqlite3_prepare(self->_connection, s, strlen(s), - (void *)&(self->statement), &tails); + /* start query */ - if (rc != SQLITE_OK) { - NSString *r; + s = [sql UTF8String]; + if ((rc = mysql_real_query(self->_connection, s, strlen(s))) != 0) { + // TODO: might need to close channel on connect exceptions + const char *error; + + error = mysql_error(self->_connection); - [self cancelFetch]; - // TODO: improve error - - r = [NSString stringWithFormat:@"could not parse SQL statement: %s", - sqlite3_errmsg(self->_connection)]; return [MySQL4Exception exceptionWithName:@"ExecutionFailed" - reason:r userInfo:nil]; + reason:[NSString stringWithUTF8String:error] + userInfo:nil]; } -#endif - /* step to first row */ + /* fetch */ - if ([sql hasPrefix:@"SELECT"] || [sql hasPrefix:@"select"]) { + if ((self->results = mysql_use_result(self->_connection)) != NULL) { self->isFetchInProgress = YES; } else { - if ((error = [self _makeMySQL4Step]) != nil) { - [self cancelFetch]; - return error; - } - - self->isFetchInProgress = self->hasPendingRow; - if (!self->isFetchInProgress) { + /* error _OR_ statement without result-set */ + const char *error; + + if ((error = mysql_error(self->_connection)) != NULL) { + return [MySQL4Exception exceptionWithName:@"FetchFailed" + reason:[NSString stringWithUTF8String:error] + userInfo:nil]; } } - /* only on empty results? */ if (delegateRespondsTo.didEvaluateExpression) [delegate adaptorChannel:self didEvaluateExpression:sql]; @@ -672,9 +670,7 @@ static int openConnectionCount = 0; return ms; } -@end /* MySQL4Channel */ - -@implementation MySQL4Channel(PrimaryKeyGeneration) +/* PrimaryKeyGeneration */ - (NSDictionary *)primaryKeyForNewRowWithEntity:(EOEntity *)_entity { NSArray *pkeys; @@ -718,7 +714,7 @@ static int openConnectionCount = 0; return pkey; } -@end /* MySQL4Channel(PrimaryKeyGeneration) */ +@end /* MySQL4Channel */ void __link_MySQL4Channel() { // used to force linking of object file diff --git a/sope-gdl1/MySQL4/README b/sope-gdl1/MySQL4/README index 6babe403..a7f99698 100644 --- a/sope-gdl1/MySQL4/README +++ b/sope-gdl1/MySQL4/README @@ -36,3 +36,11 @@ mysql --password=abc > create database Test; > use Test; > CREATE TABLE my_table ( pkey INT PRIMARY KEY ); + + +Notes +===== + +mysql_store_result - does not block the server, full result in memory +vs +mysql_use_result - does block the server, one row in memory diff --git a/sope-gdl1/MySQL4/Version b/sope-gdl1/MySQL4/Version index 4010e5dd..648edbe2 100644 --- a/sope-gdl1/MySQL4/Version +++ b/sope-gdl1/MySQL4/Version @@ -1,3 +1,3 @@ # Version file -SUBMINOR_VERSION:=1 +SUBMINOR_VERSION:=2