From: helge Date: Tue, 19 Apr 2005 15:31:42 +0000 (+0000) Subject: fixed to MySQL API X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cbdd575735ac19a28091b358dda9e3e8d5cc12ca;p=sope fixed to MySQL API git-svn-id: http://svn.opengroupware.org/SOPE/trunk@739 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-gdl1/GDLAccess/EOAttribute.m b/sope-gdl1/GDLAccess/EOAttribute.m index 8e2e1ac2..bcfab5e0 100644 --- a/sope-gdl1/GDLAccess/EOAttribute.m +++ b/sope-gdl1/GDLAccess/EOAttribute.m @@ -23,7 +23,6 @@ If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id: EOAttribute.m 1 2004-08-20 10:38:46Z znek $ #import "common.h" #import "EOAttribute.h" diff --git a/sope-gdl1/MySQL4/ChangeLog b/sope-gdl1/MySQL4/ChangeLog index 81ae9e47..b2e772ed 100644 --- a/sope-gdl1/MySQL4/ChangeLog +++ b/sope-gdl1/MySQL4/ChangeLog @@ -1,3 +1,14 @@ +2005-04-19 Helge Hess + + * v4.5.5 + + * MySQL4Values.m: added a workaround to support NSTemporaryString + + * MySQL4Channel.m: fixed errno result handling + + * MySQL4Adaptor.m: do not fall back to PGHOST variable if not hostname + is set + 2005-04-13 Helge Hess * MySQL4Channel.m: finished fetching code (v4.5.4) diff --git a/sope-gdl1/MySQL4/MySQL4Adaptor.m b/sope-gdl1/MySQL4/MySQL4Adaptor.m index 66dda5a0..ecfa5c6e 100644 --- a/sope-gdl1/MySQL4/MySQL4Adaptor.m +++ b/sope-gdl1/MySQL4/MySQL4Adaptor.m @@ -55,10 +55,10 @@ serverName = [[self connectionDictionary] objectForKey:@"hostName"]; - if (serverName == nil) { // lookup env-variable - serverName = - [[[NSProcessInfo processInfo] environment] objectForKey:@"PGHOST"]; - } +#if 0 // do not default to something, to allow for sockets? + if (serverName == nil) + serverName = @"127.0.0.1"; +#endif return [[serverName copy] autorelease]; } diff --git a/sope-gdl1/MySQL4/MySQL4Channel.m b/sope-gdl1/MySQL4/MySQL4Channel.m index 5531aa38..6e5b983e 100644 --- a/sope-gdl1/MySQL4/MySQL4Channel.m +++ b/sope-gdl1/MySQL4/MySQL4Channel.m @@ -171,8 +171,8 @@ static int openConnectionCount = 0; } if (mysql_query(self->_connection, "SET CHARACTER SET utf8") != 0) { - NSLog(@"ERROR: could not put MySQL4 connection into UTF-8 mode: %s", - mysql_error(self->_connection)); + NSLog(@"ERROR(%s): could not put MySQL4 connection into UTF-8 mode: %s", + __PRETTY_FUNCTION__, mysql_error(self->_connection)); mysql_close(self->_connection); self->_connection = NULL; return NO; @@ -453,9 +453,12 @@ static int openConnectionCount = 0; if ((rawRow = mysql_fetch_row(self->results)) == NULL) { // TODO: might need to close channel on connect exceptions - const char *error; + unsigned int merrno; - if ((error = mysql_error(self->_connection)) != NULL) { + if ((merrno = mysql_errno(self->_connection)) != 0) { + const char *error; + + error = mysql_error(self->_connection); [MySQL4Exception raise:@"FetchFailed" format:@"%@",[NSString stringWithUTF8String:error]]; return nil; @@ -544,9 +547,10 @@ static int openConnectionCount = 0; *(&result) = YES; if (_expression == nil) { - [NSException raise:@"InvalidArgumentException" - format:@"parameter for evaluateExpression: " - @"must not be null (channel=%@)", self]; + return [NSException exceptionWithName:@"InvalidArgumentException" + reason: + @"parameter for evaluateExpression: must not be null" + userInfo:nil]; } sql = [[_expression mutableCopy] autorelease]; @@ -589,7 +593,7 @@ static int openConnectionCount = 0; if (isDebuggingEnabled) NSLog(@"%@ SQL: %@", self, sql); - + /* reset environment */ self->isFetchInProgress = NO; @@ -602,6 +606,8 @@ static int openConnectionCount = 0; const char *error; error = mysql_error(self->_connection); + if (isDebuggingEnabled) + NSLog(@"%@ ERROR: %s", self, error); return [MySQL4Exception exceptionWithName:@"ExecutionFailed" reason:[NSString stringWithUTF8String:error] @@ -611,17 +617,28 @@ static int openConnectionCount = 0; /* fetch */ if ((self->results = mysql_use_result(self->_connection)) != NULL) { + if (isDebuggingEnabled) + NSLog(@"%@ query has results, entering fetch-mode.", self); self->isFetchInProgress = YES; } else { /* error _OR_ statement without result-set */ - const char *error; - - if ((error = mysql_error(self->_connection)) != NULL) { + unsigned int merrno; + + if ((merrno = mysql_errno(self->_connection)) != 0) { + const char *error; + + if (isDebuggingEnabled) + NSLog(@"%@ cannot use result: '%s'", self, error); + + error = mysql_error(self->_connection); return [MySQL4Exception exceptionWithName:@"FetchFailed" reason:[NSString stringWithUTF8String:error] userInfo:nil]; } + + if (isDebuggingEnabled) + NSLog(@"%@ query has no results.", self); } if (delegateRespondsTo.didEvaluateExpression) @@ -642,6 +659,8 @@ static int openConnectionCount = 0; return NO; if ([n isEqualToString:@"EODelegateRejects"]) return NO; + + NSLog(@"ERROR eval '%@': %@", _sql, e); [e raise]; return NO; diff --git a/sope-gdl1/MySQL4/MySQL4Values.m b/sope-gdl1/MySQL4/MySQL4Values.m index 5bf7dbb6..f7395c72 100644 --- a/sope-gdl1/MySQL4/MySQL4Values.m +++ b/sope-gdl1/MySQL4/MySQL4Values.m @@ -25,6 +25,7 @@ #include "MySQL4Values.h" #include "common.h" +#include @implementation MySQL4DataTypeMappingException @@ -73,12 +74,33 @@ @implementation NSObject(MySQL4Values) - (id)initWithMySQL4Type:(int)_type value:(const void *)_v length:(int)_len { - [self release]; + /* Note: called for NSTemporaryString! */ + + if (![self respondsToSelector:@selector(initWithUTF8String:)]) { + if (_v == NULL) { + [self release]; + return nil; + } + NSLog(@"WARNING(%s): falling back to NSString for MySQL4 value!", + __PRETTY_FUNCTION__); + + [self release]; + return [[NSString alloc] initWithMySQL4Type:_type value:_v length:_len]; + } - NSLog(@"WARNING(%s): falling back to NSString for MySQL4 value!", - __PRETTY_FUNCTION__); + /* we assume NSTemporaryString here */ - return [[NSString alloc] initWithMySQL4Type:_type value:_v length:_len]; + switch (_type) { + case FIELD_TYPE_BLOB: + case FIELD_TYPE_TINY_BLOB: + case FIELD_TYPE_MEDIUM_BLOB: + case FIELD_TYPE_LONG_BLOB: + ; /* fall through */ + + default: + /* we always fallback to the UTF-8 string ... */ + return [(NSString *)self initWithUTF8String:_v]; + } } #if 0 diff --git a/sope-gdl1/MySQL4/NSString+MySQL4.m b/sope-gdl1/MySQL4/NSString+MySQL4.m index dbaab708..e9b9e8ad 100644 --- a/sope-gdl1/MySQL4/NSString+MySQL4.m +++ b/sope-gdl1/MySQL4/NSString+MySQL4.m @@ -27,9 +27,9 @@ # include #endif -#import +#include "NSString+MySQL4.h" #include "common.h" -#import "NSString+MySQL4.h" +#import @implementation NSString(MySQL4MiscStrings) diff --git a/sope-gdl1/MySQL4/NSString+MySQL4Val.m b/sope-gdl1/MySQL4/NSString+MySQL4Val.m index 47a56e07..df4c1199 100644 --- a/sope-gdl1/MySQL4/NSString+MySQL4Val.m +++ b/sope-gdl1/MySQL4/NSString+MySQL4Val.m @@ -34,6 +34,7 @@ static Class EOExprClass = Nil; - (id)initWithMySQL4Type:(int)_type value:(const void *)_v length:(int)_len { + // Note: never used on lF (NSTemporaryString!) if (_v == NULL) { [self release]; return nil; diff --git a/sope-gdl1/MySQL4/Version b/sope-gdl1/MySQL4/Version index 23e43c1d..5c20787e 100644 --- a/sope-gdl1/MySQL4/Version +++ b/sope-gdl1/MySQL4/Version @@ -1,3 +1,3 @@ # Version file -SUBMINOR_VERSION:=4 +SUBMINOR_VERSION:=5 diff --git a/sope-gdl1/MySQL4/condict.plist b/sope-gdl1/MySQL4/condict.plist index 250e134f..8e31a9bd 100644 --- a/sope-gdl1/MySQL4/condict.plist +++ b/sope-gdl1/MySQL4/condict.plist @@ -1,3 +1,6 @@ { - databaseName = "Test.sqldb"; + hostName = "127.0.0.1"; + userName = "OGo"; + password = "OGo"; + databaseName = "OGo"; }