diff --git a/plugins/woocommerce/changelog/refactor-mysql-dual-table-in-favor-of-real-table b/plugins/woocommerce/changelog/refactor-mysql-dual-table-in-favor-of-real-table new file mode 100644 index 00000000000..d429f43bd7c --- /dev/null +++ b/plugins/woocommerce/changelog/refactor-mysql-dual-table-in-favor-of-real-table @@ -0,0 +1,4 @@ +Significance: patch +Type: tweak + +Use existing table instead of 'DUAL' to support hosts which do not support 'DUAL'. diff --git a/plugins/woocommerce/includes/data-stores/class-wc-coupon-data-store-cpt.php b/plugins/woocommerce/includes/data-stores/class-wc-coupon-data-store-cpt.php index 73bdb6c5411..d36e547d215 100644 --- a/plugins/woocommerce/includes/data-stores/class-wc-coupon-data-store-cpt.php +++ b/plugins/woocommerce/includes/data-stores/class-wc-coupon-data-store-cpt.php @@ -532,16 +532,16 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat ); $query_for_tentative_usages = $this->get_tentative_usage_query( $coupon->get_id() ); - $db_timestamp = $wpdb->get_var( 'SELECT UNIX_TIMESTAMP() FROM DUAL' ); + $db_timestamp = $wpdb->get_var( 'SELECT UNIX_TIMESTAMP() FROM ' . $wpdb->posts . ' LIMIT 1' ); $coupon_usage_key = '_coupon_held_' . ( (int) $db_timestamp + $held_time ) . '_' . wp_generate_password( 6, false ); $insert_statement = $wpdb->prepare( " INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value ) - SELECT %d, %s, %s FROM DUAL + SELECT %d, %s, %s FROM $wpdb->posts WHERE ( $query_for_usages ) + ( $query_for_tentative_usages ) < %d - ", + LIMIT 1", $coupon->get_id(), $coupon_usage_key, '', @@ -629,15 +629,15 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat ); // WPCS: unprepared SQL ok. $query_for_tentative_usages = $this->get_tentative_usage_query_for_user( $coupon->get_id(), $user_aliases ); - $db_timestamp = $wpdb->get_var( 'SELECT UNIX_TIMESTAMP() FROM DUAL' ); + $db_timestamp = $wpdb->get_var( 'SELECT UNIX_TIMESTAMP() FROM ' . $wpdb->posts . ' LIMIT 1' ); $coupon_used_by_meta_key = '_maybe_used_by_' . ( (int) $db_timestamp + $held_time ) . '_' . wp_generate_password( 6, false ); $insert_statement = $wpdb->prepare( " INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value ) - SELECT %d, %s, %s FROM DUAL + SELECT %d, %s, %s FROM $wpdb->posts WHERE ( $query_for_usages ) + ( $query_for_tentative_usages ) < %d - ", + LIMIT 1", $coupon->get_id(), $coupon_used_by_meta_key, $user_alias,