make binding of std::string configurable (SQL_LONGVARCHAR - default or SQL_VARCHAR) in Connector

This commit is contained in:
Günter Obiltschnig 2019-08-16 14:16:01 +02:00
parent 3c3bc44d3f
commit 1282d757dc
3 changed files with 35 additions and 1 deletions

View File

@ -52,6 +52,26 @@ public:
static void unregisterConnector();
/// Unregisters the Connector under the Keyword Connector::KEY at the Poco::Data::SessionFactory
static void bindStringToLongVarChar(bool flag = true);
/// If set to true (default), std::string is bound to SQL_LONGVARCHAR.
///
/// This can cause issues with SQL Server, resulting in an error
/// ("The data types varchar and text are incompatible in the equal to operator")
/// when comparing against a VARCHAR.
///
/// Set this to false to bind std::string to SQL_VARCHAR.
///
/// NOTE: This is a global setting, affecting all sessions.
/// This setting should not be changed after the first Session has
/// been created.
static bool stringBoundToLongVarChar();
/// Returns true if std::string is bound to SQL_LONGVARCHAR,
/// otherwise false (bound to SQL_VARCHAR).
private:
static bool _bindStringToLongVarChar;
};
@ -64,6 +84,12 @@ inline const std::string& Connector::name() const
}
inline bool Connector::stringBoundToLongVarChar()
{
return _bindStringToLongVarChar;
}
} } } // namespace Poco::Data::ODBC

View File

@ -14,6 +14,7 @@
#include "Poco/Data/ODBC/Binder.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/Data/ODBC/Connector.h"
#include "Poco/Data/LOB.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include "Poco/DateTime.h"
@ -132,7 +133,7 @@ void Binder::bind(std::size_t pos, const std::string& val, Direction dir)
(SQLUSMALLINT) pos + 1,
toODBCDirection(dir),
SQL_C_CHAR,
SQL_LONGVARCHAR,
Connector::stringBoundToLongVarChar() ? SQL_LONGVARCHAR : SQL_VARCHAR,
(SQLUINTEGER) colSize,
0,
pVal,

View File

@ -23,6 +23,7 @@ namespace ODBC {
const std::string Connector::KEY("ODBC");
bool Connector::_bindStringToLongVarChar(true);
Connector::Connector()
@ -54,4 +55,10 @@ void Connector::unregisterConnector()
}
void Connector::bindStringToLongVarChar(bool flag)
{
_bindStringToLongVarChar = flag;
}
} } } // namespace Poco::Data::ODBC