Click here to Skip to main content
15,882,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Heya everyone.
I'm stuck while working on my programm.
The problem is the following:
Preambulae:
My app is connecting to the SQL SERVER 2008r2 via ODBC driver and then executes INSERT statement. There're lots of params in it, but i'm stuck with inserting time data. DB has field which needs to be filled and that causes confuse. That Field has type time(0)
Here's the code which is

C++
SQLDriverConnect (sqlconnectionhandle,NULL,(SQLWCHAR*)CONNECTION_STRING,1433;DATABASE=SOMEDB; UID=SOMEUSER;PWD=SOMEPWD;Trusted_Connection=Yes;",SQL_NTS,retconstring,1024,NULL,SQL_DRIVER_NOPROMPT))
SQLSetEnvAttr(sqlenvhandle,SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER)
  ...
  SQLRETURN retCode;
  SQLLEN cbTime = sizeof(SQL_TIME_STRUCT);
  SQL_TIME_STRUCT Duration;
  ...

  Duration.hour = 00;
  Duration.minute = 03;
  Duration.second = 59;

  wchar_t* insertStatement = L"INSERT INTO [SOMEDB].[dbo].[SOMETABLE] (...,[Duration], ...) VALUES (..., ?, ...)";
  ...
  retCode = SQLBindParameter(sqlstatementhandle, 5, SQL_PARAM_INPUT, SQL_C_TYPE_TIME, SQL_TYPE_TIMESTAMP, SQL_TIME_LEN, 0, &Duration, 0, &cbTime);


  retCode = SQLPrepare(sqlstatementhandle, insertStatement, SQL_NTS);
  retCode = SQLExecute(sqlstatementhandle);


While debugging no error is noticed. Every last function returns SQL_SUCCESS which is good.
But when i look at table i with SQL Management Studio i see new row which was just added. But the problem is that field of interest has value and it's almost correct except that seconds = 00.
I've tried to fill structure with different values but result is still the same:
HH:MM:00
Looking forward for your answers,
Best Regards.

--Added:
After some more debugging i figured out that SQLExecute returns 1(SUCCESS_WITH_INFO)
I get
message: message 0x00e5e420 L"[Microsoft][ODBC SQL Server Driver]Fractional truncation" wchar_t[1024]
SQLSTATE: 01S07
Posted
Updated 14-Feb-13 0:15am
v4

1 solution

I've found out what caused the problem. Found it in expierence way.

The THING that was wrong is:
C++
retCode = SQLBindParameter(sqlstatementhandle, 5, SQL_PARAM_INPUT, SQL_C_TYPE_TIME, SQL_TYPE_TIMESTAMP, SQL_TIME_LEN, 0, &Duration, 0, &cbTime);

SQL_TIME_LEN - is made by microsoft. by default it's value is 8 (hh:mm:ss - 8 symbols).
After few iterations of changing this parameter i'd found that correct value for this parameter is 17.
Tried looking on the internet but no luck.

So.... case is happily closed.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900