WordPress.org

Make WordPress Core

Opened 8 years ago

Closed 4 years ago

#22115 closed enhancement (wontfix)

Further Simplifying errors

Reported by: msolution Owned by: johnbillion
Milestone: Priority: normal
Severity: normal Version: 3.4.2
Component: Database Keywords: has-patch
Focuses: Cc:

Description

tracking errors while making API's and cron jobs, is a tad difficult.

from the latest wordpress pack, /includes/wp-db.php

function query( $query ) {
...
...
if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES )
	$this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );

// If there is an error then take note of it..
if ( $this->last_error = mysql_error( $this->dbh ) ) {
	$this->print_error();
	return false;
}
...
...

if we change the above to simply

// If there is an error then take note of it..
$this->last_error = '';
if ( $this->last_error = mysql_error( $this->dbh ) )
	$this->print_error();

if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES )
	$this->queries[] = array( $query, $this->timer_stop(), $this->get_caller(), $this->last_error );

// If there is an error then take note of it..
if ( ! empty( $this->last_error ) )
	return false;

then we have all required info in the array queries, for use later. may it be wp_footer, or for a plugin as debug info.

Attachments (2)

22115.patch (766 bytes) - added by SergeyBiryukov 8 years ago.
ticket-22115-save-query-errors.2.patch (941 bytes) - added by bpetty 7 years ago.

Download all attachments as: .zip

Change History (11)

#1 @SergeyBiryukov
8 years ago

  • Keywords has-patch added

#2 @SergeyBiryukov
8 years ago

  • Milestone changed from Awaiting Review to 3.6

#3 @SergeyBiryukov
8 years ago

  • Type changed from feature request to enhancement

#4 @ryan
8 years ago

  • Milestone changed from 3.6 to Future Release

#5 @bpetty
7 years ago

  • Keywords 2nd-opinion dev-feedback removed

A good amount of code has changed in WPDB since the original patch here. I've refreshed the patch, though note that I still leave the call to print_error() in the same place rather than moving it up. This is mostly since WPDB now automatically tries to reconnect to the DB if the connection is lost - something that didn't happen when this patch was originally submitted.

I tested this briefly with bad queries and the Debug Bar plugin installed with SAVEQUERIES defined, and while Debug Bar doesn't use this extra value, I still wanted to make sure it didn't throw it off that it was there. It still works smoothly.

So I think this is still a good patch.

Note that this will need to be refreshed again if/when #21663 is applied to account for MySQLi.

#6 @johnbillion
7 years ago

We could take this a little further. My Query Monitor plugin extends the wpdb class in order to log the result of each query (the number of affected rows) in the $wpdb->queries array. When a result is an error it adds it as a WP_Error. The code can be seen here.

#7 @chriscct7
5 years ago

@johnbillion did you still want to go further with this?

#8 @johnbillion
5 years ago

  • Owner set to johnbillion
  • Status changed from new to reviewing

#9 @johnbillion
4 years ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from reviewing to closed

I'm going to close this in favour of the functionality remaining in a debugging plugin (as mentioned above, Query Monitor provides this). I don't want to increase the amount of memory that wpdb uses on every database call, even if it is a small increase.

Note: See TracTickets for help on using tickets.