Fix checking table columns when there's more schemas/databases in postgres/mysql (#6047)

pull/5874/merge
Aleksander Machniak 7 years ago
parent a6c37b7735
commit 4cb7713520

@ -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)

@ -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
*

@ -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
*

Loading…
Cancel
Save