WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#4826 closed defect (bug) (fixed)

Change to wpdb::get_col() breaks documented behavior

Reported by: mdawaffe Owned by:
Milestone: 2.3 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch 2nd-opinion
Focuses: Cc:

Description

[5858] [5861] Change get_col(), get_row(), and get_results() to return null if given an empty argument.

According to the documentation, get_col() should be able to be called with an empty argument in the following situation.

$a = get_col( "SELECT a, b FROM table" );
$b = get_col( '', 1 );

This is almost never needed since get_results() is almost always more efficient for grabbing data from multiple columns. Very ocassionally, this use of get_col() is more efficient and should still be supported. Otherwise, it will be necessary to write a wrapper function around get_results() to achieve the same thing. Since core WP does not make use of this type of call to get_col(), any plugin that does will have to write their own wrapper functions for the few cases where the old get_col() is more efficient than get_results().

I cannot think of when it would be useful for get_row() or get_results() to act in the old manner. It's only in the transformation of the data from row-centric to column-centric that this issue occurs.

Attached is a patch that reverts get_col() and fixes a PHP warning.

Attachments (1)

4826.diff (697 bytes) - added by mdawaffe 7 years ago.

Download all attachments as: .zip

Change History (2)

mdawaffe7 years ago

comment:1 ryan7 years ago

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

(In [5950]) Revert get_col behavior. Props mdawaffe. fixes #4826

Note: See TracTickets for help on using tickets.