Date: Monday, November 28, 2005 @ 15:58:55
  Author: gilles
    Path: /cvsroot/carob/carob/src

Modified: DriverResultSet.cpp (1.8 -> 1.9)

Implemented toString() function for other types (than string).
Big switch on column metadata to determine type, then conversion for supported 
types
Other types throw NotImplemented Exception


---------------------+
 DriverResultSet.cpp |   61 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 60 insertions(+), 1 deletion(-)


Index: carob/src/DriverResultSet.cpp
diff -u carob/src/DriverResultSet.cpp:1.8 carob/src/DriverResultSet.cpp:1.9
--- carob/src/DriverResultSet.cpp:1.8   Mon Nov 28 13:55:24 2005
+++ carob/src/DriverResultSet.cpp       Mon Nov 28 15:58:55 2005
@@ -19,6 +19,8 @@
  * Contributor(s): 
  */
 
+#include <sstream> //for wostringstream
+
 #include "CarobException.hpp"
 #include "Common.hpp"
 #include "Connection.hpp"
@@ -147,10 +149,67 @@
   if (wasNullFlag)
     return NULL;
 
+  wostringstream buffer;
 
   //TODO: big switch on column data type
+  switch (fields[columnIndex - 1]->getSqlType())
+  {
+    case SQLT_TINYINT:
+      buffer << *(int8_t*)((data[currentRow])[columnIndex - 1]);
+    break;
+    case SQLT_SMALLINT:
+      buffer << *(int16_t*)((data[currentRow])[columnIndex - 1]);
+    break;
+    case SQLT_INTEGER:
+      buffer << *(int32_t*)((data[currentRow])[columnIndex - 1]);
+    break;
+    case SQLT_BIGINT:
+      buffer << *(int64_t*)((data[currentRow])[columnIndex - 1]);
+    break;
+    case SQLT_REAL:
+      buffer << *(float*)((data[currentRow])[columnIndex - 1]);
+    break;
+    case SQLT_FLOAT:
+    case SQLT_DOUBLE:
+      buffer << *(double*)((data[currentRow])[columnIndex - 1]);
+    break;
+    case SQLT_CHAR:
+    case SQLT_VARCHAR:
+    case SQLT_LONGVARCHAR:
+      buffer << *(wstring*)((data[currentRow])[columnIndex - 1]);
+    break;
+    case SQLT_BIT:
+      buffer << (*(int8_t*)((data[currentRow])[columnIndex - 1]) == 0 ? 0 : 1);
+    break;
+    case SQLT_BOOLEAN:
+      buffer << (*(bool*)((data[currentRow])[columnIndex - 1]) == 0 ? L"false" 
: L"true");
+    break;
+ 
+    case SQLT_DECIMAL:
+      //BigDecimal
+    case SQLT_NUMERIC:
+      //BigDecimal
+    case SQLT_DATE:
+    case SQLT_TIME:
+    case SQLT_TIMESTAMP:
+    case SQLT_BINARY:
+    case SQLT_VARBINARY:
+    case SQLT_LONGVARBINARY:
+    case SQLT_OTHER:
+    case SQLT_JAVA_OBJECT:
+    case SQLT_DISTINCT:
+    case SQLT_STRUCT:
+    case SQLT_ARRAY:
+    case SQLT_BLOB:
+    case SQLT_CLOB:
+    case SQLT_REF:
+    case SQLT_DATALINK:
+    default:
+      throw NotImplementedException(L"Type not supported yet");
+  }
+  return (new wstring(buffer.str()));
 
-  return (wstring*)((data[currentRow])[columnIndex - 1]);
+//  return (wstring*)((data[currentRow])[columnIndex - 1]);
 }
 
 int32_t* DriverResultSet::getInt(int32_t columnIndex) throw (SQLException, 

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

Reply via email to