Skip to content

Commit

Permalink
Merge pull request pocoproject#5 in FSF_POCO/upstream from ~LUTKOS/up…
Browse files Browse the repository at this point in the history
…stream:ms-develop to ms-develop

* commit '335631b64f9557d5ff4dac54bf916e0b61280fd8':
  MSTKPROJ-1466 Fixed posgres error reporting
  • Loading branch information
Kostya Lutsenko authored and Kostya Lutsenko committed May 15, 2015
2 parents d46726c + 335631b commit ad31fb7
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 4 deletions.
1 change: 1 addition & 0 deletions Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class ODBC_API ODBCStatementImpl: public Poco::Data::StatementImpl
mutable std::size_t _affectedRowCount;
bool _canCompile;
bool _numericToString;
bool _isPostgres;
};


Expand Down
3 changes: 2 additions & 1 deletion Data/ODBC/include/Poco/Data/ODBC/Preparator.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class ODBC_API Preparator : public AbstractPreparator
const std::string& statement,
std::size_t maxFieldSize,
DataExtraction dataExtraction,
bool numericToString
bool numericToString,
bool isPostgres
);
/// Creates the Preparator.

Expand Down
14 changes: 12 additions & 2 deletions Data/ODBC/src/ODBCStatementImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ ODBCStatementImpl::ODBCStatementImpl(SessionImpl& rSession):
_prepared(false),
_affectedRowCount(0),
_canCompile(true),
_numericToString(rSession.numericToString())
_numericToString(rSession.numericToString()),
_isPostgres(false)
{
int queryTimeout = rSession.queryTimeout();
if (queryTimeout >= 0)
Expand All @@ -58,6 +59,15 @@ ODBCStatementImpl::ODBCStatementImpl(SessionImpl& rSession):
(SQLPOINTER) uqt,
0);
}
SQLSMALLINT t;
SQLRETURN r = SQLGetInfo(_rConnection, SQL_DRIVER_NAME, NULL, 0, &t);
if (!Utility::isError(r) && t > 0)
{
std::string serverString;
serverString.resize(static_cast<std::size_t>(t) + 2);
r = SQLGetInfo(_rConnection, SQL_DRIVER_NAME, &serverString[0], SQLSMALLINT((serverString.length() - 1) * sizeof(serverString[0])), &t);
_isPostgres = (!Utility::isError(r) && Poco::toUpperInPlace(serverString).find("PSQLODBC") == 0);
}
}


Expand Down Expand Up @@ -140,7 +150,7 @@ void ODBCStatementImpl::addPreparator()

std::size_t maxFieldSize = AnyCast<std::size_t>(session().getProperty("maxFieldSize"));

_preparations.push_back(new Preparator(_stmt, statement, maxFieldSize, ext, _numericToString));
_preparations.push_back(new Preparator(_stmt, statement, maxFieldSize, ext, _numericToString, _isPostgres));
}
else
_preparations.push_back(new Preparator(*_preparations[0]));
Expand Down
13 changes: 12 additions & 1 deletion Data/ODBC/src/Preparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Preparator::Preparator(const StatementHandle& rStmt,
const std::string& statement,
std::size_t maxFieldSize,
DataExtraction dataExtraction,
bool numericToString) :
bool numericToString,
bool isPostgres) :
_rStmt(rStmt),
_maxFieldSize(maxFieldSize),
_dataExtraction(dataExtraction),
Expand All @@ -40,6 +41,16 @@ Preparator::Preparator(const StatementHandle& rStmt,
SQLCHAR* pStr = (SQLCHAR*) statement.c_str();
if (Utility::isError(Poco::Data::ODBC::SQLPrepare(_rStmt, pStr, (SQLINTEGER) statement.length())))
throw StatementException(_rStmt);
// PostgreSQL error swallowing workaround:
// Postgres may execute a statement with sintax error fine,
// but would return error once num of columns requested!
if (isPostgres)
{
SQLSMALLINT t = 0;
SQLRETURN r = SQLNumResultCols(rStmt, &t);
if (r != SQL_NO_DATA && Utility::isError(r))
throw StatementException(rStmt, "Failed to get number of columns");
}
}


Expand Down
1 change: 1 addition & 0 deletions Data/ODBC/testsuite/src/ODBCDB2Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ CppUnit::Test* ODBCDB2Test::suite()
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCDB2Test");

