drmy1050
2017-01-27 07:50
浏览 172
已采纳

使用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

图片转代码服务由CSDN问答提供 功能建议

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

我的codigniter上次查询是

 更新`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')
   
 
 

我希望在增加“fundCategoryValue”列

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douzengjian1535 2017-01-27 09:21
    已采纳

    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) ));
    
    打赏 评论

相关推荐 更多相似问题