Click here to Skip to main content
13,593,097 members
Rate this:
Please Sign up or sign in to vote.
See more:
Heya everyone.
I'm stuck while working on my programm.
The problem is the following:
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

SQLDriverConnect (sqlconnectionhandle,NULL,(SQLWCHAR*)CONNECTION_STRING,1433;DATABASE=SOMEDB; UID=SOMEUSER;PWD=SOMEPWD;Trusted_Connection=Yes;",SQL_NTS,retconstring,1024,NULL,SQL_DRIVER_NOPROMPT))
  SQLRETURN retCode;
  SQLLEN cbTime = sizeof(SQL_TIME_STRUCT);

  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:
Looking forward for your answers,
Best Regards.

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]
Posted 13-Feb-13 23:37pm
Updated 14-Feb-13 0:15am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

The THING that was wrong is:
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.180618.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100