diff --git a/apiDocumentation/classes/Query_State/appendGroupArray.html b/apiDocumentation/classes/Query_State/appendGroupArray.html
index d2277d1..1c4ad44 100644
--- a/apiDocumentation/classes/Query_State/appendGroupArray.html
+++ b/apiDocumentation/classes/Query_State/appendGroupArray.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/appendHavingMap.html b/apiDocumentation/classes/Query_State/appendHavingMap.html
index 3e05e8a..678835c 100644
--- a/apiDocumentation/classes/Query_State/appendHavingMap.html
+++ b/apiDocumentation/classes/Query_State/appendHavingMap.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/appendMap.html b/apiDocumentation/classes/Query_State/appendMap.html
index daf1d9b..8855011 100644
--- a/apiDocumentation/classes/Query_State/appendMap.html
+++ b/apiDocumentation/classes/Query_State/appendMap.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/appendSelectString.html b/apiDocumentation/classes/Query_State/appendSelectString.html
index b43ade2..23531a3 100644
--- a/apiDocumentation/classes/Query_State/appendSelectString.html
+++ b/apiDocumentation/classes/Query_State/appendSelectString.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/appendSetArrayKeys.html b/apiDocumentation/classes/Query_State/appendSetArrayKeys.html
index 87047c5..0368ff3 100644
--- a/apiDocumentation/classes/Query_State/appendSetArrayKeys.html
+++ b/apiDocumentation/classes/Query_State/appendSetArrayKeys.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/appendValues.html b/apiDocumentation/classes/Query_State/appendValues.html
index f264207..f0be47b 100644
--- a/apiDocumentation/classes/Query_State/appendValues.html
+++ b/apiDocumentation/classes/Query_State/appendValues.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/appendWhereValues.html b/apiDocumentation/classes/Query_State/appendWhereValues.html
index 8a72434..27855d8 100644
--- a/apiDocumentation/classes/Query_State/appendWhereValues.html
+++ b/apiDocumentation/classes/Query_State/appendWhereValues.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/getFromString.html b/apiDocumentation/classes/Query_State/getFromString.html
index 3889c12..a916758 100644
--- a/apiDocumentation/classes/Query_State/getFromString.html
+++ b/apiDocumentation/classes/Query_State/getFromString.html
@@ -59,7 +59,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/getGroupArray.html b/apiDocumentation/classes/Query_State/getGroupArray.html
index c2da074..58baf63 100644
--- a/apiDocumentation/classes/Query_State/getGroupArray.html
+++ b/apiDocumentation/classes/Query_State/getGroupArray.html
@@ -59,7 +59,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/getGroupString.html b/apiDocumentation/classes/Query_State/getGroupString.html
index 50ef54d..a703ded 100644
--- a/apiDocumentation/classes/Query_State/getGroupString.html
+++ b/apiDocumentation/classes/Query_State/getGroupString.html
@@ -59,7 +59,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/getHavingMap.html b/apiDocumentation/classes/Query_State/getHavingMap.html
index 1225654..2e070a3 100644
--- a/apiDocumentation/classes/Query_State/getHavingMap.html
+++ b/apiDocumentation/classes/Query_State/getHavingMap.html
@@ -59,7 +59,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/getLimit.html b/apiDocumentation/classes/Query_State/getLimit.html
index 9890e48..83027a4 100644
--- a/apiDocumentation/classes/Query_State/getLimit.html
+++ b/apiDocumentation/classes/Query_State/getLimit.html
@@ -59,7 +59,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/getOffset.html b/apiDocumentation/classes/Query_State/getOffset.html
index 57bee3f..5c988a7 100644
--- a/apiDocumentation/classes/Query_State/getOffset.html
+++ b/apiDocumentation/classes/Query_State/getOffset.html
@@ -59,7 +59,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/getOrderArray.html b/apiDocumentation/classes/Query_State/getOrderArray.html
index a2f21f9..e6d5630 100644
--- a/apiDocumentation/classes/Query_State/getOrderArray.html
+++ b/apiDocumentation/classes/Query_State/getOrderArray.html
@@ -59,7 +59,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/getOrderString.html b/apiDocumentation/classes/Query_State/getOrderString.html
index ab1ab33..ccf44d7 100644
--- a/apiDocumentation/classes/Query_State/getOrderString.html
+++ b/apiDocumentation/classes/Query_State/getOrderString.html
@@ -59,7 +59,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/getQueryMap.html b/apiDocumentation/classes/Query_State/getQueryMap.html
index e7039ea..245bfa6 100644
--- a/apiDocumentation/classes/Query_State/getQueryMap.html
+++ b/apiDocumentation/classes/Query_State/getQueryMap.html
@@ -59,7 +59,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/getSelectString.html b/apiDocumentation/classes/Query_State/getSelectString.html
index df4ba3d..0e5cf7c 100644
--- a/apiDocumentation/classes/Query_State/getSelectString.html
+++ b/apiDocumentation/classes/Query_State/getSelectString.html
@@ -59,7 +59,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/getSetArrayKeys.html b/apiDocumentation/classes/Query_State/getSetArrayKeys.html
index d3e835a..d8d829a 100644
--- a/apiDocumentation/classes/Query_State/getSetArrayKeys.html
+++ b/apiDocumentation/classes/Query_State/getSetArrayKeys.html
@@ -59,7 +59,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/getSetString.html b/apiDocumentation/classes/Query_State/getSetString.html
index 106a1f6..6348cc4 100644
--- a/apiDocumentation/classes/Query_State/getSetString.html
+++ b/apiDocumentation/classes/Query_State/getSetString.html
@@ -59,7 +59,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/getValues.html b/apiDocumentation/classes/Query_State/getValues.html
index b8168b4..be236e4 100644
--- a/apiDocumentation/classes/Query_State/getValues.html
+++ b/apiDocumentation/classes/Query_State/getValues.html
@@ -59,7 +59,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/getWhereValues.html b/apiDocumentation/classes/Query_State/getWhereValues.html
index 4ad6cd0..d4befa9 100644
--- a/apiDocumentation/classes/Query_State/getWhereValues.html
+++ b/apiDocumentation/classes/Query_State/getWhereValues.html
@@ -59,7 +59,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/setFromString.html b/apiDocumentation/classes/Query_State/setFromString.html
index 818ddc8..189973d 100644
--- a/apiDocumentation/classes/Query_State/setFromString.html
+++ b/apiDocumentation/classes/Query_State/setFromString.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/setGroupArray.html b/apiDocumentation/classes/Query_State/setGroupArray.html
index be0a6ac..6fb0a84 100644
--- a/apiDocumentation/classes/Query_State/setGroupArray.html
+++ b/apiDocumentation/classes/Query_State/setGroupArray.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/setGroupString.html b/apiDocumentation/classes/Query_State/setGroupString.html
index bf2d216..3993a73 100644
--- a/apiDocumentation/classes/Query_State/setGroupString.html
+++ b/apiDocumentation/classes/Query_State/setGroupString.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/setLimit.html b/apiDocumentation/classes/Query_State/setLimit.html
index da244d2..bf8b3e8 100644
--- a/apiDocumentation/classes/Query_State/setLimit.html
+++ b/apiDocumentation/classes/Query_State/setLimit.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/setOffset.html b/apiDocumentation/classes/Query_State/setOffset.html
index 9949c6d..a378955 100644
--- a/apiDocumentation/classes/Query_State/setOffset.html
+++ b/apiDocumentation/classes/Query_State/setOffset.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/setOrderArray.html b/apiDocumentation/classes/Query_State/setOrderArray.html
index 87e1a2c..6bd2b94 100644
--- a/apiDocumentation/classes/Query_State/setOrderArray.html
+++ b/apiDocumentation/classes/Query_State/setOrderArray.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/setOrderString.html b/apiDocumentation/classes/Query_State/setOrderString.html
index 792cdb6..acd1dba 100644
--- a/apiDocumentation/classes/Query_State/setOrderString.html
+++ b/apiDocumentation/classes/Query_State/setOrderString.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/setSelectString.html b/apiDocumentation/classes/Query_State/setSelectString.html
index ad2e548..80eecc0 100644
--- a/apiDocumentation/classes/Query_State/setSelectString.html
+++ b/apiDocumentation/classes/Query_State/setSelectString.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/setSetArrayKeys.html b/apiDocumentation/classes/Query_State/setSetArrayKeys.html
index f82227d..e636344 100644
--- a/apiDocumentation/classes/Query_State/setSetArrayKeys.html
+++ b/apiDocumentation/classes/Query_State/setSetArrayKeys.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/classes/Query_State/setSetString.html b/apiDocumentation/classes/Query_State/setSetString.html
index a267d26..c1f2976 100644
--- a/apiDocumentation/classes/Query_State/setSetString.html
+++ b/apiDocumentation/classes/Query_State/setSetString.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/interfaces/Query_QueryBuilderInterface.html b/apiDocumentation/interfaces/Query_QueryBuilderInterface.html
index ac8232e..fee725b 100644
--- a/apiDocumentation/interfaces/Query_QueryBuilderInterface.html
+++ b/apiDocumentation/interfaces/Query_QueryBuilderInterface.html
@@ -106,7 +106,6 @@
public int countAllResults()
public PDOStatement insert()
public PDOStatement insertBatch()
- public PDOStatement replace()
public PDOStatement update()
public ?int updateBatch()
public PDOStatement delete()
@@ -186,8 +185,6 @@
— OR WHERE NOT IN (FOO) clause
orderBy()
— Order the results by the selected field(s)
-
replace()
- — Insertion with automatic overwrite, rather than attempted duplication
resetQuery()
— Clear out the class variables, so the next query can be run
select()
diff --git a/apiDocumentation/interfaces/Query_QueryBuilderInterface/delete.html b/apiDocumentation/interfaces/Query_QueryBuilderInterface/delete.html
index 126f0d3..ab62a55 100644
--- a/apiDocumentation/interfaces/Query_QueryBuilderInterface/delete.html
+++ b/apiDocumentation/interfaces/Query_QueryBuilderInterface/delete.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/interfaces/Query_QueryBuilderInterface/getCompiledDelete.html b/apiDocumentation/interfaces/Query_QueryBuilderInterface/getCompiledDelete.html
index 9f97328..c276037 100644
--- a/apiDocumentation/interfaces/Query_QueryBuilderInterface/getCompiledDelete.html
+++ b/apiDocumentation/interfaces/Query_QueryBuilderInterface/getCompiledDelete.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/interfaces/Query_QueryBuilderInterface/getCompiledInsert.html b/apiDocumentation/interfaces/Query_QueryBuilderInterface/getCompiledInsert.html
index 6ee9d3d..2054a95 100644
--- a/apiDocumentation/interfaces/Query_QueryBuilderInterface/getCompiledInsert.html
+++ b/apiDocumentation/interfaces/Query_QueryBuilderInterface/getCompiledInsert.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/interfaces/Query_QueryBuilderInterface/getCompiledSelect.html b/apiDocumentation/interfaces/Query_QueryBuilderInterface/getCompiledSelect.html
index 54665f9..7f3f135 100644
--- a/apiDocumentation/interfaces/Query_QueryBuilderInterface/getCompiledSelect.html
+++ b/apiDocumentation/interfaces/Query_QueryBuilderInterface/getCompiledSelect.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/interfaces/Query_QueryBuilderInterface/getCompiledUpdate.html b/apiDocumentation/interfaces/Query_QueryBuilderInterface/getCompiledUpdate.html
index 501f544..5140342 100644
--- a/apiDocumentation/interfaces/Query_QueryBuilderInterface/getCompiledUpdate.html
+++ b/apiDocumentation/interfaces/Query_QueryBuilderInterface/getCompiledUpdate.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/interfaces/Query_QueryBuilderInterface/replace.html b/apiDocumentation/interfaces/Query_QueryBuilderInterface/replace.html
deleted file mode 100644
index 40ce7d2..0000000
--- a/apiDocumentation/interfaces/Query_QueryBuilderInterface/replace.html
+++ /dev/null
@@ -1,105 +0,0 @@
-
-
-
-
-
phpDox - Query\QueryBuilderInterface::replace
-
-
-
-
-
-
-
-
-
- Query\QueryBuilderInterface::replace
- Insertion with automatic overwrite, rather than attempted duplication
-
-
- Signature
-
- public function replace(string
- $table,
- [array
- $data = ] )
-
-
- Parameters
-
- $table
- —
- string
-
- $data
- —
- array
-
-
- Returns
-
- - PDOStatement
-
-
-
-
-
-
-
-
diff --git a/apiDocumentation/interfaces/Query_QueryBuilderInterface/resetQuery.html b/apiDocumentation/interfaces/Query_QueryBuilderInterface/resetQuery.html
index 3405387..27d6d64 100644
--- a/apiDocumentation/interfaces/Query_QueryBuilderInterface/resetQuery.html
+++ b/apiDocumentation/interfaces/Query_QueryBuilderInterface/resetQuery.html
@@ -59,7 +59,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/interfaces/Query_QueryBuilderInterface/update.html b/apiDocumentation/interfaces/Query_QueryBuilderInterface/update.html
index d9bbfe3..45d3a96 100644
--- a/apiDocumentation/interfaces/Query_QueryBuilderInterface/update.html
+++ b/apiDocumentation/interfaces/Query_QueryBuilderInterface/update.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/interfaces/Query_QueryBuilderInterface/updateBatch.html b/apiDocumentation/interfaces/Query_QueryBuilderInterface/updateBatch.html
index 0fc7dd0..c30add8 100644
--- a/apiDocumentation/interfaces/Query_QueryBuilderInterface/updateBatch.html
+++ b/apiDocumentation/interfaces/Query_QueryBuilderInterface/updateBatch.html
@@ -62,7 +62,7 @@
Return
- Source
+ Source
diff --git a/apiDocumentation/source/Drivers/AbstractDriver.php.html b/apiDocumentation/source/Drivers/AbstractDriver.php.html
index 4efeb6d..713c28b 100644
--- a/apiDocumentation/source/Drivers/AbstractDriver.php.html
+++ b/apiDocumentation/source/Drivers/AbstractDriver.php.html
@@ -1,6 +1,6 @@
phpDox - Source of AbstractDriver.phpSource of file AbstractDriver.php
- Size: 15,022 Bytes - Last Modified: 2018-01-26T14:47:49+00:00
src/Drivers/AbstractDriver.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
+ Size: 14,938 Bytes - Last Modified: 2018-02-09T21:14:20+00:00src/Drivers/AbstractDriver.php1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
Covered by 7 test(s):
- Query\Tests\ConnectionManagerTest::testConnect
- Query\Tests\ConnectionManagerTest::testGetConnection
- Query\Tests\QueryParserTest::testGeneric
- Query\Tests\QueryParserTest::testGeneric2
- Query\Tests\QueryParserTest::testWUnderscore
- Query\Tests\QueryParserTest::testFunction
- Query\Tests\Drivers\SQLite\SQLiteDriverTest::testConnection
90
Covered by 7 test(s):
@@ -280,4 +280,4 @@
Covered by 5 test(s):
- Query\Tests\Drivers\PgSQL\PgSQLDriverTest::testCreateTable
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testQueryExplain
- Query\Tests\Drivers\SQLite\SQLiteDriverTest::testDeleteTable
- Query\Tests\Drivers\SQLite\SQLiteDriverTest::testTruncate
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testQueryExplain
684685686687688 | <?php declare(strict_types=1);
use InvalidArgumentException;
abstract class AbstractDriver implements DriverInterface {
protected $escapeCharOpen = '"';
protected $escapeCharClose = '"';
protected $lastQuery = '';
protected $tablePrefix = '';
protected $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->sql = 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($f[0], $f[1], $raw);
$raw = str_replace($f[3], $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($table): ?array return $this->driverQuery($this->getSql()->columnList($this->prefixTable($table)), FALSE);
public function getFks($table): ?array return $this->driverQuery($this->getSql()->fkList($table), FALSE);
public function getIndexes($table): ?array return $this->driverQuery($this->getSql()->indexList($this->prefixTable($table)), FALSE);
public function getTypes(): ?array return $this->driverQuery('typeList', FALSE);
public function driverQuery($query, $filteredIndex=TRUE): ?array if (\is_string($query) && method_exists($this->sql, $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, 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 _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; |
+ - Query\Tests\Drivers\MySQL\MySQLDriverTest::testCreateTable
- Query\Tests\Drivers\MySQL\MySQLDriverTest::testTruncate
- Query\Tests\Drivers\MySQL\MySQLDriverTest::testGetColumns
- Query\Tests\Drivers\MySQL\MySQLDriverTest::testGetIndexes
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testQueryExplain
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testFunctionGet
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testGet
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testPrefixGet
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testGetWNumRows
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testGetLimit
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testGetLimitSkip
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testGetWhere
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testHaving
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testOrHaving
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testSelectWhereGet
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testSelectAvg
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testSelectSum
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testSelectDistinct
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testSelectGet
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testSelectFromGet
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testSelectFromLimitGet
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testSelectWhereGet2
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testSelectMax
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testSelectMin
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testMultiOrderBy
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testGroup
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testOrGroup
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testOrNotGroup
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testAndNotGroupStart
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testNotGroupStart
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testGroupCamelCase
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testWhereIn
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testOrWhereIn
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testWhereNotIn
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testOrWhereNotIn
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testOrderBy
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testOrderByRandom
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testGroupBy
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testOrWhere
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testLike
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testOrLike
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testOrNotLike
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testNotLike
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testLikeBefore
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testLikeAfter
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testJoin
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testLeftJoin
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testInnerJoin
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testJoinWithMultipleWhereValues
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testInsert
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testInsertArray
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testInsertBatch
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testUpdate
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testDriverUpdateBatch
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testSetArrayUpdate
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testWhereSetUpdate
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testDelete
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testDeleteWithMultipleWhereValues
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testCountAll
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testCountAllResults
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testCountAllResults2
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testNumRows
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testGetCompiledSelect
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testGetCompiledUpdate
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testGetCompiledInsert
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testGetCompiledDelete
- Query\Tests\Drivers\MySQL\MySQLQueryBuilderTest::testBadNumRows
- Query\Tests\Drivers\PgSQL\PgSQLDriverTest::testTruncate
- Query\Tests\Drivers\PgSQL\PgSQLDriverTest::testGetColumns
- Query\Tests\Drivers\PgSQL\PgSQLDriverTest::testGetIndexes
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testFunctionGet
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testGet
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testPrefixGet
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testGetWNumRows
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testGetLimit
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testGetLimitSkip
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testGetWhere
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testHaving
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testOrHaving
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testSelectWhereGet
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testSelectAvg
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testSelectSum
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testSelectDistinct
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testSelectGet
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testSelectFromGet
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testSelectFromLimitGet
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testSelectWhereGet2
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testSelectMax
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testSelectMin
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testMultiOrderBy
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testGroup
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testOrGroup
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testOrNotGroup
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testAndNotGroupStart
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testNotGroupStart
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testGroupCamelCase
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testWhereIn
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testOrWhereIn
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testWhereNotIn
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testOrWhereNotIn
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testOrderBy
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testOrderByRandom
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testGroupBy
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testOrWhere
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testLike
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testOrLike
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testOrNotLike
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testNotLike
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testLikeBefore
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testLikeAfter
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testJoin
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testLeftJoin
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testInnerJoin
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testJoinWithMultipleWhereValues
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testInsert
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testInsertArray
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testInsertBatch
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testUpdate
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testDriverUpdateBatch
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testSetArrayUpdate
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testWhereSetUpdate
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testDelete
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testDeleteWithMultipleWhereValues
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testCountAll
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testCountAllResults
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testCountAllResults2
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testNumRows
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testGetCompiledSelect
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testGetCompiledUpdate
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testGetCompiledInsert
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testGetCompiledDelete
- Query\Tests\Drivers\PgSQL\PgSQLQueryBuilderTest::testBadNumRows
- Query\Tests\Drivers\SQLite\SQLiteDriverTest::testGetColumns
- Query\Tests\Drivers\SQLite\SQLiteDriverTest::testGetIndexes
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testFunctionGet
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testGet
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testPrefixGet
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testGetWNumRows
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testGetLimit
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testGetLimitSkip
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testGetWhere
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testHaving
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testOrHaving
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testSelectWhereGet
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testSelectAvg
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testSelectSum
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testSelectDistinct
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testSelectGet
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testSelectFromGet
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testSelectFromLimitGet
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testSelectWhereGet2
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testSelectMax
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testSelectMin
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testMultiOrderBy
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testGroup
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testOrGroup
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testOrNotGroup
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testAndNotGroupStart
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testNotGroupStart
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testGroupCamelCase
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testWhereIn
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testOrWhereIn
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testWhereNotIn
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testOrWhereNotIn
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testOrderBy
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testOrderByRandom
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testGroupBy
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testOrWhere
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testLike
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testOrLike
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testOrNotLike
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testNotLike
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testLikeBefore
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testLikeAfter
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testJoin
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testLeftJoin
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testInnerJoin
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testJoinWithMultipleWhereValues
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testInsert
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testInsertArray
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testInsertBatch
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testUpdate
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testDriverUpdateBatch
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testSetArrayUpdate
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testWhereSetUpdate
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testDelete
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testDeleteWithMultipleWhereValues
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testCountAll
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testCountAllResults
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testCountAllResults2
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testNumRows
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testGetCompiledSelect
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testGetCompiledUpdate
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testGetCompiledInsert
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testGetCompiledDelete
- Query\Tests\Drivers\SQLite\SQLiteQueryBuilderTest::testBadNumRows
687688 | <?php declare(strict_types=1);
use InvalidArgumentException;
abstract class AbstractDriver implements DriverInterface {
protected $escapeCharOpen = '"';
protected $escapeCharClose = '"';
protected $lastQuery = '';
protected $tablePrefix = '';
protected $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->sql = 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($f[0], $f[1], $raw);
$raw = str_replace($f[3], $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($table): ?array return $this->driverQuery($this->getSql()->columnList($this->prefixTable($table)), FALSE);
public function getFks($table): ?array return $this->driverQuery($this->getSql()->fkList($table), FALSE);
public function getIndexes($table): ?array return $this->driverQuery($this->getSql()->indexList($this->prefixTable($table)), FALSE);
public function getTypes(): ?array return $this->driverQuery('typeList', FALSE);
public function driverQuery($query, $filteredIndex=TRUE): ?array if (\is_string($query) && method_exists($this->sql, $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, 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 _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; |