Make WordPress Core

Opened 7 years ago

Closed 5 years ago

#11372 closed defect (bug) (fixed)

wpdb::query returns FALSE on TRUNCATE

Reported by: marcis20 Owned by: ryan
Milestone: 3.2 Priority: normal
Severity: normal Version: 2.8.5
Component: Database Keywords: has-patch
Focuses: Cc:


When executing a "TRUNCATE" SQL query, wpdb returns FALSE (num_rows = 0) although it's succesfull.

Maybe it should be included in the "if" section of the method check:

if ( preg_match("/^\\s*(insert|delete|update|replace|alter) /i",$query) ) {

And returns the "$this->rows_affected" value (1).

Attachments (3)

11372.diff (658 bytes) - added by scribu 6 years ago.
11372.2.diff (714 bytes) - added by scribu 6 years ago.
Move 'alter' to the first if () as well
11372.3.diff (817 bytes) - added by scribu 6 years ago.
Use single quotes, for readability

Download all attachments as: .zip

Change History (12)

#1 @scribu
7 years ago

For insert|delete|update|replace statements, rows_affected is set correctly.

The problematic ones are DDL statements: CREATE, DROP, TRUNCATE, ALTER etc.

#2 @hakre
7 years ago

Current trunk still has preg_match("/^\\s*(insert|delete|update|replace|alter) /i",$query) in there.

Related: #11799

#3 @Denis-de-Bernardy
7 years ago

  • Keywords bug-hunt added
  • Milestone changed from Unassigned to Future Release

#4 @Denis-de-Bernardy
7 years ago

  • Keywords featured added; bug-hunt removed

#5 @solarissmoke
6 years ago

Related/duplicate: #16228

6 years ago

#6 @scribu
6 years ago

  • Keywords has-patch added; featured database query truncate removed

11372.diff handles CREATE, TRUNCATE and DROP.

#7 @scribu
6 years ago

  • Keywords 3.2-early added

6 years ago

Move 'alter' to the first if () as well

6 years ago

Use single quotes, for readability

#8 @scribu
5 years ago

  • Keywords 3.2-early removed
  • Milestone changed from Future Release to 3.2

#9 @ryan
5 years ago

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

In [18063]:

Properly handle return value of DDL statements. Props scribu, marcis20. fixes #11372

Note: See TracTickets for help on using tickets.