#32029 closed defect (bug) (fixed)
WP_Error( 'wpdb_get_table_charset_failure' ) thrown when doing "SHOW TABLES LIKE %s"
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.2 | Priority: | high |
Severity: | normal | Version: | 4.2 |
Component: | Database | Keywords: | has-patch |
Focuses: | Cc: |
Description
When attempting to check if a DB table exists, the "wpdb_get_table_charset_failure" error is being thrown. Here's where I believe the error is being thrown (wp-includes/wp-db.php:2235~2238):
$results = $this->get_results( "SHOW FULL COLUMNS FROM `$table`" ); if ( ! $results ) { return new WP_Error( 'wpdb_get_table_charset_failure' ); }
My PHP error log has "WordPress database error Table 'private.wp_dfrpswc_temp_post_ids_by_set_id' doesn't exist for query SHOW FULL COLUMNS FROM wp_dfrpswc_temp_post_ids_by_set_id
".
I believe the issue is related to the get_table_charset() method being called before the new table has been created.
I'm running WP 4.2-RC1-32175. This is my custom code which generates the error:
$table_name = $wpdb->prefix . 'dfrpswc_temp_post_ids_by_set_id'; $query = $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name ); if ( $wpdb->get_var( $query ) != $table_name ) { dfrpswc_create_table(); }
Let me know if you need any additional information.
Thanks
Eric
Attachments (1)
Change History (17)
#1
@
10 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to 4.2
- Priority changed from normal to high
This ticket was mentioned in Slack in #core by drew. View the logs.
10 years ago
#4
follow-up:
↓ 16
@
10 years ago
- Keywords has-patch needs-testing added; needs-patch removed
32029.diff doesn't try and check the collation of tables when it's a query that really doesn't need it.
@datafeedr.com: Would you be able to test this patch against your code, please?
#5
follow-up:
↓ 6
@
10 years ago
- Keywords needs-testing removed
I ran into this very same thing earlier today with one of my plugins. Even though this is definitely an issue that should be solved in Core, I also think there is a better way to see if a table exists. Try the following instead:
$table_name = $wpdb->prefix . 'dfrpswc_temp_post_ids_by_set_id'; if ( ! in_array( $table_name, $wpdb->tables() ) ) { dfrpswc_create_table(); }
@pento I tested the patch and can confirm it solves the issue.
#6
in reply to:
↑ 5
@
10 years ago
Replying to valendesigns:
$table_name = $wpdb->prefix . 'dfrpswc_temp_post_ids_by_set_id'; if ( ! in_array( $table_name, $wpdb->tables() ) ) { dfrpswc_create_table(); }
Nope. $wpdb->tables()
isn't based on the database. This will never return true.
#8
@
10 years ago
- Owner set to pento
- Resolution set to fixed
- Status changed from new to closed
In 32232:
#32033 was marked as a duplicate.