Ticket #20838: lazy-col-info.diff
File lazy-col-info.diff, 2.1 KB (added by , 12 years ago) |
---|
-
wp-includes/wp-db.php
137 137 * @access private 138 138 * @var array 139 139 */ 140 var$col_info;140 private $col_info; 141 141 142 142 /** 143 143 * Saved queries that were executed … … 514 514 function __destruct() { 515 515 return true; 516 516 } 517 518 /** 519 * PHP5 style magic getter, used to lazy-load expensive data. 520 * 521 * @since 3.5.0 522 * @param string $var The private member to get, and optionally process 523 * @return mixed The private member 524 */ 525 function __get( $var ) { 526 if ( 'col_info' == $var ) 527 $this->load_col_info(); 528 529 return $this->$var; 530 } 517 531 518 532 /** 519 533 * Set $this->charset and $this->collate … … 1025 1039 $this->last_result = array(); 1026 1040 $this->col_info = null; 1027 1041 $this->last_query = null; 1042 @mysql_free_result( $this->result ); 1028 1043 } 1029 1044 1030 1045 /** … … 1117 1132 // Return number of rows affected 1118 1133 $return_val = $this->rows_affected; 1119 1134 } else { 1120 $i = 0;1121 while ( $i < @mysql_num_fields( $this->result ) ) {1122 $this->col_info[$i] = @mysql_fetch_field( $this->result );1123 $i++;1124 }1125 1135 $num_rows = 0; 1126 1136 while ( $row = @mysql_fetch_object( $this->result ) ) { 1127 1137 $this->last_result[$num_rows] = $row; 1128 1138 $num_rows++; 1129 1139 } 1130 1140 1131 @mysql_free_result( $this->result );1132 1133 1141 // Log number of rows the query returned 1134 1142 // and return number of rows selected 1135 1143 $this->num_rows = $num_rows; … … 1456 1464 } 1457 1465 return null; 1458 1466 } 1467 1468 /** 1469 * Load the column metadata from the last query. 1470 * 1471 * @since 3.5.0 1472 */ 1473 function load_col_info() { 1474 if( empty( $this->col_info ) ) { 1475 for ( $i = 0; $i < @mysql_num_fields( $this->result ); $i++ ) 1476 $this->col_info[$i] = @mysql_fetch_field( $this->result, $i ); 1477 } 1478 } 1459 1479 1460 1480 /** 1461 1481 * Retrieve column metadata from the last query. … … 1467 1487 * @return mixed Column Results 1468 1488 */ 1469 1489 function get_col_info( $info_type = 'name', $col_offset = -1 ) { 1490 $this->load_col_info(); 1491 1470 1492 if ( $this->col_info ) { 1471 1493 if ( $col_offset == -1 ) { 1472 1494 $i = 0;