List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:August 30 2007 5:36am
Subject:Rev 141: Added length calculations for NdbScanFilter::cmp (thanks JD) in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmerge
View as plain text  
At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmerge

------------------------------------------------------------
revno: 141
revision-id: mtaylor@stripped
parent: johan@stingray-20070802163619-e2c9121956414ff4
committer: Monty Taylor <mtaylor@stripped>
branch nick: ndbjmerge
timestamp: Wed 2007-08-29 22:34:54 -0700
message:
  Added length calculations for NdbScanFilter::cmp (thanks JD) 
  Fixed (?) exception thrown by NdbRecAttr::getTimestamp. Seems like there's no way for
this to thrown an exception? 
modified:
  swig/NdbRecAttr.i              ndbrecattr.i-20070228021421-qkr4cbpxymyqdrf3-4
  swig/NdbScanFilter.i           ndbscanfilter.i-20070521223726-lvjwmtu5b6uvgsft-1
=== modified file 'swig/NdbRecAttr.i'
--- a/swig/NdbRecAttr.i	2007-08-01 16:44:14 +0000
+++ b/swig/NdbRecAttr.i	2007-08-30 05:34:54 +0000
@@ -174,13 +174,17 @@
     return NULL;
   }
 
+  MYSQL_TIME * getDatetime() { 
+    return NULL;
+  }
+
+  %ndbexception("NdbApiException") {
+    $action
+  }
 
   NdbTimestamp getTimestamp() { 
     return (NdbTimestamp)(self->u_32_value());
   }
 
-  MYSQL_TIME * getDatetime() { 
-    return NULL;
-  }
-
+  %ndbnoexception;
 };

=== modified file 'swig/NdbScanFilter.i'
--- a/swig/NdbScanFilter.i	2007-05-29 15:45:11 +0000
+++ b/swig/NdbScanFilter.i	2007-08-30 05:34:54 +0000
@@ -17,6 +17,38 @@
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
+%{
+
+  Uint32 cmpGetColumnLength(const NdbDictionary::Column * theColumn) { 
+
+    Uint32 cmpLength = 0; 
+    switch(theColumn->getType()) {
+    case NDB_TYPE_VARCHAR:
+    case NDB_TYPE_VARBINARY:
+    { 
+      cmpLength=theColumn->getLength()+1;
+      break;
+    }
+    case NDB_TYPE_LONGVARCHAR:
+    case NDB_TYPE_LONGVARBINARY:
+    {
+      cmpLength=theColumn->getLength()+2;
+      break; 
+    }
+    case NDB_TYPE_CHAR:
+    case NDB_TYPE_BINARY:
+    { 
+      cmpLength=theColumn->getLength();
+      break;
+    }
+    default:
+      return 0;
+    }
+    return cmpLength;
+  }
+
+%}
+
 class NdbScanFilter {
 
   class NdbScanFilterImpl & m_impl;
@@ -209,7 +241,12 @@
     char * stringVal = ndbFormatString(theColumn,BYTE,len);
     if (stringVal == NULL) 
       return -1;
-    int retval = self->cmp(cond,ColId,(void *)stringVal);
+
+    Uint32 cmpLength = cmpGetColumnLength(theColumn);
+    if (cmpLength == 0) 
+      return -1;
+
+    int retval = self->cmp(cond,ColId,(void *)stringVal,cmpLength);
     free(stringVal);
     return retval;
   };
@@ -218,7 +255,12 @@
     char * stringVal = ndbFormatString(theColumn,anInputString,len);
     if (stringVal == NULL) 
       return -1;
-    int retval = self->cmp(cond,ColId,(void *)stringVal);
+
+    Uint32 cmpLength = cmpGetColumnLength(theColumn);
+    if (cmpLength == 0) 
+      return -1;
+
+    int retval = self->cmp(cond,ColId,(void *)stringVal,cmpLength);
     free(stringVal);
     return retval;
   };
@@ -301,7 +343,12 @@
     char * stringVal = ndbFormatString(theColumn,BYTE,len);
     if (stringVal == NULL) 
       return -1;
-    int retval = self->cmp(cond,ColId,(void *)stringVal);
+
+    Uint32 cmpLength = cmpGetColumnLength(theColumn);
+    if (cmpLength == 0) 
+      return -1;
+
+    int retval = self->cmp(cond,ColId,(void *)stringVal,cmpLength);
     free(stringVal);
     return retval;
   };
@@ -314,7 +361,11 @@
     char * stringVal = ndbFormatString(theColumn,anInputString,len);
     if (stringVal == NULL) 
       return -1;
-    int retval = self->cmp(cond,ColId,(void *)stringVal);
+    Uint32 cmpLength = cmpGetColumnLength(theColumn);
+    if (cmpLength == 0) 
+      return -1;
+    
+    int retval = self->cmp(cond,ColId,(void *)stringVal,cmpLength);
     free(stringVal);
     return retval;
   };

Thread
Rev 141: Added length calculations for NdbScanFilter::cmp (thanks JD) in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmergeMonty Taylor30 Aug