Date: Thursday, March 2, 2006 @ 16:01:36
  Author: zsolt
    Path: /cvsroot/carob/carob

Modified: include/DriverResultSet.hpp (1.31 -> 1.32)
          include/ParameterStatement.hpp (1.12 -> 1.13)
          src/DriverResultSet.cpp (1.42 -> 1.43)
          src/ParameterStatement.cpp (1.23 -> 1.24)

- implemented in DriverResultSet public methods: getBlob(), getByteArray(), 
getClob(), and private method: getLargeObject()
- implemented in ParameterStatement setByteArray(), setBlob() and private 
method base64Encode()


--------------------------------+
 include/DriverResultSet.hpp    |   63 +++++++++++++++++++++++++++++++++++++++
 include/ParameterStatement.hpp |   33 ++++++++++++++++++++
 src/DriverResultSet.cpp        |   21 +++++++++++++
 src/ParameterStatement.cpp     |   44 +++++++++++++++++++++++++++
 4 files changed, 161 insertions(+)


Index: carob/include/DriverResultSet.hpp
diff -u carob/include/DriverResultSet.hpp:1.31 
carob/include/DriverResultSet.hpp:1.32
--- carob/include/DriverResultSet.hpp:1.31      Wed Feb 15 12:34:46 2006
+++ carob/include/DriverResultSet.hpp   Thu Mar  2 16:01:36 2006
@@ -278,6 +278,54 @@
                                   UnexpectedException);
 
   /**
+   * Gets the blob data value of a column in the current row only if the
+   * given column is of blob type, throws an exception otherwise.
+   * 
+   * @param columnIndex the first column is 1, the second is 2,...
+   * @return the column value; NULL if SQL NULL
+   * @throw DriverException if the ResultSet is closed or the cursor is out of
+   *        bounds
+   * @throw DriverException if the column is not of type string
+   * @throw NullValueException if the retrieved value is NULL
+   */
+  LargeData&                  getBlob(int columnIndex) throw (DriverException,
+                                  NullValueException, NotImplementedException,
+                                  UnexpectedException)
+                                      { return getLargeObject(columnIndex); }
+
+  /**
+   * Gets the clob data value of a column in the current row only if the
+   * given column is of blob type, throws an exception otherwise.
+   * 
+   * @param columnIndex the first column is 1, the second is 2,...
+   * @return the column value; NULL if SQL NULL
+   * @throw DriverException if the ResultSet is closed or the cursor is out of
+   *        bounds
+   * @throw DriverException if the column is not of type string
+   * @throw NullValueException if the retrieved value is NULL
+   */
+  LargeData&                  getClob(int columnIndex) throw (DriverException,
+                                  NullValueException, NotImplementedException,
+                                  UnexpectedException)
+                                      { return getLargeObject(columnIndex); }
+
+  /**
+   * Gets the byte array value of a column in the current row only if the
+   * given column is of byte array type, throws an exception otherwise.
+   * 
+   * @param columnIndex the first column is 1, the second is 2,...
+   * @return the column value; NULL if SQL NULL
+   * @throw DriverException if the ResultSet is closed or the cursor is out of
+   *        bounds
+   * @throw DriverException if the column is not of type string
+   * @throw NullValueException if the retrieved value is NULL
+   */
+  LargeData&                  getByteArray(int columnIndex) throw 
(DriverException,
+                                  NullValueException, NotImplementedException,
+                                  UnexpectedException)
+                                      { return getLargeObject(columnIndex); }
+
+  /**
    * Closes the remote ResultSet if the ResultSet was streamed else just closes
    * the ResultSet locally.
    */
@@ -413,6 +461,21 @@
                                   throw (DriverException, UnexpectedException);
   /** Clear/delete data, nulls and typeTags vectors */
   void                        clearAllData();
+
+  /**
+   * Gets the large data value of a column in the current row only if the
+   * given column is of blob, clob or byte array type, throws an exception 
otherwise.
+   * 
+   * @param columnIndex the first column is 1, the second is 2,...
+   * @return the column value; NULL if SQL NULL
+   * @throw DriverException if the ResultSet is closed or the cursor is out of
+   *        bounds
+   * @throw DriverException if the column is not of type string
+   * @throw NullValueException if the retrieved value is NULL
+   */
+  LargeData&                  getLargeObject(int columnIndex) throw 
(DriverException,
+                                  NullValueException, NotImplementedException,
+                                  UnexpectedException);
 };
 
 /**
Index: carob/include/ParameterStatement.hpp
diff -u carob/include/ParameterStatement.hpp:1.12 
carob/include/ParameterStatement.hpp:1.13
--- carob/include/ParameterStatement.hpp:1.12   Mon Jan 30 22:57:35 2006
+++ carob/include/ParameterStatement.hpp        Thu Mar  2 16:01:36 2006
@@ -216,6 +216,32 @@
                               throw (DriverException, UnexpectedException);
 
   /**
+   *
+   * This JDBC call will be forwarded to the JDBC driver of the
+   * backend(s) of a sequoia controller. It will encode the buffer
+   * to Base64 after that will set the parameter as a string.
+   *
+   * @param parameterIndex the first parameter is 1...
+   * @param buffer the parameter value
+   * @param len length of the buffer
+   */
+  void                    setByteArray(int parameterIndex, const void *buffer, 
size_t len)
+                              throw (DriverException, UnexpectedException);
+
+  /**
+   *
+   * This JDBC call will be forwarded to the JDBC driver of the
+   * backend(s) of a sequoia controller. It will encode the buffer
+   * to Base64 after that will set the parameter as a string.
+   *
+   * @param parameterIndex the first parameter is 1...
+   * @param buffer the parameter value
+   * @param len length of the buffer
+   */
+  void                    setBlob(int parameterIndex, const void *buffer, 
size_t len)
+                              throw (DriverException, UnexpectedException);
+
+  /**
    * In general, parameter values remain in force for repeated used of a
    * <code>Statement</code>. Setting a parameter value automatically clears
    * its previous value. However, in coms cases, it is useful to immediately
@@ -282,6 +308,13 @@
    * @throws DriverException if a parameter was not set
    */
   std::wstring                compileQuery(bool throwException) throw 
