------------------------------------------------------------
revno: 107
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: exceptions
timestamp: Sat 2007-05-05 20:22:10 -0700
message:
Support in Java for char*/size_t input typemap and timestamp truncation.
modified:
csharp/ndbapi.i
svn-v2:10@5fca6d9a-db22-0410-b55c-899b0a28da89-trunk-csharp%2fndb.i
java/ndbapi.i ndbapi.i-20070130002924-gcvhapmvh0lu1pkd-3
java/test.java test.java-20070130002924-gcvhapmvh0lu1pkd-4
swig/NdbOperation.i ndboperation.i-20070228021421-qkr4cbpxymyqdrf3-3
=== modified file 'csharp/ndbapi.i'
--- a/csharp/ndbapi.i 2007-05-05 08:08:13 +0000
+++ b/csharp/ndbapi.i 2007-05-06 03:22:10 +0000
@@ -38,6 +38,39 @@
return ret;
}
+%typemap(in) (MYSQL_TIME *) {
+ if (PyDateTime_Check($input)) {
+ MYSQL_TIME * dt = (MYSQL_TIME *)malloc(sizeof(MYSQL_TIME));
+ if (dt==NULL)
+ NDB_exception(NdbApiException,"Failed to allocate a MYSQL_TIME");
+ dt->year = PyDateTime_GET_YEAR($input);
+ dt->month = PyDateTime_GET_MONTH($input);
+ dt->day = PyDateTime_GET_DAY($input);
+ dt->hour = PyDateTime_DATE_GET_HOUR($input);
+ dt->minute = PyDateTime_DATE_GET_MINUTE($input);
+ dt->second = PyDateTime_DATE_GET_SECOND($input);
+ $1 = dt;
+ } else {
+ NDB_exception(NdbApiException,"DateTime argument required!");
+ }
+ }
+
+%typemap(in) (const char* anInputString, size_t len) {
+ /* Check that we are getting a string */
+ if (PyString_Check($input)) {
+ // We are going to try not copying this string, since it's not going to
+ // be modified and we're going to copy it in the main function
+ $1=PyString_AsString($input);
+ $2=PyString_Size($input);
+ } else {
+ NDB_exception(NdbApiException,"Couldn't convert argument");
+ }
+ }
+
+%typemap(freearg) (MYSQL_TIME *) {
+ free((MYSQL_TIME *) $1);
+ }
+
/*%typemap(csfinalize) Ndb_cluster_connection %{
~$csclassname() {
Dispose();
=== modified file 'java/ndbapi.i'
--- a/java/ndbapi.i 2007-05-04 20:45:38 +0000
+++ b/java/ndbapi.i 2007-05-06 03:22:10 +0000
@@ -83,6 +83,40 @@
%typemap(jtype) asynch_callback_t * "Object"
%typemap(jstype) asynch_callback_t * "INdbCallable"
%typemap(javain) asynch_callback_t * "(Object)$javainput"
+
+ /*
+%typemap(in) (MYSQL_TIME *) {
+ if (PyDateTime_Check($input)) {
+ MYSQL_TIME * dt = (MYSQL_TIME *)malloc(sizeof(MYSQL_TIME));
+ if (dt==NULL)
+ NDB_exception(NdbApiException,"Failed to allocate a MYSQL_TIME");
+ dt->year = PyDateTime_GET_YEAR($input);
+ dt->month = PyDateTime_GET_MONTH($input);
+ dt->day = PyDateTime_GET_DAY($input);
+ dt->hour = PyDateTime_DATE_GET_HOUR($input);
+ dt->minute = PyDateTime_DATE_GET_MINUTE($input);
+ dt->second = PyDateTime_DATE_GET_SECOND($input);
+ $1 = dt;
+ } else {
+ NDB_exception(NdbApiException,"DateTime argument required!");
+ }
+ }
+ */
+%typemap(in) (const char* anInputString, size_t len) {
+ /* Check that we are getting a string */
+ $1 = (char *)(jenv->GetStringUTFChars($input,0));
+ $2 = jenv->GetStringLength($input);
+ }
+
+%typemap(in) (Int64 anInputTimestamp) {
+ // Java timestamp is higher precision - so we cut it down
+ $1 = (Int64) ($input / 1000);
+ }
+/*
+%typemap(freearg) (MYSQL_TIME *) {
+ free((MYSQL_TIME *) $1);
+ }
+*/
/*
%pragma(java) modulecode=%{
=== modified file 'java/test.java'
--- a/java/test.java 2007-05-04 20:45:38 +0000
+++ b/java/test.java 2007-05-06 03:22:10 +0000
@@ -64,7 +64,8 @@
s.executeUpdate("CREATE TABLE if not exists " +
table_name +
" (ATTR1 INT UNSIGNED," +
- " ATTR2 INT UNSIGNED NOT NULL," +
+ " ATTR2 varchar(32) not null, " +
+// " ATTR2 INT UNSIGNED NOT NULL," +
" PRIMARY KEY (ATTR1) )" +
" ENGINE=NDBCLUSTER");
} catch (SQLException e) {
@@ -148,7 +149,7 @@
java.math.BigInteger auto_id = myNdb.getAutoIncrementValue(table_name,BATCH_SIZE);
myOperation.equal("ATTR1",auto_id);
- myOperation.setValue("ATTR2", t*BATCH_SIZE+i);
+ myOperation.setString("ATTR2", "monty"+t*BATCH_SIZE+i);
}
=== modified file 'swig/NdbOperation.i'
--- a/swig/NdbOperation.i 2007-05-06 02:34:17 +0000
+++ b/swig/NdbOperation.i 2007-05-06 03:22:10 +0000
@@ -19,9 +19,39 @@
// ndbFormatString mallocs memory. Return value must be free'd by calling code
%newobject ndbformatString;
+
+#if defined(SWIGJAVA)
+ %javaexception("NdbApiException") {
+#else
+ %exception { // this applies to everything until we clear it
+#endif
+ $action
+ if (result==NULL) {
+ NDB_exception(NdbApiException,"Error Converting Argument Type!");
+ }
+ }
+
char * ndbFormatString(const NdbDictionary::Column * theColumn, const char* aString,
size_t len);
+
+#if defined(SWIGJAVA)
+ %javaexception("NdbApiException") {
+#else
+ %exception { // this applies to everything until we clear it
+#endif
+ $action
+ if (result==1) {
+ NDB_exception(NdbApiException,"Error Converting Argument Type!");
+ }
+ }
+
Uint64 ndbFormatDateTime(const NdbDictionary::Column * theColumn, MYSQL_TIME *
aDateTime);
+#if defined(SWIGJAVA)
+ %nojavaexception;
+#else
+ %noexception; // clear exception handler
+#endif
+
%{
char * ndbFormatString(const NdbDictionary::Column * theColumn, const char* aString,
size_t len) {
@@ -32,7 +62,6 @@
return 0;
}
if ((!theColumn) || (len>65535)) {
- NDB_exception(NdbApiException,"Invalid input for (var)char column");
return NULL;
}
@@ -40,7 +69,6 @@
case NDB_TYPE_VARCHAR:
case NDB_TYPE_VARBINARY:
if (len>255) {
- NDB_exception(NdbApiException,"Value to long for column");
return NULL;
} else {
char * buf = (char *)malloc((len+1)*sizeof(char *));
@@ -66,7 +94,6 @@
case NDB_TYPE_CHAR:
case NDB_TYPE_BINARY:
if (len>255) {
- NDB_exception(NdbApiException,"Value to long for column");
return NULL;
} else {
int colLength = theColumn->getLength();
@@ -77,19 +104,15 @@
}
break;
default:
- NDB_exception(NdbApiException,"Can't set string value on non-string column");
return NULL;
}
-fail:
- return NULL;
}
Uint64 ndbFormatDateTime(const NdbDictionary::Column * theColumn, MYSQL_TIME * tm) {
- // If we are at this point - we are assuming that a typemap has converted a date or
time
- // to the appropriate format. The per-language storage is going to be too different
to
- // handle this here since we don't have access to str_to_datetime()
+ // Returns 1 on failure. How much does that suck?
+
char dt_buf[20];
Uint64 val = 0;
switch(theColumn->getType()) {
@@ -115,12 +138,9 @@
}
break;
default:
- NDB_exception(NdbApiException,"Can't set DateTime on a non-datetime column");
- return -1;
+ return 1;
}
return val;
-fail:
- return -1;
}
%}
@@ -376,6 +396,8 @@
const NdbDictionary::Column * theColumn =
self->getTable()->getColumn(anAttrName);
Uint64 dtval = ndbFormatDateTime(theColumn,anInputDateTime);
+ if (dtval == 1)
+ return dtval;
return self->setValue(anAttrName,dtval);
}
@@ -384,6 +406,8 @@
const NdbDictionary::Column * theColumn =
self->getTable()->getColumn(anAttrId);
Uint64 dtval = ndbFormatDateTime(theColumn,anInputDateTime);
+ if (dtval == 1)
+ return dtval;
return self->setValue(anAttrId,dtval);
}
int setTimestamp(const char* anAttrName, Int64 anInputTimestamp) {
| Thread |
|---|
| • Rev 107: Support in Java for char*/size_t input typemap and timestamp truncation. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/except... | Monty Taylor | 6 May |