From 4eb234db7044799d4eab49af1be5d3448b3ddc35 Mon Sep 17 00:00:00 2001
From: Timothy J Warren
Date: Thu, 23 Apr 2020 18:21:35 -0400
Subject: [PATCH] Update API docs
---
apiDocumentation/classes.html | 16 ++
.../classes/Query_ConnectionManager.html | 79 ++++++++
.../Query_ConnectionManager/connect.html | 69 +++++++
.../Query_ConnectionManager/parseParams.html | 20 ++
.../classes/Query_Drivers_AbstractDriver.html | 35 ++--
.../Query_Drivers_AbstractDriver/__call.html | 2 +-
.../__construct.html | 2 +-
.../Query_Drivers_AbstractDriver/_quote.html | 22 ++-
.../affectedRows.html | 2 +-
.../driverQuery.html | 22 ++-
.../getColumns.html | 2 +-
.../Query_Drivers_AbstractDriver/getDbs.html | 2 +-
.../Query_Drivers_AbstractDriver/getFks.html | 2 +-
.../getFunctions.html | 2 +-
.../getIndexes.html | 2 +-
.../getLastQuery.html | 2 +-
.../getProcedures.html | 2 +-
.../getSchemas.html | 2 +-
.../getSequences.html | 2 +-
.../Query_Drivers_AbstractDriver/getSql.html | 2 +-
.../getSystemTables.html | 2 +-
.../getTables.html | 2 +-
.../getTriggers.html | 2 +-
.../getTypes.html | 2 +-
.../Query_Drivers_AbstractDriver/getUtil.html | 2 +-
.../getVersion.html | 2 +-
.../getViews.html | 2 +-
.../insertBatch.html | 2 +-
.../Query_Drivers_AbstractDriver/numRows.html | 2 +-
.../prefixTable.html | 2 +-
.../prepareExecute.html | 2 +-
.../prepareQuery.html | 2 +-
.../quoteIdent.html | 32 +---
.../quoteTable.html | 2 +-
.../returning.html | 2 +-
.../setLastQuery.html | 2 +-
.../setTablePrefix.html | 2 +-
.../truncate.html | 2 +-
.../updateBatch.html | 2 +-
.../classes/Query_Drivers_AbstractUtil.html | 23 +++
.../createTable.html | 20 ++
.../classes/Query_Drivers_Mysql_Util.html | 44 +++++
.../backupStructure.html | 41 ++++
.../classes/Query_Drivers_Pgsql_Driver.html | 44 +++++
.../Query_Drivers_Pgsql_Driver/getFks.html | 41 ++++
.../classes/Query_Drivers_Sqlite_Util.html | 30 +++
.../Query_Drivers_Sqlite_Util/backupData.html | 27 +++
apiDocumentation/classes/Query_JoinType.html | 110 +++++++++++
apiDocumentation/classes/Query_LikeType.html | 102 ++++++++++
.../classes/Query_QueryBuilder.html | 175 +++++++++++++++++-
.../classes/Query_QueryBuilder/countAll.html | 2 +-
.../Query_QueryBuilder/countAllResults.html | 22 ++-
.../classes/Query_QueryBuilder/delete.html | 2 +-
.../classes/Query_QueryBuilder/distinct.html | 2 +-
.../classes/Query_QueryBuilder/explain.html | 2 +-
.../classes/Query_QueryBuilder/from.html | 6 +-
.../classes/Query_QueryBuilder/get.html | 2 +-
.../Query_QueryBuilder/getCompiledDelete.html | 22 ++-
.../Query_QueryBuilder/getCompiledInsert.html | 22 ++-
.../Query_QueryBuilder/getCompiledSelect.html | 22 ++-
.../Query_QueryBuilder/getCompiledUpdate.html | 22 ++-
.../classes/Query_QueryBuilder/getWhere.html | 2 +-
.../classes/Query_QueryBuilder/groupBy.html | 22 ++-
.../classes/Query_QueryBuilder/groupEnd.html | 2 +-
.../Query_QueryBuilder/groupStart.html | 2 +-
.../classes/Query_QueryBuilder/having.html | 2 +-
.../classes/Query_QueryBuilder/insert.html | 2 +-
.../Query_QueryBuilder/insertBatch.html | 36 +++-
.../classes/Query_QueryBuilder/join.html | 2 +-
.../classes/Query_QueryBuilder/like.html | 4 +-
.../classes/Query_QueryBuilder/limit.html | 2 +-
.../Query_QueryBuilder/notGroupStart.html | 2 +-
.../classes/Query_QueryBuilder/notLike.html | 4 +-
.../Query_QueryBuilder/orGroupStart.html | 2 +-
.../classes/Query_QueryBuilder/orHaving.html | 2 +-
.../classes/Query_QueryBuilder/orLike.html | 4 +-
.../Query_QueryBuilder/orNotGroupStart.html | 2 +-
.../classes/Query_QueryBuilder/orNotLike.html | 4 +-
.../classes/Query_QueryBuilder/orWhere.html | 2 +-
.../classes/Query_QueryBuilder/orWhereIn.html | 2 +-
.../Query_QueryBuilder/orWhereNotIn.html | 2 +-
.../classes/Query_QueryBuilder/orderBy.html | 2 +-
.../classes/Query_QueryBuilder/returning.html | 2 +-
.../classes/Query_QueryBuilder/select.html | 2 +-
.../classes/Query_QueryBuilder/selectAvg.html | 29 ++-
.../classes/Query_QueryBuilder/selectMax.html | 29 ++-
.../classes/Query_QueryBuilder/selectMin.html | 29 ++-
.../classes/Query_QueryBuilder/selectSum.html | 29 ++-
.../classes/Query_QueryBuilder/set.html | 22 ++-
.../classes/Query_QueryBuilder/table.html | 108 +++++++++++
.../classes/Query_QueryBuilder/update.html | 2 +-
.../Query_QueryBuilder/updateBatch.html | 43 ++++-
.../classes/Query_QueryBuilder/where.html | 2 +-
.../classes/Query_QueryBuilder/whereIn.html | 2 +-
.../Query_QueryBuilder/whereNotIn.html | 2 +-
.../classes/Query_QueryParser.html | 23 +++
.../Query_QueryParser/__construct.html | 20 ++
.../Query_Drivers_DriverInterface.html | 22 ++-
.../driverQuery.html | 20 ++
.../quoteTable.html | 11 +-
.../Query_QueryBuilderInterface.html | 107 +++++++++++
.../Query_QueryBuilderInterface/countAll.html | 2 +-
.../countAllResults.html | 22 ++-
.../Query_QueryBuilderInterface/delete.html | 2 +-
.../Query_QueryBuilderInterface/from.html | 6 +-
.../Query_QueryBuilderInterface/get.html | 2 +-
.../getCompiledDelete.html | 22 ++-
.../getCompiledInsert.html | 22 ++-
.../getCompiledSelect.html | 22 ++-
.../getCompiledUpdate.html | 22 ++-
.../Query_QueryBuilderInterface/getWhere.html | 2 +-
.../Query_QueryBuilderInterface/groupBy.html | 2 +-
.../Query_QueryBuilderInterface/groupEnd.html | 2 +-
.../groupStart.html | 2 +-
.../Query_QueryBuilderInterface/having.html | 2 +-
.../Query_QueryBuilderInterface/insert.html | 2 +-
.../insertBatch.html | 2 +-
.../Query_QueryBuilderInterface/join.html | 4 +-
.../Query_QueryBuilderInterface/like.html | 4 +-
.../Query_QueryBuilderInterface/limit.html | 2 +-
.../notGroupStart.html | 2 +-
.../Query_QueryBuilderInterface/notLike.html | 4 +-
.../orGroupStart.html | 2 +-
.../Query_QueryBuilderInterface/orHaving.html | 2 +-
.../Query_QueryBuilderInterface/orLike.html | 4 +-
.../orNotGroupStart.html | 2 +-
.../orNotLike.html | 4 +-
.../Query_QueryBuilderInterface/orWhere.html | 2 +-
.../orWhereIn.html | 2 +-
.../orWhereNotIn.html | 2 +-
.../Query_QueryBuilderInterface/orderBy.html | 2 +-
.../resetQuery.html | 2 +-
.../selectAvg.html | 27 +++
.../selectMax.html | 27 +++
.../selectMin.html | 27 +++
.../selectSum.html | 27 +++
.../Query_QueryBuilderInterface/set.html | 2 +-
.../Query_QueryBuilderInterface/table.html | 99 ++++++++++
.../Query_QueryBuilderInterface/update.html | 2 +-
.../updateBatch.html | 2 +-
.../Query_QueryBuilderInterface/where.html | 2 +-
.../Query_QueryBuilderInterface/whereIn.html | 2 +-
.../whereNotIn.html | 2 +-
apiDocumentation/namespaces.html | 2 +-
.../source/Drivers/AbstractDriver.php.html | 2 +-
.../source/Drivers/DriverInterface.php.html | 2 +-
apiDocumentation/source/JoinType.php.html | 3 +
apiDocumentation/source/LikeType.php.html | 3 +
apiDocumentation/source/QueryBuilder.php.html | 2 +-
.../source/QueryBuilderBase.php.html | 2 +-
.../source/QueryBuilderInterface.php.html | 2 +-
151 files changed, 1977 insertions(+), 184 deletions(-)
create mode 100644 apiDocumentation/classes/Query_JoinType.html
create mode 100644 apiDocumentation/classes/Query_LikeType.html
create mode 100644 apiDocumentation/classes/Query_QueryBuilder/table.html
create mode 100644 apiDocumentation/interfaces/Query_QueryBuilderInterface/table.html
create mode 100644 apiDocumentation/source/JoinType.php.html
create mode 100644 apiDocumentation/source/LikeType.php.html
diff --git a/apiDocumentation/classes.html b/apiDocumentation/classes.html
index 6fd35fd..49a4db4 100644
--- a/apiDocumentation/classes.html
+++ b/apiDocumentation/classes.html
@@ -123,6 +123,22 @@
EMPTY
|
+
+
+ JoinType
+ |
+ 'Enum' of join types |
+ EMPTY
+ |
+
+
+
+ LikeType
+ |
+ 'Enum' of join types |
+ EMPTY
+ |
+
MapType
diff --git a/apiDocumentation/classes/Query_ConnectionManager.html b/apiDocumentation/classes/Query_ConnectionManager.html
index a25875b..95c5300 100644
--- a/apiDocumentation/classes/Query_ConnectionManager.html
+++ b/apiDocumentation/classes/Query_ConnectionManager.html
@@ -52,6 +52,9 @@
Synopsis
+
+ Violations
+
Methods
@@ -77,6 +80,82 @@
}
+ Violations
+
+ PHPMessDetector
+
+
+
+ Line |
+ Rule |
+ Message |
+
+
+
+ 129 |
+
+ UndefinedVariable
+ |
+ Avoid using undefined variables such as '$dsn' which will lead to PHP notices. |
+
+
+ 129 |
+
+ UndefinedVariable
+ |
+ Avoid using undefined variables such as '$options' which will lead to PHP notices. |
+
+
+ 135 |
+
+ ShortVariable
+ |
+ Avoid variables with short names like $db. Configured minimum length is 3. |
+
+
+ 136 |
+
+ UndefinedVariable
+ |
+ Avoid using undefined variables such as '$dsn' which will lead to PHP notices. |
+
+
+ 136 |
+
+ UndefinedVariable
+ |
+ Avoid using undefined variables such as '$options' which will lead to PHP notices. |
+
+
+ 137 |
+
+ UndefinedVariable
+ |
+ Avoid using undefined variables such as '$dsn' which will lead to PHP notices. |
+
+
+ 137 |
+
+ UndefinedVariable
+ |
+ Avoid using undefined variables such as '$options' which will lead to PHP notices. |
+
+
+ 155 - 157 |
+
+ ElseExpression
+ |
+ The method connect uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. |
+
+
+ 196 - 198 |
+
+ ElseExpression
+ |
+ The method parseParams uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. |
+
+
+
Methods
public
diff --git a/apiDocumentation/classes/Query_ConnectionManager/connect.html b/apiDocumentation/classes/Query_ConnectionManager/connect.html
index 4afee89..f66c0dc 100644
--- a/apiDocumentation/classes/Query_ConnectionManager/connect.html
+++ b/apiDocumentation/classes/Query_ConnectionManager/connect.html
@@ -102,6 +102,75 @@
+ Violations
+
+ PHPMessDetector
+
+
+
+ Line |
+ Rule |
+ Message |
+
+
+
+ 129 |
+
+ UndefinedVariable
+ |
+ Avoid using undefined variables such as '$dsn' which will lead to PHP notices. |
+
+
+ 129 |
+
+ UndefinedVariable
+ |
+ Avoid using undefined variables such as '$options' which will lead to PHP notices. |
+
+
+ 135 |
+
+ ShortVariable
+ |
+ Avoid variables with short names like $db. Configured minimum length is 3. |
+
+
+ 136 |
+
+ UndefinedVariable
+ |
+ Avoid using undefined variables such as '$dsn' which will lead to PHP notices. |
+
+
+ 136 |
+
+ UndefinedVariable
+ |
+ Avoid using undefined variables such as '$options' which will lead to PHP notices. |
+
+
+ 137 |
+
+ UndefinedVariable
+ |
+ Avoid using undefined variables such as '$dsn' which will lead to PHP notices. |
+
+
+ 137 |
+
+ UndefinedVariable
+ |
+ Avoid using undefined variables such as '$options' which will lead to PHP notices. |
+
+
+ 155 - 157 |
+
+ ElseExpression
+ |
+ The method connect uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. |
+
+
+
|
- 7
+ 9
|
0 |
diff --git a/apiDocumentation/source/Drivers/AbstractDriver.php.html b/apiDocumentation/source/Drivers/AbstractDriver.php.html
index 4ca8a1c..efa7ed8 100644
--- a/apiDocumentation/source/Drivers/AbstractDriver.php.html
+++ b/apiDocumentation/source/Drivers/AbstractDriver.php.html
@@ -1,3 +1,3 @@
phpDox - Source of AbstractDriver.phpSource of file AbstractDriver.php
- Size: 15,613 Bytes - Last Modified: 2020-04-17T14:56:27-04:00
src/Drivers/AbstractDriver.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717 | <?php declare(strict_types=1);
use InvalidArgumentException;
abstract class AbstractDriver implements DriverInterface {
protected PDOStatement $statement;
protected string $escapeCharOpen = '"';
protected string $escapeCharClose = '"';
protected SQLInterface $driverSQL;
protected AbstractUtil $util;
protected string $lastQuery = '';
protected string $tablePrefix = '';
protected bool $hasTruncate = TRUE;
public function __construct(string $dsn, string $username=NULL, string $password=NULL, array $driverOptions=[]) $driverOptions[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; parent::__construct($dsn, $username, $password, $driverOptions);
$this->_loadSubClasses();
protected function _loadSubClasses(): void $thisClass = \get_class($this); $nsArray = explode("\\", $thisClass); $driver = array_pop($nsArray); $sqlClass = __NAMESPACE__ . "\\{$driver}\\SQL"; $utilClass = __NAMESPACE__ . "\\{$driver}\\Util";
$this->driverSQL = new $sqlClass(); $this->util = new $utilClass($this);
public function __call(string $name, array $args = []) && \is_object($this->$name) && method_exists($this->$name, '__invoke') return \call_user_func_array([$this->$name, '__invoke'], $args);
public function getLastQuery(): string
public function setLastQuery(string $queryString): void $this->lastQuery = $queryString;
public function getSql(): SQLInterface
public function getUtil(): AbstractUtil
public function setTablePrefix(string $prefix): void $this->tablePrefix = $prefix;
public function prepareQuery(string $sql, array $data): PDOStatement $this->statement = $this->prepare($sql);
foreach($data as $k => $value) $this->statement->bindValue($k, $value);
public function prepareExecute(string $sql, array $params): PDOStatement $this->statement = $this->prepareQuery($sql, $params); $this->statement->execute();
public function affectedRows(): int return $this->statement->rowCount();
public function prefixTable(string $table): string if ( ! empty($this->tablePrefix)) $identifiers = explode('.', $table); $segments = count($identifiers);
$identifiers[$segments - 1] = $this->_prefix(end($identifiers));
$table = implode('.', $identifiers);
public function quoteTable($table): string $table = $this->prefixTable($table);
return $this->quoteIdent($table);
public function quoteIdent($identifier) if (is_array($identifier)) return array_map([$this, __METHOD__], $identifier);
if (strpos($identifier, ',') !== FALSE) $parts = array_map('mb_trim', explode(',', $identifier)); $parts = array_map([$this, __METHOD__], $parts); $identifier = implode(',', $parts);
$hiers = explode('.', $identifier); $hiers = array_map('mb_trim', $hiers);
$raw = implode('.', array_map([$this, '_quote'], $hiers));
preg_match_all("#{$this->escapeCharOpen}([a-zA-Z0-9_]+(\((.*?)\))){$this->escapeCharClose}#iu", $raw, $funcs, PREG_SET_ORDER); $raw = str_replace(array($f[0], $f[3]), array($f[1], $this->quoteIdent($f[3])), $raw);
public function getSchemas(): ?array
public function getTables(): ?array $tables = $this->driverQuery('tableList');
public function getDbs(): ?array return $this->driverQuery('dbList');
public function getViews(): ?array $views = $this->driverQuery('viewList');
public function getSequences(): ?array return $this->driverQuery('sequenceList');
public function getFunctions(): ?array return $this->driverQuery('functionList', FALSE);
public function getProcedures(): ?array return $this->driverQuery('procedureList', FALSE);
public function getTriggers(): ?array return $this->driverQuery('triggerList', FALSE);
public function getSystemTables(): ?array return $this->driverQuery('systemTableList');
public function getColumns(string $table): ?array return $this->driverQuery($this->getSql()->columnList($this->prefixTable($table)), FALSE);
public function getFks(string $table): ?array return $this->driverQuery($this->getSql()->fkList($table), FALSE);
public function getIndexes(string $table): ?array return $this->driverQuery($this->getSql()->indexList($this->prefixTable($table)), FALSE);
public function getTypes(): ?array return $this->driverQuery('typeList', FALSE);
public function getVersion(): string return $this->getAttribute(PDO::ATTR_SERVER_VERSION);
public function driverQuery($query, $filteredIndex=TRUE): ?array if (is_string($query) && method_exists($this->driverSQL, $query)) $query = $this->getSql()->$query();
if ( ! is_string($query))
$res = $this->query($query);
$flag = $filteredIndex ? PDO::FETCH_NUM : PDO::FETCH_ASSOC; $all = $res->fetchAll($flag);
return $filteredIndex ? dbFilter($all, 0) : $all;
public function numRows(): ?int $regex = '/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/i';
if (preg_match($regex, $this->lastQuery, $output) > 0) $stmt = $this->query("SELECT COUNT(*) FROM {$output[1]}"); return (int) $stmt->fetchColumn();
public function insertBatch(string $table, array $data=[]): array $firstRow = (array) current($data);
$vals = array_merge($vals, array_values($group));
$table = $this->quoteTable($table); $fields = array_keys($firstRow);
$sql = "INSERT INTO {$table} (" . implode(',', $this->quoteIdent($fields))
$params = array_fill(0, count($fields), '?'); $paramString = '(' . implode(',', $params) . ')'; $paramList = array_fill(0, count($data), $paramString);
$sql .= implode(',', $paramList);
public function updateBatch(string $table, array $data, string $where): array
$sql = 'UPDATE ' . $this->quoteTable($table) . ' SET ';
array_reduce($data, static function ($previous, $current) use (&$affectedRows, $where) { $keys = array_diff(array_keys($current), [$where]);
return array_merge($previous, $keys);
foreach ($fields as $field) $line = $this->quoteIdent($field) . " = CASE\n";
if (array_key_exists($field, $case)) $insertData[] = $case[$where]; $insertData[] = $case[$field]; $cases[] = 'WHEN ' . $this->quoteIdent($where) . ' =? '
$line .= implode("\n", $cases) . "\n"; $line .= 'ELSE ' . $this->quoteIdent($field) . ' END';
$sql .= implode(",\n", $fieldLines) . "\n";
$whereValues = array_column($data, $where); foreach ($whereValues as $value)
$placeholders = array_fill(0, count($whereValues), '?');
$sql .= 'WHERE ' . $this->quoteIdent($where) . ' IN '; $sql .= '(' . implode(',', $placeholders) . ')';
return [$sql, $insertData, $affectedRows];
public function truncate(string $table): PDOStatement $sql = $this->hasTruncate
$sql .= $this->quoteTable($table);
$this->statement = $this->query($sql);
public function returning(string $query, string $select): string return "{$query} RETURNING {$select}";
public function _quote($str) && strpos($str, $this->escapeCharOpen) !== 0 && strrpos($str, $this->escapeCharClose) !== 0 ? "{$this->escapeCharOpen}{$str}{$this->escapeCharClose}"
protected function _prefix(string $str): string if (strpos($str, $this->tablePrefix) !== FALSE)
return $this->tablePrefix . $str;
|
Generated using phpDox 0.12.0-dev - Copyright (C) 2010 - 2020 by Arne Blankerts and Contributors
+ Size: 15,753 Bytes - Last Modified: 2020-04-23T17:37:07-04:00
src/Drivers/AbstractDriver.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722 | <?php declare(strict_types=1);
use InvalidArgumentException;
use function call_user_func_array;
abstract class AbstractDriver implements DriverInterface {
protected PDOStatement $statement;
protected string $escapeCharOpen = '"';
protected string $escapeCharClose = '"';
protected SQLInterface $driverSQL;
protected AbstractUtil $util;
protected string $lastQuery = '';
protected string $tablePrefix = '';
protected bool $hasTruncate = TRUE;
public function __construct(string $dsn, string $username=NULL, string $password=NULL, array $driverOptions=[]) $driverOptions[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; parent::__construct($dsn, $username, $password, $driverOptions);
$this->_loadSubClasses();
protected function _loadSubClasses(): void $thisClass = \get_class($this); $nsArray = explode("\\", $thisClass); $driver = array_pop($nsArray); $sqlClass = __NAMESPACE__ . "\\{$driver}\\SQL"; $utilClass = __NAMESPACE__ . "\\{$driver}\\Util";
$this->driverSQL = new $sqlClass(); $this->util = new $utilClass($this);
public function __call(string $name, array $args = []) && is_object($this->$name) && method_exists($this->$name, '__invoke') return call_user_func_array([$this->$name, '__invoke'], $args);
public function getLastQuery(): string
public function setLastQuery(string $queryString): void $this->lastQuery = $queryString;
public function getSql(): SQLInterface
public function getUtil(): AbstractUtil
public function setTablePrefix(string $prefix): void $this->tablePrefix = $prefix;
public function prepareQuery(string $sql, array $data): PDOStatement $this->statement = $this->prepare($sql);
foreach($data as $k => $value) $this->statement->bindValue($k, $value);
public function prepareExecute(string $sql, array $params): PDOStatement $this->statement = $this->prepareQuery($sql, $params); $this->statement->execute();
public function affectedRows(): int return $this->statement->rowCount();
public function prefixTable(string $table): string if ( ! empty($this->tablePrefix)) $identifiers = explode('.', $table); $segments = count($identifiers);
$identifiers[$segments - 1] = $this->_prefix(end($identifiers));
$table = implode('.', $identifiers);
public function quoteTable(string $table): string $table = $this->prefixTable($table);
return $this->quoteIdent($table);
public function quoteIdent($identifier) if (is_array($identifier)) return array_map([$this, __METHOD__], $identifier);
$identifier = (string)$identifier;
if (strpos($identifier, ',') !== FALSE) $parts = array_map('mb_trim', explode(',', $identifier)); $parts = array_map([$this, __METHOD__], $parts); $identifier = implode(',', $parts);
$hiers = explode('.', $identifier); $hiers = array_map('mb_trim', $hiers);
$raw = implode('.', array_map([$this, '_quote'], $hiers));
preg_match_all("#{$this->escapeCharOpen}([a-zA-Z0-9_]+(\((.*?)\))){$this->escapeCharClose}#iu", $raw, $funcs, PREG_SET_ORDER); $raw = str_replace([$f[0], $f[3]], [$f[1], $this->quoteIdent($f[3])], $raw);
public function getSchemas(): ?array
public function getTables(): ?array $tables = $this->driverQuery('tableList');
public function getDbs(): ?array return $this->driverQuery('dbList');
public function getViews(): ?array $views = $this->driverQuery('viewList');
public function getSequences(): ?array return $this->driverQuery('sequenceList');
public function getFunctions(): ?array return $this->driverQuery('functionList', FALSE);
public function getProcedures(): ?array return $this->driverQuery('procedureList', FALSE);
public function getTriggers(): ?array return $this->driverQuery('triggerList', FALSE);
public function getSystemTables(): ?array return $this->driverQuery('systemTableList');
public function getColumns(string $table): ?array return $this->driverQuery($this->getSql()->columnList($this->prefixTable($table)), FALSE);
public function getFks(string $table): ?array return $this->driverQuery($this->getSql()->fkList($table), FALSE);
public function getIndexes(string $table): ?array return $this->driverQuery($this->getSql()->indexList($this->prefixTable($table)), FALSE);
public function getTypes(): ?array return $this->driverQuery('typeList', FALSE);
public function getVersion(): string return $this->getAttribute(PDO::ATTR_SERVER_VERSION);
public function driverQuery($query, $filteredIndex=TRUE): ?array if (is_string($query) && method_exists($this->driverSQL, $query)) $query = $this->getSql()->$query();
if ( ! is_string($query))
$res = $this->query($query);
$flag = $filteredIndex ? PDO::FETCH_NUM : PDO::FETCH_ASSOC; $all = $res->fetchAll($flag);
return $filteredIndex ? dbFilter($all, 0) : $all;
public function numRows(): ?int $regex = '/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/i';
if (preg_match($regex, $this->lastQuery, $output) > 0) $stmt = $this->query("SELECT COUNT(*) FROM {$output[1]}"); return (int) $stmt->fetchColumn();
public function insertBatch(string $table, array $data=[]): array $firstRow = (array) current($data);
$vals = array_merge($vals, array_values($group));
$table = $this->quoteTable($table); $fields = array_keys($firstRow);
$sql = "INSERT INTO {$table} (" . implode(',', $this->quoteIdent($fields))
$params = array_fill(0, count($fields), '?'); $paramString = '(' . implode(',', $params) . ')'; $paramList = array_fill(0, count($data), $paramString);
$sql .= implode(',', $paramList);
public function updateBatch(string $table, array $data, string $where): array
$sql = 'UPDATE ' . $this->quoteTable($table) . ' SET ';
array_reduce($data, static function ($previous, $current) use (&$affectedRows, $where) { $keys = array_diff(array_keys($current), [$where]);
return array_merge($previous, $keys);
foreach ($fields as $field) $line = $this->quoteIdent($field) . " = CASE\n";
if (array_key_exists($field, $case)) $insertData[] = $case[$where]; $insertData[] = $case[$field]; $cases[] = 'WHEN ' . $this->quoteIdent($where) . ' =? '
$line .= implode("\n", $cases) . "\n"; $line .= 'ELSE ' . $this->quoteIdent($field) . ' END';
$sql .= implode(",\n", $fieldLines) . "\n";
$whereValues = array_column($data, $where); foreach ($whereValues as $value)
$placeholders = array_fill(0, count($whereValues), '?');
$sql .= 'WHERE ' . $this->quoteIdent($where) . ' IN '; $sql .= '(' . implode(',', $placeholders) . ')';
return [$sql, $insertData, $affectedRows];
public function truncate(string $table): PDOStatement $sql = $this->hasTruncate
$sql .= $this->quoteTable($table);
$this->statement = $this->query($sql);
public function returning(string $query, string $select): string return "{$query} RETURNING {$select}";
public function _quote($str) && strpos($str, $this->escapeCharOpen) !== 0 && strrpos($str, $this->escapeCharClose) !== 0 ? "{$this->escapeCharOpen}{$str}{$this->escapeCharClose}"
protected function _prefix(string $str): string if (strpos($str, $this->tablePrefix) !== FALSE)
return $this->tablePrefix . $str;
|
Generated using phpDox 0.12.0-dev - Copyright (C) 2010 - 2020 by Arne Blankerts and Contributors