Date: Thursday, December 15, 2005 @ 12:29:06
  Author: gilles
    Path: /cvsroot/carob/carob

Modified: include/DriverResultSet.hpp (1.22 -> 1.23)
          src/DriverResultSet.cpp (1.23 -> 1.24)

Implemented getInt for all supported types
Renamed getInt to getInt32() (java ints)
Introduced getInt (native ints) that justs casts java 32 bits integers into 
native ints


-----------------------------+
 include/DriverResultSet.hpp |   18 ++++++++-
 src/DriverResultSet.cpp     |   79 +++++++++++++++++++++++++++++++++++++++---
 2 files changed, 91 insertions(+), 6 deletions(-)


Index: carob/include/DriverResultSet.hpp
diff -u carob/include/DriverResultSet.hpp:1.22 
carob/include/DriverResultSet.hpp:1.23
--- carob/include/DriverResultSet.hpp:1.22      Wed Dec 14 18:23:43 2005
+++ carob/include/DriverResultSet.hpp   Thu Dec 15 12:29:06 2005
@@ -145,7 +145,7 @@
                                   NullValueException, NotImplementedException,
                                   UnexpectedException);
   /**
-   * Get the value of a column in the current row as an int.
+   * Get the value of a column in the current row as a java int (32 bits)
    * 
    * @param columnIndex the first column is 1, the second is 2,...
    * @return the column value; NULL if SQL NULL
@@ -153,7 +153,21 @@
    *            out of bounds
    * @throw NullValueException if the retrieved value is NULL
    */
-  int32_t                     getInt(int columnIndex) throw (DriverException,
+  int32_t                     getInt32(int columnIndex) throw (DriverException,
+                                  NullValueException, NotImplementedException,
+                                  UnexpectedException);
+  /**
+   * Get the value of a column in the current row as a native integer (system
+   * dependant). <b>Note:</b> be very carefull ! a cast is done on the actual
+   * value, so if your system is less than 32bits, you may encounter data loss!
+   * 
+   * @param columnIndex the first column is 1, the second is 2,...
+   * @return the column value; NULL if SQL NULL
+   * @exception DriverException if the ResultSet is closed or the cursor is
+   *            out of bounds
+   * @throw NullValueException if the retrieved value is NULL
+   */
+  int                         getInt(int columnIndex) throw (DriverException,
                                   NullValueException, NotImplementedException,
                                   UnexpectedException);
   /**
Index: carob/src/DriverResultSet.cpp
diff -u carob/src/DriverResultSet.cpp:1.23 carob/src/DriverResultSet.cpp:1.24
--- carob/src/DriverResultSet.cpp:1.23  Wed Dec 14 18:23:44 2005
+++ carob/src/DriverResultSet.cpp       Thu Dec 15 12:29:06 2005
@@ -209,7 +209,7 @@
 
   std::wostringstream buffer;
 
-  //TODO: big switch on column data type
+  // big switch on column data type
   switch (columnTypeTags[columnIndex - 1])
   {
     case TT_STRING:
@@ -257,7 +257,7 @@
   return buffer.str();
 }
 
-int32_t DriverResultSet::getInt(int columnIndex) throw (DriverException,
+int32_t DriverResultSet::getInt32(int columnIndex) throw (DriverException,
     NullValueException, NotImplementedException, UnexpectedException)
 {
   checkRowAndColPosAndSetNullFlag(columnIndex);
@@ -268,8 +268,79 @@
         + L" column " + toWString(columnIndex) + L" is NULL"));
   }
 
-  //TODO: implement getInt for types other than int...
-  return (data[currentRow][columnIndex - 1].as_int);
+  int ret = -1;
+  // 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(*(wstring*)(data[currentRow][columnIndex - 
1].as_other));
+      //Tries to parse the string as an integer
+      if(!wstringToA<int>(ret, valAsString, std::dec))
+      {
+        //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 (DriverException(L"The value " + valAsString
+              + L" is not a valid int number"));
+        }
+      }
+    }
+    break;
+    case TT_BIGDECIMAL:
+      throw NotImplementedException(L"BigDecimal to int conversion not 
implemented yet.");
+    break;
+    case TT_BOOLEAN:
+      if (((data[currentRow])[columnIndex - 1]).as_bool)
+        ret = 1;
+      else
+        ret = 0;
+    break;
+    case TT_INTEGER:
+      ret = ((data[currentRow])[columnIndex - 1]).as_int;
+    break;
+    case TT_LONG:
+      ret = (int)(((data[currentRow])[columnIndex - 1]).as_long);
+    break;
+    case TT_FLOAT:
+      ret = (int)(((data[currentRow])[columnIndex - 1]).as_float);
+    break;
+    case TT_DOUBLE:
+      ret = (int)(((data[currentRow])[columnIndex - 1]).as_double);
+    break;
+    case TT_BYTE_ARRAY:
+      throw NotImplementedException(L"ByteArray to int conversion not 
implemented yet.");
+    break;
+    case TT_SQL_DATE:
+      throw NotImplementedException(L"SQL Date to int conversion not 
implemented yet.");
+    break;
+    case TT_SQL_TIME:
+      throw NotImplementedException(L"SQL Time to int conversion not 
implemented yet.");
+    break;
+    case TT_SQL_TIMESTAMP:
+      throw NotImplementedException(L"SQL TimeStamp to int conversion not 
implemented yet.");
+    break;
+    case TT_BLOB:
+      throw NotImplementedException(L"Blob to int conversion not implemented 
yet.");
+    break;
+    case TT_JAVA_SERIALIZABLE:
+      throw NotImplementedException(L"SQL TimeStamp to int conversion not 
implemented yet.");
+    break;
+    default:
+      throw NotImplementedException(L"Int conversion not implemented for this 
type yet.");
+  }
+  return ret;
+}
+
+int DriverResultSet::getInt(int columnIndex) throw (DriverException,
+    NullValueException, NotImplementedException, UnexpectedException)
+{
+  return (int)getInt32(columnIndex);
 }
 
 void DriverResultSet::close() throw (SocketIOException, BackendException,

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

Reply via email to