Update DatabaseMysql & DatabasePdoPgsql
parent
73a730f841
commit
5a45252587
|
@ -4,7 +4,7 @@
|
||||||
* Very stable interface for MySQL - object-oriented at last :)
|
* Very stable interface for MySQL - object-oriented at last :)
|
||||||
* Select builder is inspired by MediaWiki's one.
|
* Select builder is inspired by MediaWiki's one.
|
||||||
* Also usable for querying SphinxQL.
|
* Also usable for querying SphinxQL.
|
||||||
* Version: 2016-05-28
|
* Version: 2016-09-02
|
||||||
* (c) Vitaliy Filippov, 2012-2016
|
* (c) Vitaliy Filippov, 2012-2016
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -480,7 +480,7 @@ class DatabaseMysql implements Database
|
||||||
$more = NULL;
|
$more = NULL;
|
||||||
$tables = $this->tables_builder($tables, $more);
|
$tables = $this->tables_builder($tables, $more);
|
||||||
if ($more)
|
if ($more)
|
||||||
$where = array_merge($where, $more);
|
$where = array_merge($where, (array)$more);
|
||||||
$where = $this->where_builder($where);
|
$where = $this->where_builder($where);
|
||||||
$sql = 'SELECT ';
|
$sql = 'SELECT ';
|
||||||
if (isset($options['CALC_FOUND_ROWS']) || isset($options['SQL_CALC_FOUND_ROWS']))
|
if (isset($options['CALC_FOUND_ROWS']) || isset($options['SQL_CALC_FOUND_ROWS']))
|
||||||
|
@ -579,7 +579,7 @@ class DatabaseMysql implements Database
|
||||||
* 'table',
|
* 'table',
|
||||||
* 'alias' => 'table',
|
* 'alias' => 'table',
|
||||||
* 'alias' => array('INNER', 'table_name', $where_for_on_clause),
|
* '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 ..."
|
* or just a string "`table1` INNER JOIN `table2` ON ..."
|
||||||
* names taken into `backticks` will be transformed using $this->tableNames
|
* 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') */
|
else /* if (!$join || $join == 'inne' || $join == 'join') */
|
||||||
$join = 'INNER';
|
$join = 'INNER';
|
||||||
if (is_array($v[1])) // nested join (left join (A join B on ...) on ...)
|
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
|
else
|
||||||
{
|
{
|
||||||
$table = (isset($this->tableNames[$v[1]]) ? $this->quoteId($this->tableNames[$v[1]]) : $v[1]);
|
$table = (isset($this->tableNames[$v[1]]) ? $this->quoteId($this->tableNames[$v[1]]) : $v[1]);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
/**
|
/**
|
||||||
* PDO/PostgreSQL wrapper with (mostly) DatabaseMySQL interface :)
|
* PDO/PostgreSQL wrapper with (mostly) DatabaseMySQL interface :)
|
||||||
* Select builder is inspired by MediaWiki's one.
|
* Select builder is inspired by MediaWiki's one.
|
||||||
* Version: 2016-03-25
|
* Version: 2016-09-02
|
||||||
* (c) Vitaliy Filippov, 2015-2016
|
* (c) Vitaliy Filippov, 2015-2016
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -168,6 +168,12 @@ class DatabasePdoPgsql implements Database
|
||||||
$this->queryCount++;
|
$this->queryCount++;
|
||||||
if ($this->queryLogFile)
|
if ($this->queryLogFile)
|
||||||
file_put_contents($this->queryLogFile, date("[Y-m-d H:i:s] ").$sql."\n", FILE_APPEND);
|
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);
|
return $this->link->query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,7 +355,7 @@ class DatabasePdoPgsql implements Database
|
||||||
$more = NULL;
|
$more = NULL;
|
||||||
$tables = $this->tables_builder($tables, $more);
|
$tables = $this->tables_builder($tables, $more);
|
||||||
if ($more)
|
if ($more)
|
||||||
$where = array_merge($where, $more);
|
$where = array_merge($where, (array)$more);
|
||||||
$where = $this->where_builder($where);
|
$where = $this->where_builder($where);
|
||||||
$this->calcFoundRows = isset($options['CALC_FOUND_ROWS']) || isset($options['SQL_CALC_FOUND_ROWS']);
|
$this->calcFoundRows = isset($options['CALC_FOUND_ROWS']) || isset($options['SQL_CALC_FOUND_ROWS']);
|
||||||
if ($this->calcFoundRows)
|
if ($this->calcFoundRows)
|
||||||
|
@ -418,7 +424,7 @@ class DatabasePdoPgsql implements Database
|
||||||
* 'table',
|
* 'table',
|
||||||
* 'alias' => 'table',
|
* 'alias' => 'table',
|
||||||
* 'alias' => array('INNER', 'table_name', $where_for_on_clause),
|
* '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 ..."
|
* or just a string "table1 INNER JOIN \"table2\" ON ..."
|
||||||
* escaped names ("table2") will be transformed using $this->tableNames
|
* escaped names ("table2") will be transformed using $this->tableNames
|
||||||
|
@ -442,7 +448,14 @@ class DatabasePdoPgsql implements Database
|
||||||
else /* if (!$join || $join == 'inne' || $join == 'join') */
|
else /* if (!$join || $join == 'inne' || $join == 'join') */
|
||||||
$join = 'INNER';
|
$join = 'INNER';
|
||||||
if (is_array($v[1])) // nested join (left join (A join B on ...) on ...)
|
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
|
else
|
||||||
{
|
{
|
||||||
$table = (isset($this->tableNames[$v[1]]) ? $this->quoteId($this->tableNames[$v[1]]) : $v[1]);
|
$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
|
* Insert or update rows
|
||||||
*/
|
*/
|
||||||
function insert($table, $rows, $onConflict = NULL, $uniqueKey = NULL)
|
function insert($table, $rows, $onConflict = NULL, $uniqueKey = NULL, $updateCols = NULL)
|
||||||
{
|
{
|
||||||
if (!$rows)
|
if (!$rows)
|
||||||
return false;
|
return false;
|
||||||
$sql = $this->insert_builder($table, $rows, $onConflict, $uniqueKey);
|
$sql = $this->insert_builder($table, $rows, $onConflict, $uniqueKey, $updateCols);
|
||||||
$r = $this->query($sql);
|
$r = $this->query($sql);
|
||||||
if ($r)
|
if ($r)
|
||||||
return $r->rowCount();
|
return $r->rowCount();
|
||||||
|
|
Loading…
Reference in New Issue