Date: Friday, March 10, 2006 @ 22:18:21
  Author: gilles
    Path: /cvsroot/carob/carob

Modified: include/DriverResultSet.hpp (1.35 -> 1.36)
          src/DriverResultSet.cpp (1.48 -> 1.49)

Added getAsUInt64_t() function. Missing some conversion


-----------------------------+
 include/DriverResultSet.hpp |   18 ++++++++-
 src/DriverResultSet.cpp     |   84 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+), 1 deletion(-)


Index: carob/include/DriverResultSet.hpp
diff -u carob/include/DriverResultSet.hpp:1.35 
carob/include/DriverResultSet.hpp:1.36
--- carob/include/DriverResultSet.hpp:1.35      Fri Mar 10 18:45:48 2006
+++ carob/include/DriverResultSet.hpp   Fri Mar 10 22:18:20 2006
@@ -220,12 +220,28 @@
    *        bounds
    * @throw NullValueException if the retrieved value is NULL
    * @throw ConversionException if the retrieved value cannot be converted to
-   *        a float
+   *        an int64
    */
   int64_t                     getAsInt64(int columnIndex) throw 
(DriverException,
                                   NullValueException, ConversionException,
                                   NotImplementedException, 
UnexpectedException);
   /**
+   * Tries to get the value of a column in the current row as an uint64. If the
+   * value at the given row/col is not of type long, tries to convert it using
+   * wstringToA conversion function.
+   * 
+   * @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 NullValueException if the retrieved value is NULL
+   * @throw ConversionException if the retrieved value cannot be converted to
+   *        an unsigned int64
+   */
+  uint64_t                     getAsUInt64(int columnIndex) throw 
(DriverException,
+                                  NullValueException, ConversionException,
+                                  NotImplementedException, 
UnexpectedException);
+  /**
    * Gets the float value of a column in the current row only if the
    * given column is of float type, throws an exception otherwise.
    * 
Index: carob/src/DriverResultSet.cpp
diff -u carob/src/DriverResultSet.cpp:1.48 carob/src/DriverResultSet.cpp:1.49
--- carob/src/DriverResultSet.cpp:1.48  Fri Mar 10 18:45:48 2006
+++ carob/src/DriverResultSet.cpp       Fri Mar 10 22:18:20 2006
@@ -505,6 +505,90 @@
   return ret;
 }
 
+uint64_t DriverResultSet::getAsUInt64(int columnIndex) throw (DriverException,
+    NullValueException, ConversionException, NotImplementedException,
+    UnexpectedException)
+{
+  checkRowAndColPosAndSetNullFlag(columnIndex);
+
+  if (wasNullFlag)
+  {
+    throw (NullValueException(L"getAsUInt64: Value at row " + 
toWString(currentRow)
+        + L" column " + toWString(columnIndex) + L" is NULL"));
+  }
+
+  uint64_t ret = 0;
+  // big switch on column data type
+  switch (columnTypeTags[columnIndex - 1])
+  {
+    case TT_STRING:
+    { //these bracket to be able to declare loc var without warns
+      wstring valAsString = 
trim(*static_cast<wstring*>((data[currentRow][columnIndex - 1].as_other)));
+      //Tries to parse the string as an integer
+      if(!wstringTo<uint64_t>(ret, valAsString))
+      {
+        //Last chance: is it a boolean ?
+        transform(valAsString.begin(),valAsString.end(), valAsString.begin(), 
tolower);
+        if (L"true" == valAsString)
+          ret = 1;
+        else if (L"false" == valAsString)
+          ret = 0;
+        else //we cannot do more... throw an exception
+        {
+          throw (ConversionException(L"The value " + valAsString
+              + L" is not a valid uint64 number"));
+        }
+      }
+    }
+    break;
+    case TT_BIGDECIMAL:
+      BigDecimal* bd = (static_cast<BigDecimal*>((data[currentRow][columnIndex 
- 1].as_other)));
+      ret = static_cast<uint64_t>(*bd);
+    break;
+    case TT_BOOLEAN:
+      if (((data[currentRow])[columnIndex - 1]).as_bool)
+        ret = 1;
+      else
+        ret = 0;
+    break;
+/* TODO: => check that the number is positive before casting it to uint
+    case TT_INTEGER:
+      ret = static_cast<int64_t>(((data[currentRow])[columnIndex - 1]).as_int);
+    break;
+    case TT_LONG:
+      ret = static_cast<int64_t>(((data[currentRow])[columnIndex - 
1]).as_long);
+    break;
+    case TT_FLOAT:
+      ret = static_cast<int64_t>(((data[currentRow])[columnIndex - 
1]).as_float);
+    break;
+    case TT_DOUBLE:
+      ret = static_cast<int64_t>(((data[currentRow])[columnIndex - 
1]).as_double);
+    break;
+    case TT_BYTE_ARRAY:
+      throw NotImplementedException(L"ByteArray to int64 conversion not 
implemented yet.");
+    break;
+    case TT_SQL_DATE:
+      ret = static_cast<int64_t>(((data[currentRow])[columnIndex - 
1]).as_long);
+    break;
+    case TT_SQL_TIME:
+      ret = static_cast<int64_t>(((data[currentRow])[columnIndex - 1]).as_int);
+    break;
+    case TT_SQL_TIMESTAMP:
+      ret = 
static_cast<int64_t>(static_cast<SQLTimeStamp*>((data[currentRow][columnIndex - 
1].as_other))->time);
+    break;
+    case TT_BLOB:
+      throw NotImplementedException(L"Blob to int64 conversion not implemented 
yet.");
+    break;
+    case TT_JAVA_SERIALIZABLE:
+      throw NotImplementedException(L"Java Serializable to int64 conversion 
not implemented yet.");
+    break;
+*/
+    default:
+      throw NotImplementedException(L"Int64 conversion not implemented for 
this type yet.");
+  }
+  return ret;
+}
+
 float DriverResultSet::getFloat(int columnIndex) throw (DriverException,
     NullValueException, NotImplementedException, UnexpectedException)
 {

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

Reply via email to