| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072 |
- //
- // ODBCMySQLTest.cpp
- //
- // $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCMySQLTest.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 "ODBCMySQLTest.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 ODBCMySQLTest::bindValues[8] = {true, true, true, false, false, true, false, false};
- Poco::SharedPtr<Poco::Data::Session> ODBCMySQLTest::_pSession = 0;
- Poco::SharedPtr<SQLExecutor> ODBCMySQLTest::_pExecutor = 0;
- std::string ODBCMySQLTest::_dbConnString;
- Poco::Data::ODBC::Utility::DriverMap ODBCMySQLTest::_drivers;
- ODBCMySQLTest::ODBCMySQLTest(const std::string& name):
- CppUnit::TestCase(name)
- {
- }
- ODBCMySQLTest::~ODBCMySQLTest()
- {
- }
- void ODBCMySQLTest::testBareboneODBC()
- {
- if (!_pSession) fail ("Test not available.");
- std::string tableCreateString = "CREATE TABLE Test "
- "(First VARCHAR(30),"
- "Second VARCHAR(30),"
- "Third VARBINARY(30),"
- "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 ODBCMySQLTest::testSimpleAccess()
- {
- 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->simpleAccess();
- i += 2;
- }
- }
- void ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::testLimitOnce()
- {
- if (!_pSession) fail ("Test not available.");
- recreateIntsTable();
- _pExecutor->limitOnce();
-
- }
- void ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::testBLOB()
- {
- if (!_pSession) fail ("Test not available.");
-
- const std::size_t maxFldSize = 65534;
- _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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::testStoredProcedure()
- {
- //MySQL is currently buggy in this area:
- // http://bugs.mysql.com/bug.php?id=17898
- // http://bugs.mysql.com/bug.php?id=27632
- }
- void ODBCMySQLTest::testStoredFunction()
- {
- //MySQL is currently buggy in this area:
- // http://bugs.mysql.com/bug.php?id=17898
- // http://bugs.mysql.com/bug.php?id=27632
- }
- void ODBCMySQLTest::dropObject(const std::string& type, const std::string& name)
- {
- *_pSession << format("DROP %s IF EXISTS %s", type, name), now;
- }
- void ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::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 ODBCMySQLTest::recreateTuplesTable()
- {
- dropObject("TABLE", "Tuples");
- try { *_pSession << "CREATE TABLE Tuples "
- "(i0 INTEGER, i1 INTEGER, i2 INTEGER, i3 INTEGER, i4 INTEGER, i5 INTEGER, i6 INTEGER, "
- "i7 INTEGER, i8 INTEGER, i9 INTEGER, i10 INTEGER, i11 INTEGER, i12 INTEGER, i13 INTEGER,"
- "i14 INTEGER, i15 INTEGER, i16 INTEGER, i17 INTEGER, i18 INTEGER, i19 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 ODBCMySQLTest::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()"); }
- }
- bool ODBCMySQLTest::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=test;"
- "SERVER=localhost;"
- "UID=root;"
- "PWD=mysql;", driver);
- return true;
- }
- void ODBCMySQLTest::setUp()
- {
- }
- void ODBCMySQLTest::tearDown()
- {
- dropObject("TABLE", "Person");
- dropObject("TABLE", "Strings");
- dropObject("TABLE", "Tuples");
- }
- bool ODBCMySQLTest::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* ODBCMySQLTest::suite()
- {
- #ifdef POCO_OS_FAMILY_WINDOWS
- if (init("MySQL ODBC 3.51 Driver", "PocoDataMySQLTest"))
- #else
- if (init("MySQL", "PocoDataMySQLTest"))
- #endif
- {
- CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCMySQLTest");
- CppUnit_addTest(pSuite, ODBCMySQLTest, testBareboneODBC);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccess);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexType);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccessVector);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexTypeVector);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertVector);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertEmptyVector);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccessList);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexTypeList);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertList);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertEmptyList);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccessDeque);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexTypeDeque);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertDeque);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertEmptyDeque);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertSingleBulk);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertSingleBulkVec);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testLimit);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitOnce);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitPrepare);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitZero);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testPrepare);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testSetSimple);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testSetComplex);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testSetComplexUnique);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testMultiSetSimple);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testMultiSetComplex);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testMapComplex);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testMapComplexUnique);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testMultiMapComplex);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testSelectIntoSingle);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testSelectIntoSingleStep);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testSelectIntoSingleFail);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testLowerLimitOk);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testLowerLimitFail);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testCombinedLimits);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testCombinedIllegalLimits);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testRange);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testIllegalRange);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testSingleSelect);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testEmptyDB);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testBLOB);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testBLOBStmt);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testFloat);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testDouble);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testTuple);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testTupleVector);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testStoredProcedure);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testStoredFunction);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testInternalExtraction);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testInternalStorageType);
- return pSuite;
- }
- return 0;
- }
|