Rodolfo Ochoa has proposed merging lp:~zorba-coders/zorba/bug1109853 into 
lp:zorba/jdbc-module.

Commit message:
BLOB support added

Requested reviews:
  Rodolfo Ochoa (rodolfo-ochoa)
Related bugs:
  Bug #1109853 in Zorba: "add BLOB support for JDBC module"
  https://bugs.launchpad.net/zorba/+bug/1109853

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug1109853/+merge/145525

BLOB support added
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug1109853/+merge/145525
Your team Zorba Coders is subscribed to branch lp:zorba/jdbc-module.
=== modified file 'include/javaids.h'
--- include/javaids.h	2013-01-05 01:04:21 +0000
+++ include/javaids.h	2013-01-30 01:14:22 +0000
@@ -77,6 +77,7 @@
   jmethodID getInt;
   jmethodID getDouble;
   jmethodID getString;
+  jmethodID getBLOB;
 };
 class JavaResultSetMetadata {
 public:
@@ -120,6 +121,13 @@
   jmethodID getParameterClassName;
   jmethodID getParameterType;
 };
+class JavaBlob {
+public:
+  bool init();
+  jclass classID;
+  jmethodID getBytes;
+  jmethodID length;
+};
 
 
 }}; // namespace zorba, jdbc

=== modified file 'include/jdbc.h'
--- include/jdbc.h	2013-01-09 19:41:52 +0000
+++ include/jdbc.h	2013-01-30 01:14:22 +0000
@@ -51,6 +51,7 @@
 extern JavaResultSetMetadata jResultSetMetadata;
 extern JavaPreparedStatement jPreparedStatement;
 extern JavaParameterMetadata jParameterMetadata;
+extern JavaBlob              jBlob;
 extern bool isOutputJSON;
 
 #define CHECK_EXCEPTION  if ((lException = env->ExceptionOccurred())) throw JavaException();

=== modified file 'include/sqltypes.h'
--- include/sqltypes.h	2012-12-22 14:35:53 +0000
+++ include/sqltypes.h	2013-01-30 01:14:22 +0000
@@ -71,6 +71,8 @@
     static void init();
     static bool isInt(long lType);
     static bool isFloat(long lType);
+    static bool isString(long lType);
+    static bool isBLOB(long lType);
 
 };
 

=== modified file 'src/jdbc.xq.src/connection/connectionoptions.cpp'
--- src/jdbc.xq.src/connection/connectionoptions.cpp	2012-12-27 22:13:59 +0000
+++ src/jdbc.xq.src/connection/connectionoptions.cpp	2013-01-30 01:14:22 +0000
@@ -67,6 +67,4 @@
   return ItemSequence_t(new SingletonItemSequence(result));
 }
 
-
-
 }}; // namespace zorba, jdbc

=== modified file 'src/jdbc.xq.src/javaids.cpp'
--- src/jdbc.xq.src/javaids.cpp	2013-01-05 01:04:21 +0000
+++ src/jdbc.xq.src/javaids.cpp	2013-01-30 01:14:22 +0000
@@ -70,6 +70,7 @@
     getInt = env->GetMethodID(classID, "getInt", "(I)I");
     getDouble = env->GetMethodID(classID, "getDouble", "(I)D");
     getString = env->GetMethodID(classID, "getString", "(I)Ljava/lang/String;");
+    getBLOB = env->GetMethodID(classID, "getBlob", "(I)Ljava/sql/Blob;");
     return true;
   }
   bool JavaResultSetMetadata::init() {
@@ -111,7 +112,12 @@
     getParameterType = env->GetMethodID(classID, "getParameterType", "(I)I");
     return true;
   }
-
+  bool JavaBlob::init() {
+    classID = env->FindClass("java/sql/Blob");
+    getBytes = env->GetMethodID(classID, "getBytes", "(JI)[B");
+    length = env->GetMethodID(classID, "length", "()J");
+    return true;
+  }
 
 }}; // namespace zorba, jdbc
 

=== modified file 'src/jdbc.xq.src/jdbc.cpp'
--- src/jdbc.xq.src/jdbc.cpp	2013-01-09 22:41:07 +0000
+++ src/jdbc.xq.src/jdbc.cpp	2013-01-30 01:14:22 +0000
@@ -69,6 +69,7 @@
 JavaResultSetMetadata jResultSetMetadata;
 JavaPreparedStatement jPreparedStatement;
 JavaParameterMetadata jParameterMetadata;
+JavaBlob              jBlob;
 bool isOutputJSON = true;
 
 zorba::ExternalFunction* 
