From 74b0ec302614d0b2ccb36869ae63079bb78b5fb0 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Thu, 25 Jan 2018 10:58:41 -0500 Subject: [PATCH 01/47] Update build script to remove firebird --- build/docker_install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/docker_install.sh b/build/docker_install.sh index 63e1fe3..515b393 100644 --- a/build/docker_install.sh +++ b/build/docker_install.sh @@ -10,7 +10,7 @@ set -xe # Install git (the php image doesn't have it) which is required by composer apt-get update -yqq -apt-get install git libpq-dev libmysqlclient18 unzip firebird2.5-superclassic -yqq +apt-get install git libpq-dev libmysqlclient18 unzip -yqq # Install phpunit, the tool that we will use for testing curl -Lo /usr/local/bin/phpunit https://phar.phpunit.de/phpunit.phar @@ -25,5 +25,5 @@ mv "$DIR/../tests/settings-ci.json" "$DIR/../tests/settings.json" docker-php-ext-install pdo_mysql docker-php-ext-install pdo_pgsql #docker-php-ext-install pdo_oci -docker-php-ext-install interbase -docker-php-ext-install pdo_firebird +#docker-php-ext-install interbase +#docker-php-ext-install pdo_firebird -- 2.47.0 From 83b499e246024b160716fd20ce26bc1db312ab3e Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Thu, 25 Jan 2018 11:10:55 -0500 Subject: [PATCH 02/47] Explicitly add PHPUnit Testcase to bootstrap file --- tests/bootstrap.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 07f7b44..a85e52d 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -39,4 +39,6 @@ function get_json_config() $path = QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db'; @unlink($path); +require_once __DIR__ . 'TestCase.php'; + // End of bootstrap.php -- 2.47.0 From dca1e38f6035de640ae01918744d08849d4c8ddc Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Thu, 25 Jan 2018 11:13:54 -0500 Subject: [PATCH 03/47] Make sure the path of the require is correct --- tests/bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a85e52d..9de4588 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -39,6 +39,6 @@ function get_json_config() $path = QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db'; @unlink($path); -require_once __DIR__ . 'TestCase.php'; +require_once __DIR__ . '/TestCase.php'; // End of bootstrap.php -- 2.47.0 From 1bb1b5f7e420db53e99c28ebd1267a952efdd6de Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Thu, 25 Jan 2018 11:31:27 -0500 Subject: [PATCH 04/47] Make sure to actually set up autoloading --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index eecc367..65b11c8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,8 @@ before_script: # Install dependencies - bash build/docker_install.sh > /dev/null - + - curl -sS https://getcomposer.org/installer | php + - php composer.phar install --ignore-platform-reqs services: - mysql:latest - postgres:latest -- 2.47.0 From f5aaa59f8d802ae362bed70e34bc44edc45ff0ab Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Thu, 25 Jan 2018 11:40:39 -0500 Subject: [PATCH 05/47] Use composer-installed phpunit --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 65b11c8..05311f3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,9 +19,9 @@ variables: test:7.1: image: php:7.1 script: - - phpunit -c build --no-coverage + - vendor/bin/phpunit -c build --no-coverage test:7.2: image: php:7.2 script: - - phpunit -c build --no-coverage + - vendor/bin/phpunit -c build --no-coverage -- 2.47.0 From 56c929088afd4d692d58c5b9e70aceef289d3624 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Thu, 25 Jan 2018 15:12:46 -0500 Subject: [PATCH 06/47] Minor tweaks --- src/Drivers/DriverInterface.php | 2 +- tests/Drivers/MySQL/MySQLDriverTest.php | 6 ++++++ tests/Drivers/PgSQL/PgSQLDriverTest.php | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Drivers/DriverInterface.php b/src/Drivers/DriverInterface.php index aad7d0a..5f109f3 100644 --- a/src/Drivers/DriverInterface.php +++ b/src/Drivers/DriverInterface.php @@ -204,7 +204,7 @@ interface DriverInterface { * @param string $where * @return int|null */ - public function updateBatch(string $table, $data, $where); + public function updateBatch(string $table, $data, $where): ?int; /** * Get the SQL class for the current driver diff --git a/tests/Drivers/MySQL/MySQLDriverTest.php b/tests/Drivers/MySQL/MySQLDriverTest.php index 81ed6b3..00fae53 100644 --- a/tests/Drivers/MySQL/MySQLDriverTest.php +++ b/tests/Drivers/MySQL/MySQLDriverTest.php @@ -119,6 +119,12 @@ SQL; public function testBadPreparedStatement() { + if (is_a($this, \UnitTestCase::class)) + { + $this->markTestSkipped(); + return; + } + $this->expectException(TypeError::class); $sql = <<markTestSkipped(); + return; + } + $this->expectException(TypeError::class); $sql = << Date: Fri, 26 Jan 2018 08:39:30 -0500 Subject: [PATCH 07/47] Add updateBatch method --- src/ConnectionManager.php | 16 +-- src/Drivers/AbstractDriver.php | 74 ++++++++++-- src/Drivers/AbstractUtil.php | 4 +- src/Drivers/DriverInterface.php | 16 ++- src/QueryBuilder.php | 26 +++-- src/QueryBuilderInterface.php | 10 +- src/State.php | 4 +- tests/BaseDriverTest.php | 32 +++--- tests/BaseQueryBuilderTest.php | 106 +++++++++++------- tests/ConnectionManagerTest.php | 45 ++++---- tests/CoreTest.php | 15 ++- tests/Drivers/MySQL/MySQLDriverTest.php | 29 ++--- tests/Drivers/MySQL/MySQLQueryBuilderTest.php | 12 +- tests/Drivers/PgSQL/PgSQLDriverTest.php | 26 ++--- tests/Drivers/PgSQL/PgSQLQueryBuilderTest.php | 6 +- tests/Drivers/SQLite/SQLiteDriverTest.php | 16 +-- .../Drivers/SQLite/SQLiteQueryBuilderTest.php | 38 +++---- tests/QueryParserTest.php | 16 +-- tests/bootstrap.php | 4 +- tests/index.php | 9 +- 20 files changed, 310 insertions(+), 194 deletions(-) diff --git a/src/ConnectionManager.php b/src/ConnectionManager.php index e191952..b4daae3 100644 --- a/src/ConnectionManager.php +++ b/src/ConnectionManager.php @@ -118,12 +118,13 @@ final class ConnectionManager { /** * Parse the passed parameters and return a connection * - * @param \stdClass $params + * @param object|array $params + * @throws BadDBDriverException * @return QueryBuilderInterface */ - public function connect(\stdClass $params): QueryBuilderInterface + public function connect($params): QueryBuilderInterface { - list($dsn, $dbtype, $params, $options) = $this->parseParams($params); + [$dsn, $dbtype, $params, $options] = $this->parseParams($params); $dbtype = ucfirst($dbtype); $driver = "\\Query\\Drivers\\{$dbtype}\\Driver"; @@ -160,11 +161,12 @@ final class ConnectionManager { * Parses params into a dsn and option array * * @param \stdClass $params - * @return array + * @return object|array * @throws BadDBDriverException */ - public function parseParams(\stdClass $params): array + public function parseParams($params): array { + $params = (object) $params; $params->type = strtolower($params->type); $dbtype = ($params->type !== 'postgresql') ? $params->type : 'pgsql'; $dbtype = ucfirst($dbtype); @@ -202,10 +204,10 @@ final class ConnectionManager { * * @codeCoverageIgnore * @param string $dbtype - * @param \stdClass $params + * @param array|object $params * @return string */ - private function createDsn(string $dbtype, \stdClass $params): string + private function createDsn(string $dbtype, $params): string { $pairs = []; diff --git a/src/Drivers/AbstractDriver.php b/src/Drivers/AbstractDriver.php index 3cff181..49d7195 100644 --- a/src/Drivers/AbstractDriver.php +++ b/src/Drivers/AbstractDriver.php @@ -561,15 +561,73 @@ abstract class AbstractDriver * Creates a batch update, and executes it. * Returns the number of affected rows * - * @param string $table - * @param array|object $data - * @param string $where - * @return int|null + * @param string $table The table to update + * @param array $data an array of update values + * @param string $where The where key + * @return array */ - public function updateBatch(string $table, $data, $where) + public function updateBatch(string $table, array $data, string $where): array { - // @TODO implement - return NULL; + $affectedRows = 0; + $insertData = []; + $fieldLines = []; + + $sql = 'UPDATE ' . $this->quoteTable($table) . ' SET '; + + // Get the keys of the current set of data, except the one used to + // set the update condition + $fields = array_unique( + array_reduce($data, function ($previous, $current) use (&$affectedRows, $where) { + $affectedRows++; + $keys = array_diff(array_keys($current), [$where]); + + if ($previous === NULL) + { + return $keys; + } + + return array_merge($previous, $keys); + }) + ); + + // Create the CASE blocks for each data set + foreach ($fields as $field) + { + $line = $this->quoteIdent($field) . " = CASE\n"; + + $cases = []; + foreach ($data as $case) + { + if (array_key_exists($field, $case)) + { + $insertData[] = $case[$where]; + $insertData[] = $case[$field]; + $cases[] = 'WHEN ' . $this->quoteIdent($where) . ' =? ' + . 'THEN ? '; + } + } + + $line .= implode("\n", $cases) . "\n"; + $line .= 'ELSE ' . $this->quoteIdent($field) . ' END'; + + $fieldLines[] = $line; + } + + $sql .= implode(",\n", $fieldLines) . "\n"; + + $whereValues = array_column($data, $where); + foreach ($whereValues as $value) + { + $insertData[] = $value; + } + + // Create the placeholders for the WHERE IN clause + $placeholders = array_fill(0, count($whereValues), '?'); + + $sql .= 'WHERE ' . $this->quoteIdent($where) . ' IN '; + $sql .= '(' . implode(',', $placeholders) . ')'; + + return [$sql, $insertData, $affectedRows]; } /** @@ -578,7 +636,7 @@ abstract class AbstractDriver * @param string $table * @return PDOStatement */ - public function truncate(string $table): PDOStatement + public function truncate(string $table): ?PDOStatement { $sql = $this->hasTruncate ? 'TRUNCATE TABLE ' diff --git a/src/Drivers/AbstractUtil.php b/src/Drivers/AbstractUtil.php index d9e676d..61d605e 100644 --- a/src/Drivers/AbstractUtil.php +++ b/src/Drivers/AbstractUtil.php @@ -62,11 +62,11 @@ abstract class AbstractUtil { $existsStr = $ifNotExists ? ' IF NOT EXISTS ' : ' '; // Reorganize into an array indexed with column information - // Eg $columnArray[$colname] = array( + // Eg $columnArray[$colname] = [ // 'type' => ..., // 'constraint' => ..., // 'index' => ..., - // ) + // ] $columnArray = \arrayZipper([ 'type' => $fields, 'constraint' => $constraints diff --git a/src/Drivers/DriverInterface.php b/src/Drivers/DriverInterface.php index 5f109f3..836b7a3 100644 --- a/src/Drivers/DriverInterface.php +++ b/src/Drivers/DriverInterface.php @@ -14,6 +14,7 @@ */ namespace Query\Drivers; +use PDO; use PDOStatement; /** @@ -129,6 +130,15 @@ interface DriverInterface { */ public function getTriggers(): ?array; + /** + * Quotes a string for use in a query (from native PDO) + * + * @param string $string + * @param int $parameter_type + * @return string + */ + public function quote($string, $parameter_type = NULL); + /** * Surrounds the string with the databases identifier escape characters * @@ -200,11 +210,11 @@ interface DriverInterface { * Returns the number of affected rows * * @param string $table - * @param array|object $data + * @param array $data * @param string $where - * @return int|null + * @return array */ - public function updateBatch(string $table, $data, $where): ?int; + public function updateBatch(string $table, array $data, string $where): array; /** * Get the SQL class for the current driver diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index bda49ae..744352b 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -774,18 +774,22 @@ class QueryBuilder implements QueryBuilderInterface { * Returns the number of affected rows * * @param string $table - * @param array|object $data + * @param array $data * @param string $where - * @return PDOStatement|null + * @return int|null */ - public function updateBatch(string $table, $data, $where): ?PDOStatement + public function updateBatch(string $table, array $data, string $where): ?int { - // Get the generated values and sql string - list($sql, $data) = $this->driver->updateBatch($table, $data, $where); + if (empty($table) || empty($data) || empty($where)) + { + return NULL; + } - return $sql !== NULL - ? $this->_run('', $table, $sql, $data) - : NULL; + // Get the generated values and sql string + [$sql, $data, $affectedRows] = $this->driver->updateBatch($table, $data, $where); + + $this->_run('', $table, $sql, $data); + return $affectedRows; } /** @@ -1158,14 +1162,14 @@ class QueryBuilder implements QueryBuilderInterface { /** * Convert the prepared statement into readable sql * - * @param array $vals + * @param array $values * @param string $sql * @param int $totalTime * @return void */ - protected function _appendQuery(array $vals = NULL, string $sql, int $totalTime) + protected function _appendQuery(array $values = NULL, string $sql, int $totalTime) { - $evals = \is_array($vals) ? $vals : []; + $evals = \is_array($values) ? $values : []; $esql = str_replace('?', "%s", $sql); // Quote string values diff --git a/src/QueryBuilderInterface.php b/src/QueryBuilderInterface.php index 4e0544a..35e898e 100644 --- a/src/QueryBuilderInterface.php +++ b/src/QueryBuilderInterface.php @@ -393,12 +393,12 @@ interface QueryBuilderInterface { * Creates a batch update, and executes it. * Returns the number of affected rows * - * @param string $table - * @param array|object $data - * @param string $where - * @return PDOStatement + * @param string $table The table to update + * @param array $data an array of update values + * @param string $where The where key + * @return int|null */ - public function updateBatch(string $table, $data, $where): ?PDOStatement; + public function updateBatch(string $table, array $data, string $where): ?int; /** * Deletes data from a table diff --git a/src/State.php b/src/State.php index efab148..c9e4565 100644 --- a/src/State.php +++ b/src/State.php @@ -108,11 +108,11 @@ class State { * for complex select queries * * Format: - * array( + * [ * 'type' => 'where', * 'conjunction' => ' AND ', * 'string' => 'k=?' - * ) + * ] * * @var array */ diff --git a/tests/BaseDriverTest.php b/tests/BaseDriverTest.php index 3c5d95a..6748e14 100644 --- a/tests/BaseDriverTest.php +++ b/tests/BaseDriverTest.php @@ -35,46 +35,46 @@ abstract class BaseDriverTest extends TestCase { public function testGetTables() { $tables = self::$db->getTables(); - $this->assertTrue(is_array($tables)); + $this->assertTrue(\is_array($tables)); $this->assertTrue( ! empty($tables)); } public function testGetSystemTables() { $tables = self::$db->getSystemTables(); - $this->assertTrue(is_array($tables)); + $this->assertTrue(\is_array($tables)); $this->assertTrue( ! empty($tables)); } public function testBackupData() { - $this->assertTrue(is_string(self::$db->getUtil()->backupData(array('create_delete', FALSE)))); - $this->assertTrue(is_string(self::$db->getUtil()->backupData(array('create_delete', TRUE)))); + $this->assertTrue(\is_string(self::$db->getUtil()->backupData(['create_delete', FALSE]))); + $this->assertTrue(\is_string(self::$db->getUtil()->backupData(['create_delete', TRUE]))); } public function testGetColumns() { $cols = self::$db->getColumns('test'); - $this->assertTrue(is_array($cols)); + $this->assertTrue(\is_array($cols)); $this->assertTrue( ! empty($cols)); } public function testGetTypes() { $types = self::$db->getTypes(); - $this->assertTrue(is_array($types)); + $this->assertTrue(\is_array($types)); $this->assertTrue( ! empty($types)); } public function testGetFKs() { - $expected = array(array( + $expected = [[ 'child_column' => 'ext_id', 'parent_table' => 'testconstraints', 'parent_column' => 'someid', 'update' => 'CASCADE', 'delete' => 'CASCADE' - )); + ]]; $keys = self::$db->getFks('testconstraints2'); $this->assertEqual($expected, $keys); @@ -83,15 +83,15 @@ abstract class BaseDriverTest extends TestCase { public function testGetIndexes() { $keys = self::$db->getIndexes('test'); - $this->assertTrue(is_array($keys)); + $this->assertTrue(\is_array($keys)); } public function testGetViews() { $views = self::$db->getViews(); - $expected = array('numbersview', 'testview'); + $expected = ['numbersview', 'testview']; $this->assertEqual($expected, array_values($views)); - $this->assertTrue(is_array($views)); + $this->assertTrue(\is_array($views)); } public function testGetTriggers() @@ -99,7 +99,7 @@ abstract class BaseDriverTest extends TestCase { // @TODO standardize trigger output for different databases $triggers = self::$db->getTriggers(); - $this->assertTrue(is_array($triggers)); + $this->assertTrue(\is_array($triggers)); } public function testGetSequences() @@ -109,22 +109,22 @@ abstract class BaseDriverTest extends TestCase { // Normalize sequence names $seqs = array_map('strtolower', $seqs); - $expected = array('newtable_seq'); + $expected = ['newtable_seq']; - $this->assertTrue(is_array($seqs)); + $this->assertTrue(\is_array($seqs)); $this->assertEqual($expected, $seqs); } public function testGetProcedures() { $procedures = self::$db->getProcedures(); - $this->assertTrue(is_array($procedures)); + $this->assertTrue(\is_array($procedures)); } public function testGetFunctions() { $funcs = self::$db->getFunctions(); - $this->assertTrue(is_array($funcs)); + $this->assertTrue(\is_array($funcs)); } } // End of db_test.php \ No newline at end of file diff --git a/tests/BaseQueryBuilderTest.php b/tests/BaseQueryBuilderTest.php index e682c45..b935d24 100644 --- a/tests/BaseQueryBuilderTest.php +++ b/tests/BaseQueryBuilderTest.php @@ -14,7 +14,9 @@ */ namespace Query\Tests; +use BadMethodCallException; use PDO; +use Query\BadDBDriverException; /** * Query builder parent test class @@ -36,6 +38,11 @@ abstract class BaseQueryBuilderTest extends TestCase { public static function tearDownAfterClass() { + if (PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg') + { + echo '
' . print_r(self::$db->queries, TRUE) . '
'; + } + self::$db = NULL; } @@ -100,7 +107,7 @@ abstract class BaseQueryBuilderTest extends TestCase { public function testGetWhere() { - $query = self::$db->getWhere('test', array('id !=' => 1), 2, 1); + $query = self::$db->getWhere('test', ['id !=' => 1], 2, 1); $this->assertIsA($query, 'PDOStatement'); } @@ -110,7 +117,7 @@ abstract class BaseQueryBuilderTest extends TestCase { $query = self::$db->select('id') ->from('test') ->groupBy('id') - ->having(array('id >' => 1)) + ->having(['id >' => 1]) ->having('id !=', 3) ->get(); @@ -122,7 +129,7 @@ abstract class BaseQueryBuilderTest extends TestCase { $query = self::$db->select('id') ->from('test') ->groupBy('id') - ->having(array('id >' => 1)) + ->having(['id >' => 1]) ->orHaving('id !=', 3) ->get(); @@ -325,7 +332,7 @@ abstract class BaseQueryBuilderTest extends TestCase { public function testWhereIn() { $query = self::$db->from('test') - ->whereIn('id', array(0, 6, 56, 563, 341)) + ->whereIn('id', [0, 6, 56, 563, 341]) ->get(); $this->assertIsA($query, 'PDOStatement'); @@ -335,7 +342,7 @@ abstract class BaseQueryBuilderTest extends TestCase { { $query = self::$db->from('test') ->where('key', 'false') - ->orWhereIn('id', array(0, 6, 56, 563, 341)) + ->orWhereIn('id', [0, 6, 56, 563, 341]) ->get(); $this->assertIsA($query, 'PDOStatement'); @@ -345,7 +352,7 @@ abstract class BaseQueryBuilderTest extends TestCase { { $query = self::$db->from('test') ->where('key', 'false') - ->whereNotIn('id', array(0, 6, 56, 563, 341)) + ->whereNotIn('id', [0, 6, 56, 563, 341]) ->get(); $this->assertIsA($query, 'PDOStatement'); @@ -355,7 +362,7 @@ abstract class BaseQueryBuilderTest extends TestCase { { $query = self::$db->from('test') ->where('key', 'false') - ->orWhereNotIn('id', array(0, 6, 56, 563, 341)) + ->orWhereNotIn('id', [0, 6, 56, 563, 341]) ->get(); $this->assertIsA($query, 'PDOStatement'); @@ -395,7 +402,7 @@ abstract class BaseQueryBuilderTest extends TestCase { ->where('id >', 0) ->where('id <', 9000) ->groupBy('k') - ->groupBy(array('id','val')) + ->groupBy(['id','val']) ->orderBy('id', 'DESC') ->orderBy('k', 'ASC') ->limit(5,2) @@ -506,10 +513,10 @@ abstract class BaseQueryBuilderTest extends TestCase { { $query = self::$db->from('test ct') ->join('join cj', 'cj.id=ct.id', 'inner') - ->where(array( + ->where([ 'ct.id < ' => 3, 'ct.key' => 'foo' - )) + ]) ->get(); $this->assertIsA($query, 'PDOStatement'); @@ -529,34 +536,34 @@ abstract class BaseQueryBuilderTest extends TestCase { public function testInsertArray() { - $query = self::$db->insert('test', array( + $query = self::$db->insert('test', [ 'id' => 587, 'key' => 1, 'val' => 2, - )); + ]); $this->assertIsA($query, 'PDOStatement'); } public function testInsertBatch() { - $data = array( - array( + $data = [ + [ 'id' => 544, 'key' => 3, 'val' => 7, - ), - array( - 'id' => 89, + ], + [ + 'id' => 890, 'key' => 34, 'val' => "10 o'clock", - ), - array( - 'id' => 48, + ], + [ + 'id' => 480, 'key' => 403, 'val' => 97, - ), - ); + ], + ]; $query = self::$db->insertBatch('test', $data); @@ -566,28 +573,47 @@ abstract class BaseQueryBuilderTest extends TestCase { public function testUpdate() { $query = self::$db->where('id', 7) - ->update('test', array( + ->update('test', [ 'id' => 7, 'key' => 'gogle', 'val' => 'non-word' - )); + ]); $this->assertIsA($query, 'PDOStatement'); } - public function testUpdateBatch() + public function testUpdateBatchNull() { $query = self::$db->updateBatch('test', [], ''); $this->assertNull($query); } + public function testDriverUpdateBatch() + { + $data = [ + [ + 'id' => 480, + 'key' => 49, + 'val' => '7x7' + ], + [ + 'id' => 890, + 'key' => 100, + 'val' => '10x10' + ] + ]; + + $affectedRows = self::$db->updateBatch('test', $data, 'id'); + $this->assertEquals(2, $affectedRows); + } + public function testSetArrayUpdate() { - $array = array( + $array = [ 'id' => 22, 'key' => 'gogle', 'val' => 'non-word' - ); + ]; $query = self::$db->set($array) ->where('id', 22) @@ -609,17 +635,17 @@ abstract class BaseQueryBuilderTest extends TestCase { public function testDelete() { - $query = self::$db->delete('test', array('id' => 5)); + $query = self::$db->delete('test', ['id' => 5]); $this->assertIsA($query, 'PDOStatement'); } public function testDeleteWithMultipleWhereValues() { - $query = self::$db->delete('test', array( + $query = self::$db->delete('test', [ 'id' => 5, 'key' => 'gogle' - )); + ]); $this->assertIsA($query, 'PDOStatement'); } @@ -671,22 +697,22 @@ abstract class BaseQueryBuilderTest extends TestCase { public function testGetCompiledUpdate() { - $sql = self::$db->set(array( + $sql = self::$db->set([ 'id' => 4, 'key' => 'foo', 'val' => 'baz' - ))->getCompiledUpdate('test'); + ])->getCompiledUpdate('test'); $this->assertTrue(\is_string($sql)); } public function testGetCompiledInsert() { - $sql = self::$db->set(array( + $sql = self::$db->set([ 'id' => 4, 'key' => 'foo', 'val' => 'baz' - ))->getCompiledInsert('test'); + ])->getCompiledInsert('test'); $this->assertTrue(\is_string($sql)); } @@ -704,34 +730,34 @@ abstract class BaseQueryBuilderTest extends TestCase { */ public function testBadDriver() { - $params = array( + $params = [ 'host' => '127.0.0.1', 'port' => '3306', 'database' => 'test', 'user' => 'root', 'pass' => NULL, 'type' => 'QGYFHGEG' - ); + ]; - $this->expectException('Query\BadDBDriverException'); + $this->expectException(BadDBDriverException::class); self::$db = Query($params); } public function testBadMethod() { - $this->expectException('BadMethodCallException'); + $this->expectException(BadMethodCallException::class); self::$db->foo(); } public function testBadNumRows() { - self::$db->set(array( + self::$db->set([ 'id' => 999, 'key' => 'ring', 'val' => 'sale' - ))->insert('test'); + ])->insert('test'); $res = self::$db->numRows(); $this->assertEqual(NULL, $res); diff --git a/tests/ConnectionManagerTest.php b/tests/ConnectionManagerTest.php index e99e2b6..3019d0c 100644 --- a/tests/ConnectionManagerTest.php +++ b/tests/ConnectionManagerTest.php @@ -26,6 +26,11 @@ class ConnectionManagerTest extends TestCase { self::$instance = ConnectionManager::getInstance(); } + public static function tearDownAfterClass() + { + self::$instance = NULL; + } + public function testNoClone() { $this->expectException('DomainException'); @@ -54,34 +59,34 @@ class ConnectionManagerTest extends TestCase { public function testParseParams() { - $params = (object) array( - 'type' => 'sqlite', - 'file' => ':memory:', - 'options' => array( + $params = new class { + public $type = 'sqlite'; + public $file = ':memory:'; + public $options = [ 'foo' => 'bar' - ) - ); + ]; + }; - $expected = array( + $expected = [ ':memory:', 'Sqlite', $params, - array('foo' => 'bar') - ); + ['foo' => 'bar'] + ]; $this->assertEqual($expected, self::$instance->parseParams($params)); } public function testConnect() { - $params = (object) array( - 'type' => 'sqlite', - 'file' => ':memory:', - 'prefix' => 'create_', - 'options' => array( + $params = new class { + public $type = 'sqlite'; + public $file = ':memory:'; + public $prefix = 'create_'; + public $options = [ 'foo' => 'bar' - ) - ); + ]; + }; $conn = self::$instance->connect($params); $this->assertInstanceOf(QueryBuilderInterface::class, $conn); @@ -93,15 +98,15 @@ class ConnectionManagerTest extends TestCase { public function testGetConnection() { - $params = (object) array( + $params = (object) [ 'type' => 'sqlite', 'file' => ':memory:', 'prefix' => 'create_', 'alias' => 'conn_manager', - 'options' => array( + 'options' => [ 'foo' => 'bar' - ) - ); + ] + ]; $conn = self::$instance->connect($params); $this->assertInstanceOf(QueryBuilderInterface::class, $conn); diff --git a/tests/CoreTest.php b/tests/CoreTest.php index cf22ca2..d4b85bf 100644 --- a/tests/CoreTest.php +++ b/tests/CoreTest.php @@ -14,6 +14,10 @@ */ namespace Query\Tests; +use function Query; +use function regexInArray; +use PDO; + /** * CoreTest class - Compatibility and core functionality tests * @@ -29,8 +33,9 @@ class CoreTest extends TestCase { */ public function testPHPVersion(): void { - //$this->assertTrue(version_compare(PHP_VERSION, '7.1', 'ge')); - $this->assertTrue(PHP_VERSION_ID >= 70000); + $this->assertTrue(PHP_VERSION_ID >= 70100); + $this->assertTrue(PHP_MAJOR_VERSION >= 7); + $this->assertTrue(PHP_MINOR_VERSION >= 1); } /** @@ -52,7 +57,7 @@ class CoreTest extends TestCase { 'sqlite', ]; - $drivers = \PDO::getAvailableDrivers(); + $drivers = PDO::getAvailableDrivers(); $numSupported = count(array_intersect($drivers, $supported)); @@ -61,11 +66,11 @@ class CoreTest extends TestCase { public function testNullQuery(): void { - $this->assertNull(\Query(NULL)); + $this->assertNull(Query(NULL)); } public function testEmptyRegexInArray(): void { - $this->assertFalse(\regexInArray([], 'foo')); + $this->assertFalse(regexInArray([], 'foo')); } } \ No newline at end of file diff --git a/tests/Drivers/MySQL/MySQLDriverTest.php b/tests/Drivers/MySQL/MySQLDriverTest.php index 00fae53..66002bc 100644 --- a/tests/Drivers/MySQL/MySQLDriverTest.php +++ b/tests/Drivers/MySQL/MySQLDriverTest.php @@ -38,9 +38,9 @@ class MySQLDriverTest extends BaseDriverTest { { $params = $params->mysql; - self::$db = new Driver("mysql:host={$params->host};dbname={$params->database}", $params->user, $params->pass, array( + self::$db = new Driver("mysql:host={$params->host};dbname={$params->database}", $params->user, $params->pass, [ PDO::ATTR_PERSISTENT => TRUE - )); + ]); } self::$db->setTablePrefix('create_'); @@ -62,28 +62,28 @@ class MySQLDriverTest extends BaseDriverTest { //Attempt to create the table $sql = self::$db->getUtil()->createTable('test', - array( + [ 'id' => 'int(10)', 'key' => 'TEXT', 'val' => 'TEXT', - ), - array( + ], + [ 'id' => 'PRIMARY KEY' - ) + ] ); self::$db->query($sql); //Attempt to create the table $sql = self::$db->getUtil()->createTable('join', - array( + [ 'id' => 'int(10)', 'key' => 'TEXT', 'val' => 'TEXT', - ), - array( + ], + [ 'id' => 'PRIMARY KEY' - ) + ] ); self::$db->query($sql); @@ -94,6 +94,7 @@ class MySQLDriverTest extends BaseDriverTest { } + public function testTruncate() { self::$db->truncate('test'); @@ -109,7 +110,7 @@ class MySQLDriverTest extends BaseDriverTest { INSERT INTO `create_test` (`id`, `key`, `val`) VALUES (?,?,?) SQL; - $statement = self::$db->prepareQuery($sql, array(1,"boogers", "Gross")); + $statement = self::$db->prepareQuery($sql, [1,"boogers", "Gross"]); $res = $statement->execute(); @@ -142,9 +143,9 @@ SQL; INSERT INTO `create_test` (`id`, `key`, `val`) VALUES (?,?,?) SQL; - $res = self::$db->prepareExecute($sql, array( + $res = self::$db->prepareExecute($sql, [ 2, "works", 'also?' - )); + ]); $this->assertInstanceOf('PDOStatement', $res); @@ -184,6 +185,6 @@ SQL; public function testBackup() { - $this->assertTrue(is_string(self::$db->getUtil()->backupStructure())); + $this->assertTrue(\is_string(self::$db->getUtil()->backupStructure())); } } \ No newline at end of file diff --git a/tests/Drivers/MySQL/MySQLQueryBuilderTest.php b/tests/Drivers/MySQL/MySQLQueryBuilderTest.php index 5ea40bc..0cc74df 100644 --- a/tests/Drivers/MySQL/MySQLQueryBuilderTest.php +++ b/tests/Drivers/MySQL/MySQLQueryBuilderTest.php @@ -25,9 +25,9 @@ class MySQLQueryBuilderTest extends BaseQueryBuilderTest { public static function setUpBeforeClass() { $params = get_json_config(); - if (($var = getenv('TRAVIS'))) // Travis CI Connection Info + if ($var = getenv('TRAVIS')) // Travis CI Connection Info { - $params = array( + $params = [ 'host' => '127.0.0.1', 'port' => '3306', 'database' => 'test', @@ -35,14 +35,14 @@ class MySQLQueryBuilderTest extends BaseQueryBuilderTest { 'user' => 'root', 'pass' => NULL, 'type' => 'mysql' - ); + ]; } // Attempt to connect, if there is a test config file else if ($params !== FALSE) { $params = $params->mysql; - $params->type = "MySQL"; - $params->options = array(); + $params->type = 'MySQL'; + $params->options = []; $params->options[PDO::ATTR_PERSISTENT] = TRUE; } @@ -67,7 +67,7 @@ class MySQLQueryBuilderTest extends BaseQueryBuilderTest { // The exact results are version dependent // The important thing is that there is an array // of results returned - $this->assertTrue(is_array($res)); + $this->assertTrue(\is_array($res)); $this->assertTrue(count(array_keys($res[0])) > 1); $this->assertTrue(array_key_exists('table', $res[0])); } diff --git a/tests/Drivers/PgSQL/PgSQLDriverTest.php b/tests/Drivers/PgSQL/PgSQLDriverTest.php index dde5b20..4eb7e38 100644 --- a/tests/Drivers/PgSQL/PgSQLDriverTest.php +++ b/tests/Drivers/PgSQL/PgSQLDriverTest.php @@ -81,28 +81,28 @@ class PgSQLDriverTest extends BaseDriverTest { //Attempt to create the table $sql = self::$db->getUtil()->createTable('create_test', - array( + [ 'id' => 'integer', 'key' => 'TEXT', 'val' => 'TEXT', - ), - array( + ], + [ 'id' => 'PRIMARY KEY' - ) + ] ); self::$db->query($sql); //Attempt to create the table $sql = self::$db->getUtil()->createTable('create_join', - array( + [ 'id' => 'integer', 'key' => 'TEXT', 'val' => 'TEXT', - ), - array( + ], + [ 'id' => 'PRIMARY KEY' - ) + ] ); self::$db->query($sql); @@ -133,7 +133,7 @@ class PgSQLDriverTest extends BaseDriverTest { INSERT INTO "create_test" ("id", "key", "val") VALUES (?,?,?) SQL; - $statement = self::$db->prepareQuery($sql, array(1,'boogers', 'Gross')); + $statement = self::$db->prepareQuery($sql, [1,'boogers', 'Gross']); $statement->execute(); @@ -173,9 +173,9 @@ SQL; INSERT INTO "create_test" ("id", "key", "val") VALUES (?,?,?) SQL; - self::$db->prepareExecute($sql, array( + self::$db->prepareExecute($sql, [ 2, 'works', 'also?' - )); + ]); $res = self::$db->query('SELECT * FROM "create_test" WHERE "id"=2') ->fetch(PDO::FETCH_ASSOC); @@ -215,12 +215,12 @@ SQL; public function testGetSchemas() { - $this->assertTrue(is_array(self::$db->getSchemas())); + $this->assertTrue(\is_array(self::$db->getSchemas())); } public function testGetDBs() { - $this->assertTrue(is_array(self::$db->getDbs())); + $this->assertTrue(\is_array(self::$db->getDbs())); } public function testGetFunctions() diff --git a/tests/Drivers/PgSQL/PgSQLQueryBuilderTest.php b/tests/Drivers/PgSQL/PgSQLQueryBuilderTest.php index bd36aef..879f028 100644 --- a/tests/Drivers/PgSQL/PgSQLQueryBuilderTest.php +++ b/tests/Drivers/PgSQL/PgSQLQueryBuilderTest.php @@ -27,7 +27,7 @@ class PgSQLQueryBuilderTest extends BaseQueryBuilderTest { $params = get_json_config(); if (getenv('TRAVIS')) // Travis CI Connection Info { - $params = array( + $params = [ 'host' => '127.0.0.1', 'port' => '5432', 'database' => 'test', @@ -35,7 +35,7 @@ class PgSQLQueryBuilderTest extends BaseQueryBuilderTest { 'pass' => '', 'type' => 'pgsql', 'prefix' => 'create_' - ); + ]; } // Attempt to connect, if there is a test config file else if ($params !== FALSE) @@ -44,7 +44,7 @@ class PgSQLQueryBuilderTest extends BaseQueryBuilderTest { $params->type = 'pgsql'; //$params->port = 5432; //$params->prefix = 'create_'; - $params->options = array(); + $params->options = []; $params->options[PDO::ATTR_PERSISTENT] = TRUE; } diff --git a/tests/Drivers/SQLite/SQLiteDriverTest.php b/tests/Drivers/SQLite/SQLiteDriverTest.php index bbe30b9..323c4d1 100644 --- a/tests/Drivers/SQLite/SQLiteDriverTest.php +++ b/tests/Drivers/SQLite/SQLiteDriverTest.php @@ -28,15 +28,15 @@ class SQLiteDriverTest extends BaseDriverTest { public static function setupBeforeClass() { - $params = array( + $params = [ 'type' => 'sqlite', 'file' => ':memory:', 'prefix' => 'create_', 'alias' => 'test_sqlite', - 'options' => array( + 'options' => [ PDO::ATTR_PERSISTENT => TRUE - ) - ); + ] + ]; self::$db = Query($params); self::$db->setTablePrefix('create_'); @@ -64,7 +64,7 @@ class SQLiteDriverTest extends BaseDriverTest { /*public function testBackupData() { - $sql = mb_trim(self::$db->getUtil()->backupData(array('create_join', 'create_test'))); + $sql = mb_trim(self::$db->getUtil()->backupData(['create_join', 'create_test'])); $sqlArray = explode("\n", $sql); @@ -192,7 +192,7 @@ SQL; INSERT INTO "create_test" ("id", "key", "val") VALUES (?,?,?) SQL; - $statement = self::$db->prepareQuery($sql, array(1,"boogers", "Gross")); + $statement = self::$db->prepareQuery($sql, [1,"boogers", "Gross"]); $statement->execute(); @@ -212,9 +212,9 @@ SQL; INSERT INTO "create_test" ("id", "key", "val") VALUES (?,?,?) SQL; - self::$db->prepareExecute($sql, array( + self::$db->prepareExecute($sql, [ 2, "works", 'also?' - )); + ]); $res = self::$db->query('SELECT * FROM "create_test" WHERE "id"=2') ->fetch(PDO::FETCH_ASSOC); diff --git a/tests/Drivers/SQLite/SQLiteQueryBuilderTest.php b/tests/Drivers/SQLite/SQLiteQueryBuilderTest.php index 6bb7f62..af9b34f 100644 --- a/tests/Drivers/SQLite/SQLiteQueryBuilderTest.php +++ b/tests/Drivers/SQLite/SQLiteQueryBuilderTest.php @@ -34,7 +34,7 @@ use Query\Tests\BaseQueryBuilderTest; { $db = Query('test_sqlite'); - $this->assertTrue(self::$db === $db, "Alias passed into query function gives the original object back"); + $this->assertTrue(self::$db === $db, 'Alias passed into query function gives the original object back'); } public function testQueryExplain() @@ -47,49 +47,49 @@ use Query\Tests\BaseQueryBuilderTest; $res = $query->fetchAll(PDO::FETCH_ASSOC); - $expectedPossibilities = array(); + $expectedPossibilities = []; - $expectedPossibilities[] = array( - array( + $expectedPossibilities[] = [ + [ 'order' => '0', 'from' => '0', 'detail' => 'TABLE create_test USING PRIMARY KEY', - ) - ); + ] + ]; - $expectedPossibilities[] = array ( - array ( + $expectedPossibilities[] = [ + [ 'selectid' => '0', 'order' => '0', 'from' => '0', 'detail' => 'SEARCH TABLE create_test USING INTEGER PRIMARY KEY (rowid>? AND rowid '0', 'order' => '0', 'from' => '0', 'detail' => 'SEARCH TABLE create_test USING INTEGER PRIMARY KEY (rowid>? AND rowid '0', 'order' => '0', 'from' => '0', 'detail' => 'SEARCH TABLE create_test USING INTEGER PRIMARY KEY (rowid>? AND rowidassertTrue(TRUE); $passed = TRUE; diff --git a/tests/QueryParserTest.php b/tests/QueryParserTest.php index d12af98..b63fb61 100644 --- a/tests/QueryParserTest.php +++ b/tests/QueryParserTest.php @@ -35,32 +35,32 @@ class QueryParserTest extends TestCase { public function testGeneric() { $matches = $this->parser->parseJoin('table1.field1=table2.field2'); - $this->assertEqual($matches['combined'], array( + $this->assertEqual($matches['combined'], [ 'table1.field1', '=', 'table2.field2' - )); + ]); } public function testGeneric2() { $matches = $this->parser->parseJoin('db1.table1.field1!=db2.table2.field2'); - $this->assertEqual($matches['combined'], array( + $this->assertEqual($matches['combined'], [ 'db1.table1.field1','!=','db2.table2.field2' - )); + ]); } public function testWUnderscore() { $matches = $this->parser->parseJoin('table_1.field1 = tab_le2.field_2'); - $this->assertEqual($matches['combined'], array( + $this->assertEqual($matches['combined'], [ 'table_1.field1', '=', 'tab_le2.field_2' - )); + ]); } public function testFunction() { $matches = $this->parser->parseJoin('table1.field1 > SUM(3+5)'); - $this->assertEqual($matches['combined'], array( + $this->assertEqual($matches['combined'], [ 'table1.field1', '>', 'SUM(3+5)' - )); + ]); } } \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9de4588..fcf10d9 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -20,10 +20,10 @@ define('QDS', DIRECTORY_SEPARATOR); function get_json_config() { - $files = array( + $files = [ __DIR__ . '/settings.json', __DIR__ . '/settings.json.dist' - ); + ]; foreach($files as $file) { diff --git a/tests/index.php b/tests/index.php index be4767b..cf7a263 100644 --- a/tests/index.php +++ b/tests/index.php @@ -87,6 +87,11 @@ namespace Query\Tests { $this->skipUnless(FALSE, $message); } + public function expectException($exception = FALSE, $message = '%s') + { + return parent::expectException(FALSE); + } + /** * Alias to the method in PHPUnit * @@ -106,10 +111,10 @@ namespace Query\Tests { namespace { function get_json_config() { - $files = array( + $files = [ __DIR__ . '/settings.json', __DIR__ . '/settings.json.dist' - ); + ]; foreach ($files as $file) { if (is_file($file)) { -- 2.47.0 From a2d5092b5ea9c31fa09660737c041cd069c41f3c Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Fri, 26 Jan 2018 09:00:45 -0500 Subject: [PATCH 08/47] Attempt to fix Gitlab build for PHP 7.2 --- build/docker_install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/docker_install.sh b/build/docker_install.sh index 515b393..1dfad0e 100644 --- a/build/docker_install.sh +++ b/build/docker_install.sh @@ -10,7 +10,7 @@ set -xe # Install git (the php image doesn't have it) which is required by composer apt-get update -yqq -apt-get install git libpq-dev libmysqlclient18 unzip -yqq +apt-get install git libpq-dev unzip -yqq # Install phpunit, the tool that we will use for testing curl -Lo /usr/local/bin/phpunit https://phar.phpunit.de/phpunit.phar -- 2.47.0 From 6a3db6581a4bc87d4b2c70b21c30f9a6a6bad636 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Fri, 26 Jan 2018 09:16:13 -0500 Subject: [PATCH 09/47] Update README and documentation --- README.md | 13 +- .../classes/Query_ConnectionManager.html | 22 +- .../Query_ConnectionManager/connect.html | 18 +- .../Query_ConnectionManager/parseParams.html | 11 +- .../classes/Query_Drivers_AbstractDriver.html | 40 +- .../Query_Drivers_AbstractDriver/_quote.html | 2 +- .../truncate.html | 2 +- .../updateBatch.html | 29 +- .../classes/Query_Drivers_AbstractUtil.html | 20 +- .../classes/Query_Drivers_Mysql_Driver.html | 18 +- .../classes/Query_Drivers_Pgsql_Driver.html | 18 +- .../classes/Query_Drivers_Sqlite_Driver.html | 18 +- .../classes/Query_QueryBuilder.html | 22 +- .../classes/Query_QueryBuilder/delete.html | 2 +- .../Query_QueryBuilder/getCompiledDelete.html | 2 +- .../Query_QueryBuilder/getCompiledInsert.html | 2 +- .../Query_QueryBuilder/getCompiledSelect.html | 2 +- .../Query_QueryBuilder/getCompiledUpdate.html | 2 +- .../classes/Query_QueryBuilder/replace.html | 2 +- .../Query_QueryBuilder/resetQuery.html | 2 +- .../Query_QueryBuilder/updateBatch.html | 8 +- apiDocumentation/classes/Query_State.html | 10 + .../Query_Drivers_DriverInterface.html | 7 +- .../__construct.html | 2 +- .../affectedRows.html | 2 +- .../driverQuery.html | 2 +- .../getColumns.html | 2 +- .../Query_Drivers_DriverInterface/getDbs.html | 2 +- .../Query_Drivers_DriverInterface/getFks.html | 2 +- .../getFunctions.html | 2 +- .../getIndexes.html | 2 +- .../getProcedures.html | 2 +- .../getSequences.html | 2 +- .../Query_Drivers_DriverInterface/getSql.html | 2 +- .../getSystemTables.html | 2 +- .../getTables.html | 2 +- .../getTriggers.html | 2 +- .../getTypes.html | 2 +- .../getUtil.html | 2 +- .../getViews.html | 2 +- .../insertBatch.html | 2 +- .../numRows.html | 2 +- .../prefixTable.html | 2 +- .../prepareExecute.html | 2 +- .../prepareQuery.html | 2 +- .../Query_Drivers_DriverInterface/quote.html | 104 ++++++ .../quoteIdent.html | 2 +- .../quoteTable.html | 2 +- .../setLastQuery.html | 2 +- .../updateBatch.html | 13 +- .../Query_QueryBuilderInterface.html | 2 +- .../updateBatch.html | 12 +- .../source/BadDBDriverException.php.html | 2 +- .../source/ConnectionManager.php.html | 52 +-- .../source/Drivers/AbstractDriver.php.html | 210 +++++++---- .../source/Drivers/AbstractSQL.php.html | 2 +- .../source/Drivers/AbstractUtil.php.html | 4 +- .../source/Drivers/DriverInterface.php.html | 2 +- .../source/Drivers/Mysql/Driver.php.html | 2 +- .../source/Drivers/Mysql/SQL.php.html | 2 +- .../source/Drivers/Mysql/Util.php.html | 2 +- .../source/Drivers/Pgsql/Driver.php.html | 2 +- .../source/Drivers/Pgsql/SQL.php.html | 2 +- .../source/Drivers/Pgsql/Util.php.html | 2 +- .../source/Drivers/SQLInterface.php.html | 2 +- .../source/Drivers/Sqlite/Driver.php.html | 2 +- .../source/Drivers/Sqlite/SQL.php.html | 2 +- .../source/Drivers/Sqlite/Util.php.html | 2 +- apiDocumentation/source/QueryBuilder.php.html | 348 +++++++++--------- .../source/QueryBuilderInterface.php.html | 2 +- apiDocumentation/source/QueryParser.php.html | 2 +- apiDocumentation/source/State.php.html | 4 +- apiDocumentation/source/common.php.html | 6 +- 73 files changed, 613 insertions(+), 494 deletions(-) create mode 100644 apiDocumentation/interfaces/Query_Drivers_DriverInterface/quote.html diff --git a/README.md b/README.md index b5df5fa..1c75bc4 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ A query builder/database abstraction layer, using prepared statements for securi ## Requirements * PDO extensions for the databases you wish to use (unless it's Firebird, in which case, the interbase extension is required) -* Supported version of PHP (Older versions may work, but are not supported) - +* PHP 7.1 or later + ## Databases Supported * MySQL @@ -78,8 +78,13 @@ Query('old')->query($sql); ``` ### Running Queries -Query uses the same interface as CodeIgniter's [Query Builder](http://www.codeigniter.com/user_guide/database/query_builder.html) class. However, it does not implement the `update_batch` or caching methods. For specific query builder methods, see the [class documentation](https://gitdev.timshomepage.net/Query/docs/classes/Query_QueryBuilder.html#methods). -Underscored methods are also aliased to camel case methods. +Query is based on CodeIgniter's [Query Builder](http://www.codeigniter.com/user_guide/database/query_builder.html) class. +However, it has camelCased method names, and does not implement the caching methods. +For specific query builder methods, see the [class documentation](https://gitdev.timshomepage.net/Query/apiDocumentation/classes/Query_QueryBuilder.html#methods). + +Other database methods not directly involved in building queries, are also available from the query builder object. +The methods available depend on the database, but common methods are documented +[here](https://gitdev.timshomepage.net/Query/apiDocumentation/classes/Query_Drivers_AbstractDriver.html#methods). #### You can also run queries manually. diff --git a/apiDocumentation/classes/Query_ConnectionManager.html b/apiDocumentation/classes/Query_ConnectionManager.html index 20da68e..ba75c15 100644 --- a/apiDocumentation/classes/Query_ConnectionManager.html +++ b/apiDocumentation/classes/Query_ConnectionManager.html @@ -118,6 +118,16 @@

