------------------------------------------------------------
revno: 89
revision-id: monty@stripped
parent: monty@stripped
parent: mikie@stripped
committer: Monty Taylor <monty@stripped>
branch nick: mika-merge
timestamp: Fri 2007-04-27 16:28:54 -0700
message:
Merged changes from Mika.
modified:
perl/swig/perl_ndbrecattr_typemap.i
perl_ndbrecattr_type-20070426145807-eyq5m0w83sabygjh-1
swig/NdbOperation.i ndboperation.i-20070228021421-qkr4cbpxymyqdrf3-3
------------------------------------------------------------
revno: 83.1.2
merged: mikie@stripped
parent: mikie@stripped
committer: Mika Raento <mikie@stripped>
branch nick: devel-mine-new3
timestamp: Fri 2007-04-27 16:35:25 +0300
message:
support for setValue on most datatypes
support for value_any for perl
=== modified file 'perl/swig/perl_ndbrecattr_typemap.i'
--- a/perl/swig/perl_ndbrecattr_typemap.i 2007-04-26 15:30:02 +0000
+++ b/perl/swig/perl_ndbrecattr_typemap.i 2007-04-27 13:35:25 +0000
@@ -1,3 +1,51 @@
+%{
+#include <my_time.h>
+
+void factor_HHMMSS(MYSQL_TIME *tm, int int_time) {
+ if(int_time < 0) {
+ tm->neg = true; int_time = - int_time;
+ }
+ tm->hour = int_time/10000;
+ tm->minute = int_time/100 % 100;
+ tm->second = int_time % 100;
+}
+
+void factor_YYYYMMDD(MYSQL_TIME *tm, int int_date) {
+ tm->year = int_date/10000 % 10000;
+ tm->month = int_date/100 % 100;
+ tm->day = int_date % 100;
+}
+
+void field_to_tm(MYSQL_TIME *tm, const NdbRecAttr &rec) {
+ int int_date = -1, int_time = -99;
+ Uint64 datetime;
+
+ bzero (tm, sizeof(MYSQL_TIME));
+ switch(rec.getType()) {
+ case NdbDictionary::Column::Datetime :
+ datetime = rec.u_64_value();
+ int_date = datetime / 1000000;
+ int_time = datetime - (unsigned long long) int_date * 1000000;
+ break;
+ case NdbDictionary::Column::Time :
+ int_time = sint3korr(rec.aRef());
+ break;
+ case NdbDictionary::Column::Date :
+ int_date = uint3korr(rec.aRef());
+ tm->day = (int_date & 31); // five bits
+ tm->month = (int_date >> 5 & 15); // four bits
+ tm->year = (int_date >> 9);
+ return;
+ default:
+ assert(0);
+ }
+ if(int_time != -99)factor_HHMMSS(tm, int_time);
+ if(int_date != -1) factor_YYYYMMDD(tm, int_date);
+}
+
+
+%}
+
%typemap(in, numinputs=0) const NdbRecAttr** OutValueProxy (NdbRecAttr* temp) {
temp=0;
$1=&temp;
@@ -11,17 +59,19 @@
if (rec->isNULL()) {
$result=newSV(0);
} else {
+ char dt_buf[20];
+ MYSQL_TIME tm;
switch(rec->getType()) {
case NDB_TYPE_CHAR:
case NDB_TYPE_BINARY:
- $result=newSVpv(rec->aRef(), rec->get_size_in_bytes());
+ $result=newSVpvn(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);
+ $result=newSVpvn(buf, len);
break;
case NDB_TYPE_TINYINT:
$result=newSViv(rec->char_value());
@@ -35,6 +85,38 @@
case NDB_TYPE_INT:
$result=newSViv(rec->int32_value());
break;
+ case NDB_TYPE_TINYUNSIGNED:
+ $result=newSVuv(rec->u_char_value());
+ break;
+ case NDB_TYPE_SMALLUNSIGNED:
+ $result=newSVuv(rec->u_short_value());
+ break;
+ case NDB_TYPE_MEDIUMUNSIGNED:
+ $result=newSVuv(uint3korr(rec->aRef()));
+ break;
+ case NDB_TYPE_UNSIGNED:
+ $result=newSVuv(rec->u_32_value());
+ break;
+
+ case NDB_TYPE_DATETIME:
+ case NDB_TYPE_DATE:
+ case NDB_TYPE_TIME:
+ field_to_tm(&tm, *rec);
+ switch(rec->getType()) {
+ case NDB_TYPE_DATETIME:
+ snprintf(dt_buf, 20, "%04d-%02d-%02d %02d:%02d:%02d", tm.year,
tm.month,
+ tm.day, tm.hour, tm.minute, tm.second);
+ break;
+ case NDB_TYPE_DATE:
+ snprintf(dt_buf, 20, "%04d-%02d-%02d",tm.year, tm.month, tm.day);
+ break;
+ case NDB_TYPE_TIME:
+ snprintf(dt_buf, 20, "%s%02d:%02d:%02d", tm.neg ? "-" : "" ,
+ tm.hour, tm.minute, tm.second);
+ break;
+ }
+ $result=newSVpv(dt_buf, 0);
+ break;
}
}
argvi++;
=== modified file 'swig/NdbOperation.i'
--- a/swig/NdbOperation.i 2007-04-26 15:30:02 +0000
+++ b/swig/NdbOperation.i 2007-04-27 13:35:25 +0000
@@ -17,6 +17,98 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+%{
+ #include <my_time.h>
+
+ typedef int (NdbOperation::*bufMethodPtr)(const char* attr, const char* buf);
+ typedef int (NdbOperation::*uint64MethodPtr)(const char* attr, Uint64 value);
+ int callNdbOperationBufMethod(NdbOperation& op, bufMethodPtr m, uint64MethodPtr
um,
+ const char* anAttr, const char* aString, int len) {
+ if (aString==0) {
+ return (op.*m)(anAttr, aString);
+ }
+ const NdbDictionary::Column * theColumn = op.getTable()->getColumn(anAttr);
+ if (!theColumn) return -1;
+ if (len>65535) return -1;
+ switch(theColumn->getType()) {
+ case NDB_TYPE_VARCHAR:
+ case NDB_TYPE_VARBINARY:
+ if (len>255) {
+ return -1;
+ } else {
+ char buf[257];
+ unsigned char lowb=len;
+ buf[0]=lowb;
+ memcpy(buf+1, aString, len);
+ return (op.*m)(anAttr, buf);
+ }
+ break;
+ case NDB_TYPE_LONGVARCHAR:
+ case NDB_TYPE_LONGVARBINARY:
+ {
+ char* buf=(char*)malloc(len+2);
+ unsigned char lowb=len & 0xff;
+ unsigned char highb=len << 8;
+ buf[1]=highb;
+ buf[0]=lowb;
+ memcpy(buf+2, aString, len);
+ int ret=(op.*m)(anAttr, buf);
+ free(buf);
+ return ret;
+ }
+ break;
+ case NDB_TYPE_CHAR:
+ case NDB_TYPE_BINARY:
+ if (len>255) {
+ return -1;
+ } else {
+ char buf[256];
+ memset(buf, ' ', 256);
+ memcpy(buf, aString, len);
+ return (op.*m)(anAttr, buf);
+ }
+ break;
+ case NDB_TYPE_DATETIME:
+ case NDB_TYPE_DATE:
+ case NDB_TYPE_TIME:
+ {
+ MYSQL_TIME tm;
+ bzero(&tm, sizeof(MYSQL_TIME));
+ int was_cut;
+ char dt_buf[20];
+ str_to_datetime(aString, len, &tm, 0, &was_cut);
+ switch(theColumn->getType()) {
+ case NDB_TYPE_DATETIME:
+ {
+ snprintf(dt_buf, 20, "%04d%02d%02d%02d%02d%02d",
+ tm.year, tm.month, tm.day, tm.hour, tm.minute,
tm.second);
+ Uint64 val=strtoull(dt_buf, 0, 10);
+ return (op.*um)(anAttr, val);
+ }
+ break;
+ case NDB_TYPE_TIME:
+ {
+ snprintf(dt_buf, 20, "%02d%02d%02d",
+ tm.hour, tm.minute, tm.second);
+ int val=strtol(dt_buf, 0, 10);
+ int3store(dt_buf, val);
+ }
+ break;
+ case NDB_TYPE_DATE:
+ {
+ int val=(tm.year << 9) | (tm.month << 5) |
tm.day;
+ int3store(dt_buf, val);
+ }
+ break;
+ }
+ return (op.*m)(anAttr, dt_buf);
+ }
+ default:
+ return -1;
+ }
+ }
+%}
+
class NdbOperation {
friend class Ndb;
@@ -72,7 +164,7 @@
$action
if (result==-1) {
NdbError err = arg1->getNdbError();
- SWIG_exception(SWIG_RuntimeError,err.message);
+ SWIG_exception(SWIG_RuntimeError,err.message);
}
}
@@ -80,14 +172,14 @@
%rename(setValueU) setValue(const char *, Uint32);
%rename(setValueU64) setValue(const char *, Uint64);
- %rename(setVal) setValue(const char* anAttrName, const char* aValue);
+ //%rename(setVal) setValue(const char* anAttrName, const char* aValue);
%rename(setVal) setValue(const char* anAttrName, Int32 aValue);
%rename(setVal) setValue(const char* anAttrName, Uint32 aValue);
%rename(setVal) setValue(const char* anAttrName, Uint64 aValue);
%rename(setVal) setValue(const char* anAttrName, Int64 aValue);
%rename(setVal) setValue(const char* anAttrName, float aValue);
%rename(setVal) setValue(const char* anAttrName, double aValue);
- %rename(setVal) setValue(Uint32 anAttrId, const char* aValue);
+ //%rename(setVal) setValue(Uint32 anAttrId, const char* aValue);
%rename(setVal) setValue(Uint32 anAttrId, Int32 aValue);
%rename(setVal) setValue(Uint32 anAttrId, Uint32 aValue);
%rename(setVal) setValue(Uint32 anAttrId, Int64 aValue);
@@ -98,14 +190,14 @@
#endif
- int setValue(const char* anAttrName, const char* aValue);
+ //int setValue(const char* anAttrName, const char* aValue);
int setValue(const char* anAttrName, Int32 aValue);
int setValue(const char* anAttrName, Uint32 aValue);
int setValue(const char* anAttrName, Uint64 aValue);
int setValue(const char* anAttrName, Int64 aValue);
int setValue(const char* anAttrName, float aValue);
int setValue(const char* anAttrName, double aValue);
- int setValue(Uint32 anAttrId, const char* aValue);
+ //int setValue(Uint32 anAttrId, const char* aValue);
int setValue(Uint32 anAttrId, Int32 aValue);
int setValue(Uint32 anAttrId, Uint32 aValue);
int setValue(Uint32 anAttrId, Int64 aValue);
@@ -226,6 +318,15 @@
NdbRecAttr* getValue(const NdbDictionary::Column* col) {
return self->getValue(col,NULL);
}
+
+ %exception { // this applies to everything until we clear it
+ $action
+ if (result==-1) {
+ NdbError err = arg1->getNdbError();
+ SWIG_exception(SWIG_RuntimeError,err.message);
+ }
+ }
+
int equalNull(const char* anAttrName) {
return self->equal(anAttrName, (char*)0);
}
@@ -234,22 +335,16 @@
}
%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);
- }
- }
+ bufMethodPtr m=&NdbOperation::equal;
+ uint64MethodPtr um=&NdbOperation::equal;
+ return callNdbOperationBufMethod(*self, m, um, anAttrName, aString, len);
+ }
+ %cstring_input_binary(const char *aString, size_t len);
+ int setVal(const char* anAttrName, const char* aString, size_t len) {
+ bufMethodPtr m=&NdbOperation::setValue;
+ uint64MethodPtr um=&NdbOperation::setValue;
+ return callNdbOperationBufMethod(*self, m, um, anAttrName, aString, len);
+ }
+ %exception; // clear exception handler
};
| Thread |
|---|
| • Rev 89: Merged changes from Mika. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/mika-merge | Monty Taylor | 28 Apr |