| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094 |
- //
- // ODBCPostgreSQLTest.cpp
- //
- // $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCPostgreSQLTest.cpp#3 $
- //
- // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
- // and Contributors.
- //
- // Permission is hereby granted, free of charge, to any person or organization
- // obtaining a copy of the software and accompanying documentation covered by
- // this license (the "Software") to use, reproduce, display, distribute,
- // execute, and transmit the Software, and to prepare derivative works of the
- // Software, and to permit third-parties to whom the Software is furnished to
- // do so, all subject to the following:
- //
- // The copyright notices in the Software and this entire statement, including
- // the above license grant, this restriction and the following disclaimer,
- // must be included in all copies of the Software, in whole or in part, and
- // all derivative works of the Software, unless such copies or derivative
- // works are solely in the form of machine-executable object code generated by
- // a source language processor.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
- // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
- // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
- // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- // DEALINGS IN THE SOFTWARE.
- //
- #include "ODBCPostgreSQLTest.h"
- #include "CppUnit/TestCaller.h"
- #include "CppUnit/TestSuite.h"
- #include "Poco/String.h"
- #include "Poco/Format.h"
- #include "Poco/Tuple.h"
- #include "Poco/Exception.h"
- #include "Poco/Data/Common.h"
- #include "Poco/Data/BLOB.h"
- #include "Poco/Data/StatementImpl.h"
- #include "Poco/Data/ODBC/Connector.h"
- #include "Poco/Data/ODBC/Utility.h"
- #include "Poco/Data/ODBC/Diagnostics.h"
- #include "Poco/Data/ODBC/ODBCException.h"
- #include "Poco/Data/ODBC/ODBCStatementImpl.h"
- #include <sqltypes.h>
- #include <iostream>
- using namespace Poco::Data;
- using Poco::Data::ODBC::Utility;
- using Poco::Data::ODBC::ConnectionException;
- using Poco::Data::ODBC::StatementException;
- using Poco::Data::ODBC::StatementDiagnostics;
- using Poco::format;
- using Poco::Tuple;
- using Poco::NotFoundException;
- const bool ODBCPostgreSQLTest::bindValues[8] = {true, true, true, false, false, true, false, false};
- Poco::SharedPtr<Poco::Data::Session> ODBCPostgreSQLTest::_pSession = 0;
- Poco::SharedPtr<SQLExecutor> ODBCPostgreSQLTest::_pExecutor = 0;
- std::string ODBCPostgreSQLTest::_dbConnString;
- Poco::Data::ODBC::Utility::DriverMap ODBCPostgreSQLTest::_drivers;
- ODBCPostgreSQLTest::ODBCPostgreSQLTest(const std::string& name):
- CppUnit::TestCase(name)
- {
- }
- ODBCPostgreSQLTest::~ODBCPostgreSQLTest()
- {
- }
- void ODBCPostgreSQLTest::testBareboneODBC()
- {
- if (!_pSession) fail ("Test not available.");
- std::string tableCreateString = "CREATE TABLE Test "
- "(First VARCHAR(30),"
- "Second VARCHAR(30),"
- "Third BYTEA,"
- "Fourth INTEGER,"
- "Fifth FLOAT)";
- _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
- _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
- _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
- _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
- }
- void ODBCPostgreSQLTest::testSimpleAccess()
- {
- if (!_pSession) fail ("Test not available.");
- std::string tableName("Person");
- for (int i = 0; i < 8;)
- {
- recreatePersonTable();
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->simpleAccess();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testComplexType()
- {
- 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->complexType();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testSimpleAccessVector()
- {
- 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->simpleAccessVector();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testComplexTypeVector()
- {
- 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->complexTypeVector();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testInsertVector()
- {
- if (!_pSession) fail ("Test not available.");
- for (int i = 0; i < 8;)
- {
- recreateStringsTable();
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->insertVector();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testInsertEmptyVector()
- {
- if (!_pSession) fail ("Test not available.");
- for (int i = 0; i < 8;)
- {
- recreateStringsTable();
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->insertEmptyVector();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testSimpleAccessList()
- {
- 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->simpleAccessList();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testComplexTypeList()
- {
- 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->complexTypeList();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testInsertList()
- {
- if (!_pSession) fail ("Test not available.");
- for (int i = 0; i < 8;)
- {
- recreateStringsTable();
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->insertList();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testInsertEmptyList()
- {
- if (!_pSession) fail ("Test not available.");
- for (int i = 0; i < 8;)
- {
- recreateStringsTable();
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->insertEmptyList();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testSimpleAccessDeque()
- {
- 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->simpleAccessDeque();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testComplexTypeDeque()
- {
- 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->complexTypeDeque();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testInsertDeque()
- {
- if (!_pSession) fail ("Test not available.");
- for (int i = 0; i < 8;)
- {
- recreateStringsTable();
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->insertDeque();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testInsertEmptyDeque()
- {
- if (!_pSession) fail ("Test not available.");
- for (int i = 0; i < 8;)
- {
- recreateStringsTable();
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->insertEmptyDeque();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testInsertSingleBulk()
- {
- if (!_pSession) fail ("Test not available.");
- for (int i = 0; i < 8;)
- {
- recreateIntsTable();
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->insertSingleBulk();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testInsertSingleBulkVec()
- {
- if (!_pSession) fail ("Test not available.");
- for (int i = 0; i < 8;)
- {
- recreateIntsTable();
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->insertSingleBulkVec();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testLimit()
- {
- if (!_pSession) fail ("Test not available.");
- for (int i = 0; i < 8;)
- {
- recreateIntsTable();
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->limits();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testLimitZero()
- {
- if (!_pSession) fail ("Test not available.");
- for (int i = 0; i < 8;)
- {
- recreateIntsTable();
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->limitZero();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testLimitOnce()
- {
- if (!_pSession) fail ("Test not available.");
- recreateIntsTable();
- _pExecutor->limitOnce();
-
- }
- void ODBCPostgreSQLTest::testLimitPrepare()
- {
- if (!_pSession) fail ("Test not available.");
- for (int i = 0; i < 8;)
- {
- recreateIntsTable();
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->limitPrepare();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testPrepare()
- {
- if (!_pSession) fail ("Test not available.");
- for (int i = 0; i < 8;)
- {
- recreateIntsTable();
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->prepare();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testSetSimple()
- {
- 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->setSimple();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testSetComplex()
- {
- 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->setComplex();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testSetComplexUnique()
- {
- 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->setComplexUnique();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testMultiSetSimple()
- {
- 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->multiSetSimple();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testMultiSetComplex()
- {
- 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->multiSetComplex();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testMapComplex()
- {
- 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->mapComplex();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testMapComplexUnique()
- {
- 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->mapComplexUnique();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testMultiMapComplex()
- {
- 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->multiMapComplex();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::testSelectIntoSingle()
- {
- 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->selectIntoSingle();
- i += 2;
- }
- }
- void ODBCPostgreSQLTest::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 ODBCPostgreSQLTest::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 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::testInternalStorageType()
- {
- 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->internalStorageType();
- 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()"); }
- }
- bool ODBCPostgreSQLTest::canConnect(const std::string& driver, const std::string& dsn)
- {
- Utility::DriverMap::iterator itDrv = _drivers.begin();
- for (; itDrv != _drivers.end(); ++itDrv)
- {
- if (((itDrv->first).find(driver) != std::string::npos))
- {
- std::cout << "Driver found: " << itDrv->first
- << " (" << itDrv->second << ')' << std::endl;
- break;
- }
- }
- if (_drivers.end() == itDrv)
- {
- std::cout << driver << " driver NOT found, tests not available." << std::endl;
- return false;
- }
- Utility::DSNMap dataSources;
- Utility::dataSources(dataSources);
- Utility::DSNMap::iterator itDSN = dataSources.begin();
- for (; itDSN != dataSources.end(); ++itDSN)
- {
- if (itDSN->first == dsn && itDSN->second == driver)
- {
- std::cout << "DSN found: " << itDSN->first
- << " (" << itDSN->second << ')' << std::endl;
- format(_dbConnString, "DSN=%s", dsn);
- return true;
- }
- }
- // DSN not found, try connect without it
- format(_dbConnString, "DRIVER=%s;"
- "DATABASE=postgres;"
- "SERVER=localhost;"
- "PORT=5432;"
- "UID=postgres;"
- "PWD=postgres;"
- "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;", driver);
- return true;
- }
- void ODBCPostgreSQLTest::setUp()
- {
- }
- void ODBCPostgreSQLTest::tearDown()
- {
- dropTable("Person");
- dropTable("Strings");
- dropTable("Tuples");
- }
- bool ODBCPostgreSQLTest::init(const std::string& driver, const std::string& dsn)
- {
- Utility::drivers(_drivers);
- if (!canConnect(driver, dsn)) return false;
-
- ODBC::Connector::registerConnector();
- try
- {
- _pSession = new Session(ODBC::Connector::KEY, _dbConnString);
- }catch (ConnectionException& ex)
- {
- std::cout << ex.toString() << std::endl;
- return false;
- }
- if (_pSession && _pSession->isConnected())
- std::cout << "*** Connected to [" << driver << "] test database." << std::endl;
-
- _pExecutor = new SQLExecutor(driver + " SQL Executor", _pSession);
- return true;
- }
- CppUnit::Test* ODBCPostgreSQLTest::suite()
- {
- if (init("PostgreSQL ANSI", "PocoDataPostgreSQLTest"))
- {
- 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, testSimpleAccessList);
- CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexTypeList);
- CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertList);
- CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertEmptyList);
- CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccessDeque);
- CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexTypeDeque);
- CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertDeque);
- CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertEmptyDeque);
- 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);
- CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInternalStorageType);
- return pSuite;
- }
- return 0;
- }
|