Date: Wednesday, January 11, 2006 @ 20:16:19
Author: gilles
Path: /cvsroot/carob/carob/test
Added: 40-Parameter-PreparedStatement/TestPreparedStatement.cpp (1.1)
40-Parameter-PreparedStatement/TestPreparedStatement.hpp (1.1)
Modified: CarobTestLauncher.cpp (1.15 -> 1.16)
Added getMetaData() new function tests
As it is a pseudo-prepare command, gave it "prepare" name.
Also tests few ResultSetMeta functions
----------------------------------------------------------+
40-Parameter-PreparedStatement/TestPreparedStatement.cpp | 215 +++++++++++++
40-Parameter-PreparedStatement/TestPreparedStatement.hpp | 76 ++++
CarobTestLauncher.cpp | 3
3 files changed, 293 insertions(+), 1 deletion(-)
Index: carob/test/40-Parameter-PreparedStatement/TestPreparedStatement.cpp
diff -u /dev/null
carob/test/40-Parameter-PreparedStatement/TestPreparedStatement.cpp:1.1
--- /dev/null Wed Jan 11 20:16:19 2006
+++ carob/test/40-Parameter-PreparedStatement/TestPreparedStatement.cpp Wed Jan
11 20:16:19 2006
@@ -0,0 +1,215 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2005-2006 Continuent, Inc.
+ * Contact: [EMAIL PROTECTED]
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Initial developer(s): Gilles Rayrat
+ * Contributor(s):
+ */
+
+#include <iostream>
+
+#include "TestPreparedStatement.hpp"
+#include "ParameterStatement.hpp"
+#include "ResultSetMetaData.hpp"
+
+using std::wstring;
+using std::endl;
+
+using namespace CarobNS;
+
+void TestPreparedStatement::testPrepareEmptyStatement()
+{
+ wstring fctName(L"testPrepareEmptyStatement");
+ Statement* statementPtr = NULL;
+ try
+ {
+ statementPtr = connectionPtr->createStatement();
+ if (isDebugEnabled())
+ {
+ logDebug(fctName, L"Executing getMetaData() on empty statement - should
fail");
+ }
+ ResultSetMetaData* rsmdPtr = statementPtr->getMetaData();
+ CPPUNIT_ASSERT(rsmdPtr == NULL); //just to avoid warning on unsused var
+ }
+ catch (BackendException be)
+ {
+ if (isErrorEnabled())
+ {
+ logError(fctName, L"Query failed (this is ok). Exception: "
+ + be.description());
+ }
+ }
+ delete statementPtr;
+}
+void TestPreparedStatement::testPrepareEmptyParameterStatement()
+{
+ wstring fctName(L"testPrepareEmptyParameterStatement");
+ ParameterStatement* psPtr = NULL;
+ try
+ {
+ psPtr = connectionPtr->createParameterStatement(L"");
+ if (isDebugEnabled())
+ {
+ logDebug(fctName, L"Executing getMetaData() on empty parameter statement
- should fail");
+ }
+ ResultSetMetaData* rsmdPtr = psPtr->getMetaData();
+ CPPUNIT_ASSERT(rsmdPtr == NULL);
+ }
+ catch (BackendException be)
+ {
+ if (isErrorEnabled())
+ {
+ logError(fctName, L"Query failed (this is ok). Exception: "
+ + be.description());
+ }
+ }
+ delete psPtr;
+}
+
+void TestPreparedStatement::testPrepareUpdateStatement()
+{
+ wstring fctName(L"testPrepareUpdateStatement");
+ Statement* statementPtr = NULL;
+ try
+ {
+ statementPtr = connectionPtr->createStatement();
+ int nbRowsAffected = statementPtr->executeUpdate(
+ L"update product set name='changed by testPrepareUpdate' where id=0");
+ if (isDebugEnabled())
+ {
+ logDebug(fctName, L"Executing getMetaData() on update statement - should
fail");
+ }
+ ResultSetMetaData* rsmdPtr = statementPtr->getMetaData();
+ CPPUNIT_ASSERT(nbRowsAffected == 0 && rsmdPtr == NULL); //just to avoid
warning on unsused var
+ }
+ catch (BackendException be)
+ {
+ if (isErrorEnabled())
+ {
+ logError(fctName, L"Query failed (this is ok). Exception: "
+ + be.description());
+ }
+ }
+ delete statementPtr;
+}
+void TestPreparedStatement::testPrepareUpdateParameterStatement()
+{
+ wstring fctName(L"testPrepareUpdateParameterStatement");
+ ParameterStatement* psPtr = connectionPtr->createParameterStatement(L"update
address set name='changed by testPrepareUpdateParameterStatement' where id=?");
+ psPtr->setInt(1,0);
+ psPtr->executeUpdate();
+ if (isDebugEnabled())
+ {
+ logDebug(fctName, L"Executing getMetaData() on empty parameter statement");
+ }
+ ResultSetMetaData* rsmdPtr = psPtr->getMetaData();
+ CPPUNIT_ASSERT(rsmdPtr == NULL);
+ delete psPtr;
+}
+
+void TestPreparedStatement::testPrepareExecuteQueryStatement()
+{
+ wstring fctName(L"testPrepareExecuteQueryStatement");
+ Statement* statementPtr = connectionPtr->createStatement();
+ statementPtr->executeQuery(L"SELECT * FROM address");
+ if (isDebugEnabled())
+ {
+ logDebug(fctName, L"Executing getMetaData() on empty statement");
+ }
+ ResultSetMetaData* rsmdPtr = statementPtr->getMetaData();
+ CPPUNIT_ASSERT(rsmdPtr != NULL); //just to avoid warning on unsused var
+ CPPUNIT_ASSERT(rsmdPtr->getColumnCount() == 5);
+ delete statementPtr;
+}
+
+void TestPreparedStatement::testPrepareExecuteQueryParameterStatement()
+{
+ wstring fctName(L"testPrepareExecuteQueryParameterStatement");
+ ParameterStatement* psPtr = connectionPtr->createParameterStatement(L"SELECT
* FROM address where id=?");
+ psPtr->setInt(1,0);
+ psPtr->executeQuery();
+ if (isDebugEnabled())
+ {
+ logDebug(fctName, L"Executing getMetaData() on empty parameter statement");
+ }
+ ResultSetMetaData* rsmdPtr = psPtr->getMetaData();
+ CPPUNIT_ASSERT(rsmdPtr != NULL);
+ CPPUNIT_ASSERT(rsmdPtr->getColumnName(1) == L"ID");
+ delete psPtr;
+}
+
+void TestPreparedStatement::testPrepareExecuteStatement()
+{
+ wstring fctName(L"testPrepareExecuteStatement");
+ Statement* statementPtr = connectionPtr->createStatement();
+ statementPtr->execute(L"SELECT * FROM address");
+ if (isDebugEnabled())
+ {
+ logDebug(fctName, L"Executing getMetaData() on empty statement");
+ }
+ ResultSetMetaData* rsmdPtr = statementPtr->getMetaData();
+ CPPUNIT_ASSERT(rsmdPtr != NULL); //just to avoid warning on unsused var
+ CPPUNIT_ASSERT(rsmdPtr->getTableName(2) == L"ADDRESS");
+ delete statementPtr;
+}
+
+void TestPreparedStatement::testPrepareExecuteParameterStatement()
+{
+ wstring fctName(L"testPrepareExecuteParameterStatement");
+ ParameterStatement* psPtr = connectionPtr->createParameterStatement(L"SELECT
* FROM address where id=?");
+ psPtr->setInt(1,0);
+ psPtr->execute();
+ if (isDebugEnabled())
+ {
+ logDebug(fctName, L"Executing getMetaData() on empty parameter statement");
+ }
+ ResultSetMetaData* rsmdPtr = psPtr->getMetaData();
+ CPPUNIT_ASSERT(rsmdPtr != NULL);
+ CPPUNIT_ASSERT(rsmdPtr->getColumnType(3) == SQLT_VARCHAR);
+ delete psPtr;
+}
+
+CppUnit::Test* TestPreparedStatement::suite()
+{
+ CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite(
"TestPreparedStatement" );
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestPreparedStatement>(
+ "testPrepareEmptyStatement",
+
&TestPreparedStatement::testPrepareEmptyStatement));
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestPreparedStatement>(
+ "testPrepareEmptyParameterStatement",
+
&TestPreparedStatement::testPrepareEmptyParameterStatement));
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestPreparedStatement>(
+ "testPrepareUpdateStatement",
+
&TestPreparedStatement::testPrepareUpdateStatement));
+//TODO: re-enable this test once SEQUOIA-262 is fixed
+/* suiteOfTests->addTest(new CppUnit::TestCaller<TestPreparedStatement>(
+ "testPrepareUpdateParameterStatement",
+
&TestPreparedStatement::testPrepareUpdateParameterStatement));
+*/
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestPreparedStatement>(
+ "testPrepareExecuteQueryStatement",
+
&TestPreparedStatement::testPrepareExecuteQueryStatement));
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestPreparedStatement>(
+ "testPrepareExecuteQueryParameterStatement",
+
&TestPreparedStatement::testPrepareExecuteQueryParameterStatement));
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestPreparedStatement>(
+ "testPrepareExecuteStatement",
+
&TestPreparedStatement::testPrepareExecuteStatement));
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestPreparedStatement>(
+ "testPrepareExecuteParameterStatement",
+
&TestPreparedStatement::testPrepareExecuteParameterStatement));
+ return suiteOfTests;
+}
Index: carob/test/40-Parameter-PreparedStatement/TestPreparedStatement.hpp
diff -u /dev/null
carob/test/40-Parameter-PreparedStatement/TestPreparedStatement.hpp:1.1
--- /dev/null Wed Jan 11 20:16:19 2006
+++ carob/test/40-Parameter-PreparedStatement/TestPreparedStatement.hpp Wed Jan
11 20:16:19 2006
@@ -0,0 +1,76 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2005-2006 Continuent, Inc.
+ * Contact: [EMAIL PROTECTED]
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Initial developer(s): Gilles Rayrat
+ * Contributor(s):
+ */
+
+#ifndef TESTPREPAREDSTATEMENT_H_
+#define TESTPREPAREDSTATEMENT_H_
+
+#include "../ConnectionSetup.hpp"
+
+/**
+ * Test class for prepared statement.
+ * Even there is no real prepared statement class, any statement or parameter
+ * statement can be prepared by the command <code>getMetaData()</code>.
+ * This class tests both statement types preparation.
+ * This is basically a copy of exec read and exec write commands testing
+ * demo-raidb1 *MUST* run locally for test success !!!
+ */
+class TestPreparedStatement : public ConnectionSetup
+{
+public:
+ /** Suite of tests to be run */
+ static CppUnit::Test* suite();
+
+ /**
+ * Creates a Statement and prepares it without setting the query first
+ */
+ void testPrepareEmptyStatement();
+ /**
+ * Creates a ParameterStatement and prepares it without setting the query
first
+ */
+ void testPrepareEmptyParameterStatement();
+ /**
+ * Creates a Statement, executes an update and prepares it
+ */
+ void testPrepareUpdateStatement();
+ /**
+ * Creates a ParameterStatement, executes an update and prepares it
+ */
+ void testPrepareUpdateParameterStatement();
+ /**
+ * Creates a Statement, set the query and prepares it
+ */
+ void testPrepareExecuteQueryStatement();
+ /**
+ * Creates a ParameterStatement, set the query and prepares it
+ */
+ void testPrepareExecuteQueryParameterStatement();
+ /**
+ * Creates a Statement, set the query and prepares it
+ */
+ void testPrepareExecuteStatement();
+ /**
+ * Creates a ParameterStatement, set the query and prepares it
+ */
+ void testPrepareExecuteParameterStatement();
+
+};
+
+#endif /*TESTPREPAREDSTATEMENT_H_*/
Index: carob/test/CarobTestLauncher.cpp
diff -u carob/test/CarobTestLauncher.cpp:1.15
carob/test/CarobTestLauncher.cpp:1.16
--- carob/test/CarobTestLauncher.cpp:1.15 Thu Dec 22 17:04:38 2005
+++ carob/test/CarobTestLauncher.cpp Wed Jan 11 20:16:19 2006
@@ -39,6 +39,7 @@
#include "01-Unit/TestStringCodecs.hpp"
#include "30-ResultSet/TestSimpleUnicode.hpp"
#include "40-Parameter-PreparedStatement/TestParameterStatement.hpp"
+#include "40-Parameter-PreparedStatement/TestPreparedStatement.hpp"
using namespace CarobNS;
@@ -64,7 +65,7 @@
runner.addTest(TestStringCodecs::suite());
runner.addTest(TestSimpleUnicode::suite());
runner.addTest(TestParameterStatement::suite());
-
+ runner.addTest(TestPreparedStatement::suite());
// add our own protector
CarobProtector* cprot = new CarobProtector();
runner.eventManager().pushProtector(cprot);
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits