【发布时间】:2020-03-27 12:57:48
【问题描述】:
当我按该顺序选择int1, int2, str1 时,我得到一个无效的转换错误。当我在str1, int1, int2 order 中选择它们时,sql 调用成功完成。
sql 调用如下所示(再次简化)
Select int1, int2, str1 from table where int1 = ? (my variable)
在此调用中没有实际的值转换。
代码是 c++,使用 Native Client 11 的 ODBC 连接到 MSSQL 数据库。 变量和绑定列都是静态声明的,并且具有适当的类型和长度(并且按照我更改顺序时的调用顺序)。
我正在寻找任何其他想法,以了解当我在 int 值之后选择 char 值时如何找到它失败的原因。失败发生在SqlFetch函数调用(返回的数据试图加载到绑定列时)
非简化查询返回 140 列混合类型,我想将解决方案应用于整个查询。
(注意) c++ 列绑定看起来像这样,按选择的顺序排列:
sqlret = SQLBindCol(hstmt_myQuery,item_col,SQL_C_LONG,&int1, (SDWORD) sizeof(int1), &indicator[item_col++]); exec_sql_error(__FILE__, &henv, &hdbc, last_connect_time, "BindCol hstmt_myQuery", hstmt_myQuery, &sqlret);
sqlret = SQLBindCol(hstmt_myQuery,item_col,SQL_C_LONG,&int2, (SDWORD) sizeof(int2), &indicator[item_col++]); exec_sql_error(__FILE__ , &henv, &hdbc, last_connect_time , "BindCol hstmt_myQuery" , hstmt_myQuery , &sqlret );
sqlret = SQLBindCol(hstmt_myQuery,item_col,SQL_C_CHAR,str1, (SDWORD) sizeof(str1), &indicator[item_col++]); exec_sql_error(__FILE__ , &henv, &hdbc, last_connect_time , "BindCol hstmt_myQuery" , hstmt_myQuery , &sqlret );
【问题讨论】:
标签: c++ sql-server