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

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

  • 写回答

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) ));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化