gpt4 book ai didi

windows - 更改几行后 SQLRowCount 的行为发生变化

转载 作者:可可西里 更新时间:2023-11-01 10:37:34 25 4
gpt4 key购买 nike

我有一个客户 ODBC 应用程序,它在大多数操作后对受影响的行进行完整性检查。突然间,这些检查都失败了。在这种情况下,插入后受影响的行预计为 1。在查看日志后,该值返回未知 (-1)。

有谁知道为什么行为会改变

附加信息:

  • 应用程序正在 Windows 服务器上运行
  • 数据库是 Oracle。
  • 驱动是Microsoft Oracle Driver
  • 客户表示最近没有对数据库或驱动程序进行升级。
  • 客户声称问题是在更改/删除表中的几行后开始的。

其他详细信息:

驱动程序是“Microsoft ODBC for Oracle”,版本是 2.576.3959.00,文件名是 MSORCL32.dll,日期是 2/17/2007。 Oracle数据库级别为10.2。

有什么想法吗?

这是我让他们捕获的 ODBC 日志:

dpxag35         a5c-cac   ENTER SQLExecDirect 
HSTMT 015A2270
UCHAR * 0x00177D9C [ 364] "begin \ a <single simple insert statement here>; \ aend;"
SDWORD 364

dpxag35 a5c-cac EXIT SQLExecDirect with return code 0 (SQL_SUCCESS)
HSTMT 015A2270
UCHAR * 0x00177D9C [ 364] "begin \ a <single simple insert statement here>; \ aend;"
SDWORD 364

dpxag35 a5c-cac ENTER SQLNumResultCols
HSTMT 015A2270
SWORD * 0x0012F9B0

dpxag35 a5c-cac EXIT SQLNumResultCols with return code 0 (SQL_SUCCESS)
HSTMT 015A2270
SWORD * 0x0012F9B0 (0)

dpxag35 a5c-cac ENTER SQLRowCount
HSTMT 015A2270
SQLLEN * 0x00163B88

dpxag35 a5c-cac EXIT SQLRowCount with return code 0 (SQL_SUCCESS)
HSTMT 015A2270
SQLLEN * 0x00163B88 (-1)

dpxag35 a5c-cac ENTER SQLFreeStmt
HSTMT 015A2270
UWORD 0 <SQL_CLOSE>

dpxag35 a5c-cac EXIT SQLFreeStmt with return code 0 (SQL_SUCCESS)
HSTMT 015A2270
UWORD 0 <SQL_CLOSE>

供引用,这是来自 MSDN 上的 ODBC 文档:

RowCountPtr [Output] Points to a buffer in which to return a row count. For UPDATE, INSERT, and DELETE statements, for the SQL_ADD, SQL_UPDATE_BY_BOOKMARK, and SQL_DELETE_BY_BOOKMARK operations in SQLBulkOperations, and for the SQL_UPDATE or SQL_DELETE operations in SQLSetPos, the value returned in *RowCountPtr is either the number of rows affected by the request or –1 if the number of affected rows is not available. When SQLExecute, SQLExecDirect, SQLBulkOperations, SQLSetPos, or SQLMoreResults is called, the SQL_DIAG_ROW_COUNT field of the diagnostic data structure is set to the row count, and the row count is cached in an implementation-dependent way. SQLRowCount returns the cached row count value. The cached row count value is valid until the statement handle is set back to the prepared or allocated state, the statement is reexecuted, or SQLCloseCursor is called. Note that if a function has been called since the SQL_DIAG_ROW_COUNT field was set, the value returned by SQLRowCount might be different from the value in the SQL_DIAG_ROW_COUNT field because the SQL_DIAG_ROW_COUNT field is reset to 0 by any function call. For other statements and functions, the driver may define the value returned in *RowCountPtr. For example, some data sources may be able to return the number of rows returned by a SELECT statement or a catalog function before fetching the rows. Note Many data sources cannot return the number of rows in a result set before fetching them; for maximum interoperability, applications should not rely on this behavior.

在 doco 页面的最后,我们得到了这个:

If the last SQL statement executed on the statement handle was not an UPDATE, INSERT, or DELETE statement or if the Operation argument in the previous call to SQLBulkOperations was not SQL_ADD, SQL_UPDATE_BY_BOOKMARK, or SQL_DELETE_BY_BOOKMARK, or if the Operation argument in the previous call to SQLSetPos was not SQL_UPDATE or SQL_DELETE, the value of *RowCountPtr is driver-defined. For more information, see Determining the Number of Affected Rows.

我想这是合理的,因为它被包裹在一个批处理中,所以产量未知。

但我不能忘记这个应用程序已经运行两年并且从未遇到过这个问题。客户说他们更改/删除了一些表格数据,然后应用程序失败了。我发现这不太可能,经验告诉我他们做了其他事情,但没有说什么。

最佳答案

MSDN documentation 中所述,执行批处理操作后 SQLRowCount 的行为(我想这是一个批处理,因为它包含在 begin ... end 中;)是驱动程序定义的,这是检查 ODBC 驱动程序版本的一个很好的理由.

关于windows - 更改几行后 SQLRowCount 的行为发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16905569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com