• SQLiteDatabase执行update、insert操作的时候,conflictAlgorithm参数的含义区别


       /**
         * When a constraint violation occurs, an immediate ROLLBACK occurs,
         * thus ending the current transaction, and the command aborts with a
         * return code of SQLITE_CONSTRAINT. If no transaction is active
         * (other than the implied transaction that is created on every command)
         * then this algorithm works the same as ABORT.
         */
        public static final int CONFLICT_ROLLBACK = 1;
    
        /**
         * When a constraint violation occurs,no ROLLBACK is executed
         * so changes from prior commands within the same transaction
         * are preserved. This is the default behavior.
         */
        public static final int CONFLICT_ABORT = 2;
    
        /**
         * When a constraint violation occurs, the command aborts with a return
         * code SQLITE_CONSTRAINT. But any changes to the database that
         * the command made prior to encountering the constraint violation
         * are preserved and are not backed out.
         */
        public static final int CONFLICT_FAIL = 3;
    
        /**
         * When a constraint violation occurs, the one row that contains
         * the constraint violation is not inserted or changed.
         * But the command continues executing normally. Other rows before and
         * after the row that contained the constraint violation continue to be
         * inserted or updated normally. No error is returned.
         */
        public static final int CONFLICT_IGNORE = 4;
    
        /**
         * When a UNIQUE constraint violation occurs, the pre-existing rows that
         * are causing the constraint violation are removed prior to inserting
         * or updating the current row. Thus the insert or update always occurs.
         * The command continues executing normally. No error is returned.
         * If a NOT NULL constraint violation occurs, the NULL value is replaced
         * by the default value for that column. If the column has no default
         * value, then the ABORT algorithm is used. If a CHECK constraint
         * violation occurs then the IGNORE algorithm is used. When this conflict
         * resolution strategy deletes rows in order to satisfy a constraint,
         * it does not invoke delete triggers on those rows.
         * This behavior might change in a future release.
         */
        public static final int CONFLICT_REPLACE = 5;
    
        /**
         * Use the following when no conflict action is specified.
         */
        public static final int CONFLICT_NONE = 0;
    
        private static final String[] CONFLICT_VALUES = new String[]
                {"", " OR ROLLBACK ", " OR ABORT ", " OR FAIL ", " OR IGNORE ", " OR REPLACE "};

    1、CONFLICT_ROLLBACK

      当发生约束冲突时,会立即回滚,从而结束当前事务,并且命令将终止,返回代码为SQLITE_CONSTRAINT。如果没有事务处于活动状态(每个命令上创建的隐式事务除外),则此算法的工作原理与ABORT相同。

    2、CONFLICT_ABORT

      当发生约束冲突时,不会执行回滚,因此将保留同一事务中先前命令的更改。这是默认行为。

    3、CONFLICT_FAIL

      当发生约束冲突时,该命令将使用返回代码SQLITE_CONSTRAINT中止。但是,命令在遇到违反约束之前对数据库所做的任何更改都将保留,不会被取消。

    4、CONFLICT_IGNORE

      当发生约束违反时,不插入或更改包含约束违反的一行。但是命令仍然正常执行。包含违反约束的行之前和之后的其他行将继续正常插入或更新。没有返回错误。

    5、CONFLICT_REPLACE

      当发生唯一约束违反时,在插入或更新当前行之前,将删除导致违反约束的现有行。因此,插入或更新总是发生。命令继续正常执行。没有返回错误。如果发生NOT NULL约束冲突,则该列的默认值将替换NULL值。如果列没有默认值,则使用ABORT算法。如果发生检查约束冲突,则使用忽略算法。当此冲突解决策略删除行以满足约束时,它不会对这些行调用delete触发器。这种行为在将来的版本中可能会改变。

    6、CONFLICT_NONE

      当没有指定冲突操作时,请使用以下命令。

  • 相关阅读:
    II、Python HelloWorld
    初次比较正式的IT职场面试后几点对自己web开发的思考
    网页调用迅雷下载文件
    php PAC 安装
    php 大文件上传的实现
    正则表达式
    怎么看待php 面向对象思想
    IT职场初体验一
    php 发送邮件
    web的seo
  • 原文地址:https://www.cnblogs.com/diyishijian/p/11541717.html
Copyright © 2020-2023  润新知