Make WordPress Core


Ignore:
Timestamp:
03/06/2009 12:50:19 AM (18 years ago)
Author:
ryan
Message:

Add some default field types. see #7171

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/wp-db.php

    r10724 r10725  
    703703         * @return mixed Results of $this->query()
    704704         */
    705         function insert($table, $data, $format = '%s') {
    706                 $format = (array) $format;
     705        function insert($table, $data, $format = null) {
     706                global $db_field_types;
     707
     708                $formats = $format = (array) $format;
    707709                $fields = array_keys($data);
    708710                $formatted_fields = array();
    709                 foreach ( $data as $field ) {
    710                         $form = ( $form = array_shift($format) ) ? $form : $formatted_fields[0];
     711                foreach ( $fields as $field ) {
     712                        if ( !empty($format) )
     713                                $form = ( $form = array_shift($formats) ) ? $form : $format[0];
     714                        elseif ( isset($db_field_types[$field]) )
     715                                $form = $db_field_types[$field];
     716                        else
     717                                $form = '%s';
    711718                        $formatted_fields[] = $form;
    712719                }
    713720                $sql = "INSERT INTO $table (`" . implode( '`,`', $fields ) . "`) VALUES ('" . implode( "','", $formatted_fields ) . "')";
     721                error_log($sql);
    714722                return $this->query( $this->prepare( $sql, $data) );
    715723        }
    … …  
    727735         * @return mixed Results of $this->query()
    728736         */
    729         function update($table, $data, $where, $format = '%s', $where_format = '%s') {
     737        function update($table, $data, $where, $format = null, $where_format = null) {
     738                global $db_field_types;
     739
    730740                if ( !is_array( $where ) )
    731741                        return false;
    … …  
    733743                $formats = $format = (array) $format;
    734744                $bits = $wheres = array();
    735                 foreach ( (array) array_keys($data) as $k ) {
    736                         $form = ( $form = array_shift($formats) ) ? $form : $format[0];
    737                         $bits[] = "`$k` = {$form}";
     745                foreach ( (array) array_keys($data) as $field ) {
     746                        if ( !empty($format) )
     747                                $form = ( $form = array_shift($formats) ) ? $form : $format[0];
     748                        elseif ( isset($db_field_types[$field]) )
     749                                $form = $db_field_types[$field];
     750                        else
     751                                $form = '%s';
     752                        $bits[] = "`$field` = {$form}";
    738753                }
    739754
    740755                $where_formats = $where_format = (array) $where_format;
    741                 foreach ( $where as $c => $v ) {
    742                         $form = ( $form = array_shift($where_formats) ) ? $form : $where_format[0];
    743                         $wheres[] = "$c = {$form}";
     756                foreach ( (array) array_keys($where) as $field ) {
     757                        if ( !empty($where_format) )
     758                                $form = ( $form = array_shift($where_formats) ) ? $form : $where_format[0];
     759                        elseif ( isset($db_field_types[$field]) )
     760                                $form = $db_field_types[$field];
     761                        else
     762                                $form = '%s';
     763                        $wheres[] = "$field = {$form}";
    744764                }
    745765
    746766                $sql = "UPDATE $table SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres );
     767                error_log($sql);
    747768                return $this->query( $this->prepare( $sql, array_merge(array_values($data), array_values($where))) );
    748769        }
Note: See TracChangeset for help on using the changeset viewer.