CppUnit_addTest(pSuite, ODBCDB2Test, testBareboneODBC);
CppUnit_addTest(pSuite, ODBCDB2Test, testSyntaxError);
CppUnit_addTest(pSuite, ODBCDB2Test, testSimpleAccess);
CppUnit_addTest(pSuite, ODBCDB2Test, testComplexType);
CppUnit_addTest(pSuite, ODBCDB2Test, testSimpleAccessVector);
Expand Down
1 change: 1 addition & 0 deletions Data/ODBC/testsuite/src/ODBCMySQLTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ CppUnit::Test* ODBCMySQLTest::suite()
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCMySQLTest");

CppUnit_addTest(pSuite, ODBCMySQLTest, testBareboneODBC);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSyntaxError);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccess);
CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexType);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccessVector);
Expand Down
1 change: 1 addition & 0 deletions Data/ODBC/testsuite/src/ODBCOracleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ CppUnit::Test* ODBCOracleTest::suite()
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCOracleTest");

CppUnit_addTest(pSuite, ODBCOracleTest, testBareboneODBC);
CppUnit_addTest(pSuite, ODBCOracleTest, testSyntaxError);
CppUnit_addTest(pSuite, ODBCOracleTest, testSimpleAccess);
CppUnit_addTest(pSuite, ODBCOracleTest, testComplexType);
CppUnit_addTest(pSuite, ODBCOracleTest, testComplexTypeTuple);
Expand Down
1 change: 1 addition & 0 deletions Data/ODBC/testsuite/src/ODBCPostgreSQLTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ CppUnit::Test* ODBCPostgreSQLTest::suite()
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCPostgreSQLTest");

CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBareboneODBC);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSyntaxError);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccess);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexType);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccessVector);
Expand Down
1 change: 1 addition & 0 deletions Data/ODBC/testsuite/src/ODBCSQLServerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ CppUnit::Test* ODBCSQLServerTest::suite()
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCSQLServerTest");

CppUnit_addTest(pSuite, ODBCSQLServerTest, testBareboneODBC);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSyntaxError);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSimpleAccess);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testComplexType);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSimpleAccessVector);
Expand Down
1 change: 1 addition & 0 deletions Data/ODBC/testsuite/src/ODBCSQLiteTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ CppUnit::Test* ODBCSQLiteTest::suite()
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCSQLiteTest");

CppUnit_addTest(pSuite, ODBCSQLiteTest, testBareboneODBC);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSyntaxError);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSimpleAccess);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testComplexType);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSimpleAccessVector);
Expand Down
1 change: 1 addition & 0 deletions Data/ODBC/testsuite/src/ODBCSybaseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ CppUnit::Test* SybaseODBC::suite()
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SybaseODBC");

CppUnit_addTest(pSuite, SybaseODBC, testBareboneODBC);
CppUnit_addTest(pSuite, SybaseODBC, testSyntaxError);
CppUnit_addTest(pSuite, SybaseODBC, testSimpleAccess);
CppUnit_addTest(pSuite, SybaseODBC, testComplexType);
CppUnit_addTest(pSuite, SybaseODBC, testSimpleAccessVector);
Expand Down
23 changes: 23 additions & 0 deletions Data/ODBC/testsuite/src/ODBCTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ using Poco::Data::ODBC::ODBCException;
using Poco::Data::ODBC::ConnectionException;
using Poco::Data::ODBC::StatementException;
using Poco::Data::ODBC::StatementDiagnostics;
using Poco::Data::Statement;
using Poco::format;
using Poco::Tuple;
using Poco::Any;
Expand Down Expand Up @@ -1278,6 +1279,28 @@ void ODBCTest::testReconnect()
}


void ODBCTest::testSyntaxError()
{
try {
session() << "select fro oops", now;
fail("Expected syntax error exception");
}
catch (const StatementException&)
{
}

try {
Statement stat(session());
stat << "select fro oops";
stat.execute();
fail("Expected syntax error exception");
}
catch (const StatementException&)
{
}
}


bool ODBCTest::canConnect(const std::string& driver,
std::string& dsn,
std::string& uid,
Expand Down
1 change: 1 addition & 0 deletions Data/ODBC/testsuite/src/ODBCTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class ODBCTest: public CppUnit::TestCase

virtual void testReconnect();
virtual void testNumeric();
virtual void testSyntaxError();

protected:
typedef Poco::Data::ODBC::Utility::DriverMap Drivers;
Expand Down

0 comments on commit ad31fb7

Please sign in to comment.