Click here to Skip to main content
11,415,973 members (84,137 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ SQL-Server ODBC
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

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 14-Feb-13 0:37am
Edited 14-Feb-13 1:15am
v4

1 solution

Rate this: bad
good
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.
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,270
1 OriginalGriff 7,512
2 Maciej Los 3,710
3 Abhinav S 3,325
4 Peter Leow 3,084


Advertise | Privacy | Mobile
Web03 | 2.8.150427.4 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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