| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175 |
- //
- // ODBCMySQLTest.cpp
- //
- // $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCMySQLTest.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 "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,"
- "Sixth DATETIME)";
- _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);
- tableCreateString = "CREATE TABLE Test "
- "(First VARCHAR(30),"
- "Second VARCHAR(30),"
- "Third VARBINARY(30),"
- "Fourth INTEGER,"
- "Fifth FLOAT,"
- "Sixth DATE)";
- _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL, false);
- _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND, false);
- _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL, false);
- _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND, false);
- }
- 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::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 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::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("HYT00");
- 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 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
- // Additionally, the standard ODBC stored procedure call syntax
- // {call storedProcedure(?)} is currently (3.51.12.00) not supported.
- // See http://bugs.mysql.com/bug.php?id=26535
- // Poco::Data support for MySQL ODBC is postponed until the above
- // issues are resolved.
- }
- 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
- // Additionally, the standard ODBC stored procedure call syntax
- // {call storedProcedure(?)} is currently (3.51.12.00) not supported.
- // See http://bugs.mysql.com/bug.php?id=26535
- // Poco::Data support for MySQL ODBC is postponed until the above
- // issues are resolved.
- }
- void ODBCMySQLTest::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 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::recreatePersonDateTimeTable()
- {
- dropObject("TABLE", "Person");
- try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Born DATETIME)", now; }
- catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
- catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
- }
- 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()"); }
- }
- void ODBCMySQLTest::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 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, testDateTime);
- 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);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testNull);
- CppUnit_addTest(pSuite, ODBCMySQLTest, testRowIterator);
- return pSuite;
- }
- return 0;
- }
|