]> err.no Git - sope/commitdiff
added query call
authorhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Tue, 12 Apr 2005 13:51:38 +0000 (13:51 +0000)
committerhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Tue, 12 Apr 2005 13:51:38 +0000 (13:51 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@729 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-gdl1/MySQL4/ChangeLog
sope-gdl1/MySQL4/MySQL4Channel.h
sope-gdl1/MySQL4/MySQL4Channel.m
sope-gdl1/MySQL4/README
sope-gdl1/MySQL4/Version

index a85905be77111813d1ab358affeead74ccef04d4..0728516d5dbecc1ae8bdb16026a1f1e67c13d063 100644 (file)
@@ -1,3 +1,7 @@
+2005-04-12  Helge Hess  <helge.hess@skyrix.com>
+
+       * MySQL4Channel.m: implemented query (v4.5.2)
+
 2005-04-11  Helge Hess  <helge.hess@opengroupware.org>
 
        * started MySQL4 adaptor based on SQLite one (v4.5.1)
index 5ef914e15394083ae976ea204d835cca979ecfdd..93b8d0eb78955e5b69522c6b45119ee07e77e11c 100644 (file)
@@ -27,7 +27,6 @@
 #define ___MySQL4_Channel_H___
 
 #import <GDLAccess/EOAdaptorChannel.h>
-#include <sqlite3.h>
 
 @class NSArray, NSString, NSMutableDictionary;
 
index a61889eeb002de428fca47a33f79082085565c79..96fd947624c14a5cd64afee7a02f18bbfc40ef9d 100644 (file)
@@ -272,6 +272,11 @@ static int openConnectionCount = 0;
 }
 
 - (void)cancelFetch {
+  if (self->results != NULL) {
+    mysql_free_result(self->results);
+    self->results = NULL;
+  }
+  
   self->isDone        = NO;
   self->hasPendingRow = NO;
   [super cancelFetch];
@@ -598,43 +603,36 @@ static int openConnectionCount = 0;
   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];
   
@@ -672,9 +670,7 @@ static int openConnectionCount = 0;
   return ms;
 }
 
-@end /* MySQL4Channel */
-
-@implementation MySQL4Channel(PrimaryKeyGeneration)
+/* PrimaryKeyGeneration */
 
 - (NSDictionary *)primaryKeyForNewRowWithEntity:(EOEntity *)_entity {
   NSArray       *pkeys;
@@ -718,7 +714,7 @@ static int openConnectionCount = 0;
   return pkey;
 }
 
-@end /* MySQL4Channel(PrimaryKeyGeneration) */
+@end /* MySQL4Channel */
 
 void __link_MySQL4Channel() {
   // used to force linking of object file
index 6babe403d946c6f8bb2df154aad9e5d8eceae215..a7f99698c58333aa687d40abdfe243a824439b57 100644 (file)
@@ -36,3 +36,11 @@ mysql --password=abc
 > create database Test;
 > use Test;
 > CREATE TABLE my_table ( pkey INT PRIMARY KEY );
+
+
+Notes
+=====
+
+mysql_store_result      - does not block the server, full result in memory
+vs
+mysql_use_result        - does block the server, one row in memory
index 4010e5dd4508f14e0784ae5a7757e1e1d16272ab..648edbe20adf383833080c4544f0380bae83d496 100644 (file)
@@ -1,3 +1,3 @@
 # Version file
 
-SUBMINOR_VERSION:=1
+SUBMINOR_VERSION:=2