List:NDB Connectors« Previous MessageNext Message »
From:Mika Raento Date:April 26 2007 3:36pm
Subject:Support for NdbIndex(Scan)Operation, prelim. support for typed attribute
access
View as plain text  
In the attached patch. Also simplified some exception definitions.

I've noticed also that if you fail to set the actual operation type 
(readTuples() etc) on an operation, you'll get a bus error. Should these 
kinds of things be reported as bugs against ndbapi, or is it assumed 
that it's pretty harsh?

Regards,
    Mika

# Bazaar revision bundle v0.8
#
# message:
#   support for NdbIndexOperation and NdbIndexScanOperation
#   preliminary support for reading strings for all target languages
#   preliminary support for reading values as appropriate types for perl
#   
# committer: Mika Raento <mikie@stripped>
# date: Thu 2007-04-26 18:30:02.405999899 +0300

=== added file perl/swig/perl_extend_ndbrecattr.i // file-id:perl_extend_ndbrec
... at-20070426144041-56zrx1r6lro1c0px-1
--- /dev/null
+++ perl/swig/perl_extend_ndbrecattr.i
@@ -0,0 +1,6 @@
+%extend NdbRecAttr {
+public:
+    void value_any(const NdbRecAttr** OutValueProxy) {
+        *OutValueProxy=self;
+    }
+};

=== added file perl/swig/perl_ndbrecattr_typemap.i // file-id:perl_ndbrecattr_t
... ype-20070426145807-eyq5m0w83sabygjh-1
--- /dev/null
+++ perl/swig/perl_ndbrecattr_typemap.i
@@ -0,0 +1,41 @@
+%typemap(in, numinputs=0) const NdbRecAttr** OutValueProxy (NdbRecAttr* temp) {
+    temp=0;
+    $1=&temp;
+}
+
+%typemap(argout) const NdbRecAttr** OutValueProxy {
+    NdbRecAttr* rec=*$1;
+    if (rec->isNULL()==-1) {
+        croak("record not fetched");
+    }
+    if (rec->isNULL()) {
+        $result=newSV(0);
+    } else {
+        switch(rec->getType()) {
+            case NDB_TYPE_CHAR:
+            case NDB_TYPE_BINARY:
+                $result=newSVpv(rec->aRef(), rec->get_size_in_bytes());
+                break;
+            case NDB_TYPE_VARCHAR:
+            case NDB_TYPE_VARBINARY:
+                const char* buf=rec->aRef();
+                int len=buf[0];
+                buf++;
+                $result=newSVpv(buf, len);
+                break;
+            case NDB_TYPE_TINYINT:
+                $result=newSViv(rec->char_value());
+                break;
+            case NDB_TYPE_SMALLINT:
+                $result=newSViv(rec->short_value());
+                break;
+            case NDB_TYPE_MEDIUMINT:
+                $result=newSViv(sint3korr(rec->aRef()));
+                break;
+            case NDB_TYPE_INT:
+                $result=newSViv(rec->int32_value());
+                break;
+        }
+    }
+    argvi++;
+}

=== added file swig/NdbIndexOperation.i // file-id:ndbindexoperation.i-20070426
... 125056-cdc2fzutv5osp12a-1
--- /dev/null
+++ swig/NdbIndexOperation.i
@@ -0,0 +1,51 @@
+/* Copyright (C) 2003 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+class NdbIndexOperation : public NdbOperation
+{
+public:
+
+  %exception { // this applies to everything until we clear it
+    $action
+      if (result==-1) { 
+        NdbError err = arg1->getNdbError();
+	SWIG_exception(SWIG_RuntimeError,err.message);
+      }
+  }
+
+  /** insert is not allowed */
+  int insertTuple();
+  int readTuple(LockMode);
+  int updateTuple();
+  int deleteTuple();
+
+
+  int interpretedUpdateTuple();
+  int interpretedDeleteTuple();
+  
+  %exception { // this applies to everything until we clear it
+    $action
+      if (result==0) { 
+        NdbError err = arg1->getNdbError();
+	SWIG_exception(SWIG_RuntimeError,err.message);
+      }
+  }
+
+  const NdbDictionary::Index * getIndex() const;
+
+private:
+  NdbIndexOperation(Ndb* aNdb);
+  ~NdbIndexOperation();
+};

