Date: Wednesday, January 18, 2006 @ 12:46:14
Author: zsolt
Path: /cvsroot/carob/carob
Modified: include/DriverResultSet.hpp (1.25 -> 1.26)
src/DriverResultSet.cpp (1.31 -> 1.32)
Implemented the following functions:
DriverResultSet::getInt64()
DriverResultSet::getAsInt64()
DriverResultSet::getFloat()
DriverResultSet::getDouble()
-----------------------------+
include/DriverResultSet.hpp | 57 +++++++++++++++++
src/DriverResultSet.cpp | 140 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 197 insertions(+)
Index: carob/include/DriverResultSet.hpp
diff -u carob/include/DriverResultSet.hpp:1.25
carob/include/DriverResultSet.hpp:1.26
--- carob/include/DriverResultSet.hpp:1.25 Fri Dec 30 17:51:07 2005
+++ carob/include/DriverResultSet.hpp Wed Jan 18 12:46:14 2006
@@ -191,6 +191,63 @@
NullValueException, NotImplementedException,
UnexpectedException);
/**
+ * Gets the 64bits integer value of a column in the current row only if the
+ * given column is of int type, throws an exception otherwise. To get the
+ * value as an int64 anyway, use #getAsInt64(int)
+ *
+ * @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
+ */
+ int64_t getInt64(int columnIndex) throw (DriverException,
+ NullValueException, NotImplementedException,
+ UnexpectedException);
+ /**
+ * Tries to get the value of a column in the current row as an int64. 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
+ */
+ int64_t getAsInt64(int columnIndex) throw
(DriverException,
+ NullValueException, 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.
+ *
+ * @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
+ */
+ float getFloat(int columnIndex) throw (DriverException,
+ NullValueException, NotImplementedException,
+ UnexpectedException);
+ /**
+ * Gets the double value of a column in the current row only if the
+ * given column is of double 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
+ */
+ double getDouble(int columnIndex) throw
(DriverException,
+ NullValueException, NotImplementedException,
+ UnexpectedException);
+ /**
* Closes the remote ResultSet if the ResultSet was streamed else just closes
* the ResultSet locally.
*/
Index: carob/src/DriverResultSet.cpp
diff -u carob/src/DriverResultSet.cpp:1.31 carob/src/DriverResultSet.cpp:1.32
--- carob/src/DriverResultSet.cpp:1.31 Mon Jan 2 11:51:39 2006
+++ carob/src/DriverResultSet.cpp Wed Jan 18 12:46:14 2006
@@ -374,6 +374,146 @@
return ret;
}
+int64_t DriverResultSet::getInt64(int columnIndex) throw (DriverException,
+ NullValueException, NotImplementedException, UnexpectedException)
+{
+ checkRowAndColPosAndSetNullFlag(columnIndex);
+
+ if (wasNullFlag)
+ {
+ throw (NullValueException(L"getInt64: Value at row " +
toWString(currentRow)
+ + L" column " + toWString(columnIndex) + L" is NULL"));
+ }
+
+ if (columnTypeTags[columnIndex - 1] != TT_LONG)
+ {
+ throw (DriverException(L"getInt64: Value at row " + toWString(currentRow)
+ + L" column " + toWString(columnIndex) + L" is not of type integer"));
+ }
+
+ return ((data[currentRow])[columnIndex - 1]).as_long;
+}
+
+int64_t DriverResultSet::getAsInt64(int columnIndex) throw (DriverException,
+ NullValueException, NotImplementedException, UnexpectedException)
+{
+ checkRowAndColPosAndSetNullFlag(columnIndex);
+
+ if (wasNullFlag)
+ {
+ throw (NullValueException(L"getAsInt64: Value at row " +
toWString(currentRow)
+ + L" column " + toWString(columnIndex) + L" is NULL"));
+ }
+
+ int64_t 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(!wstringTo<int64_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 (DriverException(L"The value " + valAsString
+ + L" is not a valid int number"));
+ }
+ }
+ }
+ break;
+ case TT_BIGDECIMAL:
+ throw NotImplementedException(L"BigDecimal to int64 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 = (((data[currentRow])[columnIndex - 1]).as_long);
+ break;
+ case TT_FLOAT:
+ ret = (int64_t)(((data[currentRow])[columnIndex - 1]).as_float);
+ break;
+ case TT_DOUBLE:
+ ret = (int64_t)(((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:
+ ret = (((data[currentRow])[columnIndex - 1]).as_long);
+ break;
+ case TT_SQL_TIME:
+ ret = ((data[currentRow])[columnIndex - 1]).as_int;
+ break;
+ case TT_SQL_TIMESTAMP:
+ throw NotImplementedException(L"SQL TimeStamp to string 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"Java Serializable to int conversion not
implemented yet.");
+ break;
+ default:
+ throw NotImplementedException(L"Int conversion not implemented for this
type yet.");
+ }
+ return ret;
+}
+
+float DriverResultSet::getFloat(int columnIndex) throw (DriverException,
+ NullValueException, NotImplementedException, UnexpectedException)
+{
+ checkRowAndColPosAndSetNullFlag(columnIndex);
+
+ if (wasNullFlag)
+ {
+ throw (NullValueException(L"getFloat: Value at row " +
toWString(currentRow)
+ + L" column " + toWString(columnIndex) + L" is NULL"));
+ }
+
+ if (columnTypeTags[columnIndex - 1] != TT_FLOAT)
+ {
+ throw (DriverException(L"getFloat: Value at row " + toWString(currentRow)
+ + L" column " + toWString(columnIndex) + L" is not of type float"));
+ }
+
+ return ((data[currentRow])[columnIndex - 1]).as_float;
+}
+
+double DriverResultSet::getDouble(int columnIndex) throw (DriverException,
+ NullValueException, NotImplementedException, UnexpectedException)
+{
+ checkRowAndColPosAndSetNullFlag(columnIndex);
+
+ if (wasNullFlag)
+ {
+ throw (NullValueException(L"getDouble: Value at row " +
toWString(currentRow)
+ + L" column " + toWString(columnIndex) + L" is NULL"));
+ }
+
+ if (columnTypeTags[columnIndex - 1] != TT_DOUBLE)
+ {
+ throw (DriverException(L"getDouble: Value at row " + toWString(currentRow)
+ + L" column " + toWString(columnIndex) + L" is not of type double"));
+ }
+
+ return ((data[currentRow])[columnIndex - 1]).as_double;
+}
+
void DriverResultSet::close() throw (SocketIOException, BackendException,
ControllerException, ProtocolException, UnexpectedException)
{
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits