}
- (void)cancelFetch {
+ if (self->results != NULL) {
+ mysql_free_result(self->results);
+ self->results = NULL;
+ }
+
self->isDone = NO;
self->hasPendingRow = NO;
[super cancelFetch];
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];
return ms;
}
-@end /* MySQL4Channel */
-
-@implementation MySQL4Channel(PrimaryKeyGeneration)
+/* PrimaryKeyGeneration */
- (NSDictionary *)primaryKeyForNewRowWithEntity:(EOEntity *)_entity {
NSArray *pkeys;
return pkey;
}
-@end /* MySQL4Channel(PrimaryKeyGeneration) */
+@end /* MySQL4Channel */
void __link_MySQL4Channel() {
// used to force linking of object file