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
This commit is contained in:
ryan 2008-03-20 23:34:32 +00:00
parent 4784e3bd97
commit da37142561
3 changed files with 5 additions and 4 deletions

View File

@ -764,7 +764,7 @@ class WP_Ajax_Response {
$response .= "<wp_error_data code='$code'$class>";
if ( is_scalar($error_data) ) {
$response .= "<![CDATA[$v]]>";
$response .= "<![CDATA[$error_data]]>";
} elseif ( is_array($error_data) ) {
foreach ( $error_data as $k => $v )
$response .= "<$k><![CDATA[$v]]></$k>";

View File

@ -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;
}

View File

@ -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;
}