📄 odbcpostgresqltest.cpp
字号:
_pExecutor->selectIntoSingleFail();
i += 2;
}
}
void ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::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(1000000);
i += 2;
}
}
void ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::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 (7 == it->_nativeError)//(table does not exist)
{
ignoreError = true;
break;
}
}
if (!ignoreError) throw;
}
}
void ODBCPostgreSQLTest::recreatePersonTable()
{
dropTable("Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(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 ODBCPostgreSQLTest::recreatePersonBLOBTable()
{
dropTable("Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BYTEA)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
}
void ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::recreateFloatsTable()
{
dropTable("Strings");
try { *_pSession << "CREATE TABLE Strings (str FLOAT)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
}
void ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::recreateVectorsTable()
{
dropTable("Vectors");
try { *_pSession << "CREATE TABLE Vectors (int0 INTEGER, flt0 FLOAT, 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 ODBCPostgreSQLTest::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("PostgreSQL") != std::string::npos))
{
std::cout << "Driver found: " << itDrv->first
<< " (" << itDrv->second << ')' << std::endl;
driverFound = true;
break;
}
}
if (!driverFound)
{
std::cout << "PostgreSQL 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("PostgreSQL") != std::string::npos))
{
std::cout << "DSN found: " << itDSN->first
<< " (" << itDSN->second << ')' << std::endl;
dsnFound = true;
break;
}
}
if (!dsnFound)
{
if (!_pSession && _dbConnString.empty())
{
std::cout << "PostgreSQL DSN NOT found, will attempt to connect without it." << std::endl;
_dbConnString = "DRIVER=" POSTGRESQL_ODBC_DRIVER ";"
"DATABASE=" POSTGRESQL_DB ";"
"SERVER=" POSTGRESQL_SERVER ";"
"PORT=" POSTGRESQL_PORT ";"
"UID=" POSTGRESQL_UID ";"
"PWD=" POSTGRESQL_PWD ";"
"SSLMODE=prefer;"
"LowerCaseIdentifier=0;"
"UseServerSidePrepare=0;"
"ByteaAsLongVarBinary=1;"
"BI=0;"
"TrueIsMinus1=0;"
"DisallowPremature=0;"
"UpdatableCursors=0;"
"LFConversion=1;"
"CancelAsFreeStmt=0;"
"Parse=0;"
"BoolsAsChar=1;"
"UnknownsAsLongVarchar=0;"
"TextAsLongVarchar=1;"
"UseDeclareFetch=0;"
"Ksqo=1;"
"Optimizer=1;"
"CommLog=0;"
"Debug=0;"
"MaxLongVarcharSize=8190;"
"MaxVarcharSize=254;"
"UnknownSizes=0;"
"Socket=8192;"
"Fetch=100;"
"ConnSettings=;"
"ShowSystemTables=0;"
"RowVersioning=0;"
"ShowOidColumn=0;"
"FakeOidIndex=0;"
"ReadOnly=0;";
}
else if (!_dbConnString.empty())
{
std::cout << "PostgreSQL tests not available." << std::endl;
return;
}
}
}
if (!_pSession)
format(_dbConnString, "DSN=%s;", _dsn);
}
void ODBCPostgreSQLTest::setUp()
{
}
void ODBCPostgreSQLTest::tearDown()
{
dropTable("Person");
dropTable("Strings");
}
CppUnit::Test* ODBCPostgreSQLTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCPostgreSQLTest");
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBareboneODBC);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccess);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexType);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccessVector);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexTypeVector);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertVector);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertEmptyVector);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertSingleBulk);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertSingleBulkVec);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimit);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimitOnce);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimitPrepare);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimitZero);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testPrepare);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSetSimple);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSetComplex);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSetComplexUnique);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultiSetSimple);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultiSetComplex);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMapComplex);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMapComplexUnique);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultiMapComplex);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSelectIntoSingle);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSelectIntoSingleStep);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSelectIntoSingleFail);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLowerLimitOk);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLowerLimitFail);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testCombinedLimits);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testCombinedIllegalLimits);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testRange);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testIllegalRange);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSingleSelect);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testEmptyDB);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBLOB);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBLOBStmt);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testFloat);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testDouble);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTuple);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTupleVector);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInternalExtraction);
return pSuite;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -