1 message in com.mysql.lists.ndb-connectorsRev 407: Replaced MYSQL_TIME with new...
FromSent OnAttachments
Monty Taylor04 Jan 2008 11:27 
Subject:Rev 407: Replaced MYSQL_TIME with new class NdbDateTime to simplify typemappings. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel
From:Monty Taylor (mtay@mysql.com)
Date:01/04/2008 11:27:41 AM
List:com.mysql.lists.ndb-connectors

At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel

------------------------------------------------------------ revno: 407 revision-id:mtay@mysql.com-20080104192741-qxr34l0v9rptbre1 parent: mtay@mysql.com-20080104190227-ca691o71c6zuhmw3 committer: Monty Taylor <mtay@mysql.com> branch nick: devel timestamp: Fri 2008-01-04 11:27:41 -0800 message: Replaced MYSQL_TIME with new class NdbDateTime to simplify typemappings. added: csharp/ndbapi/NdbDateTimeHelper.cs
ndbdatetimehelper.cs-20080104192005-wp3jcdt7i50w7z3v-1 renamed: java/swig/mysql_time.i => java/swig/NdbDateTime.i
mysql_time.i-20071220010513-amjnzrb6ece4xkbc-17 modified: csharp/csharp.userprefs csharp.userprefs-20071231171226-bgekh6don5s6evnk-3 csharp/examples/examples.mdp test.mdp-20071231171204-0aihyf88clt213sl-1 csharp/ndbapi.i
svn-v2:10@5fca6d9a-db22-0410-b55c-899b0a28da89-trunk-csharp%2fndb.i csharp/ndbapi/ndbapi.mdp ndbapi.mdp-20071231171154-cc3a94g06bm81lq9-1 interface/ndbapi/NdbIndexScanOperation.i
ndbindexscanoperatio-20070426125039-esztodu0kcqbofgn-1 interface/ndbapi/NdbOperation.i ndboperation.i-20070228021421-qkr4cbpxymyqdrf3-3 interface/ndbapi/NdbRecAttr.i ndbrecattr.i-20070228021421-qkr4cbpxymyqdrf3-4 interface/ndbapi/NdbScanFilter.i
ndbscanfilter.i-20070521223726-lvjwmtu5b6uvgsft-1 interface/ndbapi/ndbglobals.i globals.i-20070228021421-qkr4cbpxymyqdrf3-7 java/ndbj.i ndbj.i-20070913223244-5938mztpztyn9sry-1 java/prj.el prj.el-20080104181740-bu7z9q4ss5spu65l-1 java/swig/NdbDateTime.i mysql_time.i-20071220010513-amjnzrb6ece4xkbc-17 === added file 'csharp/ndbapi/NdbDateTimeHelper.cs' --- a/csharp/ndbapi/NdbDateTimeHelper.cs 1970-01-01 00:00:00 +0000 +++ b/csharp/ndbapi/NdbDateTimeHelper.cs 2008-01-04 19:27:41 +0000 @@ -0,0 +1,39 @@ +// NdbDateTime.cs created with MonoDevelop +// User: mtaylor at 9:53 AM 1/3/2008 +// +// To change standard headers go to Edit->Preferences->Coding->Standard Headers +// + +using System; +using System.Runtime.InteropServices; + +namespace MySql.Cluster.NdbApi +{ + + internal class NdbDateTimeHelper { + public static HandleRef systemDTtoNdbDT(System.DateTime theDateTime) { + NdbDateTime dt = new NdbDateTime(); + dt.year=(uint)theDateTime.Year; + dt.month=(uint)theDateTime.Month; + dt.day=(uint)theDateTime.Day; + dt.hour=(uint)theDateTime.Hour; + dt.minute=(uint)theDateTime.Minute; + dt.second=(uint)theDateTime.Second; + return NdbDateTime.getCPtr(dt); + + } + + } + + [StructLayout (LayoutKind.Sequential)] + internal struct mtNdbDateTime + { + public uint year; + public uint month; + public uint day; + public uint hour; + public uint minute; + public uint second; + } + +}

=== renamed file 'java/swig/mysql_time.i' => 'java/swig/NdbDateTime.i' --- a/java/swig/mysql_time.i 2007-12-20 01:16:46 +0000 +++ b/java/swig/NdbDateTime.i 2008-01-04 19:27:41 +0000 @@ -17,14 +17,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */

