WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 4 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:

Description

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 5 years ago.
11372.2.diff (714 bytes) - added by scribu 5 years ago.
Move 'alter' to the first if () as well
11372.3.diff (817 bytes) - added by scribu 5 years ago.
Use single quotes, for readability

Download all attachments as: .zip

Change History (12)

comment:1 @scribu6 years ago

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

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

comment:2 @hakre6 years ago

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

Related: #11799

comment:3 @Denis-de-Bernardy6 years ago

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

comment:4 @Denis-de-Bernardy6 years ago

  • Keywords featured added; bug-hunt removed

comment:5 @solarissmoke5 years ago

Related/duplicate: #16228

@scribu5 years ago

comment:6 @scribu5 years ago

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

11372.diff handles CREATE, TRUNCATE and DROP.

comment:7 @scribu5 years ago

  • Keywords 3.2-early added

@scribu5 years ago

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

@scribu5 years ago

Use single quotes, for readability

comment:8 @scribu4 years ago

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

comment:9 @ryan4 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.