@@ -333,6 +334,7 @@
     jResultSetMetadata.init();
     jPreparedStatement.init();
     jParameterMetadata.init();
+    jBlob.init();
     SQLTypes::init();
   JDBC_MODULE_CATCH
 }

=== modified file 'src/jdbc.xq.src/jsonitemsequence.cpp'
--- src/jdbc.xq.src/jsonitemsequence.cpp	2012-12-30 14:54:17 +0000
+++ src/jdbc.xq.src/jsonitemsequence.cpp	2013-01-30 01:14:22 +0000
@@ -78,17 +78,43 @@
           double value = env->CallDoubleMethod(oResultSet, jResultSet.getDouble, i+1);
           CHECK_EXCEPTION
           aValue = itemFactory->createDouble(value);
-        } else {
-          jstring sValue = (jstring) env->CallObjectMethod(oResultSet, jResultSet.getString, i+1);
-          CHECK_EXCEPTION
-          if (sValue!=NULL) {
-            const char *value = env->GetStringUTFChars(sValue, 0);
-            CHECK_EXCEPTION
-            aValue = itemFactory->createString(String(value));
-            env->ReleaseStringUTFChars(sValue, value);
-          } else {
-            aValue = itemFactory->createJSONNull();
-          }
+        } else if (SQLTypes::isString(columnTypes[i])) {
+          jstring sValue = (jstring) env->CallObjectMethod(oResultSet, jResultSet.getString, i+1);
+          CHECK_EXCEPTION
+          if (sValue!=NULL) {
+            const char *value = env->GetStringUTFChars(sValue, 0);
+            CHECK_EXCEPTION
+            aValue = itemFactory->createString(String(value));
+            env->ReleaseStringUTFChars(sValue, value);
+          } else {
+            aValue = itemFactory->createJSONNull();
+          }
+        } else if (SQLTypes::isString(columnTypes[i])) {
+          jstring sValue = (jstring) env->CallObjectMethod(oResultSet, jResultSet.getString, i+1);
+          CHECK_EXCEPTION
+          if (sValue!=NULL) {
+            const char *value = env->GetStringUTFChars(sValue, 0);
+            CHECK_EXCEPTION
+            aValue = itemFactory->createString(String(value));
+            env->ReleaseStringUTFChars(sValue, value);
+          } else {
+            aValue = itemFactory->createJSONNull();
+          }
+        } else if (SQLTypes::isBLOB(columnTypes[i])) {
+          jobject oBlob = env->CallObjectMethod(oResultSet, jResultSet.getBLOB, i+1);
+          CHECK_EXCEPTION
+          if (oBlob!=NULL) {
+            jint length = env->CallIntMethod(oBlob, jBlob.length);
+            CHECK_EXCEPTION
+            jbyteArray bytes  = (jbyteArray) env->CallObjectMethod(oBlob, jBlob.getBytes, 1, length);
+            CHECK_EXCEPTION
+            const char* byteString = (const char*)(env->GetByteArrayElements(bytes, 0));
+            aValue = itemFactory->createBase64Binary(byteString, length);
+          } else {
+            aValue = itemFactory->createJSONNull();
+          } 
+        } else if (columnTypes[i]==SQLTypes::_NULL) {
+            aValue = itemFactory->createJSONNull();
         }
         elements.push_back(std::pair<zorba::Item, zorba::Item>(aKey, aValue));
       }

=== modified file 'src/jdbc.xq.src/sqltypes.cpp'
--- src/jdbc.xq.src/sqltypes.cpp	2012-12-24 01:58:02 +0000
+++ src/jdbc.xq.src/sqltypes.cpp	2013-01-30 01:14:22 +0000
@@ -66,48 +66,63 @@
   TypesLoaded = true;
     jclass cTypes = env->FindClass("java/sql/Types");
     ARRAY    = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "ARRAY", "I"));
-    BIGINT   = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "BIGINT", "I"));
-    BINARY   = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "BINARY", "I"));
-    BIT      = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "BIT", "I"));
-    BLOB     = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "BLOB", "I"));
+    BIGINT   = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "BIGINT", "I"));  //***
+    BINARY   = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "BINARY", "I"));  //***
+    BIT      = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "BIT", "I"));  //***
+    BLOB     = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "BLOB", "I"));  ///***
     BOOLEAN  = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "BOOLEAN", "I"));