History

    +
  • +

    2018-01-26T13:39:30+00:00 (commit #3067976)

    +
    +

    + Author: Timothy J Warren (tim@timshomepage.net) / + Commiter: Timothy J Warren (tim@timshomepage.net) +

    +
    Add updateBatch method
    +
    +
  • 2018-01-24T18:14:03+00:00 (commit #1d583bc)

    @@ -268,18 +278,6 @@
    Update lots of comments
  • -
  • -

    2015-11-10T22:30:18+00:00 (commit #8d65af5)

    -
    -

    - Author: Scrutinizer Auto-Fixer (auto-fixer@scrutinizer-ci.com) / - Commiter: Scrutinizer Auto-Fixer (auto-fixer@scrutinizer-ci.com) -

    -
    Scrutinizer Auto-Fixes
    -
    -This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com
    -
    -
diff --git a/apiDocumentation/classes/Query_ConnectionManager/connect.html b/apiDocumentation/classes/Query_ConnectionManager/connect.html index 1c646fd..85e3e56 100644 --- a/apiDocumentation/classes/Query_ConnectionManager/connect.html +++ b/apiDocumentation/classes/Query_ConnectionManager/connect.html @@ -62,7 +62,10 @@ Return
  • - Source + Throws +
  • +
  • + Source
  • @@ -73,7 +76,7 @@

      Signature

      - public function connect(stdClass + public function connect(object|array $params )
      @@ -81,7 +84,7 @@
      $params — - \stdClass
      + object



      Returns

      @@ -90,6 +93,15 @@

      +

      Errors/Exceptions

      +
      +
      + + BadDBDriverException + +
      +
      +
      diff --git a/apiDocumentation/classes/Query_ConnectionManager/parseParams.html b/apiDocumentation/classes/Query_ConnectionManager/parseParams.html index ae1b9f4..4cf9934 100644 --- a/apiDocumentation/classes/Query_ConnectionManager/parseParams.html +++ b/apiDocumentation/classes/Query_ConnectionManager/parseParams.html @@ -65,7 +65,7 @@ Throws
    • - Source + Source
    @@ -76,7 +76,7 @@

      Signature

      - public function parseParams(stdClass + public function parseParams(stdClass $params )
      @@ -84,13 +84,14 @@
      $params — - \stdClass
      + object



      Returns

      -
      array
      -
      +
      object|array
      +

      +

      Errors/Exceptions

      diff --git a/apiDocumentation/classes/Query_Drivers_AbstractDriver.html b/apiDocumentation/classes/Query_Drivers_AbstractDriver.html index 0078887..c0704fe 100644 --- a/apiDocumentation/classes/Query_Drivers_AbstractDriver.html +++ b/apiDocumentation/classes/Query_Drivers_AbstractDriver.html @@ -58,9 +58,6 @@
    • Coverage
    • -
    • - Tasks -
    • Methods
    • @@ -111,8 +108,8 @@
    • public ?array driverQuery()
    • public ?int numRows()
    • public array insertBatch() -
    • public int|null updateBatch() -
    • public PDOStatement truncate() +
    • public array updateBatch() +
    • public ?PDOStatement truncate()
    • public mixed _quote()
    • // Inherited methods from PDO
    • public void __construct()
    • public bool beginTransaction() @@ -160,19 +157,6 @@ / -

      Tasks

      - - - - - - - - - - - -
      LineTask
      571implement

      Methods

      public

      @@ -305,6 +289,16 @@

      History

        +
      • +

        2018-01-26T13:39:30+00:00 (commit #3067976)

        +
        +

        + Author: Timothy J Warren (tim@timshomepage.net) / + Commiter: Timothy J Warren (tim@timshomepage.net) +

        +
        Add updateBatch method
        +
        +
      • 2018-01-24T20:03:41+00:00 (commit #f967aaf)

        @@ -457,16 +451,6 @@ This commit consists of patches automatically generated for this project on http
        Update lots of comments
      • -
      • -

        2015-11-10T15:12:23+00:00 (commit #b5a141f)

        -
        -

        - Author: Timothy J Warren (tim@timshomepage.net) / - Commiter: Timothy J Warren (tim@timshomepage.net) -

        -
        Make class names Pascal Case
        -
        -
      diff --git a/apiDocumentation/classes/Query_Drivers_AbstractDriver/_quote.html b/apiDocumentation/classes/Query_Drivers_AbstractDriver/_quote.html index ba3aa27..9bd9fbb 100644 --- a/apiDocumentation/classes/Query_Drivers_AbstractDriver/_quote.html +++ b/apiDocumentation/classes/Query_Drivers_AbstractDriver/_quote.html @@ -62,7 +62,7 @@ Return
    • - Source + Source
    diff --git a/apiDocumentation/classes/Query_Drivers_AbstractDriver/truncate.html b/apiDocumentation/classes/Query_Drivers_AbstractDriver/truncate.html index b735847..d36af60 100644 --- a/apiDocumentation/classes/Query_Drivers_AbstractDriver/truncate.html +++ b/apiDocumentation/classes/Query_Drivers_AbstractDriver/truncate.html @@ -62,7 +62,7 @@ Return
  • - Source + Source
  • diff --git a/apiDocumentation/classes/Query_Drivers_AbstractDriver/updateBatch.html b/apiDocumentation/classes/Query_Drivers_AbstractDriver/updateBatch.html index c43a805..aadd533 100644 --- a/apiDocumentation/classes/Query_Drivers_AbstractDriver/updateBatch.html +++ b/apiDocumentation/classes/Query_Drivers_AbstractDriver/updateBatch.html @@ -64,9 +64,6 @@
  • Interface
  • -
  • - Tasks -
  • Source
  • @@ -81,7 +78,7 @@
    public function updateBatch(string $table, - array|object + array $data, string $where ) @@ -92,20 +89,20 @@
    $table — string
    -
    +
    The table to update
    $data — - object
    -



    + array +
    an array of update values
    $where — string
    -
    +
    The where key

    Returns

    -
    int|null
    -

    +
    array<string
    +
    array,int>

    Defined by Interface

    @@ -114,18 +111,6 @@ DriverInterface

    - - - - - - - - - - - -
    LineTask
    571implement