diff --git a/DatabaseMysql.php b/DatabaseMysql.php index 3705fd3..b9d44dd 100644 --- a/DatabaseMysql.php +++ b/DatabaseMysql.php @@ -4,7 +4,7 @@ * Very stable interface for MySQL - object-oriented at last :) * Select builder is inspired by MediaWiki's one. * Also usable for querying SphinxQL. - * Version: 2016-05-28 + * Version: 2016-09-02 * (c) Vitaliy Filippov, 2012-2016 */ @@ -480,7 +480,7 @@ class DatabaseMysql implements Database $more = NULL; $tables = $this->tables_builder($tables, $more); if ($more) - $where = array_merge($where, $more); + $where = array_merge($where, (array)$more); $where = $this->where_builder($where); $sql = 'SELECT '; if (isset($options['CALC_FOUND_ROWS']) || isset($options['SQL_CALC_FOUND_ROWS'])) @@ -579,7 +579,7 @@ class DatabaseMysql implements Database * 'table', * 'alias' => 'table', * 'alias' => array('INNER', 'table_name', $where_for_on_clause), - * 'alias' => array('INNER', $nested_tables), + * 'alias(ignored)' => array('INNER', $nested_tables, $on_for_join_group), * ) * or just a string "`table1` INNER JOIN `table2` ON ..." * names taken into `backticks` will be transformed using $this->tableNames @@ -601,7 +601,14 @@ class DatabaseMysql implements Database else /* if (!$join || $join == 'inne' || $join == 'join') */ $join = 'INNER'; if (is_array($v[1])) // nested join (left join (A join B on ...) on ...) - $table = '('.$this->tables_builder($v[1]).')'; + { + $more = NULL; + $table = $this->tables_builder($v[1], $more); + if ($more) + $v[2] = array_merge((array)$v[2], (array)$more); + if (count($v[1]) > 1) + $table = "($table)"; + } else { $table = (isset($this->tableNames[$v[1]]) ? $this->quoteId($this->tableNames[$v[1]]) : $v[1]); diff --git a/DatabasePdoPgsql.php b/DatabasePdoPgsql.php index 68fe897..7a138f9 100644 --- a/DatabasePdoPgsql.php +++ b/DatabasePdoPgsql.php @@ -3,7 +3,7 @@ /** * PDO/PostgreSQL wrapper with (mostly) DatabaseMySQL interface :) * Select builder is inspired by MediaWiki's one. - * Version: 2016-03-25 + * Version: 2016-09-02 * (c) Vitaliy Filippov, 2015-2016 */ @@ -168,6 +168,12 @@ class DatabasePdoPgsql implements Database $this->queryCount++; if ($this->queryLogFile) file_put_contents($this->queryLogFile, date("[Y-m-d H:i:s] ").$sql."\n", FILE_APPEND); + if (strlen($sql) == 5 && strtoupper($sql) == 'BEGIN') + return $this->link->beginTransaction(); + elseif (strlen($sql) == 8 && strtoupper($sql) == 'ROLLBACK') + return $this->link->rollBack(); + elseif (strlen($sql) == 6 && strtoupper($sql) == 'COMMIT') + return $this->link->commit(); return $this->link->query($sql); } @@ -349,7 +355,7 @@ class DatabasePdoPgsql implements Database $more = NULL; $tables = $this->tables_builder($tables, $more); if ($more) - $where = array_merge($where, $more); + $where = array_merge($where, (array)$more); $where = $this->where_builder($where); $this->calcFoundRows = isset($options['CALC_FOUND_ROWS']) || isset($options['SQL_CALC_FOUND_ROWS']); if ($this->calcFoundRows) @@ -418,7 +424,7 @@ class DatabasePdoPgsql implements Database * 'table', * 'alias' => 'table', * 'alias' => array('INNER', 'table_name', $where_for_on_clause), - * 'alias' => array('INNER', $nested_tables), + * 'alias(ignored)' => array('INNER', $nested_tables, $on_for_join_group), * ) * or just a string "table1 INNER JOIN \"table2\" ON ..." * escaped names ("table2") will be transformed using $this->tableNames @@ -442,7 +448,14 @@ class DatabasePdoPgsql implements Database else /* if (!$join || $join == 'inne' || $join == 'join') */ $join = 'INNER'; if (is_array($v[1])) // nested join (left join (A join B on ...) on ...) - $table = '('.$this->tables_builder($v[1]).')'; + { + $more = NULL; + $table = $this->tables_builder($v[1], $more); + if ($more) + $v[2] = array_merge((array)$v[2], (array)$more); + if (count($v[1]) > 1) + $table = "($table)"; + } else { $table = (isset($this->tableNames[$v[1]]) ? $this->quoteId($this->tableNames[$v[1]]) : $v[1]); @@ -724,11 +737,11 @@ class DatabasePdoPgsql implements Database /** * Insert or update rows */ - function insert($table, $rows, $onConflict = NULL, $uniqueKey = NULL) + function insert($table, $rows, $onConflict = NULL, $uniqueKey = NULL, $updateCols = NULL) { if (!$rows) return false; - $sql = $this->insert_builder($table, $rows, $onConflict, $uniqueKey); + $sql = $this->insert_builder($table, $rows, $onConflict, $uniqueKey, $updateCols); $r = $this->query($sql); if ($r) return $r->rowCount();