Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to insert Poco::Nullable< Poco::Data::Date> data into MSSQL using ODBC #2808

Closed
zhe-ma opened this issue Oct 15, 2019 · 6 comments
Closed

Comments

@zhe-ma
Copy link

zhe-ma commented Oct 15, 2019

Code:

  Poco::Nullable< Poco::Data::Date> date;
  session << "insert into student( birth) values(?)", use(date), now;

Error:


SQLExecute()
Requested SQL statement: insert into student( birth) values(?)
Native SQL statement: insert into student( birth) values(?)
: Connection:NetConn: 041B6E68
Server:Not applicable
===========================
ODBC Diagnostic record #1:
===========================
SQLSTATE = 22018
Native Error Code = 206
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Operand type clash: tinyint is incompatible with date

===========================
ODBC Diagnostic record #2:
===========================
SQLSTATE = 42000
Native Error Code = 8180
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be prepared.
@github-actions
Copy link

This issue is stale because it has been open for 365 days with no activity.

@github-actions github-actions bot added the stale label Jan 12, 2022
@github-actions
Copy link

This issue was closed because it has been inactive for 60 days since being marked as stale.

@rastocny
Copy link

Problem is caused by an invalid SQL data type in SQLBindParameter function. This cannot be solve without redesign of Poco::Data::AbstractBinder probably, which does not preserve c++ data type for NULL data. I hotfixed this issue by following changes rastocny@105e658

@aleks-f aleks-f added enhancement and removed stale labels Nov 26, 2023
@aleks-f aleks-f added this to the Release 1.13.0 milestone Nov 26, 2023
@aleks-f aleks-f reopened this Nov 26, 2023
@aleks-f aleks-f self-assigned this Dec 21, 2023
@aleks-f aleks-f added this to 1.13 Jan 14, 2024
@aleks-f aleks-f removed this from 1.13 Jan 30, 2024
@aleks-f aleks-f added this to 1.14 Jan 30, 2024
@matejk
Copy link
Contributor

matejk commented Oct 3, 2024

Poco::Data::Binder has bind functions for specific types, including NullData, which is used for null values.

SQLBindParameter requires column type for null values also. Data type is of course missing when null is passed as NullData type.

As I can see from the code, the best solution would be to replace arguments of bind member functions with Poco::Nullable<T>. Column data type and null would then be available and proper arguments could be passed to SQLBindParameter. bind overloads for NullData can be then removed.

Example:

	virtual void bind(std::size_t pos, const Poco::Nullable<UUID>& val, Direction dir = PD_IN) = 0;
		/// Binds a UUID.

	virtual void bind(std::size_t pos, const std::vector<Poco::Nullable<UUID>>& val, Direction dir = PD_IN);
		/// Binds a UUID vector.

	virtual void bind(std::size_t pos, const std::deque<Poco::Nullable<UUID>>& val, Direction dir = PD_IN);
		/// Binds a UUID deque.

	virtual void bind(std::size_t pos, const std::list<Poco::Nullable<UUID>>& val, Direction dir = PD_IN);
		/// Binds a UUID list.

However this is a major potentially breaking interface change.

@aleks-f , @obiltschnig, what is your opinion?

@aleks-f
Copy link
Member

aleks-f commented Oct 9, 2024

@matejk This looks like Poco::Date-specific, possibly also SQL server specific, problem. Other datatypes (including Poco::DateTime) seem to work fine for both insert and select. I will look into it

aleks-f added a commit that referenced this issue Oct 12, 2024
aleks-f added a commit that referenced this issue Oct 12, 2024
aleks-f added a commit that referenced this issue Oct 12, 2024
* chore(CppUnit): disable MSVC secure warning

* chore(Data): regenerate VS projects

* chore(DataTest): regenerate VS projects

* chore(Data/testsuite): regenerate VS projects

* chore(DataTest): fix VS90 project

* fix(ODBC): Failed to insert Poco::Nullable< Poco::Data::Date> data into MSSQL using ODBC #2808

* chore(Foundation): add Trace to VS project

* chore(Trace): add Trace VS projects #4692

* fix: g++ and clang build #2808
@aleks-f aleks-f moved this to Done in 1.14 Oct 12, 2024
@aleks-f aleks-f added the fixed label Oct 12, 2024
@aleks-f
Copy link
Member

aleks-f commented Oct 12, 2024

The problem was fixed (and too small in some cases) size of the binding storage. This fixed it.

@matejk matejk closed this as completed Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

4 participants