C ++:ODBC MSSQL Server SQLBindParameter()时间绑定问题 [英] C++: ODBC MSSQL Server SQLBindParameter() time binding problems

查看:180
本文介绍了C ++:ODBC MSSQL Server SQLBindParameter()时间绑定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Heya大家。

我在制作程序时遇到困难。

问题如下:

Preambulae:

我的应用程序通过ODBC驱动程序连接到SQL SERVER 2008r2,然后执行INSERT语句。其中有很多参数,但我不知道插入时间数据。 DB具有需要填充并导致混淆的字段。该字段的类型时间(0)

这里的代码是



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);





调试时没有注意到错误。每个最后一个函数都返回SQL_SUCCESS,这很好。

但是当我用SQL Management Studio查看表i时,我看到刚刚添加的新行。但问题是感兴趣的领域有价值而且它几乎是正确的,除了秒= 00.

我试图用不同的值填充结构但结果仍然是相同的:

HH:MM:00

期待您的回答,

最好的问候。



- 已添加:

经过多次调试后,我发现SQLExecute返回1(SUCCESS_WITH_INFO)

我得到

消息:消息0x00e5e420 L[Microsoft] [ODBC SQL Server驱动程序]小数截断wchar_t [1024]

SQLSTATE:01S07



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

推荐答案

我发现了导致问题的原因。以expierence的方式找到它。



错误的是:

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 - 由微软。默认情况下,它的值为8(hh:mm:ss - 8个符号)。

经过几次更改此参数的迭代后,我发现此参数的正确值为17。 br />
尝试在互联网上查找但没有运气。



所以....案件很高兴关闭。


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.


这篇关于C ++:ODBC MSSQL Server SQLBindParameter()时间绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