}
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;
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;
*(&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];
if (isDebuggingEnabled)
NSLog(@"%@ SQL: %@", self, sql);
-
+
/* reset environment */
self->isFetchInProgress = NO;
const char *error;
error = mysql_error(self->_connection);
+ if (isDebuggingEnabled)
+ NSLog(@"%@ ERROR: %s", self, error);
return [MySQL4Exception exceptionWithName:@"ExecutionFailed"
reason:[NSString stringWithUTF8String:error]
/* 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)
return NO;
if ([n isEqualToString:@"EODelegateRejects"])
return NO;
+
+ NSLog(@"ERROR eval '%@': %@", _sql, e);
[e raise];
return NO;
#include "MySQL4Values.h"
#include "common.h"
+#include <mysql/mysql.h>
@implementation MySQL4DataTypeMappingException
@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