使用update_batch增加数据库中的字段自动添加单引号

时间:2017-01-27 07:50:51

标签: php mysql

使用update_batch增加数据库中的字段自动添加单引号 调用功能代码

$this->db->update_batch("FundCategory",$create_data,'fundCategoryId')

我的共识最后查询是

UPDATE `FundCategory` SET `fundCategoryUpdatedById` = CASE 
WHEN `fundCategoryId` = '4' THEN '20000045'
WHEN `fundCategoryId` = '4' THEN '20000045'
ELSE `fundCategoryUpdatedById` END, `fundCategoryValue` = CASE 
WHEN `fundCategoryId` = '4' THEN 'fundCategoryValue + 100'
WHEN `fundCategoryId` = '4' THEN 'fundCategoryValue + 200'
ELSE `fundCategoryValue` END
WHERE `fundCategoryId` IN('4','4')

我希望在增加" fundCategoryValue"之后删除单引号。柱

1 个答案:

答案 0 :(得分:0)

通过修改核心

来尝试此操作

https://github.com/bcit-ci/CodeIgniter/blob/develop/system/database/DB_query_builder.php#L2019

功能

public function set_update_batch($key, $index = '', $escape = NULL)
{
..
..
..
}

发件人

'value'=>($escape === FALSE ? $v2 : $this->escape($v2))

'value'=>(is_array($v2) ? $v2[0] : ($escape === FALSE ? $v2 : $this->escape($v2)))

并提供如下输入

$data = array(
   array(
      'fundCategoryId' => '3' ,
      'fundCategoryValue' => '500' , // generates with single quotes

   ),
   array(
      'fundCategoryId' => '4' ,
      'fundCategoryValue' => array('fundCategoryValue + 100') // generates without single quotes

   )
);

旧CI 2.2.x

修改DB_active_rec.php

发件人

            if ($escape === FALSE)
            {
                $clean[$this->_protect_identifiers($k2)] = $v2;
            }
            else
            {
                $clean[$this->_protect_identifiers($k2)] = $this->escape($v2);
            }

 $clean[$this->_protect_identifiers($k2)] = (is_array($v2)? $v2[0] : ( ($escape === FALSE) ? $v2 : $this->escape($v2) ));