mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-23 18:42:17 +01:00
some fixes (mostly unicode/bulk)
This commit is contained in:
parent
c0310b5c74
commit
d93acd5409
@ -647,15 +647,15 @@ private:
|
||||
|
||||
setParamSetSize(val.size());
|
||||
|
||||
SQLINTEGER size = 0;
|
||||
getColumnOrParameterSize(pos, size);
|
||||
poco_assert(size > 0);
|
||||
SQLINTEGER fieldSize = 0;
|
||||
getColumnOrParameterSize(pos, fieldSize);
|
||||
poco_assert(fieldSize > 0);
|
||||
|
||||
if (size == _maxFieldSize)
|
||||
if (fieldSize == _maxFieldSize)
|
||||
{
|
||||
getMinValueSize(val, size);
|
||||
getMinValueSize(val, fieldSize);
|
||||
// accommodate for terminating zero
|
||||
if (size != _maxFieldSize) size += sizeof(UTF16Char);
|
||||
if (fieldSize != _maxFieldSize) fieldSize += sizeof(UTF16Char);
|
||||
}
|
||||
|
||||
if (_vecLengthIndicator.size() <= pos)
|
||||
@ -667,30 +667,31 @@ private:
|
||||
if (_utf16CharPtrs.size() <= pos)
|
||||
_utf16CharPtrs.resize(pos + 1, 0);
|
||||
|
||||
_utf16CharPtrs[pos] = (UTF16Char*)std::calloc(val.size() * size, sizeof(UTF16Char));
|
||||
_utf16CharPtrs[pos] = (UTF16Char*)std::calloc(val.size() * fieldSize, sizeof(UTF16Char));
|
||||
|
||||
std::size_t strSize;
|
||||
std::size_t offset = 0;
|
||||
char* pBuf = (char*)_utf16CharPtrs[pos];
|
||||
typename C::const_iterator it = val.begin();
|
||||
typename C::const_iterator end = val.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
strSize = it->size() * sizeof(UTF16Char);
|
||||
if (strSize > size)
|
||||
throw LengthExceededException("SQLBindParameter(std::vector<UTF16String>)");
|
||||
std::memcpy(_utf16CharPtrs[pos] + offset, it->data(), strSize);
|
||||
offset += (size / sizeof(UTF16Char));
|
||||
if (strSize > fieldSize - sizeof(UTF16Char))
|
||||
throw LengthExceededException("Binder::bindImplContainerUTF16String");
|
||||
std::memcpy(pBuf + offset, it->data(), strSize);
|
||||
offset += fieldSize;
|
||||
}
|
||||
SQLSMALLINT sqlType = (isInBound(dir) && size < _maxWCharColLength) ? SQL_WVARCHAR : SQL_WLONGVARCHAR;
|
||||
SQLSMALLINT sqlType = (isInBound(dir) && fieldSize < _maxWCharColLength) ? SQL_WVARCHAR : SQL_WLONGVARCHAR;
|
||||
if (Utility::isError(SQLBindParameter(_rStmt,
|
||||
(SQLUSMALLINT)pos + 1,
|
||||
toODBCDirection(dir),
|
||||
SQL_C_WCHAR,
|
||||
sqlType,
|
||||
(SQLUINTEGER)size - 1,
|
||||
(SQLUINTEGER)fieldSize,
|
||||
0,
|
||||
_utf16CharPtrs[pos],
|
||||
(SQLINTEGER)size,
|
||||
(SQLINTEGER)fieldSize,
|
||||
&(*_vecLengthIndicator[pos])[0])))
|
||||
{
|
||||
throw StatementException(_rStmt, "SQLBindParameter(std::vector<UTF16String>)");
|
||||
|
@ -573,7 +573,7 @@ void Binder::getColSizeAndPrecision(std::size_t pos,
|
||||
DynamicAny tmp;
|
||||
bool found = _pTypeInfo->tryGetInfo(cDataType, "COLUMN_SIZE", tmp);
|
||||
if (found) colSize = tmp;
|
||||
if (actualSize > colSize)
|
||||
if (colSize && actualSize > colSize)
|
||||
{
|
||||
throw LengthExceededException(Poco::format("Error binding column %z size=%z, max size=%ld)",
|
||||
pos, actualSize, static_cast<long>(colSize)));
|
||||
|
@ -139,7 +139,8 @@ std::size_t Preparator::columns() const
|
||||
void Preparator::resize() const
|
||||
{
|
||||
SQLSMALLINT nCol = 0;
|
||||
if (!Utility::isError(SQLNumResultCols(_rStmt, &nCol)) && 0 != nCol)
|
||||
int rc = SQLNumResultCols(_rStmt, &nCol);
|
||||
if (!Utility::isError(rc) && (0 != nCol))
|
||||
{
|
||||
_values.resize(nCol, 0);
|
||||
_lengths.resize(nCol, 0);
|
||||
|
@ -265,6 +265,16 @@ void ODBCMySQLTest::recreatePersonTable()
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::recreatePersonUnicodeTable()
|
||||
{
|
||||
dropObject("TABLE", ExecUtil::person());
|
||||
try { *_pSession << "CREATE TABLE " << ExecUtil::person() <<
|
||||
" (LastName VARCHAR(30) CHARACTER SET utf16, FirstName VARCHAR(30) CHARACTER SET utf16, Address VARCHAR(30) CHARACTER SET utf16, 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", ExecUtil::person());
|
||||
@ -352,7 +362,7 @@ void ODBCMySQLTest::recreateTuplesTable()
|
||||
void ODBCMySQLTest::recreateVectorsTable()
|
||||
{
|
||||
dropObject("TABLE", ExecUtil::vectors() );
|
||||
try { *_pSession << "CREATE TABLE " << ExecUtil::vectors() << " (i0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
|
||||
try{ *_pSession << "CREATE TABLE " << ExecUtil::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()"); }
|
||||
}
|
||||
@ -360,8 +370,15 @@ void ODBCMySQLTest::recreateVectorsTable()
|
||||
|
||||
void ODBCMySQLTest::recreateAnysTable()
|
||||
{
|
||||
dropObject("TABLE", ExecUtil::anys() );
|
||||
try { *_pSession << "CREATE TABLE " << ExecUtil::anys() << " (i0 INTEGER, flt0 DOUBLE, str0 VARCHAR(30))", now; }
|
||||
dropObject("TABLE", ExecUtil::anys());
|
||||
try
|
||||
{
|
||||
#ifdef POCO_ODBC_UNICODE
|
||||
*_pSession << "CREATE TABLE " << ExecUtil::anys() << " (i0 INTEGER, flt0 DOUBLE, str0 VARCHAR(30) CHARACTER SET utf16)", now;
|
||||
#else
|
||||
*_pSession << "CREATE TABLE " << ExecUtil::anys() << " (i0 INTEGER, flt0 DOUBLE, str0 VARCHAR(30))", now;
|
||||
#endif
|
||||
}
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateAnysTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateAnysTable()"); }
|
||||
}
|
||||
@ -456,7 +473,7 @@ CppUnit::Test* ODBCMySQLTest::suite()
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitPrepare);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitZero);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testPrepare);
|
||||
//CppUnit_addTest(pSuite, ODBCMySQLTest, testBulk);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testBulk);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testBulkPerformance);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testSetSimple);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testSetComplex);
|
||||
@ -498,7 +515,7 @@ CppUnit::Test* ODBCMySQLTest::suite()
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testAsync);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testAny);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testDynamicAny);
|
||||
//CppUnit_addTest(pSuite, ODBCMySQLTest, testMultipleResults);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testMultipleResults);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testSQLChannel);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testSQLLogger);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testSessionTransaction);
|
||||
|
@ -51,6 +51,7 @@ private:
|
||||
void dropObject(const std::string& type, const std::string& name);
|
||||
void recreateNullableTable();
|
||||
void recreatePersonTable();
|
||||
void recreatePersonUnicodeTable();
|
||||
void recreatePersonBLOBTable();
|
||||
void recreatePersonDateTable();
|
||||
void recreatePersonTimeTable();
|
||||
@ -65,7 +66,7 @@ private:
|
||||
void recreateNullsTable(const std::string& notNull = "");
|
||||
void recreateMiscTable();
|
||||
void recreateLogTable();
|
||||
void testInternalBulkExtraction() { std::cout << " disabled" << std::endl; }
|
||||
//void testInternalBulkExtraction() { std::cout << " disabled" << std::endl; }
|
||||
static ODBCTest::SessionPtr _pSession;
|
||||
static ODBCTest::ExecPtr _pExecutor;
|
||||
static std::string _driver;
|
||||
|
@ -176,11 +176,7 @@ void ODBCOracleTest::testInternalExtraction()
|
||||
recreateVectorsTable();
|
||||
_pSession->setFeature("autoBind", bindValue(i));
|
||||
_pSession->setFeature("autoExtract", bindValue(i+1));
|
||||
#ifdef POCO_64_BIT
|
||||
_pExecutor->internalExtraction<double>(0.);
|
||||
#else
|
||||
_pExecutor->internalExtraction(0);
|
||||
#endif
|
||||
_pExecutor->internalExtraction();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
@ -358,6 +354,8 @@ void ODBCOracleTest::testStoredProcedureAny()
|
||||
void ODBCOracleTest::testStoredProcedureAnyString()
|
||||
{
|
||||
Any sInOut = std::string("Hello");
|
||||
//strings only work with auto-binding
|
||||
session().setFeature("autoBind", true);
|
||||
|
||||
*_pSession << "CREATE OR REPLACE "
|
||||
"PROCEDURE storedProcedure(inParam IN OUT VARCHAR2) IS "
|
||||
@ -718,6 +716,15 @@ void ODBCOracleTest::recreatePersonTable()
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::recreatePersonUnicodeTable()
|
||||
{
|
||||
dropObject("TABLE", ExecUtil::person());
|
||||
try { *_pSession << "CREATE TABLE " << ExecUtil::person() << " (LastName NVARCHAR2(30), FirstName NVARCHAR2(30), Address NVARCHAR2(30), Age INTEGER)", now; }
|
||||
catch (ConnectionException& ce) { std::cout << ce.toString() << std::endl; fail("recreatePersonUnicodeTable()"); }
|
||||
catch (StatementException& se) { std::cout << se.toString() << std::endl; fail("recreatePersonUnicodeTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::recreatePersonTupleTable()
|
||||
{
|
||||
dropObject("TABLE", ExecUtil::person());
|
||||
|
@ -58,6 +58,7 @@ private:
|
||||
void dropObject(const std::string& type, const std::string& name);
|
||||
void recreateNullableTable();
|
||||
void recreatePersonTable();
|
||||
void recreatePersonUnicodeTable();
|
||||
void recreatePersonTupleTable();
|
||||
void recreatePersonBLOBTable();
|
||||
void recreatePersonDateTable();
|
||||
|
@ -74,7 +74,7 @@ static std::string postgreSettings()
|
||||
return Poco::Environment::get("POCO_TEST_POSTGRES_SETTINGS", "");
|
||||
}
|
||||
|
||||
#define POSTGRESQL_VERSION "9.3"
|
||||
#define POSTGRESQL_VERSION "10"
|
||||
|
||||
static std::string postgreConnParams()
|
||||
{
|
||||
@ -85,16 +85,16 @@ static std::string postgreConnParams()
|
||||
|
||||
static std::string postgreUid()
|
||||
{
|
||||
return Poco::Environment::get("POCO_TEST_POSTGRES_UID", "");
|
||||
return "postgres";
|
||||
}
|
||||
|
||||
static std::string postgrePwd()
|
||||
{
|
||||
return Poco::Environment::get("POCO_TEST_POSTGRES_PWD", "");
|
||||
return "poco";
|
||||
}
|
||||
|
||||
#ifdef POCO_OS_FAMILY_WINDOWS
|
||||
const std::string ODBCPostgreSQLTest::_libDir = "C:\\\\Program Files\\\\PostgreSQL\\\\" POSTGRESQL_VERSION "\\\\lib\\\\";
|
||||
const std::string ODBCPostgreSQLTest::_libDir = "C:\\\\Program Files\\\\PostgreSQL\\\\pg" POSTGRESQL_VERSION "\\\\lib\\\\";
|
||||
#else
|
||||
const std::string ODBCPostgreSQLTest::_libDir = "/usr/local/pgsql/lib/";
|
||||
#endif
|
||||
@ -388,9 +388,10 @@ void ODBCPostgreSQLTest::configurePLPgSQL()
|
||||
"HANDLER plpgsql_call_handler "
|
||||
"LANCOMPILER 'PL/pgSQL'", now;
|
||||
|
||||
}catch(StatementException& ex)
|
||||
}
|
||||
catch(StatementException& ex)
|
||||
{
|
||||
if (7 != ex.diagnostics().nativeError(0))
|
||||
if (1 != ex.diagnostics().nativeError(0))
|
||||
throw;
|
||||
}
|
||||
|
||||
@ -411,7 +412,7 @@ void ODBCPostgreSQLTest::dropObject(const std::string& type, const std::string&
|
||||
StatementDiagnostics::Iterator it = flds.begin();
|
||||
for (; it != flds.end(); ++it)
|
||||
{
|
||||
if (7 == it->_nativeError)//(table does not exist)
|
||||
if (1 == it->_nativeError)//(table does not exist)
|
||||
{
|
||||
ignoreError = true;
|
||||
break;
|
||||
@ -441,6 +442,12 @@ void ODBCPostgreSQLTest::recreatePersonTable()
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::recreatePersonUnicodeTable()
|
||||
{
|
||||
recreatePersonTable();
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::recreatePersonBLOBTable()
|
||||
{
|
||||
dropObject("TABLE", ExecUtil::person());
|
||||
@ -498,13 +505,22 @@ void ODBCPostgreSQLTest::recreateStringsTable()
|
||||
|
||||
void ODBCPostgreSQLTest::recreateFloatsTable()
|
||||
{
|
||||
dropObject("TABLE", ExecUtil::strings());
|
||||
try { session() << "CREATE TABLE " << ExecUtil::strings() <<" (str FLOAT)", now; }
|
||||
dropObject("TABLE", ExecUtil::floats());
|
||||
try { session() << "CREATE TABLE " << ExecUtil::floats() <<" (str REAL)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::recreateDoublesTable()
|
||||
{
|
||||
dropObject("TABLE", ExecUtil::doubles());
|
||||
try { session() << "CREATE TABLE " << ExecUtil::doubles() << " (str DOUBLE PRECISION)", now; }
|
||||
catch (ConnectionException& ce) { std::cout << ce.toString() << std::endl; fail("recreateDoublesTable()"); }
|
||||
catch (StatementException& se) { std::cout << se.toString() << std::endl; fail("recreateDoublesTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::recreateTuplesTable()
|
||||
{
|
||||
dropObject("TABLE", ExecUtil::tuples());
|
||||
@ -520,7 +536,7 @@ void ODBCPostgreSQLTest::recreateTuplesTable()
|
||||
void ODBCPostgreSQLTest::recreateVectorsTable()
|
||||
{
|
||||
dropObject("TABLE", ExecUtil::vectors());
|
||||
try { session() << "CREATE TABLE " << ExecUtil::vectors() << " (i0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
|
||||
try { session() << "CREATE TABLE " << ExecUtil::vectors() << " (int0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
|
||||
}
|
||||
@ -713,11 +729,14 @@ CppUnit::Test* ODBCPostgreSQLTest::suite()
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testDynamicAny);
|
||||
//neither pSQL ODBC nor Mammoth drivers support multiple results properly
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultipleResults);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultipleResultsNoProj);
|
||||
//CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultipleResultsNoProj);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSQLChannel);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSQLLogger);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSessionTransaction);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTransaction);
|
||||
// (postgres bug?)
|
||||
// local session claims to be capable of reading uncommitted changes,
|
||||
// but fails to do so
|
||||
//CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSessionTransaction);
|
||||
//CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTransaction);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTransactor);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testNullable);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testUnicode);
|
||||
|
@ -53,6 +53,7 @@ private:
|
||||
void dropObject(const std::string& type, const std::string& name);
|
||||
void recreateNullableTable();
|
||||
void recreatePersonTable();
|
||||
void recreatePersonUnicodeTable();
|
||||
void recreatePersonBLOBTable();
|
||||
void recreatePersonDateTimeTable();
|
||||
void recreatePersonDateTable();
|
||||
@ -60,6 +61,7 @@ private:
|
||||
void recreateStringsTable();
|
||||
void recreateIntsTable();
|
||||
void recreateFloatsTable();
|
||||
void recreateDoublesTable();
|
||||
void recreateTuplesTable();
|
||||
void recreateVectorsTable();
|
||||
void recreateAnysTable();
|
||||
|
@ -973,7 +973,7 @@ void ODBCTest::testInternalExtraction()
|
||||
recreateVectorsTable();
|
||||
_pSession->setFeature("autoBind", bindValue(i));
|
||||
_pSession->setFeature("autoExtract", bindValue(i+1));
|
||||
_pExecutor->internalExtraction(0);
|
||||
_pExecutor->internalExtraction();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
@ -998,12 +998,14 @@ void ODBCTest::testInternalBulkExtraction()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", true);
|
||||
_pSession->setFeature("autoExtract", true);
|
||||
|
||||
#ifdef POCO_ODBC_UNICODE
|
||||
recreatePersonUnicodeTable();
|
||||
_pExecutor->internalBulkExtractionUTF16();
|
||||
#else
|
||||
recreatePersonTable();
|
||||
_pExecutor->internalBulkExtraction();
|
||||
#endif
|
||||
}
|
||||
|
@ -162,6 +162,7 @@ protected:
|
||||
virtual void dropObject(const std::string& type, const std::string& name);
|
||||
virtual void recreateNullableTable();
|
||||
virtual void recreatePersonTable();
|
||||
virtual void recreatePersonUnicodeTable();
|
||||
virtual void recreatePersonTupleTable();
|
||||
virtual void recreatePersonBLOBTable();
|
||||
virtual void recreatePersonDateTimeTable();
|
||||
@ -282,6 +283,12 @@ inline void ODBCTest::recreatePersonTable()
|
||||
}
|
||||
|
||||
|
||||
inline void ODBCTest::recreatePersonUnicodeTable()
|
||||
{
|
||||
throw Poco::NotImplementedException("ODBCTest::recreatePersonUnicodeTable()");
|
||||
}
|
||||
|
||||
|
||||
inline void ODBCTest::recreatePersonTupleTable()
|
||||
{
|
||||
throw Poco::NotImplementedException("ODBCTest::recreatePersonTupleTable()");
|
||||
|
@ -2777,6 +2777,146 @@ void SQLExecutor::tupleVector()
|
||||
}
|
||||
|
||||
|
||||
void SQLExecutor::internalExtraction()
|
||||
{
|
||||
typedef int IntType;
|
||||
using Poco::Data::RecordSet;
|
||||
using Poco::Data::Column;
|
||||
using Poco::Data::Statement;
|
||||
using Poco::UTF16String;
|
||||
using Poco::Tuple;
|
||||
using Poco::BadCastException;
|
||||
using Poco::RangeException;
|
||||
using Poco::Data::ODBC::ConnectionException;
|
||||
using Poco::Data::ODBC::StatementException;
|
||||
using namespace Poco::Data::Keywords;
|
||||
|
||||
std::string funct = "internalExtraction()";
|
||||
std::vector<Poco::Tuple<int, double, std::string> > v;
|
||||
v.push_back(Poco::Tuple<int, double, std::string>(1, 1.5, "3"));
|
||||
v.push_back(Poco::Tuple<int, double, std::string>(2, 2.5, "4"));
|
||||
v.push_back(Poco::Tuple<int, double, std::string>(3, 3.5, "5"));
|
||||
v.push_back(Poco::Tuple<int, double, std::string>(4, 4.5, "6"));
|
||||
|
||||
try { session() << "INSERT INTO " << ExecUtil::vectors() << " VALUES (?,?,?)", use(v), now; }
|
||||
catch (ConnectionException& ce) { std::cout << ce.toString() << std::endl; fail(funct); }
|
||||
catch (StatementException& se) { std::cout << se.toString() << std::endl; fail(funct); }
|
||||
|
||||
try
|
||||
{
|
||||
Statement stmt = (session() << "SELECT * FROM " << ExecUtil::vectors(), now);
|
||||
RecordSet rset(stmt);
|
||||
|
||||
assert(3 == rset.columnCount());
|
||||
assert(4 == rset.rowCount());
|
||||
|
||||
int curVal = 3;
|
||||
do
|
||||
{
|
||||
assert(rset["str0"] == curVal);
|
||||
++curVal;
|
||||
} while (rset.moveNext());
|
||||
|
||||
rset.moveFirst();
|
||||
assert(rset["str0"] == "3");
|
||||
rset.moveLast();
|
||||
assert(rset["str0"] == "6");
|
||||
|
||||
RecordSet rset2(rset);
|
||||
assert(3 == rset2.columnCount());
|
||||
assert(4 == rset2.rowCount());
|
||||
|
||||
IntType i;
|
||||
try {
|
||||
i = rset.value<IntType>(0, 0);
|
||||
assert(1 == i);
|
||||
}
|
||||
catch (Poco::BadCastException& ex)
|
||||
{
|
||||
std::cout << ex.displayText() << std::endl;
|
||||
}
|
||||
std::string s = rset.value(0, 0).convert<std::string>();
|
||||
assert("1" == s);
|
||||
|
||||
IntType a = rset.value<IntType>(0, 2);
|
||||
assert(3 == a);
|
||||
|
||||
try
|
||||
{
|
||||
double d = rset.value<double>(1, 1);
|
||||
assert(2.5 == d);
|
||||
}
|
||||
catch (BadCastException&)
|
||||
{
|
||||
float f = rset.value<float>(1, 1);
|
||||
assert(2.5 == f);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
s = rset.value<std::string>(2, 2);
|
||||
}
|
||||
catch (BadCastException&)
|
||||
{
|
||||
UTF16String us = rset.value<Poco::UTF16String>(2, 2);
|
||||
Poco::UnicodeConverter::convert(us, s);
|
||||
}
|
||||
assert("5" == s);
|
||||
|
||||
i = rset.value("str0", 2);
|
||||
assert(5 == i);
|
||||
|
||||
const Column<std::deque<IntType> >& col = rset.column<std::deque<IntType> >(0);
|
||||
typename Column<std::deque<IntType> >::Iterator it = col.begin();
|
||||
typename Column<std::deque<IntType> >::Iterator end = col.end();
|
||||
for (int i = 1; it != end; ++it, ++i)
|
||||
assert(*it == i);
|
||||
|
||||
rset = (session() << "SELECT COUNT(*) AS cnt FROM " << ExecUtil::vectors(), now);
|
||||
|
||||
//various results for COUNT(*) are received from different drivers
|
||||
try
|
||||
{
|
||||
//this is what most drivers will return
|
||||
int i = rset.value<int>(0, 0);
|
||||
assert(4 == i);
|
||||
}
|
||||
catch (BadCastException&)
|
||||
{
|
||||
try
|
||||
{
|
||||
//this is for Oracle
|
||||
double i = rset.value<double>(0, 0);
|
||||
assert(4 == int(i));
|
||||
}
|
||||
catch (BadCastException&)
|
||||
{
|
||||
//this is for PostgreSQL
|
||||
Poco::Int64 big = rset.value<Poco::Int64>(0, 0);
|
||||
assert(4 == big);
|
||||
}
|
||||
}
|
||||
|
||||
s = rset.value("cnt", 0).convert<std::string>();
|
||||
assert("4" == s);
|
||||
|
||||
try { rset.column<std::deque<IntType> >(100); fail("must fail"); }
|
||||
catch (RangeException&) {}
|
||||
|
||||
try { rset.value<std::string>(0, 0); fail("must fail"); }
|
||||
catch (BadCastException&) {}
|
||||
|
||||
stmt = (session() << "DELETE FROM " << ExecUtil::vectors(), now);
|
||||
rset = stmt;
|
||||
|
||||
try { rset.column<std::deque<IntType> >(0); fail("must fail"); }
|
||||
catch (RangeException&) {}
|
||||
}
|
||||
catch (ConnectionException& ce) { std::cout << ce.toString() << std::endl; fail(funct); }
|
||||
catch (StatementException& se) { std::cout << se.toString() << std::endl; fail(funct); }
|
||||
}
|
||||
|
||||
|
||||
void SQLExecutor::filter(const std::string& query, const std::string& intFldName)
|
||||
{
|
||||
std::string funct = "filter()";
|
||||
@ -3805,7 +3945,6 @@ void SQLExecutor::sessionTransaction(const std::string& connect)
|
||||
setTransactionIsolation(session(), Session::TRANSACTION_READ_UNCOMMITTED);
|
||||
setTransactionIsolation(session(), Session::TRANSACTION_REPEATABLE_READ);
|
||||
setTransactionIsolation(session(), Session::TRANSACTION_SERIALIZABLE);
|
||||
|
||||
setTransactionIsolation(session(), Session::TRANSACTION_READ_COMMITTED);
|
||||
|
||||
session().begin();
|
||||
@ -3840,8 +3979,6 @@ void SQLExecutor::sessionTransaction(const std::string& connect)
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
|
||||
assert (session().isTransaction());
|
||||
|
||||
//TODO: this looks to be wrong - if a DB is fast it'd manage to execute this before another session commit is done
|
||||
// so assert below WILL fail
|
||||
Statement stmt1 = (local << "SELECT COUNT(*) FROM " << ExecUtil::person(), into(locCount), async, now);
|
||||
|
||||
session().commit();
|
||||
@ -3964,7 +4101,7 @@ void SQLExecutor::transaction(const std::string& connect)
|
||||
assert (0 == count);
|
||||
try
|
||||
{
|
||||
stmt1.wait(5000);
|
||||
stmt1.wait();
|
||||
if (local.getTransactionIsolation() == Session::TRANSACTION_READ_UNCOMMITTED)
|
||||
assert (0 == locCount);
|
||||
} catch (TimeoutException&)
|
||||
|
@ -571,151 +571,7 @@ public:
|
||||
void doubles();
|
||||
void tuples();
|
||||
void tupleVector();
|
||||
|
||||
template <typename IntType =
|
||||
#ifdef POCO_64_BIT
|
||||
Poco::Int64
|
||||
#else
|
||||
Poco::Int32
|
||||
#endif
|
||||
>
|
||||
void internalExtraction(IntType)
|
||||
{
|
||||
using Poco::Data::RecordSet;
|
||||
using Poco::Data::Column;
|
||||
using Poco::Data::Statement;
|
||||
using Poco::UTF16String;
|
||||
using Poco::Tuple;
|
||||
using Poco::BadCastException;
|
||||
using Poco::RangeException;
|
||||
using Poco::Data::ODBC::ConnectionException;
|
||||
using Poco::Data::ODBC::StatementException;
|
||||
using namespace Poco::Data::Keywords;
|
||||
|
||||
std::string funct = "internalExtraction()";
|
||||
std::vector<Poco::Tuple<int, double, std::string> > v;
|
||||
v.push_back(Poco::Tuple<int, double, std::string>(1, 1.5, "3"));
|
||||
v.push_back(Poco::Tuple<int, double, std::string>(2, 2.5, "4"));
|
||||
v.push_back(Poco::Tuple<int, double, std::string>(3, 3.5, "5"));
|
||||
v.push_back(Poco::Tuple<int, double, std::string>(4, 4.5, "6"));
|
||||
|
||||
try { session() << "INSERT INTO " << ExecUtil::vectors() << " VALUES (?,?,?)", use(v), now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
|
||||
|
||||
try
|
||||
{
|
||||
Statement stmt = (session() << "SELECT * FROM " << ExecUtil::vectors() , now);
|
||||
RecordSet rset(stmt);
|
||||
|
||||
assert (3 == rset.columnCount());
|
||||
assert (4 == rset.rowCount());
|
||||
|
||||
int curVal = 3;
|
||||
do
|
||||
{
|
||||
assert (rset["str0"] == curVal);
|
||||
++curVal;
|
||||
} while (rset.moveNext());
|
||||
|
||||
rset.moveFirst();
|
||||
assert (rset["str0"] == "3");
|
||||
rset.moveLast();
|
||||
assert(rset["str0"] == "6");
|
||||
|
||||
RecordSet rset2(rset);
|
||||
assert (3 == rset2.columnCount());
|
||||
assert (4 == rset2.rowCount());
|
||||
|
||||
IntType i;
|
||||
try {
|
||||
i = rset.value<IntType>(0, 0);
|
||||
assert(1 == i);
|
||||
}
|
||||
catch (Poco::BadCastException& ex)
|
||||
{
|
||||
std::cout << ex.displayText() << std::endl;
|
||||
}
|
||||
std::string s = rset.value(0,0).convert<std::string>();
|
||||
assert ("1" == s);
|
||||
|
||||
IntType a = rset.value<IntType>(0,2);
|
||||
assert (3 == a);
|
||||
|
||||
try
|
||||
{
|
||||
double d = rset.value<double>(1,1);
|
||||
assert (2.5 == d);
|
||||
}
|
||||
catch (BadCastException&)
|
||||
{
|
||||
float f = rset.value<float>(1,1);
|
||||
assert (2.5 == f);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
s = rset.value<std::string>(2, 2);
|
||||
}
|
||||
catch (BadCastException&)
|
||||
{
|
||||
UTF16String us = rset.value<Poco::UTF16String>(2, 2);
|
||||
Poco::UnicodeConverter::convert(us, s);
|
||||
}
|
||||
assert("5" == s);
|
||||
|
||||
i = rset.value("str0", 2);
|
||||
assert (5 == i);
|
||||
|
||||
const Column<std::deque<IntType> >& col = rset.column<std::deque<IntType> >(0);
|
||||
typename Column<std::deque<IntType> >::Iterator it = col.begin();
|
||||
typename Column<std::deque<IntType> >::Iterator end = col.end();
|
||||
for (int i = 1; it != end; ++it, ++i)
|
||||
assert (*it == i);
|
||||
|
||||
rset = (session() << "SELECT COUNT(*) AS cnt FROM " << ExecUtil::vectors(), now);
|
||||
|
||||
//various results for COUNT(*) are received from different drivers
|
||||
try
|
||||
{
|
||||
//this is what most drivers will return
|
||||
int i = rset.value<int>(0,0);
|
||||
assert (4 == i);
|
||||
}
|
||||
catch(BadCastException&)
|
||||
{
|
||||
try
|
||||
{
|
||||
//this is for Oracle
|
||||
double i = rset.value<double>(0,0);
|
||||
assert (4 == int(i));
|
||||
}
|
||||
catch(BadCastException&)
|
||||
{
|
||||
//this is for PostgreSQL
|
||||
Poco::Int64 big = rset.value<Poco::Int64>(0,0);
|
||||
assert (4 == big);
|
||||
}
|
||||
}
|
||||
|
||||
s = rset.value("cnt", 0).convert<std::string>();
|
||||
assert ("4" == s);
|
||||
|
||||
try { rset.column<std::deque<IntType> >(100); fail ("must fail"); }
|
||||
catch (RangeException&) { }
|
||||
|
||||
try { rset.value<std::string>(0,0); fail ("must fail"); }
|
||||
catch (BadCastException&) { }
|
||||
|
||||
stmt = (session() << "DELETE FROM " << ExecUtil::vectors(), now);
|
||||
rset = stmt;
|
||||
|
||||
try { rset.column<std::deque<IntType> >(0); fail ("must fail"); }
|
||||
catch (RangeException&) { }
|
||||
}
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
|
||||
}
|
||||
void internalExtraction();
|
||||
|
||||
void filter(const std::string& query =
|
||||
"SELECT * FROM " + ExecUtil::vectors() + " ORDER BY int0 ASC",
|
||||
|
Loading…
x
Reference in New Issue
Block a user