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

📄 odbcsqlitetest.cpp

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


void ODBCSQLiteTest::testSelectIntoSingleStep()
{
	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->selectIntoSingleStep();
		i += 2;
	}	
}


void ODBCSQLiteTest::testSelectIntoSingleFail()
{
	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->selectIntoSingleFail();
		i += 2;
	}	
}


void ODBCSQLiteTest::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 ODBCSQLiteTest::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 ODBCSQLiteTest::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 ODBCSQLiteTest::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 ODBCSQLiteTest::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 ODBCSQLiteTest::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 ODBCSQLiteTest::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 ODBCSQLiteTest::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 ODBCSQLiteTest::testBLOB()
{
	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->blob();
		i += 2;
	}
}


void ODBCSQLiteTest::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 ODBCSQLiteTest::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 ODBCSQLiteTest::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 ODBCSQLiteTest::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 ODBCSQLiteTest::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 ODBCSQLiteTest::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 ODBCSQLiteTest::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 (1 == it->_nativeError)//(no such table)
			{
				ignoreError = true;
				break;
			}
		}

		if (!ignoreError) throw;
	}
}


void ODBCSQLiteTest::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 ODBCSQLiteTest::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 ODBCSQLiteTest::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 ODBCSQLiteTest::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 ODBCSQLiteTest::recreateFloatsTable()
{
	dropTable("Strings");
	try { *_pSession << "CREATE TABLE Strings (str REAL)", now; }
	catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
	catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
}


void ODBCSQLiteTest::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 ODBCSQLiteTest::recreateVectorsTable()
{
	dropTable("Vectors");
	try { *_pSession << "CREATE TABLE Vectors (int0 INTEGER, flt0 REAL, str0 VARCHAR)", now; }
	catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
	catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
}


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

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

		Utility::DriverMap::iterator itDriver = _drivers.begin();
		for (; itDriver != _drivers.end(); ++itDriver)
		{
			if (((itDriver->first).find("SQLite3") != std::string::npos))
			{
				std::cout << "Driver found: " << itDriver->first 
					<< " (" << itDriver->second << ')' << std::endl;

				driverFound = true; 
				break;
			}
		}

		if (!driverFound) 
		{
			if (!_pSession && _dbConnString.empty())
			{
				std::cout << "SQLite3 DSN NOT found, will attempt to connect without it." << std::endl;
				_dbConnString = "Driver=SQLite3 ODBC Driver;Database=dummy.db;";
			}
			else if (!_dbConnString.empty())
			{
				std::cout << "SQLite3 tests not available." << std::endl;
				return;
			}
		}
	}

	if (!_pSession)
		_dbConnString = "Driver=SQLite3 ODBC Driver;Database=dummy.db;";
}


void ODBCSQLiteTest::setUp()
{
}


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


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

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

	return pSuite;
}

⌨️ 快捷键说明

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