关于解决oracle数据库insert【临时办法】

由于项目需要使用Oracle数据库,之前遇到一个insert不成功。原以为官方会解决,但是到目前应该还是没解决。
以下是我自己的解决办法,这样修改不清楚有什么不良效果,但能实现功能(MYSQL不合适)

thinkphp\library\think\db\Query.php 中的insert

public function insert(array $data = [], $replace = false, $getLastInsID = false, $sequence = null)
    {
        // 分析查询表达式
        $options = $this->parseExpress();
        $data    = array_merge($options['data'], $data);
        // 生成SQL语句
        $sql = $this->builder->insert($data, $options, $replace);
        // 获取参数绑定
        $bind = $this->getBind();
        if ($options['fetch_sql']) {
            // 获取实际执行的SQL语句
            return $this->connection->getRealSql($sql, $bind);
        }
        
     // 执行操作
//$result = 0 === $sql ? 0 : $this->execute($sql, $bind);

//修改
$realsql=$this->connection->getRealSql($sql, $bind);
        $result = $this->execute($realsql);
//修改


        if ($result) {
            $sequence  = $sequence ?: (isset($options['sequence']) ? $options['sequence'] : null);
            $lastInsId = $this->getLastInsID($sequence);
            if ($lastInsId) {
                $pk = $this->getPk($options);
                if (is_string($pk)) {
                    $data[$pk] = $lastInsId;
                }
            }
            $options['data'] = $data;
            $this->trigger('after_insert', $options);

            if ($getLastInsID) {
                return $lastInsId;
            }
        }
        return $result;
    }

复制代码

 

thinkphp\library\think\db\Connection.php中的getLastInsID

public function getLastInsID($sequence = null)
    {
//        return $this->linkID->lastInsertId($sequence);
        switch($this->config['type']) {
                        case '\think\oracle\Connection':
            if(preg_match("/^\s*(INSERT\s+INTO)\s+(\w+)\s+/i", $this->queryStr, $match)) {
            $seq=$this->config['sequence_prefix'];
            $fix1=$this->config['prefix'];
            $fix=str_ireplace($fix1, "", $match[2]);
            
        $this->table = $seq.$fix;
        }
                $sequence = $this->table;
                $vo = $this->query("SELECT {$sequence}.currval currval FROM dual");
                return $vo?$vo[0]["currval"]:0;
        }
    }

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值