#include "MySQL4Values.h"
#include "EOAttribute+MySQL4.h"
#include "common.h"
+#include <mysql/mysql.h>
#ifndef MIN
# define MIN(x, y) ((x > y) ? y : x)
[[NSUserDefaults standardUserDefaults]
integerForKey:@"MySQL4MaxOpenConnectionCount"];
if (MaxOpenConnectionCount == 0)
- MaxOpenConnectionCount = 15;
+ MaxOpenConnectionCount = 150;
return MaxOpenConnectionCount;
}
- (BOOL)openChannel {
const unsigned char *cDBName;
MySQL4Adaptor *adaptor;
- int rc;
+ NSString *host, *socket;
+ void *rc;
- if (self->_connection) {
+ if (self->_connection != NULL) {
NSLog(@"%s: Connection already open !!!", __PRETTY_FUNCTION__);
return NO;
}
if (![super openChannel])
return NO;
-
+
if (openConnectionCount > [self maxOpenConnectionCount]) {
[MySQL4CouldNotOpenChannelException
raise:@"NoMoreConnections"
cDBName = [[adaptor databaseName] UTF8String];
-#if 1
-# warning IMPLEMENT ME
-#else
- rc = sqlite3_open(cDBName, (void *)&(self->_connection));
- if (rc != SQLITE_OK) {
- // could not login ..
- // Note: connection *is* set! (might be required to deallocate)
+ if ((self->_connection = mysql_init(NULL)) == NULL) {
+ NSLog(@"ERROR(%s): could not allocate MySQL4 connection!");
+ return NO;
+ }
+
+ // TODO: could change options using mysql_options()
+
+ host = [adaptor serverName];
+ if ([host hasPrefix:@"/"]) { /* treat hostname as Unix socket path */
+ socket = host;
+ host = nil;
+ }
+ else
+ socket = nil;
+
+ rc = mysql_real_connect(self->_connection,
+ [host UTF8String],
+ [[adaptor loginName] UTF8String],
+ [[adaptor loginPassword] UTF8String],
+ cDBName,
+ [[adaptor port] intValue],
+ [socket cString],
+ 0);
+ if (rc == NULL) {
NSLog(@"WARNING: could not open MySQL4 connection to database '%@': %s",
- [adaptor databaseName], sqlite3_errmsg(self->_connection));
- sqlite3_close(self->_connection);
+ [adaptor databaseName], mysql_error(self->_connection));
+ mysql_close(self->_connection);
+ self->_connection = NULL;
return NO;
}
-#endif
if (isDebuggingEnabled)
NSLog(@"MySQL4 connection established 0x%08X", self->_connection);
}
- (void)primaryCloseChannel {
- if (self->statement != NULL) {
-#if 1
-# warning IMPLEMENT ME
-#else
- sqlite3_finalize(self->statement);
-#endif
- self->statement = NULL;
- }
-
if (self->_connection != NULL) {
-#if 1
-# warning IMPLEMENT ME
-#else
- sqlite3_close(self->_connection);
-#endif
+ mysql_close(self->_connection);
#if 0
NSLog(@"---------- %s: %@ close channel count[%d]", __PRETTY_FUNCTION__,
self, openConnectionCount);
}
- (void)cancelFetch {
- if (self->statement != NULL) {
-#if 1
-# warning IMPLEMENT ME
-#else
- sqlite3_finalize(self->statement);
-#endif
- self->statement = NULL;
- }
self->isDone = NO;
self->hasPendingRow = NO;
[super cancelFetch];
NSException *error;
unsigned attrCount = [_attributes count];
unsigned cnt;
-
+
+#if 0
if (self->statement == NULL) {
NSLog(@"ERROR: no fetch in progress?");
[self cancelFetch];
return nil;
}
+#endif
if (!self->hasPendingRow && !self->isDone) {
if ((error = [self _makeMySQL4Step]) != nil) {
reason:@"MySQL4 connection is not open"
userInfo:nil];
}
+#if 0
if (self->statement != NULL) {
return [MySQL4Exception exceptionWithName:@"CommandInProgressException"
reason:@"an evaluation is in progress"
userInfo:nil];
return NO;
}
+#endif
if ([self isFetchInProgress]) {
NSLog(@"WARNING: a fetch is still in progress: %@", self);
if ([sql hasPrefix:@"SELECT"] || [sql hasPrefix:@"select"]) {
self->isFetchInProgress = YES;
- NSAssert(self->statement, @"missing statement");
}
else {
if ((error = [self _makeMySQL4Step]) != nil) {
self->isFetchInProgress = self->hasPendingRow;
if (!self->isFetchInProgress) {
-#if 1
-# warning IMPLEMENT ME
-#else
- sqlite3_finalize(self->statement);
-#endif
- self->statement = NULL;
}
}