-    CHAR     = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "CHAR", "I"));
-    CLOB     = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "CLOB", "I"));
+    CHAR     = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "CHAR", "I"));  //**
+    CLOB     = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "CLOB", "I"));  //***
     DATALINK = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "DATALINK", "I"));
-    DATE     = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "DATE", "I"));
-    DECIMAL  = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "DECIMAL", "I"));
-    DOUBLE   = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "DOUBLE", "I"));
-    FLOAT    = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "FLOAT", "I"));
-    INTEGER  = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "INTEGER", "I"));
+    DATE     = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "DATE", "I"));  //----
+    DECIMAL  = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "DECIMAL", "I"));  //***
+    DOUBLE   = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "DOUBLE", "I"));   ///****
+    FLOAT    = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "FLOAT", "I"));   ///***
+    INTEGER  = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "INTEGER", "I"));  //***
     JAVA_OBJECT   = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "JAVA_OBJECT", "I"));
-    LONGVARCHAR   = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "LONGVARCHAR", "I"));
-    LONGNVARCHAR  = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "LONGNVARCHAR", "I"));
-    LONGVARBINARY = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "LONGVARBINARY", "I"));
-    NCHAR     = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "NCHAR", "I"));
-    NCLOB     = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "NCLOB", "I"));
-    _NULL     = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "NULL", "I"));
-    NUMERIC   = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "NUMERIC", "I"));
-    NVARCHAR  = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "NVARCHAR", "I"));
+    LONGVARCHAR   = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "LONGVARCHAR", "I"));  //**
+    LONGNVARCHAR  = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "LONGNVARCHAR", "I"));  //**
+    LONGVARBINARY = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "LONGVARBINARY", "I"));  //***
+    NCHAR     = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "NCHAR", "I"));  //***
+    NCLOB     = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "NCLOB", "I"));  //**
+    _NULL     = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "NULL", "I"));   //***
+    NUMERIC   = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "NUMERIC", "I"));  //**
+    NVARCHAR  = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "NVARCHAR", "I"));  //***
     OTHER     = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "OTHER", "I"));
-    REAL      = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "REAL", "I"));
+    REAL      = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "REAL", "I"));   //***
     REF       = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "REF", "I"));
     ROWID     = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "ROWID", "I"));
-    SMALLINT  = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "SMALLINT", "I"));
-    SQLXML    = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "SQLXML", "I"));
-    TIME      = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "TIME", "I"));
-    TIMESTAMP = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "TIMESTAMP", "I"));
-    TINYINT   = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "TINYINT", "I"));
-    VARBINARY = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "VARBINARY", "I"));
-    VARCHAR   = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "VARCHAR", "I"));
+    SMALLINT  = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "SMALLINT", "I"));  //***
+    SQLXML    = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "SQLXML", "I"));  //--
+    TIME      = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "TIME", "I"));  //---
+    TIMESTAMP = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "TIMESTAMP", "I"));  //---
+    TINYINT   = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "TINYINT", "I")); //***
+    VARBINARY = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "VARBINARY", "I"));  //**
+    VARCHAR   = env->GetStaticIntField(cTypes, env->GetStaticFieldID(cTypes, "VARCHAR", "I"));  //***
+}
+
+bool SQLTypes::isBLOB(long lType) {
+  return (
+          (lType == BINARY) || (lType == BLOB) || (lType==LONGVARBINARY) || (lType==VARBINARY) ||
+          (lType == ARRAY) || (lType == DATALINK) || (lType==JAVA_OBJECT) || (lType==OTHER) ||
+          (lType == REF)
+         );
+}
+
+bool SQLTypes::isString(long lType) {
+  return (
+          (lType == CHAR) || (lType == CLOB) || (lType == LONGVARCHAR) || (lType==LONGNVARCHAR) || 
+          (lType==NCHAR) || (lType==NCLOB) || (lType==NVARCHAR) || (lType==VARCHAR) ||
+          (lType==DATE) || (lType==TIME) || (lType==TIMESTAMP) || (lType==SQLXML) 
+          );
 }
 
 bool SQLTypes::isInt(long lType){
-  return ( (lType == INTEGER) || (lType==BIGINT) || (lType==TINYINT) || (lType==BIT) );
+  return ( (lType == INTEGER) || (lType==BIGINT) || (lType==TINYINT) || (lType==SMALLINT) || (lType==BIT) );
 }
 
 bool SQLTypes::isFloat(long lType){
   return ((lType == DECIMAL) || (lType==DOUBLE) || (lType==FLOAT) || (lType==NUMERIC) || (lType==REAL) );
 }
 
-
 }}; // namespace zorba, jdbc

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to