| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329 |
- //
- // ODBCDB2Test.cpp
- //
- // $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCDB2Test.cpp#5 $
- //
- // 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 "ODBCDB2Test.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 ODBCDB2Test::bindValues[8] = {true, true, true, false, false, true, false, false};
- Poco::SharedPtr<Poco::Data::Session> ODBCDB2Test::_pSession = 0;
- Poco::SharedPtr<SQLExecutor> ODBCDB2Test::_pExecutor = 0;
- std::string ODBCDB2Test::_dbConnString;
- Poco::Data::ODBC::Utility::DriverMap ODBCDB2Test::_drivers;
- ODBCDB2Test::ODBCDB2Test(const std::string& name):
- CppUnit::TestCase(name)
- {
- }
- ODBCDB2Test::~ODBCDB2Test()
- {
- }
- void ODBCDB2Test::testBareboneODBC()
- {
- if (!_pSession) fail ("Test not available.");
- std::string tableCreateString = "CREATE TABLE Test "
- "(First VARCHAR(30),"
- "Second VARCHAR(30),"
- "Third BLOB,"
- "Fourth INTEGER,"
- "Fifth FLOAT,"
- "Sixth TIMESTAMP)";
- _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 ODBCDB2Test::testSimpleAccess()
- {
- if (!_pSession) fail ("Test not available.");
- std::string tableName("Person");
- int count = 0;
- recreatePersonTable();
- *_pSession << "SELECT count(*) FROM sysibm.systables WHERE name = 'PERSON' AND creator = 'DB2ADMIN'",
- into(count),
- use(tableName),
- now;
- assert (1 == count);
- for (int i = 0; i < 8;)
- {
- recreatePersonTable();
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->simpleAccess();
- i += 2;
- }
- }
- void ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::testLimitOnce()
- {
- if (!_pSession) fail ("Test not available.");
- recreateIntsTable();
- _pExecutor->limitOnce();
-
- }
- void ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::testDateTime()
- {
- if (!_pSession) fail ("Test not available.");
- for (int i = 0; i < 8;)
- {
- recreatePersonDateTimeTable();
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->dateTime();
- i += 2;
- }
- }
- void ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::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 ODBCDB2Test::testNull()
- {
- if (!_pSession) fail ("Test not available.");
- // test for NOT NULL violation exception
- for (int i = 0; i < 8;)
- {
- recreateNullsTable("NOT NULL");
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->notNulls();
- i += 2;
- }
- // test for null insertion
- for (int i = 0; i < 8;)
- {
- recreateNullsTable();
- _pSession->setFeature("autoBind", bindValues[i]);
- _pSession->setFeature("autoExtract", bindValues[i+1]);
- _pExecutor->nulls();
- i += 2;
- }
- }
- void ODBCDB2Test::testStoredProcedure()
- {
- if (!_pSession) fail ("Test not available.");
- for (int k = 0; k < 8;)
- {
- _pSession->setFeature("autoBind", bindValues[k]);
- _pSession->setFeature("autoExtract", bindValues[k+1]);
- dropObject("PROCEDURE", "storedProcedure");
- *_pSession << "CREATE PROCEDURE storedProcedure(OUT outParam INTEGER) "
- "BEGIN "
- " SET outParam = -1; "
- "END" , now;
- int i = 0;
- *_pSession << "{call storedProcedure(?)}", out(i), now;
- assert(-1 == i);
- dropObject("PROCEDURE", "storedProcedure");
- *_pSession << "CREATE PROCEDURE storedProcedure(inParam INTEGER, OUT outParam INTEGER) "
- "BEGIN "
- " SET outParam = inParam*inParam; "
- "END" , now;
-
- i = 2;
- int j = 0;
- *_pSession << "{call storedProcedure(?, ?)}", in(i), out(j), now;
- assert(4 == j);
- dropObject("PROCEDURE", "storedProcedure");
-
- *_pSession << "CREATE PROCEDURE storedProcedure(INOUT ioParam INTEGER) "
- "BEGIN "
- " SET ioParam = ioParam*ioParam; "
- "END" , now;
- i = 2;
- *_pSession << "{call storedProcedure(?)}", io(i), now;
- assert(4 == i);
- dropObject("PROCEDURE", "storedProcedure");
- //TIMESTAMP is not supported as stored procedure parameter in DB2
- //(SQL0182N An expression with a datetime value or a labeled duration is not valid.)
- *_pSession << "CREATE PROCEDURE storedProcedure(inParam VARCHAR(1000), OUT outParam VARCHAR(1000)) "
- "BEGIN "
- " SET outParam = inParam; "
- "END" , now;
- std::string inParam =
- "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
- std::string outParam;
- *_pSession << "{call storedProcedure(?,?)}", in(inParam), out(outParam), now;
- assert(inParam == outParam);
- dropObject("PROCEDURE", "storedProcedure");
- k += 2;
- }
- }
- void ODBCDB2Test::testStoredFunction()
- {
- if (!_pSession) fail ("Test not available.");
- for (int k = 0; k < 8;)
- {
- _pSession->setFeature("autoBind", bindValues[k]);
- _pSession->setFeature("autoExtract", bindValues[k+1]);
- dropObject("PROCEDURE", "storedFunction");
- *_pSession << "CREATE PROCEDURE storedFunction() "
- "BEGIN "
- " RETURN -1; "
- "END" , now;
- int i = 0;
- *_pSession << "{? = call storedFunction()}", out(i), now;
- assert(-1 == i);
- dropObject("PROCEDURE", "storedFunction");
-
- *_pSession << "CREATE PROCEDURE storedFunction(inParam INTEGER) "
- "BEGIN "
- " RETURN inParam*inParam; "
- "END" , now;
-
- i = 2;
- int result = 0;
- *_pSession << "{? = call storedFunction(?)}", out(result), in(i), now;
- assert(4 == result);
- dropObject("PROCEDURE", "storedFunction");
- *_pSession << "CREATE PROCEDURE storedFunction(inParam INTEGER, OUT outParam INTEGER) "
- "BEGIN "
- " SET outParam = inParam*inParam; "
- " RETURN outParam; "
- "END" , now;
- i = 2;
- int j = 0;
- result = 0;
- *_pSession << "{? = call storedFunction(?, ?)}", out(result), in(i), out(j), now;
- assert(4 == j);
- assert(j == result);
- dropObject("PROCEDURE", "storedFunction");
- *_pSession << "CREATE PROCEDURE storedFunction(INOUT param1 INTEGER, INOUT param2 INTEGER) "
- "BEGIN "
- " DECLARE temp INTEGER;"
- " SET temp = param1; "
- " SET param1 = param2; "
- " SET param2 = temp; "
- " RETURN param1 + param2; "
- "END" , now;
- i = 1;
- j = 2;
- result = 0;
- *_pSession << "{? = call storedFunction(?, ?)}", out(result), io(i), io(j), now;
- assert(1 == j);
- assert(2 == i);
- assert(3 == result);
- Tuple<int, int> params(1, 2);
- assert(1 == params.get<0>());
- assert(2 == params.get<1>());
- result = 0;
- *_pSession << "{? = call storedFunction(?, ?)}", out(result), io(params), now;
- assert(1 == params.get<1>());
- assert(2 == params.get<0>());
- assert(3 == result);
- dropObject("PROCEDURE", "storedFunction");
- _pSession->setFeature("autoBind", true);
- *_pSession << "CREATE PROCEDURE storedFunction(inParam VARCHAR(10), OUT outParam VARCHAR(10)) "
- "BEGIN "
- " SET outParam = inParam; "
- " RETURN LENGTH(outParam);"//DB2 allows only integer as return type
- "END" , now;
- std::string inParam = "123456789";
- std::string outParam;
- int ret;
- *_pSession << "{? = call storedFunction(?,?)}", out(ret), in(inParam), out(outParam), now;
- assert(inParam == outParam);
- assert(ret == inParam.size());
- dropObject("PROCEDURE", "storedFunction");
- k += 2;
- }
- }
- void ODBCDB2Test::testRowIterator()
- {
- 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->rowIterator();
- i += 2;
- }
- }
- void ODBCDB2Test::dropObject(const std::string& type, const std::string& name)
- {
- try
- {
- *_pSession << format("DROP %s %s", type, name), 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 (-204 == it->_nativeError)//(table does not exist)
- {
- ignoreError = true;
- break;
- }
- }
- if (!ignoreError) throw;
- }
- }
- void ODBCDB2Test::recreatePersonTable()
- {
- dropObject("TABLE", "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 ODBCDB2Test::recreatePersonBLOBTable()
- {
- dropObject("TABLE", "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 ODBCDB2Test::recreatePersonDateTimeTable()
- {
- dropObject("TABLE", "Person");
- try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Born TIMESTAMP)", now; }
- catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
- catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
- }
- void ODBCDB2Test::recreateIntsTable()
- {
- dropObject("TABLE", "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 ODBCDB2Test::recreateStringsTable()
- {
- dropObject("TABLE", "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 ODBCDB2Test::recreateFloatsTable()
- {
- dropObject("TABLE", "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 ODBCDB2Test::recreateTuplesTable()
- {
- dropObject("TABLE", "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 ODBCDB2Test::recreateVectorsTable()
- {
- dropObject("TABLE", "Vectors");
- try { *_pSession << "CREATE TABLE Vectors (i0 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 ODBCDB2Test::recreateNullsTable(const std::string& notNull)
- {
- dropObject("TABLE", "NullTest");
- try { *_pSession << format("CREATE TABLE NullTest (i INTEGER %s, r FLOAT %s, v VARCHAR(30) %s)",
- notNull,
- notNull,
- notNull), now; }
- catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateNullsTable()"); }
- catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateNullsTable()"); }
- }
- bool ODBCDB2Test::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=POCOTEST;"
- "Hostname=localhost;"
- "Port=50000;"
- "Protocol=TCPIP;"
- "Uid=db2admin;"
- "Pwd=db2admin;", driver);
- return true;
- }
- void ODBCDB2Test::setUp()
- {
- }
- void ODBCDB2Test::tearDown()
- {
- dropObject("TABLE", "Person");
- dropObject("TABLE", "Strings");
- dropObject("TABLE", "Tuples");
- }
- bool ODBCDB2Test::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* ODBCDB2Test::suite()
- {
- if (init("IBM DB2 ODBC DRIVER - DB2COPY1", "PocoDataDB2Test"))
- {
- CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCDB2Test");
- CppUnit_addTest(pSuite, ODBCDB2Test, testBareboneODBC);
- CppUnit_addTest(pSuite, ODBCDB2Test, testSimpleAccess);
- CppUnit_addTest(pSuite, ODBCDB2Test, testComplexType);
- CppUnit_addTest(pSuite, ODBCDB2Test, testSimpleAccessVector);
- CppUnit_addTest(pSuite, ODBCDB2Test, testComplexTypeVector);
- CppUnit_addTest(pSuite, ODBCDB2Test, testInsertVector);
- CppUnit_addTest(pSuite, ODBCDB2Test, testInsertEmptyVector);
- CppUnit_addTest(pSuite, ODBCDB2Test, testSimpleAccessList);
- CppUnit_addTest(pSuite, ODBCDB2Test, testComplexTypeList);
- CppUnit_addTest(pSuite, ODBCDB2Test, testInsertList);
- CppUnit_addTest(pSuite, ODBCDB2Test, testInsertEmptyList);
- CppUnit_addTest(pSuite, ODBCDB2Test, testSimpleAccessDeque);
- CppUnit_addTest(pSuite, ODBCDB2Test, testComplexTypeDeque);
- CppUnit_addTest(pSuite, ODBCDB2Test, testInsertDeque);
- CppUnit_addTest(pSuite, ODBCDB2Test, testInsertEmptyDeque);
- CppUnit_addTest(pSuite, ODBCDB2Test, testInsertSingleBulk);
- CppUnit_addTest(pSuite, ODBCDB2Test, testInsertSingleBulkVec);
- CppUnit_addTest(pSuite, ODBCDB2Test, testLimit);
- CppUnit_addTest(pSuite, ODBCDB2Test, testLimitOnce);
- CppUnit_addTest(pSuite, ODBCDB2Test, testLimitPrepare);
- CppUnit_addTest(pSuite, ODBCDB2Test, testLimitZero);
- CppUnit_addTest(pSuite, ODBCDB2Test, testPrepare);
- CppUnit_addTest(pSuite, ODBCDB2Test, testSetSimple);
- CppUnit_addTest(pSuite, ODBCDB2Test, testSetComplex);
- CppUnit_addTest(pSuite, ODBCDB2Test, testSetComplexUnique);
- CppUnit_addTest(pSuite, ODBCDB2Test, testMultiSetSimple);
- CppUnit_addTest(pSuite, ODBCDB2Test, testMultiSetComplex);
- CppUnit_addTest(pSuite, ODBCDB2Test, testMapComplex);
- CppUnit_addTest(pSuite, ODBCDB2Test, testMapComplexUnique);
- CppUnit_addTest(pSuite, ODBCDB2Test, testMultiMapComplex);
- CppUnit_addTest(pSuite, ODBCDB2Test, testSelectIntoSingle);
- CppUnit_addTest(pSuite, ODBCDB2Test, testSelectIntoSingleStep);
- CppUnit_addTest(pSuite, ODBCDB2Test, testSelectIntoSingleFail);
- CppUnit_addTest(pSuite, ODBCDB2Test, testLowerLimitOk);
- CppUnit_addTest(pSuite, ODBCDB2Test, testLowerLimitFail);
- CppUnit_addTest(pSuite, ODBCDB2Test, testCombinedLimits);
- CppUnit_addTest(pSuite, ODBCDB2Test, testCombinedIllegalLimits);
- CppUnit_addTest(pSuite, ODBCDB2Test, testRange);
- CppUnit_addTest(pSuite, ODBCDB2Test, testIllegalRange);
- CppUnit_addTest(pSuite, ODBCDB2Test, testSingleSelect);
- CppUnit_addTest(pSuite, ODBCDB2Test, testEmptyDB);
- CppUnit_addTest(pSuite, ODBCDB2Test, testBLOB);
- CppUnit_addTest(pSuite, ODBCDB2Test, testBLOBStmt);
- CppUnit_addTest(pSuite, ODBCDB2Test, testDateTime);
- CppUnit_addTest(pSuite, ODBCDB2Test, testFloat);
- CppUnit_addTest(pSuite, ODBCDB2Test, testDouble);
- CppUnit_addTest(pSuite, ODBCDB2Test, testTuple);
- CppUnit_addTest(pSuite, ODBCDB2Test, testTupleVector);
- CppUnit_addTest(pSuite, ODBCDB2Test, testInternalExtraction);
- CppUnit_addTest(pSuite, ODBCDB2Test, testInternalStorageType);
- CppUnit_addTest(pSuite, ODBCDB2Test, testStoredProcedure);
- CppUnit_addTest(pSuite, ODBCDB2Test, testStoredFunction);
- CppUnit_addTest(pSuite, ODBCDB2Test, testNull);
- CppUnit_addTest(pSuite, ODBCDB2Test, testRowIterator);
- return pSuite;
- }
- return 0;
- }
|