diff --git a/CHANGELOG b/CHANGELOG index d9cc4e1f2..2a5d9fa36 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -46,6 +46,7 @@ CHANGELOG Roundcube Webmail - Localized timezone selector (#4983) - Use 7bit encoding for ISO-2022-* charsets in sent mail (#5640) - Handle inline images also inside multipart/mixed messages (#5905) +- Fix checking table columns when there's more schemas/databases in postgres/mysql (#6047) - Fix css conflicts in user interface and e-mail content (#5891) - Fix duplicated signature when using Back button in Chrome (#5809) - Fix touch event issue on messages list in IE/Edge (#5781) diff --git a/program/lib/Roundcube/rcube_db_mysql.php b/program/lib/Roundcube/rcube_db_mysql.php index ee2194fbf..06dac0d2c 100644 --- a/program/lib/Roundcube/rcube_db_mysql.php +++ b/program/lib/Roundcube/rcube_db_mysql.php @@ -158,14 +158,9 @@ class rcube_db_mysql extends rcube_db { // get tables if not cached if ($this->tables === null) { - // first fetch current database name - $d = $this->query("SELECT database()"); - $d = $this->fetch_array($d); - - // get list of tables in current database $q = $this->query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES" . " WHERE TABLE_SCHEMA = ? AND TABLE_TYPE = 'BASE TABLE'" - . " ORDER BY TABLE_NAME", $d ? $d[0] : ''); + . " ORDER BY TABLE_NAME", $this->db_dsnw_array['database']); $this->tables = $q ? $q->fetchAll(PDO::FETCH_COLUMN, 0) : array(); } @@ -173,6 +168,26 @@ class rcube_db_mysql extends rcube_db return $this->tables; } + /** + * Returns list of columns in database table + * + * @param string $table Table name + * + * @return array List of table cols + */ + public function list_cols($table) + { + $q = $this->query("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS" + . " WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?", + $this->db_dsnw_array['database'], $table); + + if ($q) { + return $q->fetchAll(PDO::FETCH_COLUMN, 0); + } + + return array(); + } + /** * Get database runtime variables * diff --git a/program/lib/Roundcube/rcube_db_pgsql.php b/program/lib/Roundcube/rcube_db_pgsql.php index e0ed46c84..8921d5cad 100644 --- a/program/lib/Roundcube/rcube_db_pgsql.php +++ b/program/lib/Roundcube/rcube_db_pgsql.php @@ -182,8 +182,16 @@ class rcube_db_pgsql extends rcube_db { // get tables if not cached if ($this->tables === null) { + if ($schema = $this->options['table_prefix']) { + $schema = str_replace('.', '', $schema); + $add = " AND TABLE_SCHEMA = " . $this->quote($schema); + } + else { + $add = " AND TABLE_SCHEMA NOT IN ('pg_catalog', 'information_schema')"; + } + $q = $this->query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES" - . " WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA NOT IN ('pg_catalog', 'information_schema')" + . " WHERE TABLE_TYPE = 'BASE TABLE'" . $add . " ORDER BY TABLE_NAME"); $this->tables = $q ? $q->fetchAll(PDO::FETCH_COLUMN, 0) : array(); @@ -192,6 +200,35 @@ class rcube_db_pgsql extends rcube_db return $this->tables; } + /** + * Returns list of columns in database table + * + * @param string $table Table name + * + * @return array List of table cols + */ + public function list_cols($table) + { + $args = array($table); + + if ($schema = $this->options['table_prefix']) { + $add = " AND TABLE_SCHEMA = ?"; + $args[] = str_replace('.', '', $schema); + } + else { + $add = " AND TABLE_SCHEMA NOT IN ('pg_catalog', 'information_schema')"; + } + + $q = $this->query("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS" + . " WHERE TABLE_NAME = ?" . $add, $args); + + if ($q) { + return $q->fetchAll(PDO::FETCH_COLUMN, 0); + } + + return array(); + } + /** * Returns PDO DSN string from DSN array *