Date: Monday, November 28, 2005 @ 13:55:24
Author: gilles
Path: /cvsroot/carob/carob
Modified: include/DriverResultSet.hpp (1.10 -> 1.11)
src/DriverResultSet.cpp (1.7 -> 1.8)
Removed UpdatableResultSet related stuff (mostly inserting and updating
variables)
Added dataIsNull flag to check data vector integrity
Implemented next() function (to be tested)
Cosmetic fixes
-----------------------------+
include/DriverResultSet.hpp | 53 ++++++++++++++---------------------
src/DriverResultSet.cpp | 62 ++++++++++++++----------------------------
2 files changed, 42 insertions(+), 73 deletions(-)
Index: carob/include/DriverResultSet.hpp
diff -u carob/include/DriverResultSet.hpp:1.10
carob/include/DriverResultSet.hpp:1.11
--- carob/include/DriverResultSet.hpp:1.10 Fri Nov 25 16:04:47 2005
+++ carob/include/DriverResultSet.hpp Mon Nov 28 13:55:24 2005
@@ -114,7 +114,7 @@
/**
* Cast to wstring. Handy for displaying the result set infos
*/
- operator wstring();
+ operator wstring();
/**
* A ResultSet is initially positioned before its first row, the first call
to
* next makes the first row the current row; the second call makes the second
@@ -127,7 +127,10 @@
* if there are no more rows
* @throw SQLException if an error occurs on the stream
*/
- bool next() throw (SQLException, UnexpectedException);
+ bool next() throw (SocketIOException,
+ ControllerException, ProtocolException,
+ UnexpectedException);
+
/**
* Get the value of a column in the current row as a wstring
*
@@ -135,8 +138,8 @@
* @return the column value, null for SQL NULL
* @throw SQLException if a database access error occurs
*/
- wstring* getString(int32_t columnIndex) throw (SQLException,
- UnexpectedException);
+ wstring* getString(int32_t columnIndex) throw
(SQLException,
+ UnexpectedException);
/**
* Get the value of a column in the current row as an int.
*
@@ -144,15 +147,15 @@
* @return the column value; NULL if SQL NULL
* @throw SQLException if a database access error occurs
*/
- int32_t* getInt(int32_t columnIndex) throw (SQLException,
- UnexpectedException);
+ int32_t* getInt(int32_t columnIndex) throw (SQLException,
+ UnexpectedException);
/**
* Closes the remote ResultSet if the ResultSet was streamed else just closes
* the ResultSet locally.
*
* @exception DriverSQLException if a database access error occurs
*/
- void close() throw (SQLException, UnexpectedException);
+ void close() throw (SQLException,
UnexpectedException);
/**
* Gets the number of column in this resultSet
@@ -173,14 +176,14 @@
* @throw SocketIOException stream error
* @throw ProtocolException protocol corruption
*/
- void receiveRows() throw (SocketIOException, ProtocolException,
- UnexpectedException);
+ void receiveRows() throw (SocketIOException,
+ ProtocolException, UnexpectedException);
/**
* Sets the statement.
*
* @param stmtPtr pointer to the statement to set
*/
- void setStatement(Statement* stmtPtr);
+ void setStatement(Statement* stmtPtr);
private:
/** Cursor to current row */
int32_t currentRow;
@@ -190,6 +193,8 @@
int32_t nbOfColumns;
/** The results */
vector< vector<void*> > data;
+ /** Indicates that no data has been read */
+ bool dataIsNull;
/** True if there is more data to fetch from the controller */
bool hasMoreData;
/** The fetch size */
@@ -220,42 +225,26 @@
bool isClosed;
-//TODO:
- /** Statement for deleting rows with Updatable ResultSets * */
-// private transient PreparedStatement deleteStatement = null;
- /** Statement for inserting rows with Updatable ResultSets * */
-// private transient PreparedStatement insertStatement = null;
- /** Statement for refreshing rows with Updatable ResultSets * */
-// private transient PreparedStatement refreshStatement = null;
- /** Statement for updating rows with Updatable ResultSets * */
-// private transient PreparedStatement updateStatement = null;
- /** Indicates whether cursor is on the insert row * */
- bool inserting;
- /** Indicates if the current row is being updated * */
- bool updating;
- /** Temporary object for not yet comitted ResultSet updates * */
-// private transient Object[] tempRow = null;
- /** Cache the columns forming the primary key * */
-// private transient String[] primaryKeyColumns = null;
-
/**
* Checks that the cursor is on row in the ResultSet
* @throw SQLException if the cursor is out of bounds
*/
- void checkRowPos() throw (SQLException, UnexpectedException);
+ void checkRowPos() throw (SQLException,
+ UnexpectedException);
/**
* Check if the ResultSet if closed and throws a SQLException if so.
* @throw SQLException if the ResultSet is closed
*/
- void checkIfClosed() throw (SQLException, UnexpectedException);
+ void checkIfClosed() throw (SQLException,
+ UnexpectedException);
/**
* Sanity checks for result parsing
*
* @param columnIndex the column to check
* @throws SQLException if an error occurs
*/
- void checkRowAndColPosAndSetNullFlag(int32_t columnIndex)
- throw (SQLException, UnexpectedException);
+ void checkRowAndColPosAndSetNullFlag(int32_t
columnIndex)
+ throw (SQLException, UnexpectedException);
};
Index: carob/src/DriverResultSet.cpp
diff -u carob/src/DriverResultSet.cpp:1.7 carob/src/DriverResultSet.cpp:1.8
--- carob/src/DriverResultSet.cpp:1.7 Wed Nov 23 15:14:37 2005
+++ carob/src/DriverResultSet.cpp Mon Nov 28 13:55:24 2005
@@ -40,13 +40,12 @@
currentRow(-1),
nbOfRows(-1),
nbOfColumns(-1),
+dataIsNull(true),
fetchSize(0),
wasNullFlag(false),
resultSetType(0),
resultSetConcurrency(0),
-isClosed(true),
-inserting(false),
-updating(false)
+isClosed(true)
{
wstring fctName(L"DriverResultSet::DriverResultSet");
connectionPtr = conPtr;
@@ -102,43 +101,24 @@
}
}
-bool DriverResultSet::next() throw (SQLException, UnexpectedException)
+bool DriverResultSet::next() throw (SocketIOException, ControllerException,
+ ProtocolException, UnexpectedException)
{
checkIfClosed();
-//TODO: inserting case
-/* if (inserting)
- {
- insertStatement.clearParameters();
- tempRow = null;
- inserting = false;
- }
-
- if (updating)
- cancelRowUpdates();
-*/
if (nbOfRows == 0)
return false;
-//TODO: fetch next if hasMoreData
if (currentRow + 1 >= nbOfRows)
{
-/* if (hasMoreData)
+ if (hasMoreData)
{
- //TODO: what happens if user closed this connection? What says JDBC?
- this.connection.tryFetchNext(cursorName, fetchSize);
+ // TODO: what happens if user closed this connection? What says JDBC?
+ connectionPtr->tryFetchNext(cursorName, fetchSize);
// no SQLException from controller, so let's receive our new rows
- try
- {
receiveRows();
- }
- catch (IOException ioe)
- {
- throw new DriverSQLException("I/O Error while fetching new rows:\n"
- + ioe.getLocalizedMessage(), ioe);
- }
currentRow = 0;
- if (data == null)
+ if (dataIsNull)
{
nbOfRows = 0;
return false;
@@ -149,13 +129,13 @@
return true;
}
}
-*/
+
// force scroll past end
currentRow = nbOfRows;
return false;
}
-
-// clearWarnings();
+ //TODO:
+ //clearWarnings();
currentRow++;
return true;
}
@@ -167,10 +147,9 @@
if (wasNullFlag)
return NULL;
-/* if (inserting || updating)
- return tempRow[columnIndex - 1].toString();
- else
-*/
+
+ //TODO: big switch on column data type
+
return (wstring*)((data[currentRow])[columnIndex - 1]);
}
@@ -220,6 +199,10 @@
void DriverResultSet::receiveRows() throw (SocketIOException,
ProtocolException,
UnexpectedException)
{
+ //reset data
+ dataIsNull = true;
+ data.clear();
+
const DriverSocket& socket = connectionPtr->getDriverSocket();
socket>>nbOfRows;
@@ -254,6 +237,8 @@
row[col] = deserializers[col](socket);
}
data.push_back(row);
+ //now we have some data
+ dataIsNull = false;
}
socket>>hasMoreData;
@@ -279,8 +264,7 @@
{
checkIfClosed();
- if (!inserting)
- checkRowPos();
+ checkRowPos();
if (fields.size() == 0)
throw SQLException(L"Query generated no fields for ResultSet");
@@ -290,10 +274,6 @@
+ toWString(columnIndex) + L" > " + toWString(nbOfColumns) + L").");
void* obj;
-/* if (inserting || updating)
- obj = tempRow[columnIndex - 1];
- else
-*/
if ((int32_t)data[currentRow].size()<columnIndex-1)
wasNullFlag = true;
else
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits