Search code examples
c++sql-serverbcpfreetds

Can`t insert DATE to mssql via FreeTDS bcp API on linux


When i try to insert DATE via FreeTDS bcp on linux i`m facing with that error:

Conversion failed when converting date and/or time from character string.
create table test (c_date date);

Bind type of this column is SYBCHAR, on windows i haven`t problems but i use WinApi

...
char buff[10];
time_t time = ACE_OS::time(nullptr);
struct tm *tmp = localtime(&time);
strftime(buff, 10, "%Y-%m-%d", tmp); /// example: 2008-10-22
bcp_collen(db, 10, 1);
bcp_colptr(db, reinterpret_cast<BYTE*>(buff), 1);
bcp_sendrow(db);
bcp_batch(db); /// here the exception is thrown

I have tried to use another patterns for dateformat such as %Y%m%d,%Y/%m/%d etc., another binding types, creating locales.conf near freetds.conf, but nothing...


Solution

  • I was able to insert Date, if you are facing with the same problem you should to convert to UCS2.

    Before data status

    After