我的选择语句如下所示
SELECT tb1.name FROM table1 tb1, table2 tb2 WHERE tb2.name=? AND tb2.tb1_key_id=tb1.id;
我的Bindparameter调用看起来像这样
SQLBindParameter(m_hStatement,1,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,len,0,(LPVOID)buff,len,(SQLLEN *)pcbValue);
其中buff is void*
当我在此语句上运行SQLExecute时,当我查看错误详细信息SQL_SUCCESS_WITH_INFO
时,它会返回[Firebird ODBC driver] data truncated
。
我对数据库完全陌生,如果需要更多详细信息,请告诉我
BTW同样的做法是使用32位应用程序正常工作,如果用64位编译就会遇到这个问题。 UPDATE
- 再回到这个问题。
我有SQL Trace文件
MyApp 4e0-1680 ENTER SQLPrepareW
HSTMT 0x0000000008C9E210
WCHAR * 0x000000000DF04CE0 [ -3] "SELECT tb1.name FROM table1 tb1, table2 tb2 WHERE tb2.name=? AND tb2.tb1_key_id=tb1.id;\ 0"
SDWORD -3
MyApp 4e0-1680 EXIT SQLPrepareW with return code 0 (SQL_SUCCESS)
HSTMT 0x0000000008C9E210
WCHAR * 0x000000000DF04CE0 [ -3] "SELECT tb1.name FROM table1 tb1, table2 tb2 WHERE tb2.name=? AND tb2.tb1_key_id=tb1.id;\ 0"
SDWORD -3
MyApp 4e0-1680 ENTER SQLBindParameter
HSTMT 0x0000000008C9E210
UWORD 1
SWORD 1 <SQL_PARAM_INPUT>
SWORD 1 <SQL_C_CHAR>
SWORD 1 <SQL_CHAR>
SQLULEN 48
SWORD 0
PTR 0x0000000008B932D0
SQLLEN 48
SQLLEN * 0x0000000008B93008
MyApp 4e0-1680 EXIT SQLBindParameter with return code 0 (SQL_SUCCESS)
HSTMT 0x0000000008C9E210
UWORD 1
SWORD 1 <SQL_PARAM_INPUT>
SWORD 1 <SQL_C_CHAR>
SWORD 1 <SQL_CHAR>
SQLULEN 48
SWORD 0
PTR 0x0000000008B932D0
SQLLEN 48
SQLLEN * 0x0000000008B93008 (4294967293)
MyApp 4e0-1680 ENTER SQLBindParameter
HSTMT 0x0000000008C9E210
UWORD 2
SWORD 1 <SQL_PARAM_INPUT>
SWORD 1 <SQL_C_CHAR>
SWORD 1 <SQL_CHAR>
SQLULEN 48
SWORD 0
PTR 0x0000000008B93298
SQLLEN 48
SQLLEN * 0x0000000008B93008
MyApp 4e0-1680 EXIT SQLBindParameter with return code 0 (SQL_SUCCESS)
HSTMT 0x0000000008C9E210
UWORD 2
SWORD 1 <SQL_PARAM_INPUT>
SWORD 1 <SQL_C_CHAR>
SWORD 1 <SQL_CHAR>
SQLULEN 48
SWORD 0
PTR 0x0000000008B93298
SQLLEN 48
SQLLEN * 0x0000000008B93008 (4294967293)
MyApp 4e0-1680 ENTER SQLExecute
HSTMT 0x0000000008C9E210
MyApp 4e0-1680 EXIT SQLExecute with return code 1 (SQL_SUCCESS_WITH_INFO)
HSTMT 0x0000000008C9E210
DIAG [01004] [ODBC Firebird Driver]Data truncated (0)
DIAG [01004] [ODBC Firebird Driver]Data truncated (0)
MyApp 4e0-1680 ENTER SQLErrorW
HENV 0x0000000000000000
HDBC 0x0000000000000000
HSTMT 0x0000000008C9E210
WCHAR * 0x000000000A69BFE8
SDWORD * 0x000000000A69BFD4
WCHAR * 0x0000000000123CF0
SWORD 1024
SWORD * 0x0000000000124104
MyApp 4e0-1680 EXIT SQLErrorW with return code 0 (SQL_SUCCESS)
HENV 0x0000000000000000
HDBC 0x0000000000000000
HSTMT 0x0000000008C9E210
WCHAR * 0x000000000A69BFE8 [ 5] "01004"
SDWORD * 0x000000000A69BFD4 (0)
WCHAR * 0x0000000000123CF0 [ 36] "[ODBC Firebird Driver]Data truncated"
SWORD 1024
SWORD * 0x0000000000124104 (36)
MyApp 4e0-1680 ENTER SQLRowCount
HSTMT 0x0000000008C9E210
SQLLEN * 0x0000000000123218
MyApp 4e0-1680 EXIT SQLRowCount with return code 0 (SQL_SUCCESS)
HSTMT 0x0000000008C9E210
SQLLEN * 0x0000000000123218 (-1)
MyApp 4e0-1680 ENTER SQLNumResultCols
HSTMT 0x0000000008C9E210
SWORD * 0x00000000001231F4
MyApp 4e0-1680 EXIT SQLNumResultCols with return code 0 (SQL_SUCCESS)
HSTMT 0x0000000008C9E210
SWORD * 0x00000000001231F4 (1)
MyApp 4e0-1680 ENTER SQLNumParams
HSTMT 0x0000000008C9E210
SWORD * 0x00000000001231F4
MyApp 4e0-1680 EXIT SQLNumParams with return code 0 (SQL_SUCCESS)
HSTMT 0x0000000008C9E210
SWORD * 0x00000000001231F4 (2)
我能为您提供帮助吗
答案 0 :(得分:0)
当我的SQL参数数据无法确定发送它的数据类型时,我通常会在Java中获得奇怪的数据截断问题。它几乎隐藏在几层抽象之下,但通常我通过手动转义输入来修复它。
实施例
select name from company where name = $P!{input}
有时会导致SQL Exception'数据被截断'
select name from company where name = '$P!{input}'
$ P!{表示将数据直接放入字符串中。试一试?也许这是一个类型推断问题。