2016-01-20 138 views
5

我正在运行查询,其中$sale_ids可能包含100个到几千个sale_id。我正在寻找一种方法来修正正则表达式错误,而无需修改CI 3的核心。CI 3.0.4 large where_in查询导致原因消息:preg_match():编译失败:正常表达式在偏移处太大)

这在版本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 

回答

11

有没有修改的核心的好办法,所以我想出了我与大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(); 
+0

天才!正是我在找的! – rAjA

+0

你先生是非常天才的。谢谢! – Charas

+0

非常感谢。做得好! – imilah

相关问题