Informix 在尝试更新不存在的行时不会抛出错误?

The Informix is not throwing error when trying to update a row which is not present?

我们正在分析生产中的 Informix 行为。当尝试更新不存在的行时,应用程序在生产中出现“-346:无法更新 table 中的行”错误。

然而,当我们在开发区尝试相同的操作时,应用程序运行正常。

Informix 是否应该在更新不存在的行时始终抛出错误,或者它是否可在 Informix 级别配置?

该应用程序是用 C 编写的,相应的更新查询存在于“.ec”程序中。

此外,Informix 是否有任何其他方式抛出 -346 错误?

Edit: The SQL is as follows:

update <table> set serial_number = <number1> where serial_number = <number2> 

The SQL Error is:

 Execute SQL ERROR

    SQL CODE = -346
    SQLERM =
    SQLERRP =
    SQLERRD[0] = 1
    SQLERRD[1] = -100
    SQLERRD[2] = 0
    SQLERRD[3] = 1
    SQLERRD[4] = 56
    SQLERRD[5] = 0
    SQLWARN =

再次编辑:

源码如下:

const char *sql = "update table_not_named set serial_number = ? where serial_number = ?"; 

if ( prepared_sql == 0 )
{
    exec sql prepare update_sql from :sql;
    if ( sqlca.sqlcode != SQL_OK )
    {
        logSqlError( log_err, __func__, "Prepare" );
        return FAIL;
    }
    prepared_sql = 1;
}

exec sql execute update_sql using :db_new_serial_number, :db_old_serial_number;

if ( sqlca.sqlcode != SQL_OK )
{
    logSqlError( log_err, __func__, "Execute" );
    return FAIL;
}

评论越来越多,以至于无法成为评论 — 差距很大。

错误 -346 不是 present/absent 的问题。 finderr -346 的说明说:

While the database server was processing an UPDATE, it received an unexpected error. Check the accompanying ISAM error code for more detailed information on the cause. Possible causes include hardware errors and locking conflicts.

您需要跟踪 ISAM 错误(sqca.sqlerrd[1] in ESQL/C)以获取更多信息;它应该是一个绝对值在 100 到 199 之间的错误编号。这可能意味着您的生产系统存在某种问题。

请注意,使用搜索到的 UPDATE 更新不存在的行应该只报告零行已成功更新。在 MODE ANSI 数据库中,您将获得状态 100 (SQLNOTFOUND) 而不是 0(无错误)。如果您正在执行 WHERE CURRENT OF 更新并且该行丢失了,那么确实发生了一些奇怪的事情 - 它不应该发生(因为这意味着您在选择它时没有锁定该行,但是有人即使您应该将其锁定,也设法删除了该行)。如果您没有使用 FOR UPDATE 子句,那么 WHERE CURRENT OF 应该有更具体的错误。

至此问题更新显示错误信息

好奇留言:我运行

create table sample
(
    serial_number integer not null primary key,
    value varchar(30) not null
);
insert into sample values(123, 'one hundred and twenty-three');
update sample set serial_number = 124 where serial_number = 99;

状态为 0(并报告 0 行已更新)。您的邮件有 -100 作为 ISAM 错误;这是 'ISAM error: duplicate value for a record with unique key'.

的消息

但是当我尝试时:

insert into sample values(99, 'ninety-nine');
update sample set serial_number = 123 where serial_number = 99;

我收到错误:

SQL -268: Unique constraint (jleffler.u160_350) violated.
ISAM -100: ISAM error:  duplicate value for a record with unique key.

这正是我所期望的。我注意到您不能直接更新 SERIAL(或 SERIAL8 或 BIGSERIAL)类型的列:您得到 SQL -232: A SERIAL column (s) may not be updated(其中 s 是我尝试更新以生成消息的序列列的名称— 消息中的复数形式不错)。

由于错误 -346 的主要消息表明数据库中可能存在问题,因此值得对系统进行 运行 ON-Check (oncheck) 以查看是否table 都可以。如果您不习惯 运行 ON-Check,则需要查找选项。在继续验证 table 和出现问题的索引(oncheck -cioncheck -cd).可能值得使用 -cR-cI-cD 选项来获取更多信息。