From da371425617868c8aa8a5c659047971e195b6cf8 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 20 Mar 2008 23:34:32 +0000 Subject: [PATCH] Capture last db error. Pass it in WP_Error data when term inserts fail. Fix typo in WP_Ajax_Response git-svn-id: http://svn.automattic.com/wordpress/trunk@7431 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/classes.php | 2 +- wp-includes/taxonomy.php | 4 ++-- wp-includes/wp-db.php | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/wp-includes/classes.php b/wp-includes/classes.php index 7cf3eed201..3bf318db61 100644 --- a/wp-includes/classes.php +++ b/wp-includes/classes.php @@ -764,7 +764,7 @@ class WP_Ajax_Response { $response .= ""; if ( is_scalar($error_data) ) { - $response .= ""; + $response .= ""; } elseif ( is_array($error_data) ) { foreach ( $error_data as $k => $v ) $response .= "<$k>"; diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 41d1035d94..035567c0e7 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1153,14 +1153,14 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { if ( ! $term_id = is_term($slug) ) { if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) - return new WP_Error('db_insert_error', __('Could not insert term into the database')); + return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); $term_id = (int) $wpdb->insert_id; } else if ( is_taxonomy_hierarchical($taxonomy) && !empty($parent) ) { // If the taxonomy supports hierarchy and the term has a parent, make the slug unique // by incorporating parent slugs. $slug = wp_unique_term_slug($slug, (object) $args); if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) - return new WP_Error('db_insert_error', __('Could not insert term into the database')); + return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); $term_id = (int) $wpdb->insert_id; } diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index f52d286c50..216c9cf027 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -18,6 +18,7 @@ class wpdb { var $show_errors = false; var $suppress_errors = false; + var $last_error = ''; var $num_queries = 0; var $last_query; var $col_info; @@ -278,7 +279,7 @@ class wpdb { $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() ); // If there is an error then take note of it.. - if ( mysql_error($this->dbh) ) { + if ( $this->last_error = mysql_error($this->dbh) ) { $this->print_error(); return false; }