Overview
Features
Download
Documentation
Community
Add-Ons & Services

SQL Server empty string

A general discussion forum.

SQL Server empty string

Postby giuliosporti » 11 Jun 2012, 12:29

Hello,

I am new on this forum.
We try to use Poco library to manage a MS SQL Server 2008 Database and so we use Poco::Data and Poco::Data::ODBC api.
I am using Poco 1.4.2 version and we have noticed a problem when we try to insert EMPTY string:

Code: Select all
try
{
Poco::Data::Session tSess(_ptSessPool->get());

std::string strTemp("");

tSess << "INSERT INTO TData (StrExam) "
"VALUES(?)",
Poco::Data::use(strTemp),
Poco::Data::now;
}
catch(Poco::Data::ODBC::ODBCException &tExc)
{
...
...
}


We receive this exeception message from ODBC:

==========================
ODBC Diagnostic record #1
==========================
SQLSTATE = HY10
Native Error Code =
[Microsoft][SQL Server Native Client 10.0]Invalid precision value


Do you have any ideas?

How could we resolve this issue?

Thanks a lot.
Giulio.
giuliosporti
 
Posts: 11
Joined: 11 Jun 2012, 12:15

Re: SQL Server empty string

Postby fbraem » 11 Jun 2012, 22:46

Did you try to use a placeholder instead of ?

Code: Select all
tSess << "INSERT INTO TData (StrExam) "
"VALUES(:data)",
Poco::Data::use(strTemp),
Poco::Data::now;
Zumuta!, that's the way to do IT!
fbraem
 
Posts: 102
Joined: 11 Aug 2008, 22:47
Location: Belgium

Re: SQL Server empty string

Postby giuliosporti » 12 Jun 2012, 08:14

Yes, but the only way, in any case, I have found to INSERT data in MS SQL Server 2008 is without placeholder:

Code: Select all
tSess << "INSERT INTO TData (StrExam) "
"VALUES(?)",  <----
Poco::Data::use(strTemp),
Poco::Data::now;


If the string is not empty the data is inserted in right way. Is there a way to INSERT a empty string?

Thanks
Giulio.
giuliosporti
 
Posts: 11
Joined: 11 Jun 2012, 12:15

Re: SQL Server empty string

Postby alex » 12 Jun 2012, 14:22

Question mark is the standard way to pass parameters in. What version are you using? If you are using trunk code, it could be that your column is non-nullable and "emptyStringIsNull" feature is enabled.

In any case, you can easily work around it by formatting the SQL query:

Code: Select all
tSess << Poco::format("INSERT INTO TData (StrExam) VALUES ('%s')", strTemp), now;
alex
 
Posts: 1105
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: SQL Server empty string

Postby giuliosporti » 13 Jun 2012, 08:15

I am using:
- MS SQL SERVER 2008 with ODBC Driver
- Poco C++ Ver 1.4.2

Ok, in this way it works:

Code: Select all
tSess << Poco::format("INSERT INTO TData (StrExam) VALUES ('%s')", strTemp), now;


I think is better with placeholder.
I have tried with non-nullable and nullable Column but it is the same. Where could I find the option "emptyStringIsNull"? Is it an option of SQL SERVER Column or Poco C++?

Thanks
Giulio.
giuliosporti
 
Posts: 11
Joined: 11 Jun 2012, 12:15

Re: SQL Server empty string

Postby alex » 16 Jun 2012, 19:40

See documentation for trunk version of AbstractSessionImpl
alex
 
Posts: 1105
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: SQL Server empty string

Postby giuliosporti » 18 Jun 2012, 09:47

Ok, I understand.
Now I am using Poco C++ 1.4.2, but this new feature will be included in the new version 1.5.0 released in July?

Thanks
Giulio.
giuliosporti
 
Posts: 11
Joined: 11 Jun 2012, 12:15

Re: SQL Server empty string

Postby alex » 18 Jun 2012, 15:18

giuliosporti wrote:Now I am using Poco C++ 1.4.2, but this new feature will be included in the new version 1.5.0 released in July?

Yes. The release was pushed to end of July, though.
alex
 
Posts: 1105
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: SQL Server empty string

Postby giuliosporti » 18 Jun 2012, 15:38

Ok. Thanks a lot.

Giulio.
giuliosporti
 
Posts: 11
Joined: 11 Jun 2012, 12:15


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests