Make WordPress Core

Ticket #10864: 10864.001.diff

File 10864.001.diff, 2.9 KB (added by aaroncampbell, 14 years ago)
  • wp-includes/wp-db.php

     
    11491149         * @return int|false The number of rows inserted, or false on error.
    11501150         */
    11511151        function insert( $table, $data, $format = null ) {
     1152                return $this->_insert_replace_helper($table, $data, $format, 'INSERT');
     1153        }
     1154
     1155        /**
     1156         * Replace a row into a table.
     1157         *
     1158         * <code>
     1159         * wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 'bar' ) )
     1160         * wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) )
     1161         * </code>
     1162         *
     1163         * @since 3.0.0
     1164         * @see wpdb::prepare()
     1165         * @see wpdb::$field_types
     1166         * @see wp_set_wpdb_vars()
     1167         *
     1168         * @param string $table table name
     1169         * @param array $data Data to replace (in column => value pairs).  Both $data columns and $data values should be "raw" (neither should be SQL escaped).
     1170         * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data.
     1171         *      A format is one of '%d', '%s' (decimal number, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
     1172         * @return int|false The number of rows inserted, or false on error.
     1173         */
     1174        function replace( $table, $data, $format = null ) {
     1175                return $this->_insert_replace_helper($table, $data, $format, 'REPLACE');
     1176        }
     1177
     1178        /**
     1179         * Private helper function for insert and replace.
     1180         *
     1181         * Runs an insert or replace query based on type
     1182         *
     1183         * @since 3.0.0
     1184         * @see wpdb::prepare()
     1185         * @access private
     1186         *
     1187         * @param string $table table name
     1188         * @param array $data Data to insert (in column => value pairs).  Both $data columns and $data values should be "raw" (neither should be SQL escaped).
     1189         * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data.
     1190         *      A format is one of '%d', '%s' (decimal number, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
     1191         * @return int|false The number of rows inserted, or false on error.
     1192         */
     1193        function _insert_replace_helper($table, $data, $format = null, $type = 'INSERT') {
    11521194                $formats = $format = (array) $format;
    11531195                $fields = array_keys( $data );
    11541196                $formatted_fields = array();
     
    11611203                                $form = '%s';
    11621204                        $formatted_fields[] = $form;
    11631205                }
    1164                 $sql = "INSERT INTO `$table` (`" . implode( '`,`', $fields ) . "`) VALUES ('" . implode( "','", $formatted_fields ) . "')";
     1206                $sql = "{$type} INTO `$table` (`" . implode( '`,`', $fields ) . "`) VALUES ('" . implode( "','", $formatted_fields ) . "')";
    11651207                return $this->query( $this->prepare( $sql, $data ) );
    11661208        }
    11671209
    1168 
    11691210        /**
    11701211         * Update a row in the table
    11711212         *