Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#7215 closed defect (bug) (fixed)

wpdb does not return affected rows using an ALTER query

Reported by: bjornw's profile BjornW Owned by:
Milestone: 2.7 Priority: normal
Severity: normal Version:
Component: General Keywords: wp-db, database, alter statement
Focuses: Cc:

Description

As far as I can tell the wpdb class does not return any info after performing an ALTER query. After inspection it seems that this is due to a missing 'alter' in the regex of this part in the code of /wp-includes/wp-db.php:

if ( preg_match("/^\\s*(insert|delete|update|replace) /i",$query) ) {
			$this->rows_affected = mysql_affected_rows($this->dbh);


I added 'alter' to the regex and now you'll get an INT with the number of rows affected (incl 0) or FALSE when the query failed. After update the code looks like this:

if ( preg_match("/^\\s*(insert|delete|update|replace|alter) /i",$query) ) {
			$this->rows_affected = mysql_affected_rows($this->dbh);

As far as I can tell this is backwards compatible although I did not tested this extensively.

Attachments (1)

wpdb-return-affected-rows-alter (531 bytes) - added by BjornW 17 years ago.
patch to return affected rows upon using ALTER statement in query

Download all attachments as: .zip

Change History (2)

@BjornW
17 years ago

patch to return affected rows upon using ALTER statement in query

#1 @ryan
17 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [9204]) Return affected rows for alter queries. Props BjornW. fixes #7215

Note: See TracTickets for help on using tickets.