List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:May 6 2007 4:29am
Subject:Rev 108: Added datetime and string/length typemaps to ruby. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/exceptions
View as plain text  
------------------------------------------------------------
revno: 108
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: exceptions
timestamp: Sat 2007-05-05 21:28:40 -0700
message:
  Added datetime and string/length typemaps to ruby.
  Commented out one of the versions of setString since I think I found a bug in 
    Swig/Ruby's handling of multi-methods with in typemaps. 
modified:
  ruby/ndbapi.i                  ndb.i-20070228212451-7arjxk90dkwcn5xr-3
  ruby/test.rb                   test.rb-20070228212451-7arjxk90dkwcn5xr-4
  swig/NdbOperation.i            ndboperation.i-20070228021421-qkr4cbpxymyqdrf3-3
=== modified file 'ruby/ndbapi.i'
--- a/ruby/ndbapi.i	2007-05-05 08:43:18 +0000
+++ b/ruby/ndbapi.i	2007-05-06 04:28:40 +0000
@@ -1,3 +1,4 @@
+// -*- mode: c++ -*- 
 /*  ndb-connectors: Wrappers for the NDBAPI
     Copyright (C) 2006 MySQL, Inc.
     
@@ -22,6 +23,32 @@
 
 %include "globals.i"
 
+%typemap(in) (const char* anInputString, size_t len) {
+
+  $1 = STR2CSTR($input);
+  $2 = (size_t)RSTRING($input)->len;
+ }
+
+%typemap(in) (MYSQL_TIME * anInputDateTime) { 
+
+  // How do I check that we're getting a Ruby DateTime?!!?
+
+  printf("whee!\n");
+    MYSQL_TIME * dt = (MYSQL_TIME *)malloc(sizeof(MYSQL_TIME));
+    if (dt==NULL) 
+      NDB_exception(NdbApiException,"Failed to allocate a MYSQL_TIME");
+    dt->year = NUM2INT(rb_funcall($input,rb_intern("year"),0));
+    dt->month = NUM2INT(rb_funcall($input,rb_intern("month"),0));
+    dt->day = NUM2INT(rb_funcall($input,rb_intern("day"),0));
+    dt->hour = NUM2INT(rb_funcall($input,rb_intern("hour"),0));
+    dt->minute = NUM2INT(rb_funcall($input,rb_intern("min"),0));
+    dt->second = NUM2INT(rb_funcall($input,rb_intern("sec"),0));
+
+    $1 = dt;      
+
+
+ }
+
 %{ 
 
 #define NDB_exception(code,msg) do { ndb_raise_exception(code, msg); SWIG_fail; }
while(0);

=== modified file 'ruby/test.rb'
--- a/ruby/test.rb	2007-05-02 21:31:41 +0000
+++ b/ruby/test.rb	2007-05-06 04:28:40 +0000
@@ -37,7 +37,7 @@
 puts "Inserting" , auto_id
 
 myOperation.equal("ATTR1",auto_id)
-myOperation.set_value("ATTR2",1234)
+myOperation.set_string("ATTR2","monty")
 
 myTransaction.execute(Ndbapi::Commit)
 

=== modified file 'swig/NdbOperation.i'
--- a/swig/NdbOperation.i	2007-05-06 03:22:10 +0000
+++ b/swig/NdbOperation.i	2007-05-06 04:28:40 +0000
@@ -401,7 +401,7 @@
     return self->setValue(anAttrName,dtval);
 
   }
-  int setDatetime(Uint32 anAttrId, MYSQL_TIME * anInputDateTime) { 
+/*  int setDatetime(Uint32 anAttrId, MYSQL_TIME * anInputDateTime) { 
     
     const NdbDictionary::Column * theColumn =
self->getTable()->getColumn(anAttrId);
     
@@ -409,7 +409,7 @@
     if (dtval == 1) 
       return dtval;
     return  self->setValue(anAttrId,dtval);
-  }
+    }*/
   int setTimestamp(const char* anAttrName, Int64 anInputTimestamp) { 
 
     return self->setValue(anAttrName,anInputTimestamp);

Thread
Rev 108: Added datetime and string/length typemaps to ruby. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/exceptionsMonty Taylor6 May