(DriverException);
+
+  /**
+   * Helper - this encode a byte of characters in base64.
+   * @param throwException to throw a NullValueException if a parameter is 
missing
+   * @return the encoded string
+   */
+  std::wstring                base64Encode(const void *buffer, size_t len);
 };
 
 } //namespace CarobNS
Index: carob/src/DriverResultSet.cpp
diff -u carob/src/DriverResultSet.cpp:1.42 carob/src/DriverResultSet.cpp:1.43
--- carob/src/DriverResultSet.cpp:1.42  Fri Feb 24 19:06:00 2006
+++ carob/src/DriverResultSet.cpp       Thu Mar  2 16:01:36 2006
@@ -585,6 +585,27 @@
   return *static_cast<SQLTimeStamp*>((data[currentRow][columnIndex - 
1].as_other));
 }
 
+LargeData& DriverResultSet::getLargeObject(int columnIndex) throw 
(DriverException,
+    NullValueException, NotImplementedException, UnexpectedException)
+{
+  checkRowAndColPosAndSetNullFlag(columnIndex);
+
+  if (wasNullFlag)
+  {
+    throw (NullValueException(L"getLargeData: Value at row " + 
toWString(currentRow)
+        + L" column " + toWString(columnIndex) + L" is NULL"));
+  }
+  
+  if (!(columnTypeTags[columnIndex - 1] == TT_BLOB || 
columnTypeTags[columnIndex - 1] == TT_CLOB || 
+      columnTypeTags[columnIndex - 1] == TT_BYTE_ARRAY))
+  {
+    throw (DriverException(L"getLargeData: Value at row " + 
toWString(currentRow)
+        + L" column " + toWString(columnIndex) + L" is not of type blob, clob 
or byte array"));
+  }
+  
+  return *static_cast<LargeData*>((data[currentRow][columnIndex - 
1].as_other));
+}
+
 void DriverResultSet::close() throw (SocketIOException, BackendException,
     ControllerException, ProtocolException, UnexpectedException)
 {
Index: carob/src/ParameterStatement.cpp
diff -u carob/src/ParameterStatement.cpp:1.23 
carob/src/ParameterStatement.cpp:1.24
--- carob/src/ParameterStatement.cpp:1.23       Mon Feb 20 11:34:08 2006
+++ carob/src/ParameterStatement.cpp    Thu Mar  2 16:01:36 2006
@@ -137,6 +137,39 @@
   for (; iparam != iparam_end; (*iparam++).clear()) ;
 }
 
+const wchar_t base64[] = 
L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+wstring ParameterStatement::base64Encode(const void *buffer, size_t len)
+{
+  unsigned char rc[3];
+  int usedChars;
+  wstring result;
+  char *p = (char *)buffer;
+
+  result.reserve(len*4/3+4);
+
+  while(len > 0)
+  {
+    for (int i = usedChars = 0; i < 3; i++)
+    {
+      if(len) {
+        usedChars++;
+        rc[i] = *p++;
+        len--;
+      }
+      else
+        rc[i] = 0;
+    }
+
+    result.push_back(base64[(rc[0]&0xFC) >> 2]);
+    result.push_back(base64[((rc[0]&0x03) << 4)|((rc[1]&0xF0) >> 4)]);
+    result.push_back(usedChars >= 2 ? base64[((rc[1]&0x0F) << 2) | 
((rc[2]&0xC0) >> 6)] : L'=');
+    result.push_back(usedChars >= 3 ? base64[rc[2]&0x3F] : L'=');
+  }
+
+  return result;
+}
+
 namespace {
   std::locale locC = std::locale::classic();
 }
@@ -450,6 +483,17 @@
     set<CParamType>(parameterIndex, STRING_TAG, x);
 }
 
+void ParameterStatement::setByteArray(int parameterIndex, const void *buffer, 
size_t len)
+    throw (DriverException, UnexpectedException)
+{
+  set<std::wstring>(parameterIndex, BYTES_TAG, base64Encode(buffer, len));  
+}
+
+void ParameterStatement::setBlob(int parameterIndex, const void *buffer, 
size_t len)
+    throw (DriverException, UnexpectedException)
+{
+  set<std::wstring>(parameterIndex, BLOB_TAG, base64Encode(buffer, len));
+}
 
 /*
  * Explicit instantiation of supported/approved setters

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to