-%typemap(jni) MYSQL_TIME * "jobject" -%typemap(jtype) MYSQL_TIME * "Object" -%typemap(jstype) MYSQL_TIME * "java.util.Calendar" -%typemap(javain) MYSQL_TIME * "$javainput" -%typemap(javaout) MYSQL_TIME * { return (java.util.Calendar)$jnicall; } +%typemap(jni) NdbDateTime * "jobject" +%typemap(jtype) NdbDateTime * "Object" +%typemap(jstype) NdbDateTime * "java.util.Calendar" +%typemap(javain) NdbDateTime * "$javainput" +%typemap(javaout) NdbDateTime * { return (java.util.Calendar)$jnicall; }

-%typemap(in) (MYSQL_TIME *) { - MYSQL_TIME * dt = (MYSQL_TIME *)malloc(sizeof(MYSQL_TIME)); +%typemap(in) (NdbDateTime *) { + // NdbDateTime * dt = (NdbDateTime *)malloc(sizeof(NdbDateTime)); + NdbDateTime * dt = new NdbDateTime(); static jclass calendar_class = jenv->FindClass("java/util/Calendar"); static jmethodID getID = jenv->GetMethodID(calendar_class,"get","(I)I"); static jfieldID yearID = jenv->GetFieldID(calendar_class,"YEAR","I"); @@ -45,16 +46,17 @@ jint hourval = jenv->CallIntMethod($input,getID,hourfield); jint minuteval = jenv->CallIntMethod($input,getID,minutefield); jint secondval = jenv->CallIntMethod($input,getID,secondfield); - dt->year = (int)yearval; - dt->month = (int)monthval; - dt->day = (int)dayval; - dt->hour = (int)hourval; - dt->minute = (int)minuteval; - dt->second = (int)secondval; + // TODO: Need to add sanity checking here for signed/unsigned madness + dt->year = (uint)yearval; + dt->month = (uint)monthval; + dt->day = (uint)dayval; + dt->hour = (uint)hourval; + dt->minute = (uint)minuteval; + dt->second = (uint)secondval; $1 = dt; }

-%typemap(out) (MYSQL_TIME *) { +%typemap(out) (NdbDateTime *) { static jclass calendar_class = jenv->FindClass("java/util/Calendar"); static jmethodID get_calendar_instance =
jenv->GetStaticMethodID(calendar_class,"getInstance","()Ljava/util/Calendar;"); static jmethodID setID = jenv->GetMethodID(calendar_class,"set","(IIIIII)V"); @@ -64,6 +66,7 @@ }

-%typemap(freearg) (MYSQL_TIME *) { - free((MYSQL_TIME *) $1); +%typemap(freearg) (NdbDateTime *) { +// free((NdbDateTime *) $1); + delete $1; }

=== modified file 'csharp/csharp.userprefs' --- a/csharp/csharp.userprefs 2007-12-31 22:48:46 +0000 +++ b/csharp/csharp.userprefs 2008-01-04 19:27:41 +0000 @@ -1,33 +1,33 @@ <UserCombinePreferences version="1.0"
filename="/home/mtaylor/src/ndb-connectors/devel/csharp/csharp.mds"> <Files> <File name="Welcome" /> - <File name="ndbapi/generated/NdbEventOperation.cs" line="14" column="31" /> - <File name="ndbapi/generated/NdbOperation.cs" line="27" column="34" /> - <File name="ndbapi/generated/NdbTransaction.cs" line="45" column="15" /> - <File name="ndbapi/generated/Ndb.cs" line="83" column="26" /> - <File name="mgmapi/generated/mgmapiPINVOKE.cs" line="857" column="32" /> - <File name="ndbapi/generated/NdbIndex.cs" line="125" column="7" /> - <File name="ndbapi/generated/ndbapiPINVOKE.cs" line="241" column="32" /> - <File name="test/testasync.cs" line="28" column="20" /> - <File name="test/test.cs" line="17" column="3" /> - <File name="test/test2.cs" line="23" column="12" /> - <File name="ndbapi/BaseCallback.cs" line="40" column="42" /> + <File name="ndbapi/generated/ndbapiPINVOKE.cs" line="2338" column="30" /> + <File name="ndbapi/BaseCallback.cs" line="14" column="5" /> <File name="ndbapi/NdbExceptions.cs" line="2" column="1" /> + <File name="examples/asyncexample/testasync.cs" line="13" column="1" /> + <File name="ndbapi/generated/NdbTransaction.cs" line="1" column="1" /> + <File name="ndbapi/generated/NdbRecAttr.cs" line="153" column="48" /> + <File name="ndbapi/generated/NdbOperation.cs" line="580" column="16" /> + <File name="ndbapi/NdbDateTime.cs" line="21" column="20" /> </Files> <Views> <ViewMemento id="ProjectPad"> <Node expanded="True"> - <Node name="mgmapi" expanded="True" /> + <Node name="asyncexample" expanded="True" /> <Node name="ndbapi" expanded="True"> - <Node name="generated" expanded="True" /> - </Node> - <Node name="test" expanded="True" selected="True"> - <Node name="References" expanded="True" /> + <Node name="generated" expanded="True" selected="True" /> </Node> </Node> </ViewMemento> <ViewMemento id="ClassPad"> <Node expanded="True" /> </ViewMemento> + <ViewMemento id="MonoDevelop.NUnit.TestPad"> + <Node expanded="True" /> + </ViewMemento> </Views> + <Properties> + <Property key="ActiveWindow"
value="/home/mtaylor/src/ndb-connectors/devel/csharp/ndbapi/NdbDateTime.cs" /> + <Property key="ActiveConfiguration" value="Debug" /> + </Properties> </UserCombinePreferences> \ No newline at end of file

=== modified file 'csharp/examples/examples.mdp' --- a/csharp/examples/examples.mdp 2008-01-03 00:04:44 +0000 +++ b/csharp/examples/examples.mdp 2008-01-04 19:27:41 +0000 @@ -19,6 +19,9 @@ <File name="test2.cs" subtype="Code" buildaction="Compile" /> <File name="bin/Debug/mgmapi.dll.mdb" subtype="Code" buildaction="Exclude" /> <File name="bin/Debug/ndbapi.dll.mdb" subtype="Code" buildaction="Exclude" /> + <File name="asyncexample/AssemblyInfo.cs" subtype="Code" buildaction="Compile"
/> + <File name="asyncexample/testasync.cs" subtype="Code" buildaction="Compile" /> + <File name="asyncexample/bin/Debug/ndbapi.dll.mdb" subtype="Code"
buildaction="Exclude" /> </Contents> <References> <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" />

=== modified file 'csharp/ndbapi.i' --- a/csharp/ndbapi.i 2008-01-03 00:04:44 +0000 +++ b/csharp/ndbapi.i 2008-01-04 19:27:41 +0000 @@ -40,6 +40,27 @@ } return ret; } + +%typemap(cstype) NdbDateTime * "System.DateTime"; +%typemap(csin) NdbDateTime * "NdbDateTimeHelper.systemDTtoNdbDT($csinput)"; +%typemap(csout, excode=SWIGEXCODE) NdbDateTime * { + IntPtr cPtr = $imcall;$excode + $csclassname ret = null; + if (cPtr != IntPtr.Zero) { + ret = new $csclassname(cPtr, $owner); + } + return new System.DateTime((int)ret.year, (int)ret.month, (int)ret.day,
(int)ret.hour, (int)ret.minute, (int)ret.second); + +} + +class NdbDateTime +{ + public: + unsigned int year, month, day, hour, minute, second; + NdbDateTime(); +}; + + /* %typemap(in) (MYSQL_TIME *) { if (PyDateTime_Check($input)) {

=== modified file 'csharp/ndbapi/ndbapi.mdp' --- a/csharp/ndbapi/ndbapi.mdp 2008-01-03 00:04:44 +0000 +++ b/csharp/ndbapi/ndbapi.mdp 2008-01-04 19:27:41 +0000 @@ -43,6 +43,13 @@ <File name="generated/NdbTable.cs" subtype="Code" buildaction="Compile" /> <File name="generated/NdbTransaction.cs" subtype="Code" buildaction="Compile" /> <File name="BaseCallback.cs" subtype="Code" buildaction="Compile" /> + <File name="bin/Debug/ndbapi.dll.mdb" subtype="Code" buildaction="Exclude" /> + <File name="generated/SWIGTYPE_p_BYTES.cs" subtype="Code"
buildaction="Exclude" /> + <File name="generated/SWIGTYPE_p_MYSQL_TIME.cs" subtype="Code"
buildaction="Exclude" /> + <File name="generated/SWIGTYPE_p_p_char.cs" subtype="Code"
buildaction="Exclude" /> + <File name="generated/SWIGTYPE_p_voidint.cs" subtype="Code"
buildaction="Exclude" /> + <File name="NdbDateTime.cs" subtype="Code" buildaction="Compile" /> + <File name="generated/NdbDateTime.cs" subtype="Code" buildaction="Compile" /> </Contents> <References> <ProjectReference type="Gac" localcopy="True" refto="System, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" />

=== modified file 'interface/ndbapi/NdbIndexScanOperation.i' --- a/interface/ndbapi/NdbIndexScanOperation.i 2007-11-06 22:59:00 +0000 +++ b/interface/ndbapi/NdbIndexScanOperation.i 2008-01-04 19:27:41 +0000 @@ -142,7 +142,7 @@ Uint32 value = (Uint32)anInputTimestamp; return self->setBound(anAttrId,type,(void *) &value); }; - voidint setBoundDatetime(const char* anAttrName, BoundType type,MYSQL_TIME *
anInputDateTime) { + voidint setBoundDatetime(const char* anAttrName, BoundType type,NdbDateTime *
anInputDateTime) { const NdbDictionary::Column * theColumn =
self->getTable()->getColumn(anAttrName);

Uint64 dtval = ndbFormatDateTime(theColumn,anInputDateTime); @@ -150,7 +150,7 @@ return -1; return self->setBound(anAttrName,type,(void *) &dtval); }; - voidint setBoundDatetime(Uint32 anAttrId, BoundType type, MYSQL_TIME
*anInputDateTime) { + voidint setBoundDatetime(Uint32 anAttrId, BoundType type, NdbDateTime *
anInputDateTime) { const NdbDictionary::Column * theColumn = self->getTable()->getColumn(anAttrId); Uint64 dtval = ndbFormatDateTime(theColumn,anInputDateTime); if (dtval == 1)

=== modified file 'interface/ndbapi/NdbOperation.i' --- a/interface/ndbapi/NdbOperation.i 2007-12-11 17:13:00 +0000 +++ b/interface/ndbapi/NdbOperation.i 2008-01-04 19:27:41 +0000 @@ -1,46 +1,46 @@ // -*- mode: c++ -*- /* ndb-connectors: Wrappers for the NDBAPI - Copyright (C) 2006 MySQL, Inc. - - 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; either version 2 of the License, or - (at your option) any later version. - - 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +Copyright (C) 2006 MySQL, Inc. + +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; either version 2 of the License, or +(at your option) any later version. + +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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */

// ndbFormatString mallocs memory. Return value must be free'd by calling code %newobject ndbformatString; %typemap(newfree) char * "free($1);";

- %ndbexception("NdbApiException") { - $action - if (result==NULL) { - NDB_exception(NdbApiException,"Error Converting Argument Type!"); - } - } +%ndbexception("NdbApiException") { +$action +if (result==NULL) { +NDB_exception(NdbApiException,"Error Converting Argument Type!"); +} +}

char * ndbFormatString(const NdbDictColumn * theColumn, const char* aString,
size_t len);

- %ndbexception("NdbApiException") { +/* %ndbexception("NdbApiException") { $action if (result==1) { NDB_exception(NdbApiException,"Error Converting Argument Type!"); } }

-Uint64 ndbFormatDateTime(const NdbDictColumn * theColumn, MYSQL_TIME *
aDateTime); - +Uint64 ndbFormatDateTime(const NdbDictColumn * theColumn, NdbDateTime *
aDateTime); +*/ %ndbnoexception;

%{ @@ -128,7 +128,7 @@ } }

- Uint64 ndbFormatDateTime(const NdbDictColumn * theColumn, MYSQL_TIME * tm) { + Uint64 ndbFormatDateTime(const NdbDictColumn * theColumn, NdbDateTime * tm) {

// Returns 1 on failure. How much does that suck? @@ -527,7 +527,7 @@ voidint setFloat(Uint32 anAttrId, float intVal) { return self->setValue(anAttrId,intVal); } - voidint setDatetime(const char* anAttrName, MYSQL_TIME * anInputDateTime) { + voidint setDatetime(const char* anAttrName, NdbDateTime * anInputDateTime) {

const NdbDictColumn * theColumn = self->getTable()->getColumn(anAttrName);

@@ -537,7 +537,7 @@ return self->setValue(anAttrName,dtval);

} - voidint setDatetime(Uint32 anAttrId, MYSQL_TIME * anInputDateTime) { + voidint setDatetime(Uint32 anAttrId, NdbDateTime * anInputDateTime) {

const NdbDictColumn * theColumn = self->getTable()->getColumn(anAttrId);

@@ -601,7 +601,7 @@ free(stringVal); return retval; } - voidint equalDatetime(const NdbDictColumn * theColumn, MYSQL_TIME *
anInputDateTime) { + voidint equalDatetime(const NdbDictColumn * theColumn, NdbDateTime *
anInputDateTime) {

Uint64 dtval = ndbFormatDateTime(theColumn,anInputDateTime); if (dtval == 1) @@ -609,7 +609,7 @@ return self->equal(theColumn->getName(),dtval);

} - voidint equalDatetime(const char* anAttrName, MYSQL_TIME * anInputDateTime) { + voidint equalDatetime(const char* anAttrName, NdbDateTime * anInputDateTime) {

const NdbDictColumn * theColumn = self->getTable()->getColumn(anAttrName);

@@ -619,7 +619,7 @@ return self->equal(anAttrName,dtval);

} - voidint equalDatetime(Uint32 anAttrId, MYSQL_TIME * anInputDateTime) { + voidint equalDatetime(Uint32 anAttrId, NdbDateTime * anInputDateTime) {

const NdbDictColumn * theColumn = self->getTable()->getColumn(anAttrId);

=== modified file 'interface/ndbapi/NdbRecAttr.i' --- a/interface/ndbapi/NdbRecAttr.i 2007-11-24 04:14:32 +0000 +++ b/interface/ndbapi/NdbRecAttr.i 2008-01-04 19:27:41 +0000 @@ -185,8 +185,9 @@ return NULL; }

- MYSQL_TIME * getDatetime() { - return NULL; + %ndbnoexception; + NdbDateTime * getDatetime() { + return new NdbDateTime(); }

%ndbexception("NdbApiException") {

=== modified file 'interface/ndbapi/NdbScanFilter.i' --- a/interface/ndbapi/NdbScanFilter.i 2007-11-06 22:59:00 +0000 +++ b/interface/ndbapi/NdbScanFilter.i 2008-01-04 19:27:41 +0000 @@ -228,7 +228,7 @@ Uint32 value = (Uint32)anInputTimestamp; return self->cmp(cond,ColId,(void *) &value); }; - int cmp(NdbOperation * op, BinaryCondition cond, int ColId, MYSQL_TIME
*anInputDateTime) { + int cmp(NdbOperation * op, BinaryCondition cond, int ColId, NdbDateTime *
anInputDateTime) { const NdbDictionary::Column * theColumn = op->getTable()->getColumn(ColId); Uint64 dtval = ndbFormatDateTime(theColumn,anInputDateTime); if (dtval == 1) @@ -332,7 +332,7 @@ Uint32 value = (Uint32)anInputTimestamp; return self->cmp(cond,ColId,(void *) &value); }; - int cmp(NdbOperation * op, BinaryCondition cond, const char * ColName,
MYSQL_TIME *anInputDateTime) { + int cmp(NdbOperation * op, BinaryCondition cond, const char * ColName,
NdbDateTime * anInputDateTime) { int ColId = getColumnId(op,ColName); if (ColId == -1) { return ColId;

=== modified file 'interface/ndbapi/ndbglobals.i' --- a/interface/ndbapi/ndbglobals.i 2007-11-06 22:59:00 +0000 +++ b/interface/ndbapi/ndbglobals.i 2008-01-04 19:27:41 +0000 @@ -62,6 +62,23 @@ char * theString; int theLength; } BYTES; + +class NdbDateTime +{ + public: + unsigned int year, month, day, hour, minute, second; + NdbDateTime(); +}; + +NdbDateTime::NdbDateTime() { + year=0; + month=0; + day=0; + hour=0; + minute=0; + second=0; +} + %}

long long getMicroTime(); @@ -72,15 +89,9 @@ MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 }; - -typedef struct st_mysql_time -{ - unsigned int year, month, day, hour, minute, second; - unsigned long second_part; - my_bool neg; - enum enum_mysql_timestamp_type time_type; -} MYSQL_TIME; */ + + // TODO: This is a little stupid. // Why don't we just typedef these right in the first place %rename(NdbObject) NdbDictObject;

=== modified file 'java/ndbj.i' --- a/java/ndbj.i 2007-12-20 01:16:46 +0000 +++ b/java/ndbj.i 2008-01-04 19:27:41 +0000 @@ -43,7 +43,7 @@

%include "voidint.i"

-%include "mysql_time.i" +%include "NdbDateTime.i"

%include "timestamp.i" %include "byte_array.i"

=== modified file 'java/prj.el' --- a/java/prj.el 2008-01-04 18:19:20 +0000 +++ b/java/prj.el 2008-01-04 19:27:41 +0000 @@ -2,4 +2,5 @@ (jde-set-variables '(jde-enable-abbrev-mode t) '(jde-global-classpath (quote ("./lib" "."))) - '(jde-compiler (quote ("javac" "")))) + '(jde-compiler (quote ("javac" ""))) + '(jde-complete-function (quote jde-complete-minibuf)))