Skip to content

Commit 0307860

Browse files
Replace use of SHOW TABLES with DESCRIBE. #834 - Changes (#850)
1 parent 62d4430 commit 0307860

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/data.cls.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,13 @@ public function tb($tb)
354354
public function tb_exist($tb)
355355
{
356356
global $wpdb;
357-
return $wpdb->get_var("SHOW TABLES LIKE '" . $this->tb($tb) . "'");
357+
358+
$save_state = $wpdb->suppress_errors;
359+
$wpdb->suppress_errors(true);
360+
$describe = $wpdb->get_var('DESCRIBE `' . $this->tb($tb) . '`');
361+
$wpdb->suppress_errors($save_state);
362+
363+
return $describe !== null;
358364
}
359365

360366
/**

src/data.upgrade.func.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ function litespeed_update_7_0_1()
2525
Debug2::debug('[Data] v7.0.1 upgrade started');
2626

2727
$tb_url = $wpdb->prefix . 'litespeed_url';
28-
$tb_exists = $wpdb->get_var("SHOW TABLES LIKE '" . $tb_url . "'");
28+
$save_state = $wpdb->suppress_errors;
29+
$wpdb->suppress_errors(true);
30+
$tb_exists = $wpdb->get_var('DESCRIBE `' . $tb_url . '`');
31+
$wpdb->suppress_errors($save_state);
32+
2933
if (!$tb_exists) {
3034
Debug2::debug('[Data] Table `litespeed_url` not found, bypassed migration');
3135
return;
@@ -106,7 +110,12 @@ function litespeed_update_5_3()
106110
{
107111
global $wpdb;
108112
Debug2::debug('[Data] Upgrade url_file table');
109-
$tb_exists = $wpdb->get_var('SHOW TABLES LIKE "' . $wpdb->prefix . 'litespeed_url_file"');
113+
114+
$save_state = $wpdb->suppress_errors;
115+
$wpdb->suppress_errors(true);
116+
$tb_exists = $wpdb->get_var('DESCRIBE `' . $wpdb->prefix . 'litespeed_url_file`');
117+
$wpdb->suppress_errors($save_state);
118+
110119
if ($tb_exists) {
111120
$q =
112121
'ALTER TABLE `' .
@@ -127,7 +136,12 @@ function litespeed_update_4_4_4()
127136
{
128137
global $wpdb;
129138
Debug2::debug('[Data] Upgrade url_file table');
130-
$tb_exists = $wpdb->get_var('SHOW TABLES LIKE "' . $wpdb->prefix . 'litespeed_url_file"');
139+
140+
$save_state = $wpdb->suppress_errors;
141+
$wpdb->suppress_errors(true);
142+
$tb_exists = $wpdb->get_var('DESCRIBE `' . $wpdb->prefix . 'litespeed_url_file`');
143+
$wpdb->suppress_errors($save_state);
144+
131145
if ($tb_exists) {
132146
$q =
133147
'ALTER TABLE `' .
@@ -171,7 +185,12 @@ function litespeed_update_4()
171185
{
172186
global $wpdb;
173187
$tb = $wpdb->prefix . 'litespeed_cssjs';
174-
$existed = $wpdb->get_var("SHOW TABLES LIKE '$tb'");
188+
189+
$save_state = $wpdb->suppress_errors;
190+
$wpdb->suppress_errors(true);
191+
$existed = $wpdb->get_var('DESCRIBE `' . $tb . '`');
192+
$wpdb->suppress_errors($save_state);
193+
175194
if (!$existed) {
176195
return;
177196
}
@@ -711,7 +730,12 @@ function litespeed_update_3_0($ver)
711730

712731
// Update image optm table
713732
Debug2::debug('[Data] Upgrade img_optm table');
714-
$tb_exists = $wpdb->get_var('SHOW TABLES LIKE "' . $wpdb->prefix . 'litespeed_img_optm"');
733+
734+
$save_state = $wpdb->suppress_errors;
735+
$wpdb->suppress_errors(true);
736+
$tb_exists = $wpdb->get_var('DESCRIBE `' . $wpdb->prefix . 'litespeed_img_optm`');
737+
$wpdb->suppress_errors($save_state);
738+
715739
if ($tb_exists) {
716740
$status_mapping = array(
717741
'requested' => 3,

0 commit comments

Comments
 (0)