From cc0defce869b8f27573071cca80abae59cac2713 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 21 Apr 2017 09:48:46 +0200 Subject: [PATCH] Fix failing database schema check in all engines except mysql (#5730) --- CHANGELOG | 1 + SQL/mssql.initial.sql | 1 - program/include/rcmail_install.php | 30 ++++++++++++++++++++++-------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 49851229d60..42348adb786 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,7 @@ CHANGELOG Roundcube Webmail - Enigma: Always use detached signatures (#5624) - Enigma: Fix handling of messages with nested PGP encrypted parts (#5634) - Minimize unwanted message loading in preview frame on drag (#5616) +- Fix failing database schema check in all engines except mysql (#5730) - Fix autocomplete popup closing with click outside the input, don't handle Tab key as Enter (#5606) - Fix jsdeps.json synchronization on update, warn about missing requirements of install-jsdeps.sh (#5598) - Fix missing thread expand icon on search result in widescreen mode (#5613) diff --git a/SQL/mssql.initial.sql b/SQL/mssql.initial.sql index 219aaa7752e..6030d704ae1 100644 --- a/SQL/mssql.initial.sql +++ b/SQL/mssql.initial.sql @@ -88,7 +88,6 @@ GO CREATE TABLE [dbo].[session] ( [sess_id] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL , - [created] [datetime] NOT NULL , [changed] [datetime] NULL , [ip] [varchar] (40) COLLATE Latin1_General_CI_AI NOT NULL , [vars] [text] COLLATE Latin1_General_CI_AI NOT NULL diff --git a/program/include/rcmail_install.php b/program/include/rcmail_install.php index ebc4fd165b8..d45be364d86 100644 --- a/program/include/rcmail_install.php +++ b/program/include/rcmail_install.php @@ -448,7 +448,8 @@ public function db_schema_check($db) } // read reference schema from mysql.initial.sql - $db_schema = $this->db_read_schema(INSTALL_PATH . 'SQL/mysql.initial.sql'); + $engine = $db->db_provider; + $db_schema = $this->db_read_schema(INSTALL_PATH . "SQL/$engine.initial.sql"); $errors = array(); // check list of tables @@ -484,13 +485,26 @@ private function db_read_schema($schemafile) $keywords = array('PRIMARY','KEY','INDEX','UNIQUE','CONSTRAINT','REFERENCES','FOREIGN'); foreach ($lines as $line) { - if (preg_match('/^\s*create table `?([a-z0-9_]+)`?/i', $line, $m)) { - $table_block = $m[1]; - } - else if ($table_block && preg_match('/^\s*`?([a-z0-9_-]+)`?\s+([a-z]+)/', $line, $m)) { - $col = $m[1]; - if (!in_array(strtoupper($col), $keywords)) { - $schema[$table_block][$col] = $m[2]; + if (preg_match('/^\s*create table ([\S]+)/i', $line, $m)) { + $table_name = explode('.', $m[1]); + $table_name = end($table_name); + $table_name = preg_replace('/[`"\[\]]/', '', $table_name); + } + else if ($table_name && ($line = trim($line))) { + if ($line == 'GO' || $line[0] == ')' || $line[strlen($line)-1] == ';') { + $table_name = null; + } + else { + $items = explode(' ', $line); + $col = $items[0]; + $col = preg_replace('/[`"\[\]]/', '', $col); + + if (!in_array(strtoupper($col), $keywords)) { + $type = strtolower($items[1]); + $type = preg_replace('/[^a-zA-Z0-9()]/', '', $type); + + $schema[$table_name][$col] = $type; + } } } }