我正在运行一个查询,其中 $sale_ids
可能包含 100 到数千个 sale_id。我正在寻找一种在不修改 CI 3 核心的情况下修复正则表达式错误的方法。
这在版本 2 中没有发生,并且不被认为是 CI 3 中的错误(我之前提出过这个问题)。
有什么办法可以让它发挥作用吗?我可以更改应用程序的逻辑,但这需要几天的工作。
我正在寻找一种方法来扩展/覆盖一个类,这样我就可以允许这个查询工作 如果没有办法通过覆盖来做到这一点,我将不得不破解核心(我不知道如何)。
$this->db->select('sales_payments.*, sales.sale_time');
$this->db->from('sales_payments');
$this->db->join('sales', 'sales.sale_id=sales_payments.sale_id');
$this->db->where_in('sales_payments.sale_id', $sale_ids);
$this->db->order_by('payment_date');
错误是:
Severity: Warning
Message: preg_match(): Compilation failed: regular expression is too large at offset 53249
Filename: database/DB_query_builder.php
Line Number: 2354
Backtrace:
File: /Applications/MAMP/htdocs/phppos/PHP-Point-Of-Sale/application/models/Sale.php
Line: 123
Function: get
File: /Applications/MAMP/htdocs/phppos/PHP-Point-Of-Sale/application/models/Sale.php
Line: 48
Function: _get_all_sale_payments
File: /Applications/MAMP/htdocs/phppos/PHP-Point-Of-Sale/application/models/reports/Summary_payments.php
Line: 60
Function: get_payment_data
File: /Applications/MAMP/htdocs/phppos/PHP-Point-Of-Sale/application/controllers/Reports.php
Line: 1887
Function: getData
File: /Applications/MAMP/htdocs/phppos/PHP-Point-Of-Sale/index.php
Line: 323
Function: require_once
最佳答案
没有修改核心的好方法,所以我想出了一个小改动,我对带有大 where_in 的代码进行了修改。开始一个组并创建 where_in 在更小的块中
$this->db->group_start();
$sale_ids_chunk = array_chunk($sale_ids,25);
foreach($sale_ids_chunk as $sale_ids)
{
$this->db->or_where_in('sales_payments.sale_id', $sale_ids);
}
$this->db->group_end();
关于regex - CI 3.0.4 大 where_in 查询导致消息 : preg_match(): Compilation failed: regular expression is too large at offset),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34912377/