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

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

问题描述:

Using update_batch to increment fields in database Single quotes automatically added calling function code

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

My codigniter last query is

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')

I want to remove single quotes after then when increment "fundCategoryValue" column

使用update_batch增加数据库中的字段单引号自动添加 calling函数代码 p> $ this-> db-> update_batch(“FundCategory”,$ create_data,'fundCategoryId') code> p>

我的codigniter上次查询是 p >

 更新`FundCategory`设置`fundCategoryUpdatedById` = CASE 
WHEN`fundonCategoryId` ='4'THEN'20000045'
WHEN`fundoryCategoryId` ='4'THEN'20000045'
ELSE`  fundCategoryUpdatedById`END,`fundCategoryValue` = CASE 
WHEN`fundoryCategoryId = ='4'那么'fundCategoryValue + 100'
WHEN`fundoryCategoryId` ='4'那么'fundCategoryValue + 200'
ELSE`fundoryCategoryValue`END 
WHERE`fundoryCategoryId`  IN('4','4')
  code>  pre> 
 
 

我希望在增加“fundCategoryValue”列 p> div后删除单引号 >

Try this by modifying core

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

Of function

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

From

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

To

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

and give input like below

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

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

   )
);

On old CI 2.2.x

Modify DB_active_rec.php

From

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

To

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