From 6a76d38e92e9ba945da122c3955d7636f5c63746 Mon Sep 17 00:00:00 2001 From: randhirexpresstech Date: Fri, 31 May 2024 18:26:46 +0530 Subject: [PATCH] Fixed: Sqlite database skip ALTER QUERY --- mlw_quizmaster2.php | 15 +++- php/admin/functions.php | 22 +++--- php/classes/class-qsm-install.php | 114 ++++++++++++++++-------------- readme.txt | 1 + 4 files changed, 88 insertions(+), 64 deletions(-) diff --git a/mlw_quizmaster2.php b/mlw_quizmaster2.php index d64b51bab..016ecdc0f 100644 --- a/mlw_quizmaster2.php +++ b/mlw_quizmaster2.php @@ -161,6 +161,17 @@ public function __construct() { $this->add_hooks(); } + /** + * Check if database is sql lite + * + * @since 9.0.2 + * + * @return boolean database is sqlite or not + */ + public function is_sqlite_db() { + return ( ( defined( 'DATABASE_TYPE' ) && 'sqlite' === DATABASE_TYPE ) || ( defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ) ); + } + /** * Check admin capabilities. * @@ -200,7 +211,7 @@ public function get_failed_alter_table_queries() { */ public function wpdb_alter_table_query( $query ) { // Check if admin or empty query. - if ( empty( $query ) || ! function_exists( 'is_admin' ) || ! is_admin() ) { + if ( empty( $query ) || ! function_exists( 'is_admin' ) || ! is_admin() || $this->is_sqlite_db() ) { return false; } @@ -831,7 +842,7 @@ public function qsm_admin_notices() { // Get failed alter table query list. $failed_queries = $this->get_failed_alter_table_queries(); - if ( ! empty( $failed_queries ) && 0 < count( $failed_queries ) ) { + if ( ! $this->is_sqlite_db() && ! empty( $failed_queries ) && 0 < count( $failed_queries ) ) { ?>

diff --git a/php/admin/functions.php b/php/admin/functions.php index 1f169d5fc..b10f1002c 100644 --- a/php/admin/functions.php +++ b/php/admin/functions.php @@ -55,6 +55,12 @@ function link_featured_image( $quiz_id ) { */ function qsm_add_author_column_in_db() { global $mlwQuizMasterNext; + + // return if sqlite db + if ( $mlwQuizMasterNext->is_sqlite_db() ) { + return; + } + if ( 1 !== intval( get_option( 'qsm_update_db_column', '' ) ) ) { global $wpdb; @@ -78,7 +84,7 @@ function qsm_add_author_column_in_db() { ); if ( empty( $table_col_obj ) ) { - $mlwQuizMasterNext->wpdb_alter_table_query( 'ALTER TABLE ' . $table . ' ADD ' . $col_name . ' ' . $col_def ); + $wpdb->query( 'ALTER TABLE ' . $table . ' ADD ' . $col_name . ' ' . $col_def ); } } } @@ -96,7 +102,7 @@ function qsm_add_author_column_in_db() { ) ); if ( empty( $table_result_col_obj ) ) { - if ( $mlwQuizMasterNext->wpdb_alter_table_query( "ALTER TABLE $result_table_name ADD form_type INT NOT NULL" ) ) { + if ( $wpdb->query( "ALTER TABLE $result_table_name ADD form_type INT NOT NULL" ) ) { update_option( 'qsm_update_result_db_column', '1' ); } else { $mlwQuizMasterNext->log_manager->add( 'Error Creating Column form_type in' . $result_table_name, "Tried {$wpdb->last_query} but got {$wpdb->last_error}.", 0, 'error' ); @@ -118,7 +124,7 @@ function qsm_add_author_column_in_db() { ) ); if ( ! empty( $table_quiz_col_obj ) ) { - if ( $mlwQuizMasterNext->wpdb_alter_table_query( "ALTER TABLE $quiz_table_name CHANGE `system` `quiz_system` INT(11) NOT NULL;" ) ) { + if ( $wpdb->query( "ALTER TABLE $quiz_table_name CHANGE `system` `quiz_system` INT(11) NOT NULL;" ) ) { update_option( 'qsm_update_quiz_db_column', '1' ); } else { $mlwQuizMasterNext->log_manager->add( 'Error Changing Columns system,quiz_system in' . $quiz_table_name, "Tried {$wpdb->last_query} but got {$wpdb->last_error}.", 0, 'error' ); @@ -140,7 +146,7 @@ function qsm_add_author_column_in_db() { ), ARRAY_A ); if ( isset( $table_quiz_result_obj['DATA_TYPE'] ) && 'text' === $table_quiz_result_obj['DATA_TYPE'] ) { - if ( $mlwQuizMasterNext->wpdb_alter_table_query( "ALTER TABLE $result_table_name CHANGE `quiz_results` `quiz_results` LONGTEXT;" ) ) { + if ( $wpdb->query( "ALTER TABLE $result_table_name CHANGE `quiz_results` `quiz_results` LONGTEXT;" ) ) { update_option( 'qsm_update_result_db_column_datatype', '1' ); } else { $mlwQuizMasterNext->log_manager->add( 'Error Changing Columns quiz_results in' . $result_table_name, "Tried {$wpdb->last_query} but got {$wpdb->last_error}.", 0, 'error' ); @@ -163,7 +169,7 @@ function qsm_add_author_column_in_db() { ) ); if ( empty( $table_result_col_obj ) ) { - if ( $mlwQuizMasterNext->wpdb_alter_table_query( "ALTER TABLE $question_table_name ADD deleted_question_bank INT NOT NULL" ) ) { + if ( $wpdb->query( "ALTER TABLE $question_table_name ADD deleted_question_bank INT NOT NULL" ) ) { $inc_val = $total_count_val + 1; update_option( 'qsm_add_new_column_question_table_table', $inc_val ); } else { @@ -185,7 +191,7 @@ function qsm_add_author_column_in_db() { ) ); if ( empty( $table_result_col_obj ) ) { - if ( $mlwQuizMasterNext->wpdb_alter_table_query( "ALTER TABLE $result_table_name ADD page_url varchar(255) NOT NULL" ) ) { + if ( $wpdb->query( "ALTER TABLE $result_table_name ADD page_url varchar(255) NOT NULL" ) ) { update_option( 'qsm_update_result_db_column_page_url', '1' ); } else { $error = $wpdb->last_error; @@ -208,7 +214,7 @@ function qsm_add_author_column_in_db() { ) ); if ( empty( $table_result_col_obj ) ) { - if ( $mlwQuizMasterNext->wpdb_alter_table_query( "ALTER TABLE $result_table_name ADD page_name varchar(255) NOT NULL" ) ) { + if ( $wpdb->query( "ALTER TABLE $result_table_name ADD page_name varchar(255) NOT NULL" ) ) { update_option( 'qsm_update_result_db_column_page_name', '1' ); } else { $mlwQuizMasterNext->log_manager->add( 'Error Creating Column page_name in' . $result_table_name, "Tried {$wpdb->last_query} but got {$wpdb->last_error}.", 0, 'error' ); @@ -235,7 +241,7 @@ function qsm_add_author_column_in_db() { foreach ( $tables_to_convert as $table ) { $query = "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"; - $result = $mlwQuizMasterNext->wpdb_alter_table_query($query); + $result = $wpdb->query($query); if ( ! $result ) { $success = false; diff --git a/php/classes/class-qsm-install.php b/php/classes/class-qsm-install.php index 5c026f466..d0b07ea8b 100644 --- a/php/classes/class-qsm-install.php +++ b/php/classes/class-qsm-install.php @@ -1581,6 +1581,12 @@ public static function install() { */ public function update() { global $wpdb, $mlwQuizMasterNext; + + // return if sqlite db + if ( $mlwQuizMasterNext->is_sqlite_db() ) { + return; + } + $results_table_name = $wpdb->prefix . 'mlw_results'; $data = $mlwQuizMasterNext->version; if ( ! get_option( 'qmn_original_version' ) ) { @@ -1610,11 +1616,11 @@ public function update() { // Update 0.5 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'comment_section'" ) != 'comment_section' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD comment_field_text TEXT NOT NULL AFTER phone_field_text'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $sql = 'ALTER TABLE ' . $table_name . ' ADD comment_section INT NOT NULL AFTER admin_email'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $sql = 'ALTER TABLE ' . $table_name . ' ADD message_comment TEXT NOT NULL AFTER message_after'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . " SET comment_field_text='Comments', comment_section=1, message_comment='Enter You Text Here'"; $results = $wpdb->query( $update_sql ); } @@ -1622,7 +1628,7 @@ public function update() { // Update 0.9.4 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'randomness_order'" ) != 'randomness_order' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD randomness_order INT NOT NULL AFTER system'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . ' SET randomness_order=0'; $results = $wpdb->query( $update_sql ); } @@ -1630,7 +1636,7 @@ public function update() { // Update 0.9.5 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'question_answer_template'" ) != 'question_answer_template' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD question_answer_template TEXT NOT NULL AFTER comment_field_text'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $mlw_question_answer_default = '%QUESTION%
Answer Provided: %USER_ANSWER%
Correct Answer: %CORRECT_ANSWER%
Comments Entered: %USER_COMMENTS%
'; $update_sql = 'UPDATE ' . $table_name . " SET question_answer_template='" . $mlw_question_answer_default . "'"; $results = $wpdb->query( $update_sql ); @@ -1639,7 +1645,7 @@ public function update() { // Update 0.9.6 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'contact_info_location'" ) != 'contact_info_location' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD contact_info_location INT NOT NULL AFTER send_admin_email'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . ' SET contact_info_location=0'; $results = $wpdb->query( $update_sql ); } @@ -1647,7 +1653,7 @@ public function update() { // Update 1.0 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'email_from_text'" ) != 'email_from_text' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD email_from_text TEXT NOT NULL AFTER comment_field_text'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . " SET email_from_text='Wordpress'"; $results = $wpdb->query( $update_sql ); } @@ -1655,7 +1661,7 @@ public function update() { // Update 1.3.1 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'loggedin_user_contact'" ) != 'loggedin_user_contact' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD loggedin_user_contact INT NOT NULL AFTER randomness_order'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . ' SET loggedin_user_contact=0'; $results = $wpdb->query( $update_sql ); } @@ -1663,7 +1669,7 @@ public function update() { // Update 1.5.1 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'question_from_total'" ) != 'question_from_total' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD question_from_total INT NOT NULL AFTER comment_section'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . ' SET question_from_total=0'; $results = $wpdb->query( $update_sql ); } @@ -1671,13 +1677,13 @@ public function update() { // Update 1.6.1 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'total_user_tries'" ) != 'total_user_tries' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD total_user_tries INT NOT NULL AFTER question_from_total'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . ' SET total_user_tries=0'; $results = $wpdb->query( $update_sql ); } if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'total_user_tries_text'" ) != 'total_user_tries_text' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD total_user_tries_text TEXT NOT NULL AFTER total_user_tries'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . " SET total_user_tries_text='Enter Your Text Here'"; $results = $wpdb->query( $update_sql ); } @@ -1685,13 +1691,13 @@ public function update() { // Update 1.8.1 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'message_end_template'" ) != 'message_end_template' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD message_end_template TEXT NOT NULL AFTER message_comment'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . " SET message_end_template=''"; $results = $wpdb->query( $update_sql ); } if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'certificate_template'" ) != 'certificate_template' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD certificate_template TEXT NOT NULL AFTER total_user_tries_text'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . " SET certificate_template='Enter your text here!'"; $results = $wpdb->query( $update_sql ); } @@ -1699,31 +1705,31 @@ public function update() { // Update 1.9.1 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'social_media'" ) != 'social_media' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD social_media INT NOT NULL AFTER certificate_template'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . " SET social_media='0'"; $results = $wpdb->query( $update_sql ); } if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'social_media_text'" ) != 'social_media_text' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD social_media_text TEXT NOT NULL AFTER social_media'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . " SET social_media_text='I just score a %CORRECT_SCORE%% on %QUIZ_NAME%!'"; $results = $wpdb->query( $update_sql ); } if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'pagination'" ) != 'pagination' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD pagination INT NOT NULL AFTER social_media_text'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . ' SET pagination=0'; $results = $wpdb->query( $update_sql ); } if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'pagination_text'" ) != 'pagination_text' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD pagination_text TEXT NOT NULL AFTER pagination'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . " SET pagination_text='Next'"; $results = $wpdb->query( $update_sql ); } if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'timer_limit'" ) != 'timer_limit' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD timer_limit INT NOT NULL AFTER pagination_text'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . ' SET timer_limit=0'; $results = $wpdb->query( $update_sql ); } @@ -1731,7 +1737,7 @@ public function update() { // Update 2.1.1 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'quiz_stye'" ) != 'quiz_stye' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD quiz_stye TEXT NOT NULL AFTER timer_limit'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $mlw_style_default = ' div.mlw_qmn_quiz input[type=radio], div.mlw_qmn_quiz input[type=submit], @@ -1781,7 +1787,7 @@ public function update() { // Update 2.2.1 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'question_numbering'" ) != 'question_numbering' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD question_numbering INT NOT NULL AFTER quiz_stye'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . " SET question_numbering='0'"; $results = $wpdb->query( $update_sql ); } @@ -1789,7 +1795,7 @@ public function update() { // Update 2.8.1 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'quiz_settings'" ) != 'quiz_settings' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD quiz_settings TEXT NOT NULL AFTER question_numbering'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . " SET quiz_settings=''"; $results = $wpdb->query( $update_sql ); } @@ -1797,7 +1803,7 @@ public function update() { // Update 3.0.1 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'theme_selected'" ) != 'theme_selected' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD theme_selected TEXT NOT NULL AFTER quiz_settings'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . " SET theme_selected='default'"; $results = $wpdb->query( $update_sql ); } @@ -1805,7 +1811,7 @@ public function update() { // Update 3.3.1 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'last_activity'" ) != 'last_activity' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD last_activity DATETIME NOT NULL AFTER theme_selected'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = $wpdb->prepare( "UPDATE {$table_name} SET last_activity='%s'", gmdate( 'Y-m-d H:i:s' ) ); $results = $wpdb->query( $update_sql ); } @@ -1813,25 +1819,25 @@ public function update() { // Update 3.5.1 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'require_log_in'" ) != 'require_log_in' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD require_log_in INT NOT NULL AFTER last_activity'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = $wpdb->prepare( "UPDATE {$table_name} SET require_log_in='%d'", '0' ); $results = $wpdb->query( $update_sql ); } if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'require_log_in_text'" ) != 'require_log_in_text' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD require_log_in_text TEXT NOT NULL AFTER require_log_in'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = $wpdb->prepare( 'UPDATE ' . $table_name . " SET require_log_in_text='%s'", 'Enter Text Here' ); $results = $wpdb->query( $update_sql ); } if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'limit_total_entries'" ) != 'limit_total_entries' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD limit_total_entries INT NOT NULL AFTER require_log_in_text'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = $wpdb->prepare( "UPDATE {$table_name} SET limit_total_entries='%d'", '0' ); $results = $wpdb->query( $update_sql ); } if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'limit_total_entries_text'" ) != 'limit_total_entries_text' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD limit_total_entries_text TEXT NOT NULL AFTER limit_total_entries'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = $wpdb->prepare( "UPDATE {$table_name} SET limit_total_entries_text='%s'", 'Enter Text Here' ); $results = $wpdb->query( $update_sql ); } @@ -1839,19 +1845,19 @@ public function update() { // Update 7.3.8 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'quiz_author_id'" ) != 'quiz_author_id' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD quiz_author_id TEXT NOT NULL AFTER deleted'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); } // Update 3.7.1 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'scheduled_timeframe'" ) != 'scheduled_timeframe' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD scheduled_timeframe TEXT NOT NULL AFTER limit_total_entries_text'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . " SET scheduled_timeframe=''"; $results = $wpdb->query( stripslashes( esc_sql( $update_sql ) ) ); } if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'scheduled_timeframe_text'" ) != 'scheduled_timeframe_text' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD scheduled_timeframe_text TEXT NOT NULL AFTER scheduled_timeframe'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = $wpdb->prepare( "UPDATE {$table_name} SET scheduled_timeframe_text='%s'", 'Enter Text Here' ); $results = $wpdb->query( $update_sql ); } @@ -1859,13 +1865,13 @@ public function update() { // Update 4.3.0 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'disable_answer_onselect'" ) != 'disable_answer_onselect' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD disable_answer_onselect INT NOT NULL AFTER scheduled_timeframe_text'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = $wpdb->prepare( "UPDATE {$table_name} SET disable_answer_onselect=%d", '0' ); $results = $wpdb->query( $update_sql ); } if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'ajax_show_correct'" ) != 'ajax_show_correct' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD ajax_show_correct INT NOT NULL AFTER disable_answer_onselect'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = $wpdb->prepare( "UPDATE {$table_name} SET ajax_show_correct=%d", '0' ); $results = $wpdb->query( $update_sql ); } @@ -1875,23 +1881,23 @@ public function update() { // Update 0.5 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'comments'" ) != 'comments' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD comments INT NOT NULL AFTER correct_answer'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $sql = 'ALTER TABLE ' . $table_name . ' ADD hints TEXT NOT NULL AFTER comments'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = $wpdb->prepare( "UPDATE {$table_name} SET comments=%d, hints=''", '1' ); $results = $wpdb->query( $update_sql ); } // Update 0.8 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'question_order'" ) != 'question_order' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD question_order INT NOT NULL AFTER hints'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = $wpdb->prepare( "UPDATE {$table_name} SET question_order=%d", '0' ); $results = $wpdb->query( $update_sql ); } if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'question_type'" ) != 'question_type' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD question_type INT NOT NULL AFTER question_order'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = $wpdb->prepare( "UPDATE {$table_name} SET question_type=%d", '0' ); $results = $wpdb->query( $update_sql ); } @@ -1899,7 +1905,7 @@ public function update() { // Update 1.1.1 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'question_answer_info'" ) != 'question_answer_info' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD question_answer_info TEXT NOT NULL AFTER correct_answer'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . " SET question_answer_info=''"; $results = $wpdb->query( stripslashes( esc_sql( $update_sql ) ) ); } @@ -1907,7 +1913,7 @@ public function update() { // Update 2.5.1 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'answer_array'" ) != 'answer_array' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD answer_array TEXT NOT NULL AFTER question_name'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . " SET answer_array=''"; $results = $wpdb->query( stripslashes( esc_sql( $update_sql ) ) ); } @@ -1915,7 +1921,7 @@ public function update() { // Update 3.1.1 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'question_settings'" ) != 'question_settings' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD question_settings TEXT NOT NULL AFTER question_type'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . " SET question_settings=''"; $results = $wpdb->query( stripslashes( esc_sql( $update_sql ) ) ); } @@ -1923,7 +1929,7 @@ public function update() { // Update 4.0.0 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'category'" ) != 'category' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD category TEXT NOT NULL AFTER question_settings'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = 'UPDATE ' . $table_name . " SET category=''"; $results = $wpdb->query( stripslashes( esc_sql( $update_sql ) ) ); } @@ -1931,7 +1937,7 @@ public function update() { // Update 4.0.0 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'question_type_new'" ) != 'question_type_new' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD question_type_new TEXT NOT NULL AFTER question_type'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = $wpdb->prepare( "UPDATE {$table_name} SET question_type_new=%s", 'question_type' ); $results = $wpdb->query( $update_sql ); } @@ -1940,21 +1946,21 @@ public function update() { $user_email_template_data = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $wpdb->prefix . "mlw_quizzes LIKE 'user_email_template'" ); if ( 'text' === $user_email_template_data->Type ) { $sql = 'ALTER TABLE ' . $wpdb->prefix . 'mlw_quizzes MODIFY user_email_template LONGTEXT'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); } // Update 7.3.11 $user_message_after_data = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $wpdb->prefix . "mlw_quizzes LIKE 'message_after'" ); if ( 'text' === $user_message_after_data->Type ) { $sql = 'ALTER TABLE ' . $wpdb->prefix . 'mlw_quizzes MODIFY message_after LONGTEXT'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); } // Update 2.6.1 - $results = $mlwQuizMasterNext->wpdb_alter_table_query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_qm_audit_trail CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;' ); - $results = $mlwQuizMasterNext->wpdb_alter_table_query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_questions CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci' ); - $results = $mlwQuizMasterNext->wpdb_alter_table_query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_quizzes CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci' ); - $results = $mlwQuizMasterNext->wpdb_alter_table_query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_results CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci' ); + $results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_qm_audit_trail CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;' ); + $results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_questions CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci' ); + $results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_quizzes CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci' ); + $results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_results CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci' ); global $wpdb; $table_name = $wpdb->prefix . 'mlw_results'; @@ -1963,7 +1969,7 @@ public function update() { // Update 2.6.4 if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'user'" ) != 'user' ) { $sql = 'ALTER TABLE ' . $table_name . ' ADD user INT NOT NULL AFTER phone'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = $wpdb->prepare( "UPDATE {$table_name} SET user=%d", '0' ); $results = $wpdb->query( $update_sql ); } @@ -1971,23 +1977,23 @@ public function update() { // Update 4.7.0 if ( $wpdb->get_var( "SHOW COLUMNS FROM $table_name LIKE 'user_ip'" ) != 'user_ip' ) { $sql = "ALTER TABLE $table_name ADD user_ip TEXT NOT NULL AFTER user"; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $update_sql = $wpdb->prepare( "UPDATE {$table_name} SET user_ip='%s'", 'Unknown' ); $results = $wpdb->query( $update_sql ); } // Update 7.1.11 $user_message_after_data = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $wpdb->prefix . "mlw_results LIKE 'point_score'" ); if ( 'FLOAT' != $user_message_after_data->Type ) { - $results = $mlwQuizMasterNext->wpdb_alter_table_query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_results MODIFY point_score FLOAT NOT NULL;' ); + $results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_results MODIFY point_score FLOAT NOT NULL;' ); } if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $audit_table . " LIKE 'quiz_id'" ) != 'quiz_id' ) { $sql = 'ALTER TABLE ' . $audit_table . ' ADD quiz_id TEXT NOT NULL AFTER action'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $sql = 'ALTER TABLE ' . $audit_table . ' ADD quiz_name TEXT NOT NULL AFTER quiz_id'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); $sql = 'ALTER TABLE ' . $audit_table . ' ADD form_data TEXT NOT NULL AFTER quiz_name'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); + $results = $wpdb->query( $sql ); } // Update 5.0.0 @@ -2010,7 +2016,7 @@ public function update() { // Update 8.1.14 if ( ! $wpdb->query("SHOW KEYS FROM {$results_table_name} WHERE Key_name = 'unique_id_unique'" ) ) { - $results = $mlwQuizMasterNext->wpdb_alter_table_query("ALTER TABLE {$results_table_name} ADD UNIQUE (unique_id)"); + $results = $wpdb->query("ALTER TABLE {$results_table_name} ADD UNIQUE (unique_id)"); } // Update 8.0.3 diff --git a/readme.txt b/readme.txt index ad2f973c3..22e96fd94 100644 --- a/readme.txt +++ b/readme.txt @@ -169,6 +169,7 @@ This is usually a theme conflict. You can [checkout out our common conflict solu * Feature: Added resubmit or delete failed submission * Enhancement: Added admin notification if database user does not have proper permission. * Feature: Added button in admin database notification to check if issue has been fixed. +* Fixed: Sqlite database ALTER QUERY. = 9.0.1 (April 25, 2024) = * Bug: Fixed date format in %ANSWER_X% variable