zoukankan      html  css  js  c++  java
  • ***codeigniter 2.2 affected_rows()返回值不准确

    http://blog.icodeu.com/?p=596

    问题描述
    今天在完成一个项目调用想要检验一下计划插入的数据是否都正常插入了。调用insert_batch()方法插入一百多条数据的时候发现affected_rows()返回值不准确。
    问题分析
    1.第一步打印last_query()发现插入的数据和affected_rows()数值确实是一样的
    2.检查数据库,发现需要插入的一百多条数据也确实正常插入了
    3.查看了一下代码,才知道在insert_batch()和update_batch()的时候,如果数据量大于100条,将会分多次插入,每次最多只会插入一百条。
    详见下面的代码

    1
    2
    3
    4
    5
    6
    // Batch this baby
    for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100)
    {
        $sql = $this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where);
        $this->query($sql);
    }

    影响范围
    insert_batch(),update_batch()
    解决方案
    对插入的数据进行求余然后和affected_rows()进行对比检验插入数据是否正确

    github上官方已经修复了这个问题

    https://github.com/bcit-ci/CodeIgniter/tree/2.2-stable

     
     
    1
    2
    3
    4
    5
    6
    7
        // Batch this baby
    $affected_rows = 0;
    for ($i = 0, $total = count($this->qb_set); $i < $total; $i += 100)
    {
    $this->query($this->_insert_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, 100)));
    $affected_rows += $this->affected_rows();
    }
  • 相关阅读:
    Java复制数组
    关于js正则表达式的理解
    js声明const, var, let的区别
    原生js删除多个相同类名的子元素
    python -反射hasattr、setattr、delattr
    Python-反射getattr的应用
    Python-库安装
    python -函数
    Appium -作业5(2)
    Appium appium1.6.5 使用 set_value () 输入中文,真机上无显示
  • 原文地址:https://www.cnblogs.com/kenshinobiy/p/4826288.html
Copyright © 2011-2022 走看看