=== added file swig/NdbIndexScanOperation.i // file-id:ndbindexscanoperatio-200
... 70426125039-esztodu0kcqbofgn-1
--- /dev/null
+++ swig/NdbIndexScanOperation.i
@@ -0,0 +1,41 @@
+/* Copyright (C) 2003 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+class NdbIndexScanOperation : public NdbScanOperation {
+public:
+  virtual int readTuples(LockMode lock_mode = LM_Read, 
+                         Uint32 scan_flags = 0, 
+			 Uint32 parallel = 0,
+			 Uint32 batch = 0);
+  enum BoundType {
+    BoundLE = 0,        ///< lower bound
+    BoundLT = 1,        ///< lower bound, strict
+    BoundGE = 2,        ///< upper bound
+    BoundGT = 3,        ///< upper bound, strict
+    BoundEQ = 4         ///< equality
+  };
+  int setBound(const char* attr, int type, const void* value);
+  int setBound(Uint32 anAttrId, int type, const void* aValue);
+
+  int reset_bounds(bool forceSend = false);
+  int end_of_bound(Uint32 range_no);
+  int get_range_no();
+  bool getSorted() const;
+  bool getDescending();
+
+private:
+  NdbIndexScanOperation(Ndb* aNdb);
+  virtual ~NdbIndexScanOperation();
+};

=== modified file acinclude.m4
--- acinclude.m4
+++ acinclude.m4
@@ -139,6 +139,7 @@
     ADDIFLAGS="$ADDIFLAGS $IBASE/ndb"
     ADDIFLAGS="$ADDIFLAGS $IBASE/ndb/ndbapi"
     ADDIFLAGS="$ADDIFLAGS $IBASE/ndb/mgmapi"
+    ADDIFLAGS="$ADDIFLAGS $IBASE"
 
     CFLAGS="$CFLAGS $ADDFLAGS $ADDIFLAGS"    
     CXXFLAGS="$CXXFLAGS $ADDFLAGS $ADDIFLAGS" 

=== modified file perl/ndbapi.i
--- perl/ndbapi.i
+++ perl/ndbapi.i
@@ -4,6 +4,7 @@
 %{
 #undef SWIG_exception
 #define SWIG_exception(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0)
+#include <my_global.h>
 %}
 %include "perl_callback_typemap.i"
 %include "Ndb_cluster_connection.i"
@@ -12,7 +13,11 @@
 %include "perl_extend_ndbtransaction_async.i"
 %include "NdbOperation.i"
 %include "NdbScanOperation.i"
+%include "NdbIndexOperation.i"
+%include "NdbIndexScanOperation.i"
+%include "perl_ndbrecattr_typemap.i"
 %include "NdbRecAttr.i"
+%include "perl_extend_ndbrecattr.i"
 %include "NdbError.i"
 %include "NdbBlob.i"
 %include "NdbDictionary.i"

=== modified file perl/swig/perl_callback_typemap.i
--- perl/swig/perl_callback_typemap.i
+++ perl/swig/perl_callback_typemap.i
@@ -1,12 +1,3 @@
-
-%typemap(in) SV* pFcn {
-  if (!SvROK($input))
-    croak("Expected a reference.\n");
-  if (SvTYPE($input)!=SVt_PVCV)
-    croak("Expected a CODEREF.\n");
-  $1 = SvRV($input);
-}
-
 %{
 /* This function matches the prototype of the normal C callback
    function for our widget. However, we use the clientdata pointer

=== modified file perl/swig/perl_extend_ndbtransaction_async.i
--- perl/swig/perl_extend_ndbtransaction_async.i
+++ perl/swig/perl_extend_ndbtransaction_async.i
@@ -1,9 +1,9 @@
 %extend NdbTransaction { 
   void executeAsynchPrepare(ExecType          execType,
-                            SV*         	func,
+                            SV*         	pFcn,
                             AbortOption       abortOption = AbortOnError)
   {
-    self->executeAsynchPrepare(execType,PerlCallBack,(void *)func,abortOption);
SvREFCNT_inc(func);
+    self->executeAsynchPrepare(execType,PerlCallBack,(void *)pFcn,abortOption);
SvREFCNT_inc(pFcn);
   };
 };
 

=== modified file swig/NdbDictionary.i
--- swig/NdbDictionary.i
+++ swig/NdbDictionary.i
@@ -304,6 +304,13 @@
 #endif
 
     const struct NdbError & getNdbError() const;
+  %exception { 
+    $action
+      if (result==NULL) { 
+        NdbError err = arg1->getNdbError();
+        SWIG_exception(SWIG_RuntimeError,err.message);
+      }
+  }
     const NdbDictionary::Table * getTable(const char * name) const;
     const NdbDictionary::Index * getIndex(const char * indexName,
 			   const char * tableName) const;
@@ -312,6 +319,13 @@
 			   const NdbDictionary::Table & table) const;
 #endif
 
+  %exception { 
+    $action
+      if (result==-1) { 
+        NdbError err = arg1->getNdbError();
+	SWIG_exception(SWIG_RuntimeError,err.message);
+      }
+  }
 #if 0
     int listIndexes(List & list, const char * tableName);
     int listIndexes(List & list, const char * tableName) const;
@@ -320,15 +334,16 @@
     int dropTable(NdbDictionary::Table & table);
     int dropTable(const char * name);
     int alterTable(const NdbDictionary::Table &table);
-    void invalidateTable(const char * name);
-    void removeCachedTable(const char * table);
-    void removeCachedIndex(const char * index, const char * table);
     int createIndex(const NdbDictionary::Index &index);
     int dropIndex(const char * indexName,
 		  const char * tableName);
 #if defined(MYSQL_50)
     int dropIndex(const NdbDictionary::Index &);
 #endif
+    %exception;
+    void invalidateTable(const char * name);
+    void removeCachedTable(const char * table);
+    void removeCachedIndex(const char * index, const char * table);
     void invalidateIndex(const char * indexName,
                          const char * tableName);
 private:

=== modified file swig/NdbOperation.i
--- swig/NdbOperation.i
+++ swig/NdbOperation.i
@@ -226,6 +226,30 @@
   NdbRecAttr* getValue(const NdbDictionary::Column* col) {
     return self->getValue(col,NULL);
   }
-
+  int equalNull(const char* anAttrName) {
+      return self->equal(anAttrName, (char*)0);
+  }
+  int equalNull(Uint32 anAttrId) {
+      return self->equal(anAttrId, (char*)0);
+  }
+  %cstring_input_binary(const char *aString, size_t len);
+  int equalString(const char* anAttrName, const char* aString, size_t len) {
+      if (len>65535) return -1;
+      if (len<256) {
+          char buf[257];
+          unsigned char lowb=len;
+          buf[0]=lowb;
+          memcpy(buf+1, aString, len);
+          return self->equal(anAttrName, buf);
+      } else {
+          char* buf=(char*)malloc(len+2);
+          unsigned char lowb=len & 0xff;
+          unsigned char highb=len << 8;
+          buf[0]=highb;
+          buf[1]=lowb;
+          memcpy(buf+2, aString, len);
+          return self->equal(anAttrName, buf);
+      }
+  }
 
 };

=== modified file swig/NdbRecAttr.i
--- swig/NdbRecAttr.i
+++ swig/NdbRecAttr.i
@@ -49,5 +49,18 @@
     int y = (int)x;
     return y;
   }
+  %cstring_output_allocate_size(char ** s, int *slen, void())
+  void string_value(char ** s, int *slen) {
+    char* ref=self->aRef();
+    if ( self->getType() == NDB_TYPE_VARCHAR) {
+        *slen=ref[0];
+        ref++;
+        *s=ref;
+    } else {
+        *slen=self->get_size_in_bytes();
+        *s=ref;
+    }
+  }
+
 
 };

=== modified file swig/NdbTransaction.i
--- swig/NdbTransaction.i
+++ swig/NdbTransaction.i
@@ -27,23 +27,19 @@
 
   const NdbError & getNdbError() const;
 
-  %exception getNdbOperation { 
+  %exception { 
     $action
       if (result==NULL) { 
         NdbError err = arg1->getNdbError();
-	SWIG_exception(SWIG_RuntimeError,err.message);
+        SWIG_exception(SWIG_RuntimeError,err.message);
       }
   }
   NdbOperation* getNdbOperation(const class NdbDictionary::Table* aTable);
   NdbOperation* getNdbOperation(const char* aTableName);
 
-  %exception { 
-    $action
-      if (result==NULL) { 
-        NdbError err = arg1->getNdbError();
-	SWIG_exception(SWIG_RuntimeError,err.message);
-      }
-  }
+  NdbIndexScanOperation* getNdbIndexScanOperation(const NdbDictionary::Index *anIndex);
+  NdbIndexOperation* getNdbIndexOperation(const NdbDictionary::Index *anIndex);
+
   NdbScanOperation* getNdbScanOperation(const class NdbDictionary::Table* aTable);
   NdbScanOperation* getNdbScanOperation(const char* aTableName);
   NdbOperation*	getNdbErrorOperation();

=== modified file swig/globals.i
--- swig/globals.i
+++ swig/globals.i
@@ -1,6 +1,7 @@
 
 %include "typemaps.i"
 %include "exception.i"
+%include "cstring.i"
 
 %{
 #include <NdbApi.hpp> 

=== modified directory  // last-changed:mikie@stripped
... o13y198laq48ifoj
# revision id: mikie@stripped
# sha1: c34c3385c9a37700d9e116cea8da3b706c31d4ce
# inventory sha1: 59d737426e7e08cc556eb2ad38933b49bfa9b5ab
# parent ids:
#   monty@stripped
# base id: monty@stripped
# properties:
#   branch-nick: devel-mine-new3


Thread
Language-specific wrappers/extensionsMika Raento23 Apr
  • Re: Language-specific wrappers/extensionsMonty Taylor23 Apr
    • Re: Language-specific wrappers/extensionsMonty Taylor24 Apr
      • Re: Language-specific wrappers/extensionsMika Raento24 Apr
        • Re: Language-specific wrappers/extensionsMonty Taylor24 Apr
Re: Language-specific wrappers/extensionsMonty Taylor24 Apr
  • %/% rule in Makefile?Mika Raento25 Apr
    • Re: %/% rule in Makefile?Monty Taylor25 Apr
      • Re: %/% rule in Makefile?Mika Raento26 Apr
        • DocumentationMonty Taylor27 Apr
      • lifetime of Ndb and Ndb_cluster_connection objectsMika Raento26 Apr
        • Re: lifetime of Ndb and Ndb_cluster_connection objectsMonty Taylor27 Apr
          • Re: lifetime of Ndb and Ndb_cluster_connection objectsMika Raento7 May
            • Re: lifetime of Ndb and Ndb_cluster_connection objectsMonty Taylor7 May
      • Support for NdbIndex(Scan)Operation, prelim. support for typed attributeaccessMika Raento26 Apr
        • Re: Support for NdbIndex(Scan)Operation, prelim. support for typedattribute accessMonty Taylor28 Apr
Re: lifetime of Ndb and Ndb_cluster_connection objectsMonty Taylor8 May