Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 6113b68

Browse files
committed
Merge branch 'develop'
2 parents ab1f2e8 + 83dbe94 commit 6113b68

File tree

20 files changed

+468
-33
lines changed

20 files changed

+468
-33
lines changed

CHANGELOG.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,46 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 2.9.0 - TBD
6+
7+
### Added
8+
9+
- [#216](https://github.com/zendframework/zend-db/pull/216) added AFTER support
10+
in ALTER TABLE syntax for MySQL
11+
- [#223](https://github.com/zendframework/zend-db/pull/223) added support for
12+
empty values set with IN predicate
13+
- [#271](https://github.com/zendframework/zend-db/pull/271) added support for
14+
dash character on MySQL identifier
15+
- [#273](https://github.com/zendframework/zend-db/pull/273) added support for
16+
implementing an error handler for db2_prepare
17+
- [#275](https://github.com/zendframework/zend-db/pull/275) added support for
18+
LIMIT OFFSET for db2
19+
- [#280](https://github.com/zendframework/zend-db/pull/280) added version dsn
20+
parameter for pdo_dblib
21+
22+
### Deprecated
23+
24+
- Nothing.
25+
26+
### Removed
27+
28+
- Nothing.
29+
30+
### Fixed
31+
32+
- [#205](https://github.com/zendframework/zend-db/pull/205) fixes the spaces in
33+
ORDER BY syntax
34+
- [#229](https://github.com/zendframework/zend-db/pull/229) fixes the support
35+
of SSL for mysqli
36+
- [#255](https://github.com/zendframework/zend-db/pull/255) fixes ResultSet with
37+
array values
38+
- [#261](https://github.com/zendframework/zend-db/pull/261) fixes Exception in
39+
Firebird driver doesn't support lastInsertId
40+
- [#276](https://github.com/zendframework/zend-db/pull/276) fixes the support
41+
of PHP 7.2
42+
- [#287](https://github.com/zendframework/zend-db/pull/287) fixes the usage of
43+
count() with PHP 7.2
44+
545
## 2.8.3 - TBD
646

747
### Added

docs/book/sql.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,16 @@ $select->columns(['foo', 'bar']);
161161

162162
// As an associative array with aliases as the keys
163163
// (produces 'bar' AS 'foo', 'bax' AS 'baz')
164-
$select->columns(['foo' => 'bar', 'baz' => 'bax']);
164+
$select->columns([
165+
'foo' => 'bar',
166+
'baz' => 'bax'
167+
]);
168+
169+
// Sql function call on the column
170+
// (produces CONCAT_WS('/', 'bar', 'bax') AS 'foo')
171+
$select->columns([
172+
'foo' => new \Zend\Db\Sql\Expression("CONCAT_WS('/', 'bar', 'bax')")
173+
]);
165174
```
166175

167176
### join()

phpcs.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?xml version="1.0"?>
22
<ruleset name="Zend Framework coding standard">
3-
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>
3+
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml" />
4+
<rule ref="PSR1.Files.SideEffects">
5+
<exclude-pattern>*/test/Adapter/Driver/IbmDb2/StatementTest.php</exclude-pattern>
6+
</rule>
47

58
<!-- Paths to check -->
69
<file>src</file>

src/Adapter/Driver/IbmDb2/Statement.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Zend\Db\Adapter\Driver\IbmDb2;
1111

12+
use ErrorException;
1213
use Zend\Db\Adapter\Driver\StatementInterface;
1314
use Zend\Db\Adapter\Exception;
1415
use Zend\Db\Adapter\ParameterContainer;
@@ -172,7 +173,14 @@ public function prepare($sql = null)
172173
$sql = $this->sql;
173174
}
174175

175-
$this->resource = db2_prepare($this->db2, $sql);
176+
try {
177+
set_error_handler($this->createErrorHandler());
178+
$this->resource = db2_prepare($this->db2, $sql);
179+
} catch (ErrorException $e) {
180+
throw new Exception\RuntimeException($e->getMessage() . '. ' . db2_stmt_errormsg(), db2_stmt_error(), $e);
181+
} finally {
182+
restore_error_handler();
183+
}
176184

177185
if ($this->resource === false) {
178186
throw new Exception\RuntimeException(db2_stmt_errormsg(), db2_stmt_error());
@@ -239,4 +247,31 @@ public function execute($parameters = null)
239247
$result = $this->driver->createResult($this->resource);
240248
return $result;
241249
}
250+
251+
/**
252+
* Creates and returns a callable error handler that raises exceptions.
253+
*
254+
* Only raises exceptions for errors that are within the error_reporting mask.
255+
*
256+
* @return callable
257+
*/
258+
private function createErrorHandler()
259+
{
260+
/**
261+
* @param int $errno
262+
* @param string $errstr
263+
* @param string $errfile
264+
* @param int $errline
265+
* @return void
266+
* @throws ErrorException if error is not within the error_reporting mask.
267+
*/
268+
return function ($errno, $errstr, $errfile, $errline) {
269+
if (! (error_reporting() & $errno)) {
270+
// error_reporting does not include this error
271+
return;
272+
}
273+
274+
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
275+
};
276+
}
242277
}

src/Adapter/Driver/Mysqli/Result.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,10 @@ public function key()
279279
*/
280280
public function rewind()
281281
{
282-
if ($this->position !== 0) {
283-
if ($this->isBuffered === false) {
284-
throw new Exception\RuntimeException('Unbuffered results cannot be rewound for multiple iterations');
285-
}
282+
if (0 !== $this->position && false === $this->isBuffered) {
283+
throw new Exception\RuntimeException('Unbuffered results cannot be rewound for multiple iterations');
286284
}
285+
287286
$this->resource->data_seek(0); // works for both mysqli_result & mysqli_stmt
288287
$this->currentComplete = false;
289288
$this->position = 0;

src/Adapter/Driver/Pdo/Connection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ public function connect()
202202
case 'unix_socket':
203203
$unix_socket = (string) $value;
204204
break;
205+
case 'version':
206+
$version = (string) $value;
207+
break;
205208
case 'driver_options':
206209
case 'options':
207210
$value = (array) $value;
@@ -250,6 +253,9 @@ public function connect()
250253
if (isset($unix_socket)) {
251254
$dsn[] = "unix_socket={$unix_socket}";
252255
}
256+
if (isset($version)) {
257+
$dsn[] = "version={$version}";
258+
}
253259
break;
254260
}
255261
$dsn = $pdoDriver . ':' . implode(';', $dsn);

src/Adapter/Platform/AbstractPlatform.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ abstract class AbstractPlatform implements PlatformInterface
2626
*/
2727
protected $quoteIdentifiers = true;
2828

29+
/**
30+
* @var string
31+
*/
32+
protected $quoteIdentifierFragmentPattern = '/([^0-9,a-z,A-Z$_:])/i';
33+
2934
/**
3035
* {@inheritDoc}
3136
*/
@@ -42,7 +47,7 @@ public function quoteIdentifierInFragment($identifier, array $safeWords = [])
4247
}
4348

4449
$parts = preg_split(
45-
'/([^0-9,a-z,A-Z$_:])/i',
50+
$this->quoteIdentifierFragmentPattern,
4651
$identifier,
4752
-1,
4853
PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY

src/Adapter/Platform/Mysql.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ class Mysql extends AbstractPlatform
3131
*/
3232
protected $resource = null;
3333

34+
/**
35+
* NOTE: Include dashes for MySQL only, need tests for others platforms
36+
*
37+
* @var string
38+
*/
39+
protected $quoteIdentifierFragmentPattern = '/([^0-9,a-z,A-Z$_\-:])/i';
40+
3441
/**
3542
* @param null|\Zend\Db\Adapter\Driver\Mysqli\Mysqli|\Zend\Db\Adapter\Driver\Pdo\Pdo|\mysqli|\PDO $driver
3643
*/

src/Sql/Platform/IbmDb2/SelectDecorator.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ class SelectDecorator extends Select implements PlatformDecoratorInterface
2727
*/
2828
protected $subject = null;
2929

30-
/**
30+
/**
31+
* @var bool
32+
*/
33+
protected $supportsLimitOffset = false;
34+
35+
36+
/**
3137
* @return bool
3238
*/
3339
public function getIsSelectContainDistinct()
@@ -51,6 +57,22 @@ public function setSubject($select)
5157
$this->subject = $select;
5258
}
5359

60+
/**
61+
* @return bool
62+
*/
63+
public function getSupportsLimitOffset()
64+
{
65+
return $this->supportsLimitOffset;
66+
}
67+
68+
/**
69+
* @param bool $supportsLimitOffset
70+
*/
71+
public function setSupportsLimitOffset($supportsLimitOffset)
72+
{
73+
$this->supportsLimitOffset = $supportsLimitOffset;
74+
}
75+
5476
/**
5577
* @see Select::renderTable
5678
*/
@@ -87,6 +109,23 @@ protected function processLimitOffset(
87109
return;
88110
}
89111

112+
if ($this->supportsLimitOffset) {
113+
// Note: db2_prepare/db2_execute fails with positional parameters, for LIMIT & OFFSET
114+
$limit = (int) $this->limit;
115+
if (! $limit) {
116+
return;
117+
}
118+
119+
$offset = (int) $this->offset;
120+
if ($offset) {
121+
array_push($sqls, sprintf("LIMIT %s OFFSET %s", $limit, $offset));
122+
return;
123+
}
124+
125+
array_push($sqls, sprintf("LIMIT %s", $limit));
126+
return;
127+
}
128+
90129
$selectParameters = $parameters[self::SELECT];
91130

92131
$starSuffix = $platform->getIdentifierSeparator() . self::SQL_STAR;

src/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class AlterTableDecorator extends AlterTable implements PlatformDecoratorInterfa
3333
'columnformat' => 4,
3434
'format' => 4,
3535
'storage' => 5,
36+
'after' => 6
3637
];
3738

3839
/**
@@ -130,6 +131,9 @@ protected function processAddColumns(PlatformInterface $adapterPlatform = null)
130131
$insert = ' STORAGE ' . strtoupper($coValue);
131132
$j = 2;
132133
break;
134+
case 'after':
135+
$insert = ' AFTER ' . $adapterPlatform->quoteIdentifier($coValue);
136+
$j = 2;
133137
}
134138

135139
if ($insert) {

0 commit comments

Comments
 (0)