简体   繁体   English

SQLBindParameter返回-1

[英]SQLBindParameter returns -1

ALL, 所有,

My code is as follows: 我的代码如下:

std::wstring ownerName = table->GetTableOwner();
SQLWCHAR *owner_name = new SQLWCHAR[ownerNameLen + 2];
int ownerNameLen = ownerName.length();
SQLLEN cbOwnerName = ownerNameLen == 0 ? SQL_NULL_DATA : SQL_NTS;
ret = SQLBindParameter( stmt_tableProp, 2, SQL_PARAM_INPUT, SQL_C_WCHAR, SQL_WCHAR, ownerNameLen, 0, owner_name, 0, &cbOwnerName );

The call to SQLBindParameter succeeds when the owner_name contains an actual data. 当owner_name包含实际数据时,对SQLBindParameter的调用成功。 However if the owner_name is '' the call fails. 但是,如果owner_name为“”,则调用将失败。 And the error message I am getting is "HY104 - Invalid precision or scale value". 我收到的错误消息是“ HY104-无效的精度或小数位值”。

According to the MSDN it looks like the value for the size should be the size of the column and not the size of the actual parameter. 根据MSDN,看来size的值应该是列的大小,而不是实际参数的大小。 Is this correct? 这个对吗? Or I should pass 0 as the length of the binding value? 或者我应该将0作为绑定值的长度?

Also, there is this page which uses different values. 另外, 此页面使用不同的值。

Could someone please shed some light? 有人可以说明一下吗?

TIA! TIA!

Parameter in SqlBindParameter where you are passing ownerNameLen value should contain column size, not variable size. 传递ownerNameLen值的SqlBindParameter中的参数应包含列大小,而不是变量大小。 This is what required by column data type you are working with(SQL_WCHAR) according to the docs. 根据文档,这是您正在使用的列数据类型(SQL_WCHAR)所需要的。 Below is a link to the docs. 以下是文档的链接。 Look for the "ColumnSize Argument" and see for yourself. 查找“ ColumnSize参数”,然后自己查看。

SqlBindParameter doc SqlBindParameter文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM