From f5d803f9d6efce024aa2b48856d1612676f90a8f Mon Sep 17 00:00:00 2001 From: timotewes Date: Tue, 27 Sep 2016 12:22:24 +0200 Subject: [PATCH 01/45] Fixed PHPDoc --- src/TableGateway/AbstractTableGateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TableGateway/AbstractTableGateway.php b/src/TableGateway/AbstractTableGateway.php index 0d08041446..26feb12200 100644 --- a/src/TableGateway/AbstractTableGateway.php +++ b/src/TableGateway/AbstractTableGateway.php @@ -197,7 +197,7 @@ public function select($where = null) /** * @param Select $select - * @return null|ResultSetInterface + * @return ResultSetInterface * @throws \RuntimeException */ public function selectWith(Select $select) From cd5c10787b43c953fbfef27a7279f1c818b07724 Mon Sep 17 00:00:00 2001 From: nanawel Date: Tue, 29 Nov 2016 12:58:16 +0100 Subject: [PATCH 02/45] Fix $valueSet initial value in In predicate --- src/Sql/Predicate/In.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sql/Predicate/In.php b/src/Sql/Predicate/In.php index 46ba61b62c..1354849ccf 100644 --- a/src/Sql/Predicate/In.php +++ b/src/Sql/Predicate/In.php @@ -16,7 +16,7 @@ class In extends AbstractExpression implements PredicateInterface { protected $identifier; - protected $valueSet; + protected $valueSet = []; protected $specification = '%s IN %s'; From 0463a2b4420ae857b97607d67a1ee6d9c01c9853 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Thu, 15 Dec 2016 08:03:21 -0300 Subject: [PATCH 03/45] Merge if statements --- src/Adapter/Driver/Mysqli/Result.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Adapter/Driver/Mysqli/Result.php b/src/Adapter/Driver/Mysqli/Result.php index ef30a7a2af..f306c86729 100644 --- a/src/Adapter/Driver/Mysqli/Result.php +++ b/src/Adapter/Driver/Mysqli/Result.php @@ -276,11 +276,10 @@ public function key() */ public function rewind() { - if ($this->position !== 0) { - if ($this->isBuffered === false) { - throw new Exception\RuntimeException('Unbuffered results cannot be rewound for multiple iterations'); - } + if (0 !== $this->position && false === $this->isBuffered) { + throw new Exception\RuntimeException('Unbuffered results cannot be rewound for multiple iterations'); } + $this->resource->data_seek(0); // works for both mysqli_result & mysqli_stmt $this->currentComplete = false; $this->position = 0; From 1d476644c079b7000917d079b03ffeee3e0e4cc0 Mon Sep 17 00:00:00 2001 From: David Stockton Date: Sun, 22 Jan 2017 22:17:23 -0700 Subject: [PATCH 04/45] Updated docblock on join to show TableIdentifer is allowed --- src/Sql/Join.php | 2 +- src/Sql/Select.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sql/Join.php b/src/Sql/Join.php index 770e35a4c1..d4cc06b7a1 100644 --- a/src/Sql/Join.php +++ b/src/Sql/Join.php @@ -108,7 +108,7 @@ public function getJoins() } /** - * @param string|array $name A table name on which to join, or a single + * @param string|array|TableIdentifier $name A table name on which to join, or a single * element associative array, of the form alias => table * @param string $on A string specification describing the fields to join on. * @param string|string[]|int|int[] $columns A single column name, an array diff --git a/src/Sql/Select.php b/src/Sql/Select.php index b4aac3ad29..c54330e783 100644 --- a/src/Sql/Select.php +++ b/src/Sql/Select.php @@ -254,7 +254,7 @@ public function columns(array $columns, $prefixColumnsWithTable = true) /** * Create join clause * - * @param string|array $name + * @param string|array|TableIdentifier $name * @param string $on * @param string|array $columns * @param string $type one of the JOIN_* constants From 861dd6c26f5c8cc42413a39046cdced509e10c29 Mon Sep 17 00:00:00 2001 From: Tomas Stryja Date: Wed, 1 Feb 2017 03:31:33 +0100 Subject: [PATCH 05/45] Function call on column example --- doc/book/sql.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/book/sql.md b/doc/book/sql.md index 9b6392b252..c7ad3c4aac 100644 --- a/doc/book/sql.md +++ b/doc/book/sql.md @@ -160,8 +160,12 @@ $select->from(new TableIdentifier(['t' => 'table'])); $select->columns(['foo', 'bar']); // As an associative array with aliases as the keys -// (produces 'bar' AS 'foo', 'bax' AS 'baz') -$select->columns(['foo' => 'bar', 'baz' => 'bax']); +// (produces 'bar' AS 'foo', 'bax' AS 'baz', CONCAT_WS('/', 'bar', 'bax') AS 'val') +$select->columns([ + 'foo' => 'bar', + 'baz' => 'bax', + 'val' => new \Zend\Db\Sql\Expression("CONCAT_WS('/', 'bar', 'bax')") +]); ``` ### join() From 8762727d26862e5a6e68d48b989380b48aa62661 Mon Sep 17 00:00:00 2001 From: Tomas Stryja Date: Tue, 7 Feb 2017 22:03:52 +0100 Subject: [PATCH 06/45] Function call - separation --- doc/book/sql.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/doc/book/sql.md b/doc/book/sql.md index c7ad3c4aac..2ab3e3bff9 100644 --- a/doc/book/sql.md +++ b/doc/book/sql.md @@ -160,11 +160,16 @@ $select->from(new TableIdentifier(['t' => 'table'])); $select->columns(['foo', 'bar']); // As an associative array with aliases as the keys -// (produces 'bar' AS 'foo', 'bax' AS 'baz', CONCAT_WS('/', 'bar', 'bax') AS 'val') +// (produces 'bar' AS 'foo', 'bax' AS 'baz') $select->columns([ 'foo' => 'bar', - 'baz' => 'bax', - 'val' => new \Zend\Db\Sql\Expression("CONCAT_WS('/', 'bar', 'bax')") + 'baz' => 'bax' +]); + +// Sql function call on the column +// (produces CONCAT_WS('/', 'bar', 'bax') AS 'foo') +$select->columns([ + 'foo' => new \Zend\Db\Sql\Expression("CONCAT_WS('/', 'bar', 'bax')") ]); ``` From caeff08271a2965e3a2ff09a60164066d8c62dd6 Mon Sep 17 00:00:00 2001 From: nanawel Date: Fri, 10 Feb 2017 13:06:37 +0100 Subject: [PATCH 07/45] Add support for "ADD COLUMN newcol ... AFTER othercol" on MySQL platform --- src/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php b/src/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php index 538f0b35f4..a61e7be9b3 100644 --- a/src/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php +++ b/src/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php @@ -33,6 +33,7 @@ class AlterTableDecorator extends AlterTable implements PlatformDecoratorInterfa 'columnformat' => 4, 'format' => 4, 'storage' => 5, + 'after' => 6 ]; /** @@ -130,6 +131,9 @@ protected function processAddColumns(PlatformInterface $adapterPlatform = null) $insert = ' STORAGE ' . strtoupper($coValue); $j = 2; break; + case 'after': + $insert = ' AFTER ' . $adapterPlatform->quoteIdentifier($coValue); + $j = 2; } if ($insert) { From b515680662045d6524fdf7df391ec3fc07deee0c Mon Sep 17 00:00:00 2001 From: nanawel Date: Fri, 10 Feb 2017 16:31:37 +0100 Subject: [PATCH 08/45] Revert "Fix $valueSet initial value in In predicate" This reverts commit cd5c10787b43c953fbfef27a7279f1c818b07724. --- src/Sql/Predicate/In.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sql/Predicate/In.php b/src/Sql/Predicate/In.php index 1354849ccf..46ba61b62c 100644 --- a/src/Sql/Predicate/In.php +++ b/src/Sql/Predicate/In.php @@ -16,7 +16,7 @@ class In extends AbstractExpression implements PredicateInterface { protected $identifier; - protected $valueSet = []; + protected $valueSet; protected $specification = '%s IN %s'; From c995f8327bf6df649ba96fa524bfe5c59b203dae Mon Sep 17 00:00:00 2001 From: nanawel Date: Fri, 10 Feb 2017 16:56:54 +0100 Subject: [PATCH 09/45] Add Mysql/AlterTableDecoratorTest --- .../Mysql/Ddl/AlterTableDecoratorTest.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php diff --git a/test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php b/test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php new file mode 100644 index 0000000000..e5d7b6bb7c --- /dev/null +++ b/test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php @@ -0,0 +1,54 @@ +assertSame($ctd, $ctd->setSubject($ct)); + } + + /** + * @covers Zend\Db\Sql\Platform\Mysql\Ddl\AlterTableDecorator::getSqlString + */ + public function testGetSqlString() + { + $ctd = new AlterTableDecorator(); + $ct = new AlterTable('foo'); + $ctd->setSubject($ct); + + $col = new Column('bar'); + $col->setOption('zerofill', true); + $col->setOption('unsigned', true); + $col->setOption('identity', true); + $col->setOption('comment', 'baz'); + $col->setOption('after', 'bar'); + $col->addConstraint(new PrimaryKey()); + $ct->addColumn($col); + + $this->assertEquals( + "ALTER TABLE `foo`\n ADD COLUMN `bar` INTEGER UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'baz' AFTER `bar`", + @$ctd->getSqlString(new Mysql()) + ); + } +} From db47b5a5386b395da1418dfd3045733011cd01cf Mon Sep 17 00:00:00 2001 From: nanawel Date: Fri, 10 Feb 2017 19:35:07 +0100 Subject: [PATCH 10/45] Remove unused import --- test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php b/test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php index e5d7b6bb7c..2135a707c4 100644 --- a/test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php +++ b/test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php @@ -13,7 +13,6 @@ use Zend\Db\Sql\Ddl\AlterTable; use Zend\Db\Sql\Ddl\Column\Column; use Zend\Db\Sql\Ddl\Constraint\PrimaryKey; -use Zend\Db\Sql\Ddl\CreateTable; use Zend\Db\Sql\Platform\Mysql\Ddl\AlterTableDecorator; class AlterTableDecoratorTest extends \PHPUnit_Framework_TestCase From b7c2ef668c38c59c012cf7630e70203f73007216 Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Thu, 23 Feb 2017 17:12:06 +0100 Subject: [PATCH 11/45] Updated CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cceb78f859..7e8956a333 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ All notable changes to this project will be documented in this file, in reverse ### Added -- Nothing. +- [#216](https://github.com/zendframework/zend-db/pull/216) added AFTER support + in ALTER TABLE syntax for MySQL ### Deprecated From e31a3c031f6c5ce2abed0130576068d0731c9e14 Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Thu, 23 Feb 2017 18:10:37 +0100 Subject: [PATCH 12/45] Updated CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e8956a333..780f762d3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,8 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#205](https://github.com/zendframework/zend-db/pull/205) fixes the spaces in + ORDER BY syntax. ## 2.8.3 - TBD From ca540106f6c8951411d5523807b81753f981a835 Mon Sep 17 00:00:00 2001 From: nanawel Date: Mon, 27 Feb 2017 18:19:51 +0100 Subject: [PATCH 13/45] Add support for empty values set with IN predicate + associated unit tests --- src/Sql/Predicate/In.php | 2 +- test/Sql/Predicate/InTest.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Sql/Predicate/In.php b/src/Sql/Predicate/In.php index 46ba61b62c..e2cac3e17e 100644 --- a/src/Sql/Predicate/In.php +++ b/src/Sql/Predicate/In.php @@ -33,7 +33,7 @@ public function __construct($identifier = null, $valueSet = null) if ($identifier) { $this->setIdentifier($identifier); } - if ($valueSet) { + if ($valueSet !== null) { $this->setValueSet($valueSet); } } diff --git a/test/Sql/Predicate/InTest.php b/test/Sql/Predicate/InTest.php index 30584f65a5..34aa0fa94a 100644 --- a/test/Sql/Predicate/InTest.php +++ b/test/Sql/Predicate/InTest.php @@ -29,6 +29,13 @@ public function testCanPassIdentifierAndValueSetToConstructor() $this->assertEquals([1, 2], $in->getValueSet()); } + public function testCanPassIdentifierAndEmptyValueSetToConstructor() + { + $in = new In('foo.bar', []); + $this->assertEquals('foo.bar', $in->getIdentifier()); + $this->assertEquals([], $in->getValueSet()); + } + public function testIdentifierIsMutable() { $in = new In(); @@ -82,6 +89,18 @@ public function testGetExpressionDataWithSubselect() $this->assertEquals($expected, $in->getExpressionData()); } + public function testGetExpressionDataWithEmptyValues() + { + $select = new Select; + $in = new In('foo', []); + $expected = [[ + '%s IN ()', + ['foo'], + [$in::TYPE_IDENTIFIER] + ]]; + $this->assertEquals($expected, $in->getExpressionData()); + } + public function testGetExpressionDataWithSubselectAndIdentifier() { $select = new Select; From ada552d7a28a85325eda77313c563d4f296067c1 Mon Sep 17 00:00:00 2001 From: nanawel Date: Mon, 27 Feb 2017 18:33:58 +0100 Subject: [PATCH 14/45] Fix getExpressionData() for PHP < 5.6.0 --- src/Sql/Predicate/In.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Sql/Predicate/In.php b/src/Sql/Predicate/In.php index e2cac3e17e..7c04a8182d 100644 --- a/src/Sql/Predicate/In.php +++ b/src/Sql/Predicate/In.php @@ -122,9 +122,10 @@ public function getExpressionData() foreach ($values as $argument) { list($replacements[], $types[]) = $this->normalizeArgument($argument, self::TYPE_VALUE); } + $values = count($values) > 0 ? array_fill(0, count($values), '%s') : []; $specification = vsprintf( $this->specification, - [$identifierSpecFragment, '(' . implode(', ', array_fill(0, count($values), '%s')) . ')'] + [$identifierSpecFragment, '(' . implode(', ', $values) . ')'] ); } From 699a7cff16b0b25f721a09f0f000298613c295c5 Mon Sep 17 00:00:00 2001 From: nanawel Date: Mon, 27 Feb 2017 18:36:16 +0100 Subject: [PATCH 15/45] Better naming --- src/Sql/Predicate/In.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sql/Predicate/In.php b/src/Sql/Predicate/In.php index 7c04a8182d..8953b5db12 100644 --- a/src/Sql/Predicate/In.php +++ b/src/Sql/Predicate/In.php @@ -122,10 +122,10 @@ public function getExpressionData() foreach ($values as $argument) { list($replacements[], $types[]) = $this->normalizeArgument($argument, self::TYPE_VALUE); } - $values = count($values) > 0 ? array_fill(0, count($values), '%s') : []; + $valuePlaceholders = count($values) > 0 ? array_fill(0, count($values), '%s') : []; $specification = vsprintf( $this->specification, - [$identifierSpecFragment, '(' . implode(', ', $values) . ')'] + [$identifierSpecFragment, '(' . implode(', ', $valuePlaceholders) . ')'] ); } From 07af0f8003e58d92f6611e8c34d14f8305cf2a3d Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Tue, 28 Feb 2017 19:28:38 +0100 Subject: [PATCH 16/45] Updated CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 780f762d3b..64cd08a13e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file, in reverse - [#216](https://github.com/zendframework/zend-db/pull/216) added AFTER support in ALTER TABLE syntax for MySQL +- [#223](https://github.com/zendframework/zend-db/pull/223) added support for + empty values set with IN predicate ### Deprecated From 1c73590177c86a4f3dfc57563a194ee4c8714fd3 Mon Sep 17 00:00:00 2001 From: Welling Guzman Date: Sat, 7 Oct 2017 01:24:56 -0400 Subject: [PATCH 17/45] support dash on MySQL identifier (Ref #208) --- src/Adapter/Platform/AbstractPlatform.php | 7 ++++++- src/Adapter/Platform/Mysql.php | 7 +++++++ test/Adapter/Platform/MysqlTest.php | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Adapter/Platform/AbstractPlatform.php b/src/Adapter/Platform/AbstractPlatform.php index 1857c7ba92..42b8857510 100644 --- a/src/Adapter/Platform/AbstractPlatform.php +++ b/src/Adapter/Platform/AbstractPlatform.php @@ -26,6 +26,11 @@ abstract class AbstractPlatform implements PlatformInterface */ protected $quoteIdentifiers = true; + /** + * @var string + */ + protected $quoteIdentifierFragmentPattern = '/([^0-9,a-z,A-Z$_:])/i'; + /** * {@inheritDoc} */ @@ -42,7 +47,7 @@ public function quoteIdentifierInFragment($identifier, array $safeWords = []) } $parts = preg_split( - '/([^0-9,a-z,A-Z$_:])/i', + $this->quoteIdentifierFragmentPattern, $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY diff --git a/src/Adapter/Platform/Mysql.php b/src/Adapter/Platform/Mysql.php index f239fd0e4f..1f9e1dba66 100644 --- a/src/Adapter/Platform/Mysql.php +++ b/src/Adapter/Platform/Mysql.php @@ -31,6 +31,13 @@ class Mysql extends AbstractPlatform */ protected $resource = null; + /** + * NOTE: Include dashes for MySQL only, need tests for others platforms + * + * @var string + */ + protected $quoteIdentifierFragmentPattern = '/([^0-9,a-z,A-Z$_\-:])/i'; + /** * @param null|\Zend\Db\Adapter\Driver\Mysqli\Mysqli|\Zend\Db\Adapter\Driver\Pdo\Pdo|\mysqli|\PDO $driver */ diff --git a/test/Adapter/Platform/MysqlTest.php b/test/Adapter/Platform/MysqlTest.php index c033a344ec..1c950bba10 100644 --- a/test/Adapter/Platform/MysqlTest.php +++ b/test/Adapter/Platform/MysqlTest.php @@ -141,21 +141,41 @@ public function testQuoteIdentifierInFragment() $this->assertEquals('`$TableName`.`bar`', $this->platform->quoteIdentifierInFragment('$TableName.bar')); $this->assertEquals('`cmis:$TableName` as `cmis:TableAlias`', $this->platform->quoteIdentifierInFragment('cmis:$TableName as cmis:TableAlias')); + $this->assertEquals('`foo-bar`.`bar-foo`', $this->platform->quoteIdentifierInFragment('foo-bar.bar-foo')); + $this->assertEquals('`foo-bar` as `bar-foo`', $this->platform->quoteIdentifierInFragment('foo-bar as bar-foo')); + $this->assertEquals('`$TableName-$ColumnName`.`bar-foo`', $this->platform->quoteIdentifierInFragment('$TableName-$ColumnName.bar-foo')); + $this->assertEquals('`cmis:$TableName-$ColumnName` as `cmis:TableAlias-ColumnAlias`', $this->platform->quoteIdentifierInFragment('cmis:$TableName-$ColumnName as cmis:TableAlias-ColumnAlias')); + // single char words $this->assertEquals('(`foo`.`bar` = `boo`.`baz`)', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '='])); $this->assertEquals('(`foo`.`bar`=`boo`.`baz`)', $this->platform->quoteIdentifierInFragment('(foo.bar=boo.baz)', ['(', ')', '='])); $this->assertEquals('`foo`=`bar`', $this->platform->quoteIdentifierInFragment('foo=bar', ['='])); + $this->assertEquals('(`foo-bar`.`bar-foo` = `boo-baz`.`baz-boo`)', $this->platform->quoteIdentifierInFragment('(foo-bar.bar-foo = boo-baz.baz-boo)', ['(', ')', '='])); + $this->assertEquals('(`foo-bar`.`bar-foo`=`boo-baz`.`baz-boo`)', $this->platform->quoteIdentifierInFragment('(foo-bar.bar-foo=boo-baz.baz-boo)', ['(', ')', '='])); + $this->assertEquals('`foo-bar`=`bar-foo`', $this->platform->quoteIdentifierInFragment('foo-bar=bar-foo', ['='])); + // case insensitive safe words $this->assertEquals( '(`foo`.`bar` = `boo`.`baz`) AND (`foo`.`baz` = `boo`.`baz`)', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz) AND (foo.baz = boo.baz)', ['(', ')', '=', 'and']) ); + $this->assertEquals( + '(`foo-bar`.`bar-foo` = `boo-baz`.`baz-boo`) AND (`foo-baz`.`baz-foo` = `boo-baz`.`baz-boo`)', + $this->platform->quoteIdentifierInFragment('(foo-bar.bar-foo = boo-baz.baz-boo) AND (foo-baz.baz-foo = boo-baz.baz-boo)', ['(', ')', '=', 'and']) + ); + // case insensitive safe words in field $this->assertEquals( '(`foo`.`bar` = `boo`.baz) AND (`foo`.baz = `boo`.baz)', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz) AND (foo.baz = boo.baz)', ['(', ')', '=', 'and', 'bAz']) ); + + // case insensitive safe words in field + $this->assertEquals( + '(`foo-bar`.`bar-foo` = `boo-baz`.baz-boo) AND (`foo-baz`.`baz-foo` = `boo-baz`.baz-boo)', + $this->platform->quoteIdentifierInFragment('(foo-bar.bar-foo = boo-baz.baz-boo) AND (foo-baz.baz-foo = boo-baz.baz-boo)', ['(', ')', '=', 'and', 'bAz-BOo']) + ); } } From 02313d515ef9781f6d80f94af482ec10e29dd4b3 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Fri, 13 Oct 2017 11:01:03 +0100 Subject: [PATCH 18/45] Implement our own error handler for db2_prepare db2_prepare() may issue a [warning][1] in addition to returning false. If you have an error handler set (e.g. in the Expressive pipeline) then the message created is "db2_prepare(): Statement Prepare Failed" which is not helpful. Therefore, we create our own error handler and trap this ourselves so that we can throw an ErrorException with more information from db2_stmt_errormsg(). [1]: https://github.com/php/pecl-database-ibm_db2/blob/df913feb4dff56366ac4656b0bb6b39200794bde/ibm_db2.c#L4400 --- src/Adapter/Driver/IbmDb2/Statement.php | 38 ++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Adapter/Driver/IbmDb2/Statement.php b/src/Adapter/Driver/IbmDb2/Statement.php index 338fc18d78..708425f653 100644 --- a/src/Adapter/Driver/IbmDb2/Statement.php +++ b/src/Adapter/Driver/IbmDb2/Statement.php @@ -9,6 +9,8 @@ namespace Zend\Db\Adapter\Driver\IbmDb2; +use ErrorException; +use Throwable; use Zend\Db\Adapter\Driver\StatementInterface; use Zend\Db\Adapter\Exception; use Zend\Db\Adapter\ParameterContainer; @@ -172,7 +174,14 @@ public function prepare($sql = null) $sql = $this->sql; } - $this->resource = db2_prepare($this->db2, $sql); + try { + set_error_handler($this->createErrorHandler()); + $this->resource = db2_prepare($this->db2, $sql); + } catch (Throwable $e) { + throw new Exception\RuntimeException($e->getMessage() . '. ' . db2_stmt_errormsg(), db2_stmt_error(), $e); + } finally { + restore_error_handler(); + } if ($this->resource === false) { throw new Exception\RuntimeException(db2_stmt_errormsg(), db2_stmt_error()); @@ -238,4 +247,31 @@ public function execute($parameters = null) $result = $this->driver->createResult($this->resource); return $result; } + + /** + * Creates and returns a callable error handler that raises exceptions. + * + * Only raises exceptions for errors that are within the error_reporting mask. + * + * @return callable + */ + private function createErrorHandler() : callable + { + /** + * @param int $errno + * @param string $errstr + * @param string $errfile + * @param int $errline + * @return void + * @throws ErrorException if error is not within the error_reporting mask. + */ + return function (int $errno, string $errstr, string $errfile, int $errline) : void { + if (! (error_reporting() & $errno)) { + // error_reporting does not include this error + return; + } + + throw new ErrorException($errstr, 0, $errno, $errfile, $errline); + }; + } } From ddec03b554f013f023a747f199bb4ca51c460774 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Fri, 13 Oct 2017 16:41:00 +0100 Subject: [PATCH 19/45] Add integration test --- .../IbmDb2/StatementIntegrationTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php b/test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php index 08db40c3ae..402964a7ad 100644 --- a/test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php +++ b/test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php @@ -11,6 +11,7 @@ use Zend\Db\Adapter\Driver\IbmDb2\IbmDb2; use Zend\Db\Adapter\Driver\IbmDb2\Statement; +use Zend\Db\Adapter\Exception\RuntimeException; /** * @group integration @@ -85,6 +86,24 @@ public function testPrepare() unset($resource, $db2Resource); } + /** + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::prepare + */ + public function testPrepareThrowsAnExceptionOnFailure() + { + $this->expectException(RuntimeException::class); + + $db2Resource = db2_connect( + $this->variables['database'], + $this->variables['username'], + $this->variables['password'] + ); + $statement = new Statement; + $statement->initialize($db2Resource); + $statement->prepare("SELECT"); + unset($resource, $db2Resource); + } + /** * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::execute */ From 50e1286b5b92674ceb5efb90d8170313f346d9e1 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Fri, 13 Oct 2017 19:28:22 +0100 Subject: [PATCH 20/45] Remove PHP 7 type hints --- src/Adapter/Driver/IbmDb2/Statement.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Adapter/Driver/IbmDb2/Statement.php b/src/Adapter/Driver/IbmDb2/Statement.php index 708425f653..2321086c2f 100644 --- a/src/Adapter/Driver/IbmDb2/Statement.php +++ b/src/Adapter/Driver/IbmDb2/Statement.php @@ -255,7 +255,7 @@ public function execute($parameters = null) * * @return callable */ - private function createErrorHandler() : callable + private function createErrorHandler() { /** * @param int $errno @@ -265,7 +265,7 @@ private function createErrorHandler() : callable * @return void * @throws ErrorException if error is not within the error_reporting mask. */ - return function (int $errno, string $errstr, string $errfile, int $errline) : void { + return function ($errno, $errstr, $errfile, $errline) { if (! (error_reporting() & $errno)) { // error_reporting does not include this error return; From 192d30da4f553dbe155194eaf397b8991a3d32af Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Fri, 13 Oct 2017 19:28:36 +0100 Subject: [PATCH 21/45] Make integration tests work on IBM i --- test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php b/test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php index 402964a7ad..915b94e084 100644 --- a/test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php +++ b/test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php @@ -64,7 +64,7 @@ public function testGetResource() $statement = new Statement; $statement->initialize($db2Resource); - $statement->prepare("SELECT 'foo'"); + $statement->prepare("SELECT 'foo' FROM sysibm.sysdummy1"); $resource = $statement->getResource(); $this->assertEquals('DB2 Statement', get_resource_type($resource)); unset($resource, $db2Resource); @@ -88,11 +88,10 @@ public function testPrepare() /** * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::prepare + * @expectedException RuntimeException */ public function testPrepareThrowsAnExceptionOnFailure() { - $this->expectException(RuntimeException::class); - $db2Resource = db2_connect( $this->variables['database'], $this->variables['username'], From ea15efa5c1c8af12a77e2de95095cc6433c34db8 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Fri, 13 Oct 2017 20:57:51 +0100 Subject: [PATCH 22/45] Add support for LIMIT OFFSET for db2 --- src/Sql/Platform/IbmDb2/SelectDecorator.php | 38 ++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Sql/Platform/IbmDb2/SelectDecorator.php b/src/Sql/Platform/IbmDb2/SelectDecorator.php index 28602b20e4..2994cd9bb0 100644 --- a/src/Sql/Platform/IbmDb2/SelectDecorator.php +++ b/src/Sql/Platform/IbmDb2/SelectDecorator.php @@ -27,7 +27,13 @@ class SelectDecorator extends Select implements PlatformDecoratorInterface */ protected $subject = null; - /** + /** + * @var bool + */ + protected $supportsLimitOffset = false; + + + /** * @return bool */ public function getIsSelectContainDistinct() @@ -51,6 +57,22 @@ public function setSubject($select) $this->subject = $select; } + /** + * @return bool + */ + public function getSupportsLimitOffset() + { + return $this->supportsLimitOffset; + } + + /** + * @param bool $supportsLimitOffset + */ + public function setSupportsLimitOffset($supportsLimitOffset) + { + $this->supportsLimitOffset = $supportsLimitOffset; + } + /** * @see Select::renderTable */ @@ -82,6 +104,20 @@ protected function processLimitOffset(PlatformInterface $platform, DriverInterfa return; } + if ($this->supportsLimitOffset) { + // Note: db2_prepare/db2_execute fails with positional parameters, for LIMIT & OFFSET + $limit = (int)$this->limit; + $offset = (int)$this->offset; + if ($this->limit) { + if ($this->offset) { + array_push($sqls, sprintf("LIMIT %s OFFSET %s", $limit, $offset)); + } else { + array_push($sqls, sprintf("LIMIT %s", $limit)); + } + } + return; + } + $selectParameters = $parameters[self::SELECT]; $starSuffix = $platform->getIdentifierSeparator() . self::SQL_STAR; From ead49e6adc3c16e2d5d382f549127aa4dbd81a11 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Fri, 13 Oct 2017 21:12:52 +0100 Subject: [PATCH 23/45] Add tests for DB2 limit offset --- .../Platform/IbmDb2/SelectDecoratorTest.php | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/test/Sql/Platform/IbmDb2/SelectDecoratorTest.php b/test/Sql/Platform/IbmDb2/SelectDecoratorTest.php index 4c9e939d06..c6d925dc6c 100644 --- a/test/Sql/Platform/IbmDb2/SelectDecoratorTest.php +++ b/test/Sql/Platform/IbmDb2/SelectDecoratorTest.php @@ -24,7 +24,7 @@ class SelectDecoratorTest extends \PHPUnit_Framework_TestCase * @covers Zend\Db\Sql\Platform\SqlServer\SelectDecorator::processLimitOffset * @dataProvider dataProvider */ - public function testPrepareStatement(Select $select, $expectedPrepareSql, $expectedParams, $notUsed) + public function testPrepareStatement(Select $select, $expectedPrepareSql, $expectedParams, $notUsed, $supportsLimitOffset) { $driver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface'); $driver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); @@ -47,6 +47,7 @@ public function testPrepareStatement(Select $select, $expectedPrepareSql, $expec $selectDecorator = new SelectDecorator; $selectDecorator->setSubject($select); + $selectDecorator->setSupportsLimitOffset($supportsLimitOffset); $selectDecorator->prepareStatement($adapter, $statement); $this->assertEquals($expectedParams, $parameterContainer->getNamedArray()); @@ -57,7 +58,7 @@ public function testPrepareStatement(Select $select, $expectedPrepareSql, $expec * @covers Zend\Db\Sql\Platform\IbmDb2\SelectDecorator::getSqlString * @dataProvider dataProvider */ - public function testGetSqlString(Select $select, $ignored0, $ignored1, $expectedSql) + public function testGetSqlString(Select $select, $ignored0, $ignored1, $expectedSql, $supportsLimitOffset) { $parameterContainer = new ParameterContainer; $statement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface'); @@ -65,6 +66,7 @@ public function testGetSqlString(Select $select, $ignored0, $ignored1, $expected $selectDecorator = new SelectDecorator; $selectDecorator->setSubject($select); + $selectDecorator->setSupportsLimitOffset($supportsLimitOffset); $this->assertEquals($expectedSql, @$selectDecorator->getSqlString(new IbmDb2Platform)); } @@ -109,12 +111,26 @@ public function dataProvider() $expectedPrepareSql4 = 'SELECT * FROM ( SELECT "x".*, ROW_NUMBER() OVER () AS ZEND_DB_ROWNUM FROM "foo" "x" WHERE "x"."id" > ? AND "x"."id" < ? ) AS ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION WHERE ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION.ZEND_DB_ROWNUM BETWEEN ? AND ?'; $expectedSql4 = 'SELECT * FROM ( SELECT "x".*, ROW_NUMBER() OVER () AS ZEND_DB_ROWNUM FROM "foo" "x" WHERE "x"."id" > \'10\' AND "x"."id" < \'31\' ) AS ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION WHERE ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION.ZEND_DB_ROWNUM BETWEEN 0 AND 5'; + $select5 = new Select; + $select5->from(['x' => 'foo'])->limit(5); + $expectedParams5 = []; + $expectedPrepareSql5 = 'SELECT "x".* FROM "foo" "x" LIMIT 5'; + $expectedSql5 = 'SELECT "x".* FROM "foo" "x" LIMIT 5'; + + $select6 = new Select; + $select6->columns([new Expression('DISTINCT(id) as id')])->from(['x' => 'foo'])->limit(5)->offset(10); + $expectedParams6 = []; + $expectedPrepareSql6 = 'SELECT DISTINCT(id) as id FROM "foo" "x" LIMIT 5 OFFSET 10'; + $expectedSql6 = 'SELECT DISTINCT(id) as id FROM "foo" "x" LIMIT 5 OFFSET 10'; + return [ - [$select0, $expectedPrepareSql0, $expectedParams0, $expectedSql0], - [$select1, $expectedPrepareSql1, $expectedParams1, $expectedSql1], - [$select2, $expectedPrepareSql2, $expectedParams2, $expectedSql2], - [$select3, $expectedPrepareSql3, $expectedParams3, $expectedSql3], - [$select4, $expectedPrepareSql4, $expectedParams4, $expectedSql4], + [$select0, $expectedPrepareSql0, $expectedParams0, $expectedSql0, false], + [$select1, $expectedPrepareSql1, $expectedParams1, $expectedSql1, false], + [$select2, $expectedPrepareSql2, $expectedParams2, $expectedSql2, false], + [$select3, $expectedPrepareSql3, $expectedParams3, $expectedSql3, false], + [$select4, $expectedPrepareSql4, $expectedParams4, $expectedSql4, false], + [$select5, $expectedPrepareSql5, $expectedParams5, $expectedSql5, true], + [$select6, $expectedPrepareSql6, $expectedParams6, $expectedSql6, true], ]; } } From 0d7d8efbc05e3e1d56838cb843fb6b348c575599 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Mon, 16 Oct 2017 10:21:34 +0100 Subject: [PATCH 24/45] Return early --- src/Sql/Platform/IbmDb2/SelectDecorator.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Sql/Platform/IbmDb2/SelectDecorator.php b/src/Sql/Platform/IbmDb2/SelectDecorator.php index 2994cd9bb0..015d25bd5d 100644 --- a/src/Sql/Platform/IbmDb2/SelectDecorator.php +++ b/src/Sql/Platform/IbmDb2/SelectDecorator.php @@ -108,13 +108,17 @@ protected function processLimitOffset(PlatformInterface $platform, DriverInterfa // Note: db2_prepare/db2_execute fails with positional parameters, for LIMIT & OFFSET $limit = (int)$this->limit; $offset = (int)$this->offset; - if ($this->limit) { - if ($this->offset) { - array_push($sqls, sprintf("LIMIT %s OFFSET %s", $limit, $offset)); - } else { - array_push($sqls, sprintf("LIMIT %s", $limit)); - } + + if (! $limit) { + return; + } + + if ($offset) { + array_push($sqls, sprintf("LIMIT %s OFFSET %s", $limit, $offset)); + return; } + + array_push($sqls, sprintf("LIMIT %s", $limit)); return; } From c54f5e25c96ccb1220c883bfa8aea81b6ab6deef Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Mon, 16 Oct 2017 15:16:00 +0100 Subject: [PATCH 25/45] Use setExpectedException --- test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php b/test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php index 915b94e084..79ade5803d 100644 --- a/test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php +++ b/test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php @@ -88,7 +88,6 @@ public function testPrepare() /** * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::prepare - * @expectedException RuntimeException */ public function testPrepareThrowsAnExceptionOnFailure() { @@ -99,6 +98,7 @@ public function testPrepareThrowsAnExceptionOnFailure() ); $statement = new Statement; $statement->initialize($db2Resource); + $this->setExpectedException(RuntimeException::class); $statement->prepare("SELECT"); unset($resource, $db2Resource); } From fecf111a94a6ec1e3d56ef21a4274a41cd85b301 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Mon, 16 Oct 2017 15:18:37 +0100 Subject: [PATCH 26/45] Only define $offset if needed --- src/Sql/Platform/IbmDb2/SelectDecorator.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Sql/Platform/IbmDb2/SelectDecorator.php b/src/Sql/Platform/IbmDb2/SelectDecorator.php index 015d25bd5d..f11b4eedc2 100644 --- a/src/Sql/Platform/IbmDb2/SelectDecorator.php +++ b/src/Sql/Platform/IbmDb2/SelectDecorator.php @@ -107,12 +107,11 @@ protected function processLimitOffset(PlatformInterface $platform, DriverInterfa if ($this->supportsLimitOffset) { // Note: db2_prepare/db2_execute fails with positional parameters, for LIMIT & OFFSET $limit = (int)$this->limit; - $offset = (int)$this->offset; - if (! $limit) { return; } + $offset = (int)$this->offset; if ($offset) { array_push($sqls, sprintf("LIMIT %s OFFSET %s", $limit, $offset)); return; From b4db3495f0a5d9f5eab9d1fbe0a7ab29cd6852a9 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Tue, 17 Oct 2017 07:33:28 +0100 Subject: [PATCH 27/45] Remove code never called in test --- test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php b/test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php index 79ade5803d..e976bec16c 100644 --- a/test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php +++ b/test/Adapter/Driver/IbmDb2/StatementIntegrationTest.php @@ -100,7 +100,6 @@ public function testPrepareThrowsAnExceptionOnFailure() $statement->initialize($db2Resource); $this->setExpectedException(RuntimeException::class); $statement->prepare("SELECT"); - unset($resource, $db2Resource); } /** From 547215b9a584b7e430e07aaab7a29364e9d27d66 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Fri, 20 Oct 2017 07:31:37 +0100 Subject: [PATCH 28/45] Add a space after cast --- src/Sql/Platform/IbmDb2/SelectDecorator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sql/Platform/IbmDb2/SelectDecorator.php b/src/Sql/Platform/IbmDb2/SelectDecorator.php index f11b4eedc2..f55fa73f93 100644 --- a/src/Sql/Platform/IbmDb2/SelectDecorator.php +++ b/src/Sql/Platform/IbmDb2/SelectDecorator.php @@ -106,12 +106,12 @@ protected function processLimitOffset(PlatformInterface $platform, DriverInterfa if ($this->supportsLimitOffset) { // Note: db2_prepare/db2_execute fails with positional parameters, for LIMIT & OFFSET - $limit = (int)$this->limit; + $limit = (int) $this->limit; if (! $limit) { return; } - $offset = (int)$this->offset; + $offset = (int) $this->offset; if ($offset) { array_push($sqls, sprintf("LIMIT %s OFFSET %s", $limit, $offset)); return; From ac5e8e072929dd21c9c377c33319aed1f5b91fd0 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Fri, 20 Oct 2017 08:30:49 +0100 Subject: [PATCH 29/45] Catch ErrorException That's what the error handler throws. --- src/Adapter/Driver/IbmDb2/Statement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapter/Driver/IbmDb2/Statement.php b/src/Adapter/Driver/IbmDb2/Statement.php index 2321086c2f..8b61f1206e 100644 --- a/src/Adapter/Driver/IbmDb2/Statement.php +++ b/src/Adapter/Driver/IbmDb2/Statement.php @@ -177,7 +177,7 @@ public function prepare($sql = null) try { set_error_handler($this->createErrorHandler()); $this->resource = db2_prepare($this->db2, $sql); - } catch (Throwable $e) { + } catch (ErrorException $e) { throw new Exception\RuntimeException($e->getMessage() . '. ' . db2_stmt_errormsg(), db2_stmt_error(), $e); } finally { restore_error_handler(); From e493cdaeac40354677f032cbb19e1b0ae57badb1 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Fri, 20 Oct 2017 08:32:30 +0100 Subject: [PATCH 30/45] Unit test Adapter\Driver\IbmDb2\Statement::prepare() Mock the relevant db2_xxx functions by placing them into the Zend\Db\Adapter\Driver\IbmDb2 namespace so that they are preferred over the actual ones in the idm_db2 extension. --- test/Adapter/Driver/IbmDb2/StatementTest.php | 66 ++++++++++++++++--- .../Driver/IbmDb2/TestAsset/Db2Functions.php | 57 ++++++++++++++++ 2 files changed, 113 insertions(+), 10 deletions(-) create mode 100644 test/Adapter/Driver/IbmDb2/TestAsset/Db2Functions.php diff --git a/test/Adapter/Driver/IbmDb2/StatementTest.php b/test/Adapter/Driver/IbmDb2/StatementTest.php index c56d4acc42..8074339b18 100644 --- a/test/Adapter/Driver/IbmDb2/StatementTest.php +++ b/test/Adapter/Driver/IbmDb2/StatementTest.php @@ -12,6 +12,9 @@ use Zend\Db\Adapter\Driver\IbmDb2\Statement; use Zend\Db\Adapter\Driver\IbmDb2\IbmDb2; use Zend\Db\Adapter\ParameterContainer; +use Zend\Db\Adapter\Exception\RuntimeException; + +include __DIR__ . '/TestAsset/Db2Functions.php'; class StatementTest extends \PHPUnit_Framework_TestCase { @@ -102,26 +105,69 @@ public function testGetSql() /** * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::prepare - * @todo Implement testPrepare(). + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::isPrepared */ public function testPrepare() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $sql = "SELECT 'foo' FROM SYSIBM.SYSDUMMY1"; + $this->statement->prepare($sql); + $this->assertTrue($this->statement->isPrepared()); } /** + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::prepare * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::isPrepared - * @todo Implement testIsPrepared(). */ - public function testIsPrepared() + public function testPreparingTwiceErrors() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' + $sql = "SELECT 'foo' FROM SYSIBM.SYSDUMMY1"; + $this->statement->prepare($sql); + $this->assertTrue($this->statement->isPrepared()); + + $this->setExpectedException( + RuntimeException::class, + 'This statement has been prepared already' + ); + $this->statement->prepare($sql); + } + + /** + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::prepare + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::setSql + */ + public function testPrepareThrowsRuntimeExceptionOnInvalidSql() + { + $sql = "INVALID SQL"; + $this->statement->setSql($sql); + + $this->setExpectedException( + RuntimeException::class, + 'SQL is invalid. Error message' ); + $this->statement->prepare(); + } + + /** + * If error_reporting() is turned off, then the error handler will not + * be called, but a RuntimeException will still be generated as the + * resource is false + * + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::prepare + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::setSql + */ + public function testPrepareThrowsRuntimeExceptionOnInvalidSqlWithErrorReportingDisabled() + { + $currentErrorReporting = error_reporting(0); + $sql = "INVALID SQL"; + $this->statement->setSql($sql); + + $this->setExpectedException( + RuntimeException::class, + 'Error message' + ); + $this->statement->prepare(); + + error_reporting($currentErrorReporting); } /** diff --git a/test/Adapter/Driver/IbmDb2/TestAsset/Db2Functions.php b/test/Adapter/Driver/IbmDb2/TestAsset/Db2Functions.php new file mode 100644 index 0000000000..7ac4cacec2 --- /dev/null +++ b/test/Adapter/Driver/IbmDb2/TestAsset/Db2Functions.php @@ -0,0 +1,57 @@ + Date: Fri, 20 Oct 2017 08:45:26 +0100 Subject: [PATCH 31/45] Reset error_reporting() value in tearDown --- test/Adapter/Driver/IbmDb2/StatementTest.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/Adapter/Driver/IbmDb2/StatementTest.php b/test/Adapter/Driver/IbmDb2/StatementTest.php index 8074339b18..dd40325839 100644 --- a/test/Adapter/Driver/IbmDb2/StatementTest.php +++ b/test/Adapter/Driver/IbmDb2/StatementTest.php @@ -29,6 +29,9 @@ class StatementTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { + // store current error_reporting value as we may change it + // in a test + $this->currentErrorReporting = error_reporting(); $this->statement = new Statement; } @@ -38,6 +41,8 @@ protected function setUp() */ protected function tearDown() { + // ensure error_reporting is set back to correct value + error_reporting($this->currentErrorReporting); } /** @@ -157,7 +162,7 @@ public function testPrepareThrowsRuntimeExceptionOnInvalidSql() */ public function testPrepareThrowsRuntimeExceptionOnInvalidSqlWithErrorReportingDisabled() { - $currentErrorReporting = error_reporting(0); + error_reporting(0); $sql = "INVALID SQL"; $this->statement->setSql($sql); @@ -166,8 +171,6 @@ public function testPrepareThrowsRuntimeExceptionOnInvalidSqlWithErrorReportingD 'Error message' ); $this->statement->prepare(); - - error_reporting($currentErrorReporting); } /** From 984e3553afb8f9b928a8e951ea69bf658b0a46c6 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Fri, 20 Oct 2017 08:56:00 +0100 Subject: [PATCH 32/45] Fix cs-check error --- src/Adapter/Driver/IbmDb2/Statement.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Adapter/Driver/IbmDb2/Statement.php b/src/Adapter/Driver/IbmDb2/Statement.php index 8b61f1206e..aa5ad5803f 100644 --- a/src/Adapter/Driver/IbmDb2/Statement.php +++ b/src/Adapter/Driver/IbmDb2/Statement.php @@ -10,7 +10,6 @@ namespace Zend\Db\Adapter\Driver\IbmDb2; use ErrorException; -use Throwable; use Zend\Db\Adapter\Driver\StatementInterface; use Zend\Db\Adapter\Exception; use Zend\Db\Adapter\ParameterContainer; From 313d7324cd42d867a95e4d32e0b5af658a6f80f3 Mon Sep 17 00:00:00 2001 From: Vaclav Vanik Date: Fri, 10 Nov 2017 15:28:52 +0100 Subject: [PATCH 33/45] pdo_dblib added version dsn parameter --- src/Adapter/Driver/Pdo/Connection.php | 6 ++++++ test/Adapter/Driver/Pdo/ConnectionTest.php | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Adapter/Driver/Pdo/Connection.php b/src/Adapter/Driver/Pdo/Connection.php index fe36749f57..571774e1dc 100644 --- a/src/Adapter/Driver/Pdo/Connection.php +++ b/src/Adapter/Driver/Pdo/Connection.php @@ -202,6 +202,9 @@ public function connect() case 'unix_socket': $unix_socket = (string) $value; break; + case 'version': + $version = (string) $value; + break; case 'driver_options': case 'options': $value = (array) $value; @@ -250,6 +253,9 @@ public function connect() if (isset($unix_socket)) { $dsn[] = "unix_socket={$unix_socket}"; } + if (isset($version)) { + $dsn[] = "version={$version}"; + } break; } $dsn = $pdoDriver . ':' . implode(';', $dsn); diff --git a/test/Adapter/Driver/Pdo/ConnectionTest.php b/test/Adapter/Driver/Pdo/ConnectionTest.php index 64e9ba7975..70a367a94a 100644 --- a/test/Adapter/Driver/Pdo/ConnectionTest.php +++ b/test/Adapter/Driver/Pdo/ConnectionTest.php @@ -97,4 +97,26 @@ public function testHostnameAndUnixSocketThrowsInvalidConnectionParametersExcept ]); $this->connection->connect(); } + + public function testDblibArrayOfConnectionParametersCreatesCorrectDsn() + { + $this->connection->setConnectionParameters([ + 'driver' => 'pdo_dblib', + 'charset' => 'UTF-8', + 'dbname' => 'foo', + 'port' => '1433', + 'version' => '7.3', + ]); + try { + $this->connection->connect(); + } catch (\Exception $e) { + } + $responseString = $this->connection->getDsn(); + + $this->assertStringStartsWith('dblib:', $responseString); + $this->assertContains('charset=UTF-8', $responseString); + $this->assertContains('dbname=foo', $responseString); + $this->assertContains('port=1433', $responseString); + $this->assertContains('version=7.3', $responseString); + } } From 4055ad90dd4a8a64f94a58c6b48cc394eb6aae16 Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Thu, 23 Nov 2017 14:22:29 +0100 Subject: [PATCH 34/45] Updated the CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64cd08a13e..a66faccd57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ All notable changes to this project will be documented in this file, in reverse - [#205](https://github.com/zendframework/zend-db/pull/205) fixes the spaces in ORDER BY syntax. +- [#261](https://github.com/zendframework/zend-db/pull/261) fixes Exception in + Firebird driver doesn't support lastInsertId. ## 2.8.3 - TBD From 7877c87ce46d469296b86fea01969459c7db59e9 Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Thu, 23 Nov 2017 14:25:57 +0100 Subject: [PATCH 35/45] Updated CHANGELOG --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a66faccd57..65e1df74dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ All notable changes to this project will be documented in this file, in reverse in ALTER TABLE syntax for MySQL - [#223](https://github.com/zendframework/zend-db/pull/223) added support for empty values set with IN predicate +- [#280](https://github.com/zendframework/zend-db/pull/280) added version dsn + parameter for pdo_dblib ### Deprecated @@ -22,9 +24,9 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed - [#205](https://github.com/zendframework/zend-db/pull/205) fixes the spaces in - ORDER BY syntax. + ORDER BY syntax - [#261](https://github.com/zendframework/zend-db/pull/261) fixes Exception in - Firebird driver doesn't support lastInsertId. + Firebird driver doesn't support lastInsertId ## 2.8.3 - TBD From 90552d53a92f6cd8dba71a67950832a4add23d80 Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Thu, 23 Nov 2017 14:31:04 +0100 Subject: [PATCH 36/45] Updated the CHANGELOG --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65e1df74dd..a94615d4f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ All notable changes to this project will be documented in this file, in reverse in ALTER TABLE syntax for MySQL - [#223](https://github.com/zendframework/zend-db/pull/223) added support for empty values set with IN predicate +- [#275](https://github.com/zendframework/zend-db/pull/275) added support for + LIMIT OFFSET for db2 - [#280](https://github.com/zendframework/zend-db/pull/280) added version dsn parameter for pdo_dblib @@ -26,7 +28,7 @@ All notable changes to this project will be documented in this file, in reverse - [#205](https://github.com/zendframework/zend-db/pull/205) fixes the spaces in ORDER BY syntax - [#261](https://github.com/zendframework/zend-db/pull/261) fixes Exception in - Firebird driver doesn't support lastInsertId + Firebird driver doesn't support lastInsertId ## 2.8.3 - TBD From 1730c4c6d960dbb9d0cd6aca94eee14b6c69e55a Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Thu, 23 Nov 2017 14:36:59 +0100 Subject: [PATCH 37/45] Updated CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a94615d4f6..7b615b9111 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ All notable changes to this project will be documented in this file, in reverse in ALTER TABLE syntax for MySQL - [#223](https://github.com/zendframework/zend-db/pull/223) added support for empty values set with IN predicate +- [#273](https://github.com/zendframework/zend-db/pull/273) added support for + implementing an error handler for db2_prepare - [#275](https://github.com/zendframework/zend-db/pull/275) added support for LIMIT OFFSET for db2 - [#280](https://github.com/zendframework/zend-db/pull/280) added version dsn From 0814204720b6b436ad0440e515fbf504b7a983df Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Thu, 23 Nov 2017 14:45:38 +0100 Subject: [PATCH 38/45] Updated CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b615b9111..b6b9a36ef4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ All notable changes to this project will be documented in this file, in reverse in ALTER TABLE syntax for MySQL - [#223](https://github.com/zendframework/zend-db/pull/223) added support for empty values set with IN predicate +- [#271](https://github.com/zendframework/zend-db/pull/271) added support for + dash character on MySQL identifier - [#273](https://github.com/zendframework/zend-db/pull/273) added support for implementing an error handler for db2_prepare - [#275](https://github.com/zendframework/zend-db/pull/275) added support for From f1e76accdebd540ffe69869758a02d3b2478eef9 Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Tue, 28 Nov 2017 13:52:14 +0100 Subject: [PATCH 39/45] Updated CHANGELOG --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6b9a36ef4..4bdb2f7bda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ All notable changes to this project will be documented in this file, in reverse - [#223](https://github.com/zendframework/zend-db/pull/223) added support for empty values set with IN predicate - [#271](https://github.com/zendframework/zend-db/pull/271) added support for - dash character on MySQL identifier + dash character on MySQL identifier - [#273](https://github.com/zendframework/zend-db/pull/273) added support for implementing an error handler for db2_prepare - [#275](https://github.com/zendframework/zend-db/pull/275) added support for @@ -33,6 +33,8 @@ All notable changes to this project will be documented in this file, in reverse ORDER BY syntax - [#261](https://github.com/zendframework/zend-db/pull/261) fixes Exception in Firebird driver doesn't support lastInsertId +- [#276](https://github.com/zendframework/zend-db/pull/276) fixes the support + of PHP 7.2 ## 2.8.3 - TBD From 1aceacfced20856fa6eaa4207a3841704da2294c Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Tue, 28 Nov 2017 17:50:14 +0100 Subject: [PATCH 40/45] Updated CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bdb2f7bda..5effc4fd05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,8 @@ All notable changes to this project will be documented in this file, in reverse Firebird driver doesn't support lastInsertId - [#276](https://github.com/zendframework/zend-db/pull/276) fixes the support of PHP 7.2 +- [#229](https://github.com/zendframework/zend-db/pull/229) fixes the support + of SSL for mysqli ## 2.8.3 - TBD From 507d4e272da8639babf38c8549e46fad065953ed Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Wed, 29 Nov 2017 15:58:43 +0100 Subject: [PATCH 41/45] Fixed unit tests with new PHPUnit --- test/Adapter/Driver/IbmDb2/StatementTest.php | 6 +++--- test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/test/Adapter/Driver/IbmDb2/StatementTest.php b/test/Adapter/Driver/IbmDb2/StatementTest.php index 3491b6a820..8c600219a0 100644 --- a/test/Adapter/Driver/IbmDb2/StatementTest.php +++ b/test/Adapter/Driver/IbmDb2/StatementTest.php @@ -130,7 +130,7 @@ public function testPreparingTwiceErrors() $this->statement->prepare($sql); $this->assertTrue($this->statement->isPrepared()); - $this->setExpectedException( + $this->expectException( RuntimeException::class, 'This statement has been prepared already' ); @@ -146,7 +146,7 @@ public function testPrepareThrowsRuntimeExceptionOnInvalidSql() $sql = "INVALID SQL"; $this->statement->setSql($sql); - $this->setExpectedException( + $this->expectException( RuntimeException::class, 'SQL is invalid. Error message' ); @@ -167,7 +167,7 @@ public function testPrepareThrowsRuntimeExceptionOnInvalidSqlWithErrorReportingD $sql = "INVALID SQL"; $this->statement->setSql($sql); - $this->setExpectedException( + $this->expectException( RuntimeException::class, 'Error message' ); diff --git a/test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php b/test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php index 2135a707c4..1f08097f23 100644 --- a/test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php +++ b/test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php @@ -9,13 +9,14 @@ namespace ZendTest\Db\Sql\Platform\Mysql\Ddl; +use PHPUnit\Framework\TestCase; use Zend\Db\Adapter\Platform\Mysql; use Zend\Db\Sql\Ddl\AlterTable; use Zend\Db\Sql\Ddl\Column\Column; use Zend\Db\Sql\Ddl\Constraint\PrimaryKey; use Zend\Db\Sql\Platform\Mysql\Ddl\AlterTableDecorator; -class AlterTableDecoratorTest extends \PHPUnit_Framework_TestCase +class AlterTableDecoratorTest extends TestCase { /** * @covers Zend\Db\Sql\Platform\Mysql\Ddl\AlterTableDecorator::setSubject @@ -24,7 +25,7 @@ public function testSetSubject() { $ctd = new AlterTableDecorator(); $ct = new AlterTable; - $this->assertSame($ctd, $ctd->setSubject($ct)); + self::assertSame($ctd, $ctd->setSubject($ct)); } /** @@ -45,7 +46,7 @@ public function testGetSqlString() $col->addConstraint(new PrimaryKey()); $ct->addColumn($col); - $this->assertEquals( + self::assertEquals( "ALTER TABLE `foo`\n ADD COLUMN `bar` INTEGER UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'baz' AFTER `bar`", @$ctd->getSqlString(new Mysql()) ); From f15c0f34cd1f23a1e897dd00b1b363c2032188a8 Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Thu, 30 Nov 2017 14:38:07 +0100 Subject: [PATCH 42/45] Added #255 to CHANGELOG --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1155953df..785dca0267 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,12 +31,14 @@ All notable changes to this project will be documented in this file, in reverse - [#205](https://github.com/zendframework/zend-db/pull/205) fixes the spaces in ORDER BY syntax +- [#229](https://github.com/zendframework/zend-db/pull/229) fixes the support + of SSL for mysqli +- [#255](https://github.com/zendframework/zend-db/pull/255) fixes ResultSet with + array values - [#261](https://github.com/zendframework/zend-db/pull/261) fixes Exception in Firebird driver doesn't support lastInsertId - [#276](https://github.com/zendframework/zend-db/pull/276) fixes the support of PHP 7.2 -- [#229](https://github.com/zendframework/zend-db/pull/229) fixes the support - of SSL for mysqli ## 2.8.3 - TBD From 4ccc5bc2d5d972d2dbc9b0344e0de2f52693f005 Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Thu, 30 Nov 2017 14:55:55 +0100 Subject: [PATCH 43/45] Updated CHANGELOG with #287 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 785dca0267..53d2aa4b29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,8 @@ All notable changes to this project will be documented in this file, in reverse Firebird driver doesn't support lastInsertId - [#276](https://github.com/zendframework/zend-db/pull/276) fixes the support of PHP 7.2 +- [#287](https://github.com/zendframework/zend-db/pull/287) fixes the usage of + count() with PHP 7.2 ## 2.8.3 - TBD From 541f696109c63378570d62f842b3d8716560ed35 Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Tue, 5 Dec 2017 15:02:57 +0100 Subject: [PATCH 44/45] Fixed CS issues --- src/Adapter/Driver/Sqlsrv/Statement.php | 2 +- .../Driver/Sqlsrv/SqlSrvIntegrationTest.php | 5 ++- test/Adapter/Platform/MysqlTest.php | 45 +++++++++++++++---- .../Platform/IbmDb2/SelectDecoratorTest.php | 9 +++- .../Mysql/Ddl/AlterTableDecoratorTest.php | 3 +- 5 files changed, 50 insertions(+), 14 deletions(-) diff --git a/src/Adapter/Driver/Sqlsrv/Statement.php b/src/Adapter/Driver/Sqlsrv/Statement.php index a0486e3ab7..ffc922acd9 100644 --- a/src/Adapter/Driver/Sqlsrv/Statement.php +++ b/src/Adapter/Driver/Sqlsrv/Statement.php @@ -211,7 +211,7 @@ public function prepare($sql = null, array $options = []) $pRef = &$this->parameterReferences; for ($position = 0, $count = substr_count($sql, '?'); $position < $count; $position++) { - if (!isset($this->prepareParams[$position])) { + if (! isset($this->prepareParams[$position])) { $pRef[$position] = [&$this->parameterReferenceValues[$position], SQLSRV_PARAM_IN, null, null]; } else { $pRef[$position] = &$this->prepareParams[$position]; diff --git a/test/Adapter/Driver/Sqlsrv/SqlSrvIntegrationTest.php b/test/Adapter/Driver/Sqlsrv/SqlSrvIntegrationTest.php index 72b2c3102a..33f9e5adba 100644 --- a/test/Adapter/Driver/Sqlsrv/SqlSrvIntegrationTest.php +++ b/test/Adapter/Driver/Sqlsrv/SqlSrvIntegrationTest.php @@ -53,7 +53,10 @@ public function testCreateStatement() $stmt = $this->driver->createStatement(); $this->assertInstanceOf('Zend\Db\Adapter\Driver\Sqlsrv\Statement', $stmt); - $this->setExpectedException('Zend\Db\Adapter\Exception\InvalidArgumentException', 'only accepts an SQL string or a Sqlsrv resource'); + $this->setExpectedException( + 'Zend\Db\Adapter\Exception\InvalidArgumentException', + 'only accepts an SQL string or a Sqlsrv resource' + ); $this->driver->createStatement(new \stdClass); } diff --git a/test/Adapter/Platform/MysqlTest.php b/test/Adapter/Platform/MysqlTest.php index 9f93655a5c..a5d8782ffc 100644 --- a/test/Adapter/Platform/MysqlTest.php +++ b/test/Adapter/Platform/MysqlTest.php @@ -163,10 +163,22 @@ public function testQuoteIdentifierInFragment() $this->platform->quoteIdentifierInFragment('cmis:$TableName as cmis:TableAlias') ); - $this->assertEquals('`foo-bar`.`bar-foo`', $this->platform->quoteIdentifierInFragment('foo-bar.bar-foo')); - $this->assertEquals('`foo-bar` as `bar-foo`', $this->platform->quoteIdentifierInFragment('foo-bar as bar-foo')); - $this->assertEquals('`$TableName-$ColumnName`.`bar-foo`', $this->platform->quoteIdentifierInFragment('$TableName-$ColumnName.bar-foo')); - $this->assertEquals('`cmis:$TableName-$ColumnName` as `cmis:TableAlias-ColumnAlias`', $this->platform->quoteIdentifierInFragment('cmis:$TableName-$ColumnName as cmis:TableAlias-ColumnAlias')); + $this->assertEquals( + '`foo-bar`.`bar-foo`', + $this->platform->quoteIdentifierInFragment('foo-bar.bar-foo') + ); + $this->assertEquals( + '`foo-bar` as `bar-foo`', + $this->platform->quoteIdentifierInFragment('foo-bar as bar-foo') + ); + $this->assertEquals( + '`$TableName-$ColumnName`.`bar-foo`', + $this->platform->quoteIdentifierInFragment('$TableName-$ColumnName.bar-foo') + ); + $this->assertEquals( + '`cmis:$TableName-$ColumnName` as `cmis:TableAlias-ColumnAlias`', + $this->platform->quoteIdentifierInFragment('cmis:$TableName-$ColumnName as cmis:TableAlias-ColumnAlias') + ); // single char words self::assertEquals( @@ -179,9 +191,18 @@ public function testQuoteIdentifierInFragment() ); self::assertEquals('`foo`=`bar`', $this->platform->quoteIdentifierInFragment('foo=bar', ['='])); - $this->assertEquals('(`foo-bar`.`bar-foo` = `boo-baz`.`baz-boo`)', $this->platform->quoteIdentifierInFragment('(foo-bar.bar-foo = boo-baz.baz-boo)', ['(', ')', '='])); - $this->assertEquals('(`foo-bar`.`bar-foo`=`boo-baz`.`baz-boo`)', $this->platform->quoteIdentifierInFragment('(foo-bar.bar-foo=boo-baz.baz-boo)', ['(', ')', '='])); - $this->assertEquals('`foo-bar`=`bar-foo`', $this->platform->quoteIdentifierInFragment('foo-bar=bar-foo', ['='])); + $this->assertEquals( + '(`foo-bar`.`bar-foo` = `boo-baz`.`baz-boo`)', + $this->platform->quoteIdentifierInFragment('(foo-bar.bar-foo = boo-baz.baz-boo)', ['(', ')', '=']) + ); + $this->assertEquals( + '(`foo-bar`.`bar-foo`=`boo-baz`.`baz-boo`)', + $this->platform->quoteIdentifierInFragment('(foo-bar.bar-foo=boo-baz.baz-boo)', ['(', ')', '=']) + ); + $this->assertEquals( + '`foo-bar`=`bar-foo`', + $this->platform->quoteIdentifierInFragment('foo-bar=bar-foo', ['=']) + ); // case insensitive safe words self::assertEquals( @@ -194,7 +215,10 @@ public function testQuoteIdentifierInFragment() $this->assertEquals( '(`foo-bar`.`bar-foo` = `boo-baz`.`baz-boo`) AND (`foo-baz`.`baz-foo` = `boo-baz`.`baz-boo`)', - $this->platform->quoteIdentifierInFragment('(foo-bar.bar-foo = boo-baz.baz-boo) AND (foo-baz.baz-foo = boo-baz.baz-boo)', ['(', ')', '=', 'and']) + $this->platform->quoteIdentifierInFragment( + '(foo-bar.bar-foo = boo-baz.baz-boo) AND (foo-baz.baz-foo = boo-baz.baz-boo)', + ['(', ')', '=', 'and'] + ) ); // case insensitive safe words in field @@ -209,7 +233,10 @@ public function testQuoteIdentifierInFragment() // case insensitive safe words in field $this->assertEquals( '(`foo-bar`.`bar-foo` = `boo-baz`.baz-boo) AND (`foo-baz`.`baz-foo` = `boo-baz`.baz-boo)', - $this->platform->quoteIdentifierInFragment('(foo-bar.bar-foo = boo-baz.baz-boo) AND (foo-baz.baz-foo = boo-baz.baz-boo)', ['(', ')', '=', 'and', 'bAz-BOo']) + $this->platform->quoteIdentifierInFragment( + '(foo-bar.bar-foo = boo-baz.baz-boo) AND (foo-baz.baz-foo = boo-baz.baz-boo)', + ['(', ')', '=', 'and', 'bAz-BOo'] + ) ); } } diff --git a/test/Sql/Platform/IbmDb2/SelectDecoratorTest.php b/test/Sql/Platform/IbmDb2/SelectDecoratorTest.php index 2a81d71de8..1ad37267a4 100644 --- a/test/Sql/Platform/IbmDb2/SelectDecoratorTest.php +++ b/test/Sql/Platform/IbmDb2/SelectDecoratorTest.php @@ -26,8 +26,13 @@ class SelectDecoratorTest extends TestCase * @covers \Zend\Db\Sql\Platform\SqlServer\SelectDecorator::processLimitOffset * @dataProvider dataProvider */ - public function testPrepareStatement(Select $select, $expectedPrepareSql, $expectedParams, $notUsed, $supportsLimitOffset) - { + public function testPrepareStatement( + Select $select, + $expectedPrepareSql, + $expectedParams, + $notUsed, + $supportsLimitOffset + ) { $driver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); $driver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); diff --git a/test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php b/test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php index 1f08097f23..5be80ff688 100644 --- a/test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php +++ b/test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php @@ -47,7 +47,8 @@ public function testGetSqlString() $ct->addColumn($col); self::assertEquals( - "ALTER TABLE `foo`\n ADD COLUMN `bar` INTEGER UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'baz' AFTER `bar`", + "ALTER TABLE `foo`\n ADD COLUMN `bar` INTEGER UNSIGNED ZEROFILL " . + "NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'baz' AFTER `bar`", @$ctd->getSqlString(new Mysql()) ); } From 83dbe94b69337499b0ab63f4ce3af2fd29f8ba3f Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Tue, 5 Dec 2017 17:27:53 +0100 Subject: [PATCH 45/45] Removed IbmDb2 test file from phpcs --- phpcs.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/phpcs.xml b/phpcs.xml index 9e6a751166..9a2cd69887 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,6 +1,9 @@  - + + + */test/Adapter/Driver/IbmDb2/StatementTest.php + src