Date: Friday, November 25, 2005 @ 17:29:10
Author: gilles
Path: /cvsroot/carob/carob/test
Modified: TestBeginCommitRollback.cpp (1.5 -> 1.6) TestConnect.cpp (1.4 ->
1.5) TestExecReadRequest.cpp (1.8 -> 1.9)
TestExecWriteRequest.cpp (1.9 -> 1.10) TestOnValidConnection.cpp
(1.1 -> 1.2) TestStatement.cpp (1.4 -> 1.5)
Reported Protector implementation: now, catches only awaited exceptions.
Other (unexpected) exceptions are correctly catched by the protector, so the
code
has been made 'lighter' (no more try/catch everywhere)
Also fixed logging, so it is now more meaningfull
-----------------------------+
TestBeginCommitRollback.cpp | 94 ++++++----------------
TestConnect.cpp | 35 ++------
TestExecReadRequest.cpp | 69 +++++++---------
TestExecWriteRequest.cpp | 94 ++++++++--------------
TestOnValidConnection.cpp | 21 -----
TestStatement.cpp | 172 ++++++++++++++++++------------------------
6 files changed, 180 insertions(+), 305 deletions(-)
Index: carob/test/TestBeginCommitRollback.cpp
diff -u carob/test/TestBeginCommitRollback.cpp:1.5
carob/test/TestBeginCommitRollback.cpp:1.6
--- carob/test/TestBeginCommitRollback.cpp:1.5 Thu Nov 24 15:54:46 2005
+++ carob/test/TestBeginCommitRollback.cpp Fri Nov 25 17:29:10 2005
@@ -26,94 +26,56 @@
void TestBeginCommitRollback::testReadRequestAndCommit()
{
wstring fctName(L"TestBeginCommitRollback::testReadRequestAndCommit");
- try
+ connectionPtr->setAutoCommit(false);
+ RequestWithResultSetParameters readReq(L"select * from address");
+ readReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
+ connectionPtr->statementExecuteQuery(readReq);
+ connectionPtr->commit();
+ if (isDebugEnabled())
{
- connectionPtr->setAutoCommit(false);
- RequestWithResultSetParameters readReq(L"select * from address");
- readReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
- if (isDebugEnabled())
- {
- logDebug(fctName, L"Executing read");
- }
- connectionPtr->statementExecuteQuery(readReq);
- connectionPtr->commit();
- CPPUNIT_ASSERT(true);
- }
- catch (...)
- {
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ logDebug(fctName, L"Read and commit succeeded");
}
}
void TestBeginCommitRollback::testReadRequestAndRollback()
{
wstring fctName(L"TestBeginCommitRollback::testReadRequestAndRollback");
- try
- {
- connectionPtr->setAutoCommit(false);
- RequestWithResultSetParameters readReq(L"select * from address");
- readReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
- if (isDebugEnabled())
- {
- logDebug(fctName, L"Executing read");
- }
- connectionPtr->statementExecuteQuery(readReq);
- connectionPtr->rollback();
-
- CPPUNIT_ASSERT(true);
- }
- catch (...)
+ connectionPtr->setAutoCommit(false);
+ RequestWithResultSetParameters readReq(L"select * from address");
+ readReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
+ connectionPtr->statementExecuteQuery(readReq);
+ connectionPtr->rollback();
+ if (isDebugEnabled())
{
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ logDebug(fctName, L"Read and rollback succeeded");
}
}
void TestBeginCommitRollback::testWriteRequestAndCommit()
{
wstring fctName(L"TestBeginCommitRollback::testWriteRequestAndCommit");
- try
+ connectionPtr->setAutoCommit(false);
+ Request updtReq(L"update product set name='commited' where id=0");
+ updtReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
+ connectionPtr->statementExecuteUpdate(updtReq);
+ connectionPtr->commit();
+ if (isDebugEnabled())
{
- connectionPtr->setAutoCommit(false);
- Request updtReq(L"update product set name='commited' where id=0");
- updtReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
- if (isDebugEnabled())
- {
- logDebug(fctName, L"Executing write");
- }
- connectionPtr->statementExecuteUpdate(updtReq);
- connectionPtr->commit();
-
- CPPUNIT_ASSERT(true);
- }
- catch (...)
- {
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ logDebug(fctName, L"Write and commit succeeded");
}
}
void TestBeginCommitRollback::testWriteRequestAndRollback()
{
wstring fctName(L"TestBeginCommitRollback::testWriteRequestAndRollback");
- try
- {
- connectionPtr->setAutoCommit(false);
- Request updtReq(L"update product set name='rollbacked' where id=0");
- updtReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
- if (isDebugEnabled())
- {
- logDebug(fctName, L"Executing write");
- }
- connectionPtr->statementExecuteUpdate(updtReq);
- connectionPtr->rollback();
- CPPUNIT_ASSERT(true);
- }
- catch (...)
+ connectionPtr->setAutoCommit(false);
+ Request updtReq(L"update product set name='rollbacked' where id=0");
+ updtReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
+ connectionPtr->statementExecuteUpdate(updtReq);
+ connectionPtr->rollback();
+ if (isDebugEnabled())
{
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ logDebug(fctName, L"Write and rollback succeeded");
}
}
Index: carob/test/TestConnect.cpp
diff -u carob/test/TestConnect.cpp:1.4 carob/test/TestConnect.cpp:1.5
--- carob/test/TestConnect.cpp:1.4 Fri Nov 4 11:00:49 2005
+++ carob/test/TestConnect.cpp Fri Nov 25 17:29:10 2005
@@ -50,7 +50,7 @@
{
if (isDebugEnabled())
{
- logDebug(fctName, L"Connection to controller");
+ logDebug(fctName, L"Connecting to controller - should fail");
}
connectionPtr = connectionPoolPtr->connectToController(connectionPrms);
// We should receive an exception instead of coming here
@@ -58,14 +58,10 @@
}
catch (ConnectionException ce)
{
- logError(fctName, L"ConnectionException "+ce.description());
+ logError(fctName, L"Connection failed (this is ok). Exception: "
+ + ce.description());
CPPUNIT_ASSERT(true);
}
- catch (...)
- {
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
- }
}
void TestConnect::testConnectBadPort()
@@ -81,7 +77,7 @@
{
if (isDebugEnabled())
{
- logDebug(fctName, L"Connection to controller");
+ logDebug(fctName, L"Connecting to controller - sould fail");
}
connectionPtr = connectionPoolPtr->connectToController(connectionPrms);
// We should receive an exception instead of coming here
@@ -89,14 +85,10 @@
}
catch (ConnectionException ce)
{
- logError(fctName, L"ConnectionException "+ce.description());
+ logError(fctName, L"Connection failed (this is ok). Exception: "
+ + ce.description());
CPPUNIT_ASSERT(true);
}
- catch (...)
- {
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
- }
}
void TestConnect::testConnectGood()
@@ -108,19 +100,14 @@
L"user",
L"",
DEBUG_LEVEL_DEBUG);
- try
+ if (isDebugEnabled())
{
- if (isDebugEnabled())
- {
- logDebug(fctName, L"Connection to controller");
- }
- connectionPtr = connectionPoolPtr->connectToController(connectionPrms);
-
+ logDebug(fctName, L"Connecting to controller - this should succeed");
}
- catch (...)
+ connectionPtr = connectionPoolPtr->connectToController(connectionPrms);
+ if (isDebugEnabled())
{
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ logDebug(fctName, L"Connection succeeded");
}
}
Index: carob/test/TestExecReadRequest.cpp
diff -u carob/test/TestExecReadRequest.cpp:1.8
carob/test/TestExecReadRequest.cpp:1.9
--- carob/test/TestExecReadRequest.cpp:1.8 Thu Nov 24 15:54:46 2005
+++ carob/test/TestExecReadRequest.cpp Fri Nov 25 17:29:10 2005
@@ -36,7 +36,7 @@
readReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
if (isDebugEnabled())
{
- logDebug(fctName, L"Executing read");
+ logDebug(fctName, L"Executing read - this should fail");
}
connectionPtr->statementExecuteQuery(readReq);
// We should receive an exception instead of coming here
@@ -44,13 +44,10 @@
}
catch (BackendException sioe)
{
- logError(fctName, L"BackendException "+sioe.description());
- CPPUNIT_ASSERT(true);
- }
- catch (...)
- {
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ if (isErrorEnabled())
+ {
+ logError(fctName, L"Read failed (this is ok). Exception:
"+sioe.description());
+ }
}
}
@@ -64,7 +61,7 @@
if (isDebugEnabled())
{
- logDebug(fctName, L"Executing read");
+ logDebug(fctName, L"Executing read - this should fail");
}
connectionPtr->statementExecuteQuery(readReq);
// We should receive an exception instead of coming here
@@ -72,45 +69,39 @@
}
catch (BackendException be)
{
- //logError(fctName, L"BackendException "+be.description());
- CPPUNIT_ASSERT(true);
- }
- catch (...)
- {
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ if (isErrorEnabled())
+ {
+ logError(fctName, L"Read failed (this is ok). Exception: "
+ + be.description());
+ }
}
}
void TestExecReadRequest::testReadGood()
{
wstring fctName(L"TestExecReadRequest::testReadGood");
- try
+ RequestWithResultSetParameters readReq(L"select * from address");
+ readReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
+ if (isDebugEnabled())
{
- RequestWithResultSetParameters readReq(L"select * from address");
- readReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
- if (isDebugEnabled())
- {
- logDebug(fctName, L"Executing read");
- }
- DriverResultSet* drsPtr = connectionPtr->statementExecuteQuery(readReq);
- logDebug(fctName, *drsPtr);
- //Display 50 rows for debugging...
-// wcerr<<L"Row\tId\tName\t\tCost"<<endl;
- wcerr<<L"Row\tId\tFirstName\t\tLastName"<<endl;
- for (int i=0; i<50; i++)
- {
- drsPtr->next();
- int32_t* iPtr = drsPtr->getInt(1);
- wstring* wsPtr = drsPtr->getString(2);
- wstring* ws2Ptr = drsPtr->getString(3);
- wcerr<<i+1<<L"\t"<<*iPtr<<L"\t"<<*wsPtr<<L"\t"<<*ws2Ptr<<endl;
- }
+ logDebug(fctName, L"Executing read - this should succeed");
}
- catch (...)
+ DriverResultSet* drsPtr = connectionPtr->statementExecuteQuery(readReq);
+ if (isDebugEnabled())
{
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ logDebug(fctName, L"Read succeeded. Displaying 50 rows:");
+ }
+ //Display 50 rows for debugging...
+
+// wcerr<<L"Row\tId\tName\t\tCost"<<endl;
+ wcerr<<L"Row\tId\tFirstName\tLastName"<<endl;
+ for (int i=0; i<50; i++)
+ {
+ drsPtr->next();
+ int32_t* iPtr = drsPtr->getInt(1);
+ wstring* wsPtr = drsPtr->getString(2);
+ wstring* ws2Ptr = drsPtr->getString(3);
+ wcerr<<i+1<<L"\t"<<*iPtr<<L"\t"<<*wsPtr<<L"\t\t"<<*ws2Ptr<<endl;
}
}
Index: carob/test/TestExecWriteRequest.cpp
diff -u carob/test/TestExecWriteRequest.cpp:1.9
carob/test/TestExecWriteRequest.cpp:1.10
--- carob/test/TestExecWriteRequest.cpp:1.9 Thu Nov 24 15:54:46 2005
+++ carob/test/TestExecWriteRequest.cpp Fri Nov 25 17:29:10 2005
@@ -35,7 +35,7 @@
updtReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
if (isDebugEnabled())
{
- logDebug(fctName, L"Executing write");
+ logDebug(fctName, L"Executing write - should fail");
}
connectionPtr->statementExecuteUpdate(updtReq);
// We should receive an exception instead of coming here
@@ -43,14 +43,13 @@
}
catch (BackendException be)
{
- logError(fctName, L"BackendException "+be.description());
+ if (isErrorEnabled())
+ {
+ logError(fctName, L"Write failed (this is ok). Exception:"
+ + be.description());
+ }
CPPUNIT_ASSERT(true);
}
- catch (...)
- {
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
- }
}
void TestExecWriteRequest::testWriteBadTable()
@@ -62,83 +61,62 @@
updtReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
if (isDebugEnabled())
{
- logDebug(fctName, L"Executing write");
+ logDebug(fctName, L"Executing write - should fail");
}
connectionPtr->statementExecuteUpdate(updtReq);
// We should receive an exception instead of coming here
CPPUNIT_ASSERT(false);
}
- catch (BackendException sioe)
- {
- logError(fctName, L"BackendException "+sioe.description());
- CPPUNIT_ASSERT(true);
- }
- catch (...)
+ catch (BackendException be)
{
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ if (isErrorEnabled())
+ {
+ logError(fctName, L"Write failed (this is ok). Exception:"
+ + be.description());
+ }
}
}
void TestExecWriteRequest::testWriteGood()
{
wstring fctName(L"TestExecWriteRequest::testWriteGood");
- try
- {
- Request updtReq(L"update product set name='changed' where id=0");
- updtReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
- if (isDebugEnabled())
- {
- logDebug(fctName, L"Executing write");
- }
- int32_t nbRowsAffected = connectionPtr->statementExecuteUpdate(updtReq);
- CPPUNIT_ASSERT(nbRowsAffected == 1);
-
- }
- catch (BackendException sioe)
+ Request updtReq(L"update product set name='changed' where id=0");
+ updtReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
+ if (isDebugEnabled())
{
- logError(fctName, L"BackendException "+sioe.description());
- CPPUNIT_ASSERT(true);
+ logDebug(fctName, L"Executing write - should succeed");
}
- catch (...)
+ int32_t nbRowsAffected = connectionPtr->statementExecuteUpdate(updtReq);
+ if (isDebugEnabled())
{
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ logDebug(fctName, L"Write succeed. Number of rows updated:"
+ + toWString(nbRowsAffected));
}
+ CPPUNIT_ASSERT(nbRowsAffected == 1);
}
void TestExecWriteRequest::testWriteThousandGood()
{
wstring fctName(L"TestExecWriteRequest::testWriteGood");
- try
+ wstring requestBegin = L"UPDATE product SET cost=";
+ wstring requestEnd = L" where id=";
+
+ Request updtReq(L"");
+ updtReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
+ if (isDebugEnabled())
{
- wstring requestBegin = L"UPDATE product SET cost=";
- wstring requestEnd = L" where id=";
-
- Request updtReq(L"");
- updtReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
- if (isDebugEnabled())
- {
- logDebug(fctName, L"Executing 1000 writes");
- }
- for (int i=0; i<1000; i++)
- {
- updtReq.setSqlQuery(requestBegin + toWString(i)
- + requestEnd + toWString(i%50));
- int32_t nbRowsAffected = connectionPtr->statementExecuteUpdate(updtReq);
- CPPUNIT_ASSERT(nbRowsAffected == 1);
- }
-
+ logDebug(fctName, L"Executing 1000 writes");
}
- catch (BackendException sioe)
+ for (int i=0; i<1000; i++)
{
- logError(fctName, L"BackendException "+sioe.description());
- CPPUNIT_ASSERT(true);
+ updtReq.setSqlQuery(requestBegin + toWString(i)
+ + requestEnd + toWString(i%50));
+ int32_t nbRowsAffected = connectionPtr->statementExecuteUpdate(updtReq);
+ CPPUNIT_ASSERT(nbRowsAffected == 1);
}
- catch (...)
+ if (isDebugEnabled())
{
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ logDebug(fctName, L"1000 writes succeeded");
}
}
Index: carob/test/TestOnValidConnection.cpp
diff -u carob/test/TestOnValidConnection.cpp:1.1
carob/test/TestOnValidConnection.cpp:1.2
--- carob/test/TestOnValidConnection.cpp:1.1 Wed Nov 9 14:34:10 2005
+++ carob/test/TestOnValidConnection.cpp Fri Nov 25 17:29:10 2005
@@ -35,28 +35,7 @@
L"user",
L"",
DEBUG_LEVEL_DEBUG);
- try
- {
connectionPtr = connectionPool.connectToController(connectionPrms);
- }
- catch (ConnectionException ce)
- {
- logError(fctName, L"ConnectionException "+ce.description());
- connectionPtr = NULL;
- CPPUNIT_ASSERT(false);
- }
- catch (AuthenticationException ae)
- {
- logError(fctName, L"AuthenticationException "+ae.description());
- connectionPtr = NULL;
- CPPUNIT_ASSERT(false);
- }
- catch (...)
- {
- logError(fctName, L"Unexpected excption. Aborting ");
- connectionPtr = NULL;
- CPPUNIT_ASSERT(false);
- }
}
void TestOnValidConnection::tearDown()
Index: carob/test/TestStatement.cpp
diff -u carob/test/TestStatement.cpp:1.4 carob/test/TestStatement.cpp:1.5
--- carob/test/TestStatement.cpp:1.4 Wed Nov 23 15:16:36 2005
+++ carob/test/TestStatement.cpp Fri Nov 25 17:29:10 2005
@@ -39,21 +39,19 @@
statementPtr = connectionPtr->createStatement();
if (isDebugEnabled())
{
- logDebug(fctName, L"Executing dummy read");
+ logDebug(fctName, L"Executing dummy read - should fail");
}
statementPtr->executeQuery(L"dummy request;");
// We should receive an exception instead of coming here
CPPUNIT_ASSERT(false);
}
- catch (BackendException sioe)
- {
- logError(fctName, L"BackendException "+sioe.description());
- CPPUNIT_ASSERT(true);
- }
- catch (...)
+ catch (BackendException be)
{
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ if (isErrorEnabled())
+ {
+ logError(fctName, L"Read failed (this is ok). Exception: "
+ + be.description());
+ }
}
delete statementPtr;
}
@@ -67,7 +65,7 @@
statementPtr = connectionPtr->createStatement();
if (isDebugEnabled())
{
- logDebug(fctName, L"Executing bad table read");
+ logDebug(fctName, L"Executing bad table read - should fail");
}
statementPtr->executeQuery(L"select * from dummy;");
// We should receive an exception instead of coming here
@@ -75,13 +73,11 @@
}
catch (BackendException be)
{
- //logError(fctName, L"BackendException "+be.description());
- CPPUNIT_ASSERT(true);
- }
- catch (...)
- {
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ if (isErrorEnabled())
+ {
+ logError(fctName, L"Read failed (this is ok). Exception: "
+ + be.description());
+ }
}
delete statementPtr;
}
@@ -90,32 +86,28 @@
{
wstring fctName(L"TestStatement::testExecuteQueryGood");
Statement* statementPtr = NULL;
- try
+ statementPtr = connectionPtr->createStatement();
+ if (isDebugEnabled())
{
- statementPtr = connectionPtr->createStatement();
- if (isDebugEnabled())
- {
- logDebug(fctName, L"Executing read");
- }
- DriverResultSet* drsPtr = statementPtr->executeQuery(
- L"select * from address;");
- logDebug(fctName, *drsPtr);
- //Display five rows for debugging...
-// wcerr<<L"Row\tId\tName\t\tCost"<<endl;
- wcerr<<L"Row\tId\tFirstName\t\tLastName"<<endl;
- for (int i=0; i<50; i++)
- {
- drsPtr->next();
- int32_t* iPtr = drsPtr->getInt(1);
- wstring* wsPtr = drsPtr->getString(2);
- wstring* ws2Ptr = drsPtr->getString(3);
- wcerr<<i+1<<L"\t"<<*iPtr<<L"\t"<<*wsPtr<<L"\t"<<*ws2Ptr<<endl;
- }
+ logDebug(fctName, L"Executing read - should succeed");
}
- catch (...)
+ DriverResultSet* drsPtr = statementPtr->executeQuery(
+ L"select * from address;");
+ if (isDebugEnabled())
{
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ logDebug(fctName, L"Read succeeded. Displaying 50 rows:");
+ }
+ //Display 50 rows for debugging...
+
+// wcerr<<L"Row\tId\tName\tCost"<<endl;
+ wcerr<<L"Row\tId\tFirstName\tLastName"<<endl;
+ for (int i=0; i<50; i++)
+ {
+ drsPtr->next();
+ int32_t* iPtr = drsPtr->getInt(1);
+ wstring* wsPtr = drsPtr->getString(2);
+ wstring* ws2Ptr = drsPtr->getString(3);
+ wcerr<<i+1<<L"\t"<<*iPtr<<L"\t"<<*wsPtr<<L"\t\t"<<*ws2Ptr<<endl;
}
delete statementPtr;
}
@@ -132,21 +124,19 @@
statementPtr = connectionPtr->createStatement();
if (isDebugEnabled())
{
- logDebug(fctName, L"Executing dummy update");
+ logDebug(fctName, L"Executing dummy update - should fail");
}
statementPtr->executeUpdate(L"dummy request;");
// We should receive an exception instead of coming here
CPPUNIT_ASSERT(false);
}
- catch (BackendException sioe)
- {
- logError(fctName, L"BackendException "+sioe.description());
- CPPUNIT_ASSERT(true);
- }
- catch (...)
+ catch (BackendException be)
{
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ if (isErrorEnabled())
+ {
+ logError(fctName, L"Update failed (this is ok). Exception: "
+ + be.description());
+ }
}
delete statementPtr;
}
@@ -160,7 +150,7 @@
statementPtr = connectionPtr->createStatement();
if (isDebugEnabled())
{
- logDebug(fctName, L"Executing bad table update");
+ logDebug(fctName, L"Executing bad table update - this should fail");
}
statementPtr->executeUpdate(L"update dummy set name='gotit' where id=0;");
// We should receive an exception instead of coming here
@@ -168,13 +158,11 @@
}
catch (BackendException be)
{
- //logError(fctName, L"BackendException "+be.description());
- CPPUNIT_ASSERT(true);
- }
- catch (...)
- {
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ if (isErrorEnabled())
+ {
+ logError(fctName, L"Update failed (this is ok). Exception: "
+ + be.description());
+ }
}
delete statementPtr;
}
@@ -183,58 +171,48 @@
{
wstring fctName(L"TestStatement::testExecuteUpdateGood");
Statement* statementPtr = NULL;
- try
+ statementPtr = connectionPtr->createStatement();
+ if (isDebugEnabled())
{
- statementPtr = connectionPtr->createStatement();
- if (isDebugEnabled())
- {
- logDebug(fctName, L"Executing update");
- }
- int32_t nbRowsAffected = statementPtr->executeUpdate(
- L"update product set name='changed by testExecuteUpdateGood' where
id=0;");
- CPPUNIT_ASSERT(nbRowsAffected == 1);
+ logDebug(fctName, L"Executing update - should succeed");
}
- catch (...)
+ int32_t nbRowsAffected = statementPtr->executeUpdate(
+ L"update product set name='changed by testExecuteUpdateGood' where
id=0;");
+ if (isDebugEnabled())
{
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ logDebug(fctName, L"Update succeeded. Number of affected rows = "
+ + toWString(nbRowsAffected));
}
+ CPPUNIT_ASSERT(nbRowsAffected == 1);
delete statementPtr;
}
void TestStatement::testExecuteQueryWithMaxRows()
{
- wstring fctName(L"TestStatement::testExecuteQueryGood");
+ wstring fctName(L"TestStatement::testExecuteQueryWithMaxRows");
Statement* statementPtr = NULL;
- try
+ statementPtr = connectionPtr->createStatement();
+ if (isDebugEnabled())
{
- statementPtr = connectionPtr->createStatement();
- if (isDebugEnabled())
- {
- logDebug(fctName, L"Executing read");
- }
- statementPtr->setMaxRows(1);
- DriverResultSet* drsPtr = statementPtr->executeQuery(
- L"select * from address;");
- logDebug(fctName, *drsPtr);
- //Display five rows for debugging...
-// wcerr<<L"Row\tId\tName\t\tCost"<<endl;
- wcerr<<L"Id\tFirstName\t\tLastName"<<endl;
- drsPtr->next();
- int32_t* iPtr = drsPtr->getInt(1);
- wstring* wsPtr = drsPtr->getString(2);
- wstring* ws2Ptr = drsPtr->getString(3);
- wcerr<<*iPtr<<L"\t"<<*wsPtr<<L"\t"<<*ws2Ptr<<endl;
-
- //This next() should return false because we asked just 1 row
- CPPUNIT_ASSERT(drsPtr->next() == false);
- }
- catch (...)
- {
- if (isErrorEnabled())
- logError(fctName, L"Catched unexpected exception");
- CPPUNIT_ASSERT(false);
+ logDebug(fctName, L"Executing read with max rows = 1");
}
+ statementPtr->setMaxRows(1);
+ DriverResultSet* drsPtr = statementPtr->executeQuery(
+ L"select * from address;");
+ if (isDebugEnabled())
+ {
+ logDebug(fctName, L"executeQuery succeeded. Displaying first row.");
+ }
+ //wcerr<<L"Row\tId\tName\t\tCost"<<endl;
+ wcerr<<L"Id\tFirstName\tLastName"<<endl;
+ CPPUNIT_ASSERT(drsPtr->next() == true);
+ int32_t* iPtr = drsPtr->getInt(1);
+ wstring* wsPtr = drsPtr->getString(2);
+ wstring* ws2Ptr = drsPtr->getString(3);
+ wcerr<<*iPtr<<L"\t"<<*wsPtr<<L"\t\t"<<*ws2Ptr<<endl;
+
+ //This next() should return false because we asked just 1 row
+ CPPUNIT_ASSERT(drsPtr->next() == false);
delete statementPtr;
}
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits