⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 odbcoracletest.cpp.svn-base

📁 很好用的网络封装库,不熟悉网络编程的人也可以使用。使用风格良好的标准c++编写。
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
}


void ODBCOracleTest::testLowerLimitOk()
{
	if (!_pSession) fail ("Test not available.");

	for (int i = 0; i < 8;)
	{
		recreatePersonTable();
		_pSession->setFeature("autoBind", bindValues[i]);
		_pSession->setFeature("autoExtract", bindValues[i+1]);
		_pExecutor->lowerLimitOk();
		i += 2;
	}	
}


void ODBCOracleTest::testSingleSelect()
{
	if (!_pSession) fail ("Test not available.");

	for (int i = 0; i < 8;)
	{
		recreatePersonTable();
		_pSession->setFeature("autoBind", bindValues[i]);
		_pSession->setFeature("autoExtract", bindValues[i+1]);
		_pExecutor->singleSelect();
		i += 2;
	}	
}


void ODBCOracleTest::testLowerLimitFail()
{
	if (!_pSession) fail ("Test not available.");

	for (int i = 0; i < 8;)
	{
		recreatePersonTable();
		_pSession->setFeature("autoBind", bindValues[i]);
		_pSession->setFeature("autoExtract", bindValues[i+1]);
		_pExecutor->lowerLimitFail();
		i += 2;
	}
}


void ODBCOracleTest::testCombinedLimits()
{
	if (!_pSession) fail ("Test not available.");

	for (int i = 0; i < 8;)
	{
		recreatePersonTable();
		_pSession->setFeature("autoBind", bindValues[i]);
		_pSession->setFeature("autoExtract", bindValues[i+1]);
		_pExecutor->combinedLimits();
		i += 2;
	}
}



void ODBCOracleTest::testRange()
{
	if (!_pSession) fail ("Test not available.");

	for (int i = 0; i < 8;)
	{
		recreatePersonTable();
		_pSession->setFeature("autoBind", bindValues[i]);
		_pSession->setFeature("autoExtract", bindValues[i+1]);
		_pExecutor->ranges();
		i += 2;
	}
}


void ODBCOracleTest::testCombinedIllegalLimits()
{
	if (!_pSession) fail ("Test not available.");

	for (int i = 0; i < 8;)
	{
		recreatePersonTable();
		_pSession->setFeature("autoBind", bindValues[i]);
		_pSession->setFeature("autoExtract", bindValues[i+1]);
		_pExecutor->combinedIllegalLimits();
		i += 2;
	}
}



void ODBCOracleTest::testIllegalRange()
{
	if (!_pSession) fail ("Test not available.");

	for (int i = 0; i < 8;)
	{
		recreatePersonTable();
		_pSession->setFeature("autoBind", bindValues[i]);
		_pSession->setFeature("autoExtract", bindValues[i+1]);
		_pExecutor->illegalRange();
		i += 2;
	}
}


void ODBCOracleTest::testEmptyDB()
{
	if (!_pSession) fail ("Test not available.");

	for (int i = 0; i < 8;)
	{
		recreatePersonTable();
		_pSession->setFeature("autoBind", bindValues[i]);
		_pSession->setFeature("autoExtract", bindValues[i+1]);
		_pExecutor->emptyDB();
		i += 2;
	}
}


void ODBCOracleTest::testBLOB()
{
	if (!_pSession) fail ("Test not available.");
	
	const std::size_t maxFldSize = 1000000;
	_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
	recreatePersonBLOBTable();

	try
	{
		_pExecutor->blob(maxFldSize);
		fail ("must fail");
	}
	catch (DataException&) 
	{
		_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize));
	}

	for (int i = 0; i < 8;)
	{
		recreatePersonBLOBTable();
		_pSession->setFeature("autoBind", bindValues[i]);
		_pSession->setFeature("autoExtract", bindValues[i+1]);
		_pExecutor->blob(maxFldSize);
		i += 2;
	}

	recreatePersonBLOBTable();
	try
	{
		_pExecutor->blob(maxFldSize+1);
		fail ("must fail");
	}
	catch (DataException&) { }
}


void ODBCOracleTest::testBLOBStmt()
{
	if (!_pSession) fail ("Test not available.");

	for (int i = 0; i < 8;)
	{
		recreatePersonBLOBTable();
		_pSession->setFeature("autoBind", bindValues[i]);
		_pSession->setFeature("autoExtract", bindValues[i+1]);
		_pExecutor->blobStmt();
		i += 2;
	}
}


void ODBCOracleTest::testFloat()
{
	if (!_pSession) fail ("Test not available.");

	for (int i = 0; i < 8;)
	{
		recreateFloatsTable();
		_pSession->setFeature("autoBind", bindValues[i]);
		_pSession->setFeature("autoExtract", bindValues[i+1]);
		_pExecutor->floats();
		i += 2;
	}
}


void ODBCOracleTest::testDouble()
{
	if (!_pSession) fail ("Test not available.");

	for (int i = 0; i < 8;)
	{
		recreateFloatsTable();
		_pSession->setFeature("autoBind", bindValues[i]);
		_pSession->setFeature("autoExtract", bindValues[i+1]);
		_pExecutor->doubles();
		i += 2;
	}
}


void ODBCOracleTest::testTuple()
{
	if (!_pSession) fail ("Test not available.");

	for (int i = 0; i < 8;)
	{
		recreateTuplesTable();
		_pSession->setFeature("autoBind", bindValues[i]);
		_pSession->setFeature("autoExtract", bindValues[i+1]);
		_pExecutor->tuples();
		i += 2;
	}
}


void ODBCOracleTest::testTupleVector()
{
	if (!_pSession) fail ("Test not available.");

	for (int i = 0; i < 8;)
	{
		recreateTuplesTable();
		_pSession->setFeature("autoBind", bindValues[i]);
		_pSession->setFeature("autoExtract", bindValues[i+1]);
		_pExecutor->tupleVector();
		i += 2;
	}
}


void ODBCOracleTest::testInternalExtraction()
{
	if (!_pSession) fail ("Test not available.");

	for (int i = 0; i < 8;)
	{
		recreateVectorsTable();
		_pSession->setFeature("autoBind", bindValues[i]);
		_pSession->setFeature("autoExtract", bindValues[i+1]);
		_pExecutor->internalExtraction();
		i += 2;
	}
}


void ODBCOracleTest::dropTable(const std::string& tableName)
{
	try
	{
		*_pSession << format("DROP TABLE %s", tableName), now;
	}
	catch (StatementException& ex)
	{
		bool ignoreError = false;
		const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
		StatementDiagnostics::Iterator it = flds.begin();
		for (; it != flds.end(); ++it)
		{
			if (942 == it->_nativeError)//ORA-00942 (table does not exist)
			{
				ignoreError = true;
				break;
			}
		}

		if (!ignoreError) throw;
	}
}


void ODBCOracleTest::recreatePersonTable()
{
	dropTable("Person");
	try { *_pSession << "CREATE TABLE Person (LastName VARCHAR2(30), FirstName VARCHAR2(30), Address VARCHAR2(30), Age INTEGER)", now; }
	catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
	catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
}


void ODBCOracleTest::recreatePersonBLOBTable()
{
	dropTable("Person");
	try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BLOB)", now; }
	catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
	catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
}


void ODBCOracleTest::recreateIntsTable()
{
	dropTable("Strings");
	try { *_pSession << "CREATE TABLE Strings (str INTEGER)", now; }
	catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
	catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
}


void ODBCOracleTest::recreateStringsTable()
{
	dropTable("Strings");
	try { *_pSession << "CREATE TABLE Strings (str VARCHAR(30))", now; }
	catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
	catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
}


void ODBCOracleTest::recreateFloatsTable()
{
	dropTable("Strings");
	try { *_pSession << "CREATE TABLE Strings (str NUMBER)", now; }
	catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
	catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
}


void ODBCOracleTest::recreateTuplesTable()
{
	dropTable("Tuples");
	try { *_pSession << "CREATE TABLE Tuples "
		"(int0 INTEGER, int1 INTEGER, int2 INTEGER, int3 INTEGER, int4 INTEGER, int5 INTEGER, int6 INTEGER, "
		"int7 INTEGER, int8 INTEGER, int9 INTEGER, int10 INTEGER, int11 INTEGER, int12 INTEGER, int13 INTEGER,"
		"int14 INTEGER, int15 INTEGER, int16 INTEGER, int17 INTEGER, int18 INTEGER, int19 INTEGER)", now; }
	catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
	catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
}


void ODBCOracleTest::recreateVectorsTable()
{
	dropTable("Vectors");
	try { *_pSession << "CREATE TABLE Vectors (int0 INTEGER, flt0 NUMBER, str0 VARCHAR(30))", now; }
	catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
	catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
}


void ODBCOracleTest::checkODBCSetup()
{
	static bool beenHere = false;

	if (!beenHere)
	{
		beenHere = true;
		
		bool driverFound = false;
		bool dsnFound = false;

		Utility::DriverMap::iterator itDrv = _drivers.begin();
		for (; itDrv != _drivers.end(); ++itDrv)
		{
			if (((itDrv->first).find("Oracle") != std::string::npos) &&
				((itDrv->first).find("Microsoft") == std::string::npos))
			{
				std::cout << "Driver found: " << itDrv->first 
					<< " (" << itDrv->second << ')' << std::endl;
				driverFound = true;
				break;
			}
		}

		if (!driverFound) 
		{
			std::cout << "Oracle driver NOT found, tests will fail." << std::endl;
			return;
		}
		
		Utility::DSNMap::iterator itDSN = _dataSources.begin();
		for (; itDSN != _dataSources.end(); ++itDSN)
		{
			if (((itDSN->first).find(_dsn) != std::string::npos) &&
				((itDSN->second).find("Oracle") != std::string::npos))
			{
				std::cout << "DSN found: " << itDSN->first 
					<< " (" << itDSN->second << ')' << std::endl;
				dsnFound = true;
				break;
			}
		}

		if (!dsnFound) 
		{
			if (!_pSession && _dbConnString.empty())
			{
				std::cout << "Oracle DSN NOT found, will attempt to connect without it." << std::endl;
				_dbConnString = "DRIVER={" ORACLE_ODBC_DRIVER "};"
					"UID=" ORACLE_UID ";"
					"PWD=" ORACLE_PWD ";"
					"TLO=O;" //?
					"FBS=60000;" // fetch buffer size (bytes), default 60000
					"FWC=F;" // force SQL_WCHAR support (T/F), default F
					"CSR=F;" // close cursor (T/F), default F
					"MDI=Me;" // metadata (SQL_ATTR_METADATA_ID) ID default (T/F), default T
					"MTS=T;" //?
					"DPM=F;" // disable SQLDescribeParam (T/F), default F
					"NUM=NLS;" // numeric settings (NLS implies Globalization Support)
					"BAM=IfAllSuccessful;" // batch autocommit, (IfAllSuccessful/UpToFirstFailure/AllSuccessful), default IfAllSuccessful
					"BTD=F;" // bind timestamp as date (T/F), default F
					"RST=T;" // resultsets (T/F), default T
					"LOB=T;" // LOB writes (T/F), default T
					"FDL=0;" // failover delay (default 10)
					"FRC=0;" // failover retry count (default 10)
					"QTO=T;" // query timout option (T/F), default T
					"FEN=F;" // failover (T/F), default T
					"XSM=Default;" // schema field (Default/Database/Owner), default Default
					"EXC=F;" // EXEC syntax (T/F), default F
					"APA=T;" // thread safety (T/F), default T
					"DBA=W;" // write access
					"DBQ=" ORACLE_SID ";" // TNS service name
					"SERVER="
					"(DESCRIPTION="
					" (ADDRESS=(PROTOCOL=TCP)(HOST=" ORACLE_SERVER " )(PORT=" ORACLE_PORT "))"
					" (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=" ORACLE_SID "))"
					");";

			}
			else if (!_dbConnString.empty())
			{
				std::cout << "Oracle tests not available." << std::endl;
				return;
			}
		}
	}

	if (!_pSession)
		format(_dbConnString, "DSN=%s;Uid=Scott;Pwd=Tiger;", _dsn);
}


void ODBCOracleTest::setUp()
{
}


void ODBCOracleTest::tearDown()
{
	dropTable("Person");
	dropTable("Strings");
}


CppUnit::Test* ODBCOracleTest::suite()
{
	CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCOracleTest");

	CppUnit_addTest(pSuite, ODBCOracleTest, testBareboneODBC);
	CppUnit_addTest(pSuite, ODBCOracleTest, testSimpleAccess);
	CppUnit_addTest(pSuite, ODBCOracleTest, testComplexType);
	CppUnit_addTest(pSuite, ODBCOracleTest, testSimpleAccessVector);
	CppUnit_addTest(pSuite, ODBCOracleTest, testComplexTypeVector);
	CppUnit_addTest(pSuite, ODBCOracleTest, testInsertVector);
	CppUnit_addTest(pSuite, ODBCOracleTest, testInsertEmptyVector);
	CppUnit_addTest(pSuite, ODBCOracleTest, testInsertSingleBulk);
	CppUnit_addTest(pSuite, ODBCOracleTest, testInsertSingleBulkVec);
	CppUnit_addTest(pSuite, ODBCOracleTest, testLimit);
	CppUnit_addTest(pSuite, ODBCOracleTest, testLimitOnce);
	CppUnit_addTest(pSuite, ODBCOracleTest, testLimitPrepare);
	CppUnit_addTest(pSuite, ODBCOracleTest, testLimitZero);
	CppUnit_addTest(pSuite, ODBCOracleTest, testPrepare);
	CppUnit_addTest(pSuite, ODBCOracleTest, testSetSimple);
	CppUnit_addTest(pSuite, ODBCOracleTest, testSetComplex);
	CppUnit_addTest(pSuite, ODBCOracleTest, testSetComplexUnique);
	CppUnit_addTest(pSuite, ODBCOracleTest, testMultiSetSimple);
	CppUnit_addTest(pSuite, ODBCOracleTest, testMultiSetComplex);
	CppUnit_addTest(pSuite, ODBCOracleTest, testMapComplex);
	CppUnit_addTest(pSuite, ODBCOracleTest, testMapComplexUnique);
	CppUnit_addTest(pSuite, ODBCOracleTest, testMultiMapComplex);
	CppUnit_addTest(pSuite, ODBCOracleTest, testSelectIntoSingle);
	CppUnit_addTest(pSuite, ODBCOracleTest, testSelectIntoSingleStep);
	CppUnit_addTest(pSuite, ODBCOracleTest, testSelectIntoSingleFail);
	CppUnit_addTest(pSuite, ODBCOracleTest, testLowerLimitOk);
	CppUnit_addTest(pSuite, ODBCOracleTest, testLowerLimitFail);
	CppUnit_addTest(pSuite, ODBCOracleTest, testCombinedLimits);
	CppUnit_addTest(pSuite, ODBCOracleTest, testCombinedIllegalLimits);
	CppUnit_addTest(pSuite, ODBCOracleTest, testRange);
	CppUnit_addTest(pSuite, ODBCOracleTest, testIllegalRange);
	CppUnit_addTest(pSuite, ODBCOracleTest, testSingleSelect);
	CppUnit_addTest(pSuite, ODBCOracleTest, testEmptyDB);
	CppUnit_addTest(pSuite, ODBCOracleTest, testBLOB);
	CppUnit_addTest(pSuite, ODBCOracleTest, testBLOBStmt);
	CppUnit_addTest(pSuite, ODBCOracleTest, testFloat);
	CppUnit_addTest(pSuite, ODBCOracleTest, testDouble);
	CppUnit_addTest(pSuite, ODBCOracleTest, testTuple);
	CppUnit_addTest(pSuite, ODBCOracleTest, testTupleVector);
	CppUnit_addTest(pSuite, ODBCOracleTest, testInternalExtraction);

	return pSuite;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -