Date: Thursday, March 9, 2006 @ 10:46:43
Author: gilles
Path: /cvsroot/carob/carob
Modified: include/DriverResultSet.hpp (1.33 -> 1.34)
src/DriverResultSet.cpp (1.46 -> 1.47)
Enabled recent bigdecimal conversions
Added getAsDouble
-----------------------------+
include/DriverResultSet.hpp | 14 +++
src/DriverResultSet.cpp | 169 ++++++++++++++++++++++++++++++++++++++----
2 files changed, 169 insertions(+), 14 deletions(-)
Index: carob/include/DriverResultSet.hpp
diff -u carob/include/DriverResultSet.hpp:1.33
carob/include/DriverResultSet.hpp:1.34
--- carob/include/DriverResultSet.hpp:1.33 Tue Mar 7 12:17:44 2006
+++ carob/include/DriverResultSet.hpp Thu Mar 9 10:46:43 2006
@@ -269,6 +269,20 @@
NullValueException, NotImplementedException,
UnexpectedException);
/**
+ * Tries to get the value of a column in the current row as a double.
+ *
+ * @param columnIndex the first column is 1, the second is 2,...
+ * @return the column value converted into a double
+ * @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
+ * a double
+ */
+ double getAsDouble(int columnIndex) throw
(DriverException,
+ NullValueException, ConversionException,
+ NotImplementedException,
UnexpectedException);
+ /**
* Gets the timestamp value of a column in the current row only if the
* given column is of timestamp type, throws an exception otherwise.
*
Index: carob/src/DriverResultSet.cpp
diff -u carob/src/DriverResultSet.cpp:1.46 carob/src/DriverResultSet.cpp:1.47
--- carob/src/DriverResultSet.cpp:1.46 Tue Mar 7 12:29:39 2006
+++ carob/src/DriverResultSet.cpp Thu Mar 9 10:46:43 2006
@@ -454,7 +454,7 @@
else //we cannot do more... throw an exception
{
throw (ConversionException(L"The value " + valAsString
- + L" is not a valid int number"));
+ + L" is not a valid int64 number"));
}
}
}
@@ -470,10 +470,10 @@
ret = 0;
break;
case TT_INTEGER:
- ret = ((data[currentRow])[columnIndex - 1]).as_int;
+ ret = static_cast<int64_t>(((data[currentRow])[columnIndex - 1]).as_int);
break;
case TT_LONG:
- ret = (((data[currentRow])[columnIndex - 1]).as_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);
@@ -482,25 +482,25 @@
ret = static_cast<int64_t>(((data[currentRow])[columnIndex -
1]).as_double);
break;
case TT_BYTE_ARRAY:
- throw NotImplementedException(L"ByteArray to int conversion not
implemented yet.");
+ throw NotImplementedException(L"ByteArray to int64 conversion not
implemented yet.");
break;
case TT_SQL_DATE:
- ret = (((data[currentRow])[columnIndex - 1]).as_long);
+ ret = static_cast<int64_t>(((data[currentRow])[columnIndex -
1]).as_long);
break;
case TT_SQL_TIME:
- ret = ((data[currentRow])[columnIndex - 1]).as_int;
+ ret = static_cast<int64_t>(((data[currentRow])[columnIndex - 1]).as_int);
break;
case TT_SQL_TIMESTAMP:
- ret = static_cast<SQLTimeStamp*>((data[currentRow][columnIndex -
1].as_other))->time;
+ ret =
static_cast<int64_t>(static_cast<SQLTimeStamp*>((data[currentRow][columnIndex -
1].as_other))->time);
break;
case TT_BLOB:
- throw NotImplementedException(L"Blob to int conversion not implemented
yet.");
+ throw NotImplementedException(L"Blob to int64 conversion not implemented
yet.");
break;
case TT_JAVA_SERIALIZABLE:
- throw NotImplementedException(L"Java Serializable to int conversion not
implemented yet.");
+ throw NotImplementedException(L"Java Serializable to int64 conversion
not implemented yet.");
break;
default:
- throw NotImplementedException(L"Int conversion not implemented for this
type yet.");
+ throw NotImplementedException(L"Int64 conversion not implemented for
this type yet.");
}
return ret;
}
@@ -537,15 +537,74 @@
+ L" column " + toWString(columnIndex) + L" is NULL"));
}
+ float ret = -1;
+
switch (columnTypeTags[columnIndex - 1])
{
+ case TT_STRING:
+ {
+ wstring valAsString =
trim(*static_cast<wstring*>((data[currentRow][columnIndex - 1].as_other)));
+ //Tries to parse the string as an integer
+ if(!wstringTo<float>(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 float number"));
+ }
+ }
+ }
+ break;
+ case TT_BIGDECIMAL:
+ BigDecimal* bd = (static_cast<BigDecimal*>((data[currentRow][columnIndex
- 1].as_other)));
+ ret = static_cast<float>(*bd);
+ break;
+ case TT_BOOLEAN:
+ if (((data[currentRow])[columnIndex - 1]).as_bool)
+ ret = 1;
+ else
+ ret = 0;
+ break;
+ case TT_INTEGER:
+ ret = static_cast<float>(((data[currentRow])[columnIndex - 1]).as_int);
+ break;
+ case TT_LONG:
+ ret = static_cast<float>(((data[currentRow])[columnIndex - 1]).as_long);
+ break;
case TT_FLOAT:
- return ((data[currentRow])[columnIndex - 1]).as_float;
+ ret = ((data[currentRow])[columnIndex - 1]).as_float;
+ break;
case TT_DOUBLE:
- return static_cast<float>(data[currentRow][columnIndex - 1].as_double);
- default: // TODO
- throw NotImplementedException(L"float conversion not implemented for
this type yet.");
+ ret = static_cast<float>(data[currentRow][columnIndex - 1].as_double);
+ break;
+ case TT_BYTE_ARRAY:
+ throw NotImplementedException(L"ByteArray to float conversion not
implemented yet.");
+ break;
+ case TT_SQL_DATE:
+ ret = static_cast<float>(((data[currentRow])[columnIndex - 1]).as_long);
+ break;
+ case TT_SQL_TIME:
+ ret = static_cast<float>(((data[currentRow])[columnIndex - 1]).as_int);
+ break;
+ case TT_SQL_TIMESTAMP:
+ ret =
static_cast<float>(static_cast<SQLTimeStamp*>((data[currentRow][columnIndex -
1].as_other))->time);
+ break;
+ case TT_BLOB:
+ throw NotImplementedException(L"Blob to float conversion not implemented
yet.");
+ break;
+ case TT_JAVA_SERIALIZABLE:
+ throw NotImplementedException(L"Java Serializable to float conversion
not implemented yet.");
+ break;
+ default:
+ throw NotImplementedException(L"Float conversion not implemented for
this type yet.");
}
+ return ret;
}
double DriverResultSet::getDouble(int columnIndex) throw (DriverException,
@@ -568,6 +627,88 @@
return ((data[currentRow])[columnIndex - 1]).as_double;
}
+double DriverResultSet::getAsDouble(int columnIndex) throw (DriverException,
+ NullValueException, ConversionException, NotImplementedException,
+ UnexpectedException)
+{
+ checkRowAndColPosAndSetNullFlag(columnIndex);
+
+ if (wasNullFlag)
+ {
+ throw (NullValueException(L"getAsDouble: Value at row " +
toWString(currentRow)
+ + L" column " + toWString(columnIndex) + L" is NULL"));
+ }
+
+ double ret = -1;
+
+ switch (columnTypeTags[columnIndex - 1])
+ {
+ case TT_STRING:
+ {
+ wstring valAsString =
trim(*static_cast<wstring*>((data[currentRow][columnIndex - 1].as_other)));
+ //Tries to parse the string as an integer
+ if(!wstringTo<double>(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 double number"));
+ }
+ }
+ }
+ break;
+ case TT_BIGDECIMAL:
+ BigDecimal* bd = (static_cast<BigDecimal*>((data[currentRow][columnIndex
- 1].as_other)));
+ ret = static_cast<double>(*bd);
+ break;
+ case TT_BOOLEAN:
+ if (((data[currentRow])[columnIndex - 1]).as_bool)
+ ret = 1;
+ else
+ ret = 0;
+ break;
+ case TT_INTEGER:
+ ret = static_cast<double>(((data[currentRow])[columnIndex - 1]).as_int);
+ break;
+ case TT_LONG:
+ ret = static_cast<double>(((data[currentRow])[columnIndex - 1]).as_long);
+ break;
+ case TT_FLOAT:
+ ret = static_cast<double>(((data[currentRow])[columnIndex -
1]).as_float);
+ case TT_DOUBLE:
+ ret = (data[currentRow][columnIndex - 1].as_double);
+ break;
+ case TT_BYTE_ARRAY:
+ throw NotImplementedException(L"ByteArray to double conversion not
implemented yet.");
+ break;
+ break;
+ case TT_SQL_DATE:
+ ret = static_cast<double>(((data[currentRow])[columnIndex - 1]).as_long);
+ break;
+ case TT_SQL_TIME:
+ ret = static_cast<double>(((data[currentRow])[columnIndex - 1]).as_int);
+ break;
+ case TT_SQL_TIMESTAMP:
+ ret =
static_cast<double>(static_cast<SQLTimeStamp*>((data[currentRow][columnIndex -
1].as_other))->time);
+ break;
+ case TT_BLOB:
+ throw NotImplementedException(L"Blob to double conversion not
implemented yet.");
+ break;
+ case TT_JAVA_SERIALIZABLE:
+ throw NotImplementedException(L"Java Serializable to double conversion
not implemented yet.");
+ break;
+ default:
+ throw NotImplementedException(L"Double conversion not implemented for
this type yet.");
+ }
+ return ret;
+}
+
SQLTimeStamp DriverResultSet::getTimeStamp(int columnIndex) throw
(DriverException,
NullValueException, NotImplementedException, UnexpectedException)
{
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits