Date: Wednesday, February 1, 2006 @ 13:39:24
Author: zsolt
Path: /cvsroot/carob/carob
Modified: include/DriverResultSet.hpp (1.29 -> 1.30)
include/SQLDataSerialization.hpp (1.10 -> 1.11)
src/DriverResultSet.cpp (1.35 -> 1.36)
src/SQLDataSerialization.cpp (1.22 -> 1.23)
- implemented TimeStamp serialization.
- implemented DriverResultSet::getTimeStamp()
----------------------------------+
include/DriverResultSet.hpp | 15 +++++++++++++++
include/SQLDataSerialization.hpp | 6 ++++++
src/DriverResultSet.cpp | 33 +++++++++++++++++++++++++++++++--
src/SQLDataSerialization.cpp | 17 +++++------------
4 files changed, 57 insertions(+), 14 deletions(-)
Index: carob/include/DriverResultSet.hpp
diff -u carob/include/DriverResultSet.hpp:1.29
carob/include/DriverResultSet.hpp:1.30
--- carob/include/DriverResultSet.hpp:1.29 Wed Jan 25 23:41:15 2006
+++ carob/include/DriverResultSet.hpp Wed Feb 1 13:39:24 2006
@@ -263,6 +263,21 @@
NullValueException, 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.
+ *
+ * @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
+ */
+ SQLTimeStamp getTimeStamp(int columnIndex) throw
(DriverException,
+ NullValueException, NotImplementedException,
+ UnexpectedException);
+
+ /**
* Closes the remote ResultSet if the ResultSet was streamed else just closes
* the ResultSet locally.
*/
Index: carob/include/SQLDataSerialization.hpp
diff -u carob/include/SQLDataSerialization.hpp:1.10
carob/include/SQLDataSerialization.hpp:1.11
--- carob/include/SQLDataSerialization.hpp:1.10 Wed Jan 25 23:59:02 2006
+++ carob/include/SQLDataSerialization.hpp Wed Feb 1 13:39:24 2006
@@ -77,6 +77,12 @@
};
+/** SQL TimeStamp */
+typedef struct {
+ int64_t time;
+ int32_t nanos;
+} SQLTimeStamp;
+
/**
* Defines data type that can be found in ResultSets
*/
Index: carob/src/DriverResultSet.cpp
diff -u carob/src/DriverResultSet.cpp:1.35 carob/src/DriverResultSet.cpp:1.36
--- carob/src/DriverResultSet.cpp:1.35 Wed Jan 25 23:41:15 2006
+++ carob/src/DriverResultSet.cpp Wed Feb 1 13:39:24 2006
@@ -76,6 +76,15 @@
}
}
break;
+ case TT_SQL_TIMESTAMP:
+ for (cnt=0; cnt<data.size(); cnt++)
+ {
+ if (!nulls[cnt][col])
+ {
+ delete (static_cast<SQLTimeStamp*>((data[cnt][col]).as_other));
+ }
+ }
+ break;
}
}
//Now remove data from the vector
@@ -363,7 +372,7 @@
ret = ((data[currentRow])[columnIndex - 1]).as_int;
break;
case TT_SQL_TIMESTAMP:
- throw NotImplementedException(L"SQL TimeStamp to string conversion not
implemented yet.");
+ ret = static_cast<SQLTimeStamp*>((data[currentRow][columnIndex -
1].as_other))->time;
break;
case TT_BLOB:
throw NotImplementedException(L"Blob to int conversion not implemented
yet.");
@@ -463,7 +472,7 @@
ret = ((data[currentRow])[columnIndex - 1]).as_int;
break;
case TT_SQL_TIMESTAMP:
- throw NotImplementedException(L"SQL TimeStamp to string conversion not
implemented yet.");
+ ret = static_cast<SQLTimeStamp*>((data[currentRow][columnIndex -
1].as_other))->time;
break;
case TT_BLOB:
throw NotImplementedException(L"Blob to int conversion not implemented
yet.");
@@ -539,6 +548,26 @@
return ((data[currentRow])[columnIndex - 1]).as_double;
}
+SQLTimeStamp DriverResultSet::getTimeStamp(int columnIndex) throw
(DriverException,
+ NullValueException, NotImplementedException, UnexpectedException)
+{
+ checkRowAndColPosAndSetNullFlag(columnIndex);
+
+ if (wasNullFlag)
+ {
+ throw (NullValueException(L"getTimeStamp: Value at row " +
toWString(currentRow)
+ + L" column " + toWString(columnIndex) + L" is NULL"));
+ }
+
+ if (columnTypeTags[columnIndex - 1] != TT_SQL_TIMESTAMP)
+ {
+ throw (DriverException(L"getTimeStamp: Value at row " +
toWString(currentRow)
+ + L" column " + toWString(columnIndex) + L" is not of type
timestamp"));
+ }
+
+ return *static_cast<SQLTimeStamp*>((data[currentRow][columnIndex -
1].as_other));
+}
+
void DriverResultSet::close() throw (SocketIOException, BackendException,
ControllerException, ProtocolException, UnexpectedException)
{
Index: carob/src/SQLDataSerialization.cpp
diff -u carob/src/SQLDataSerialization.cpp:1.22
carob/src/SQLDataSerialization.cpp:1.23
--- carob/src/SQLDataSerialization.cpp:1.22 Thu Jan 26 17:30:24 2006
+++ carob/src/SQLDataSerialization.cpp Wed Feb 1 13:39:24 2006
@@ -252,18 +252,11 @@
//Timestamp is a long *and* an integer. Make use of our struct to put
//both values in it
ResultSetDataType res;
- int64_t time = 0;
- input>>time;
- time = ((time/1000)*1000);
- int32_t nanos = (int)((time%1000) * 1000000);
- if (nanos < 0)
- {
- nanos = 1000000000 + nanos;
- time = ((time/1000)-1)*1000;
- }
- input>>nanos;
- res.as_long = time;
- res.as_int = nanos;
+ SQLTimeStamp ts;
+ input>>ts.time;
+ ts.time = ((ts.time/1000)*1000);
+ input>>ts.nanos;
+ res.as_other = new SQLTimeStamp(ts);
return res;
}
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits