]> err.no Git - sope/commitdiff
connect work
authorhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Mon, 11 Apr 2005 20:03:45 +0000 (20:03 +0000)
committerhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Mon, 11 Apr 2005 20:03:45 +0000 (20:03 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@725 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-gdl1/MySQL4/MySQL4Channel.h
sope-gdl1/MySQL4/MySQL4Channel.m

index b4793e63c6368182ff27dd5053dbf00568b5f9d0..5ef914e15394083ae976ea204d835cca979ecfdd 100644 (file)
@@ -37,7 +37,6 @@
   void *_connection;
   
   // valid during -evaluateExpression:
-  void     *statement;
   BOOL     hasPendingRow;
   BOOL     isDone;
   
index c3d9df0b9242e268c8ef20ab8834ac92e7f2325e..db1d80e8d9ac89c15f09f56a9cc20aad237a6b52 100644 (file)
@@ -33,6 +33,7 @@
 #include "MySQL4Values.h"
 #include "EOAttribute+MySQL4.h"
 #include "common.h"
+#include <mysql/mysql.h>
 
 #ifndef MIN
 #  define MIN(x, y) ((x > y) ? y : x)
@@ -109,16 +110,17 @@ static int openConnectionCount = 0;
     [[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;
   }
@@ -127,7 +129,7 @@ static int openConnectionCount = 0;
   
   if (![super openChannel])
     return NO;
-
+  
   if (openConnectionCount > [self maxOpenConnectionCount]) {
     [MySQL4CouldNotOpenChannelException 
        raise:@"NoMoreConnections"
@@ -137,19 +139,36 @@ static int openConnectionCount = 0;
 
   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);
@@ -174,21 +193,8 @@ static int openConnectionCount = 0;
 }
 
 - (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);
@@ -258,14 +264,6 @@ static int openConnectionCount = 0;
 }
 
 - (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];
@@ -422,12 +420,14 @@ static int openConnectionCount = 0;
   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) {
@@ -567,12 +567,14 @@ static int openConnectionCount = 0;
                            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);
@@ -612,7 +614,6 @@ static int openConnectionCount = 0;
   
   if ([sql hasPrefix:@"SELECT"] || [sql hasPrefix:@"select"]) {
     self->isFetchInProgress = YES;
-    NSAssert(self->statement, @"missing statement");
   }
   else {
     if ((error = [self _makeMySQL4Step]) != nil) {
@@ -622,12 +623,6 @@ static int openConnectionCount = 0;
   
     self->isFetchInProgress = self->hasPendingRow;
     if (!self->isFetchInProgress) {
-#if 1
-#  warning IMPLEMENT ME
-#else
-      sqlite3_finalize(self->statement); 
-#endif
-      self->statement = NULL;
     }
   }