Part of the EllisLab Network

Bug Report

DB_driver stores all the queries

Date: 09/21/2007 Severity: Major
Status: Bogus Reporter: displaynone
Version: 1.5.4
Keywords: Libraries, Database Class

Description

If you are executing a lot of queries (for example in a administration export), all the queries are stored in the $queries array.

There are not conditions for this action, so always every query executed will be stored.

The problem is that you can get a memory usage exception.

The solution is unset this array, but you must know this issue to do that.

Sorry for my bad english.

Saludos
Luis Sacristán

Expected Result

Actual Result

Comment on Bug Report

Page 1 of 1 pages
Posted by: Derek Jones on 21 September 2007 11:28am
Derek Jones's avatar

Thank you for taking the time to file a bug report, Luis, but this would be more appropriate as a feature request in the forums, as this is not a bug; the code is doing exactly what is intended.

Posted by: displaynone on 21 September 2007 11:38am
no avatar

Sorry, I will use the forum.

But if it’s not a bug, I think it’s a wrong way to make a debug. You write this code:

// Save the query for debugging
$this->queries[] = $sql;

But if you’re in a final product, you don’t need always this query history. CodeIgniter is a great, fast and good performance framework, but saving queries you are wasting the memory.

Excuse me if this message seems like bud-mannered, I have to improve my english.

Posted by: Derek Jones on 21 September 2007 11:44am
Derek Jones's avatar

Your English is fine. :-D

Honestly, if storing queries is causing you to run out of memory, I’d be concerned about the number and size of queries you are running, as the application overall should not be pushed over the edge by a simple text array.

Posted by: displaynone on 21 September 2007 1:02pm
no avatar

Thanks for my english.

I know I’m using a huge number of queries, no way, it’s impossible to do that without code. I’m exporting data from a DB to another, but it’s not a simple export, there are necessary somo operations and conditions for each record (perhaps I could use stored procedures, but I’m not sure).

I think you are right, and it won’t be a problem for the 99% of web applications.

Thanks
Luis

Posted by: Christian Land on 11 October 2007 12:41am
Christian Land's avatar

You could use simple_query() instead of query() if you’re performing large numbers of queries…

http://codeigniter.com/user_guide/database/queries.html

Posted by: barbazul on 27 October 2007 12:17pm
barbazul's avatar

I’ve just updated from the svn and checking the logs I see that this has been fixed on revision 666 by Rick on July 17th.
He added a $save_queries property to he DB_Driver class which is checked before saving the query.

I’ll try to format the changes in a comprehensible way:

File DB_Driver.php
Line 47
+ var $save_queries = TRUE;

Line 267:
- $this->queries[] = $sql;
+ if ($this->save_queries == TRUE)
+ {
+  $this->queries[] = $sql;
+ }


Note: The plus symbols mean “Add this line” and the minus symbols mean “Remove this line”

Name:

Email:

Location:

URL:

Remember my personal information

Notify me of follow-up comments?