Skip to content

Commit b8b3fc8

Browse files
committed
Merge branch '1.x'
2 parents 0386318 + f23df0c commit b8b3fc8

File tree

7 files changed

+47
-18
lines changed

7 files changed

+47
-18
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ about what to do between and after queries.
1414
An object `Jelix\Database\Log\QueryLogger` is provided, implementing this
1515
interface, and can use a `Psr\Log\LoggerInterface` object.
1616

17+
Version 1.3.2
18+
-------------
19+
20+
- Fix Sqlite3 jDb driver: it must not free results if connection is already closed
21+
1722
Version 1.3.1
1823
-------------
1924

src/AbstractConnection.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Laurent Jouanneau, Gerald Croes
44
* @contributor Julien Issler
55
*
6-
* @copyright 2005-2023 Laurent Jouanneau
6+
* @copyright 2005-2024 Laurent Jouanneau
77
* @copyright 2007-2009 Julien Issler
88
* @copyright 2001-2005 CopixTeam
99
* This class was get originally from the Copix project (CopixDbConnection, Copix 2.3dev20050901, http://www.copix.org)
@@ -73,9 +73,7 @@ public function __construct($profile)
7373

7474
public function __destruct()
7575
{
76-
if ($this->_connection !== null) {
77-
$this->_disconnect();
78-
}
76+
$this->close();
7977
}
8078

8179
/**
@@ -87,9 +85,19 @@ public function close()
8785
{
8886
if ($this->_connection !== null) {
8987
$this->_disconnect();
88+
$this->_connection = null;
9089
}
9190
}
9291

92+
/**
93+
* @since 1.8.8
94+
* @return bool
95+
*/
96+
public function isClosed()
97+
{
98+
return ($this->_connection == null) ;
99+
}
100+
93101
/**
94102
* Support of old previous public properties to keep compatibility with Jelix 1.x
95103
* @param string $name

src/Connection.php

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public static function getTools($dbType, $connection = null)
7474
$tools = new Schema\Oci\SQLTools($connection);
7575
break;
7676
default:
77-
$tools = null;
7877
throw new Exception("not implemented");
7978
}
8079
return $tools;

src/Connector/Mysqli/Connection.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @contributor Sylvain de Vathaire, Julien Issler
77
* @contributor Florian Lonqueu-Brochard
88
*
9-
* @copyright 2001-2005 CopixTeam, 2005-2023 Laurent Jouanneau, 2009 Julien Issler, 2012 Florian Lonqueu-Brochard
9+
* @copyright 2001-2005 CopixTeam, 2005-2024 Laurent Jouanneau, 2009 Julien Issler, 2012 Florian Lonqueu-Brochard
1010
*
1111
* @see https://jelix.org
1212
* @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
@@ -157,7 +157,7 @@ protected function _doQuery($query)
157157

158158
protected function _doExec($query)
159159
{
160-
if ($qI = $this->_connection->query($query)) {
160+
if ($this->_connection->query($query)) {
161161
return $this->_connection->affected_rows;
162162
}
163163

src/Connector/SQLite3/Connection.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Loic Mathaud
44
* @contributor Laurent Jouanneau
55
*
6-
* @copyright 2006 Loic Mathaud, 2007-2023 Laurent Jouanneau
6+
* @copyright 2006 Loic Mathaud, 2007-2024 Laurent Jouanneau
77
*
88
* @see https://jelix.org
99
* @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
@@ -59,7 +59,7 @@ public function prepare($query, $driverOptions = [])
5959
{
6060
$res = $this->_connection->prepare($query);
6161
if ($res) {
62-
$rs = new ResultSet(null, $res);
62+
$rs = new ResultSet(null, $res, $this);
6363
} else {
6464
throw new Exception('invalid query: '.$this->_connection->error.'('.$query.')', 403);
6565
}
@@ -117,14 +117,14 @@ protected function _disconnect()
117117
protected function _doQuery($query)
118118
{
119119
if ($qI = $this->_connection->query($query)) {
120-
return new ResultSet($qI);
120+
return new ResultSet($qI, null, $this);
121121
}
122122
throw new Exception('invalid query: '.$this->_connection->lastErrorMsg().' ('.$query.')', 403);
123123
}
124124

125125
protected function _doExec($query)
126126
{
127-
if ($qI = $this->_connection->exec($query)) {
127+
if ($this->_connection->exec($query)) {
128128
return $this->_connection->changes();
129129
}
130130

src/Connector/SQLite3/ResultSet.php

+17-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Loic Mathaud
44
* @contributor Laurent Jouanneau
55
*
6-
* @copyright 2006 Loic Mathaud, 2008-2023 Laurent Jouanneau
6+
* @copyright 2006 Loic Mathaud, 2008-2024 Laurent Jouanneau
77
*
88
* @see http://www.jelix.org
99
* @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
@@ -28,6 +28,11 @@ class ResultSet extends AbstractResultSet
2828
*/
2929
protected $_idResult;
3030

31+
/**
32+
* @var Connection
33+
*/
34+
protected $_conn;
35+
3136
/**
3237
* number of rows.
3338
*/
@@ -46,15 +51,16 @@ class ResultSet extends AbstractResultSet
4651
*/
4752
protected $buffer = array();
4853

49-
5054
/**
51-
* @param \SQLite3Result $result
52-
* @param \SQLite3Stmt $stmt
55+
* @param \SQLite3Result|null $result
56+
* @param \SQLite3Stmt|null $stmt
57+
* @param Connection
5358
*/
54-
public function __construct($result, $stmt = null)
59+
public function __construct($result, $stmt, $conn)
5560
{
5661
parent::__construct($result);
5762
$this->_stmt = $stmt;
63+
$this->_conn = $conn;
5864
}
5965

6066
protected function _fetch()
@@ -100,7 +106,12 @@ protected function _free()
100106
$this->numRows = 0;
101107
$this->buffer = array();
102108
$this->ended = false;
103-
$this->_idResult->finalize();
109+
// finalize may lead to an error if connection has been closed before
110+
// the resultset object destruction.
111+
if ($this->_conn && !$this->_conn->isClosed()) {
112+
$this->_idResult->finalize();
113+
}
114+
$this->_conn = null;
104115
}
105116

106117
protected function _rewind()

tests/docker-conf/php/Dockerfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ ARG msphpsql_version=5.12.0-beta1
88
ARG DEBIAN_FRONTEND=noninteractive
99
ENV PHP_VERSION=${php_version}
1010

11+
RUN apt-get update; apt-get upgrade; \
12+
apt-get install \
13+
php${PHP_VERSION}-xdebug \
14+
; apt-get clean;
15+
1116
# Install drivers to access to SQL server
1217
# see https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15#debian18
1318
# see https://github.com/microsoft/msphpsql/releases
@@ -25,7 +30,8 @@ RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -; \
2530
printf "; priority=20\nextension=php_sqlsrv_${shrinkphpversion}_nts.so\n" > /etc/php/${PHP_VERSION}/mods-available/sqlsrv.ini; \
2631
printf "; priority=30\nextension=php_pdo_sqlsrv_${shrinkphpversion}_nts.so\n" > /etc/php/${PHP_VERSION}/mods-available/pdo_sqlsrv.ini; \
2732
phpenmod -v ${PHP_VERSION} sqlsrv pdo_sqlsrv; \
28-
rm -rf /tmp/msodbcsql.deb /tmp/debsqlsrv.tar /tmp/Debian${debian_version_num}-${PHP_VERSION};
33+
rm -rf /tmp/msodbcsql.deb /tmp/debsqlsrv.tar /tmp/Debian${debian_version_num}-${PHP_VERSION}; \
34+
apt-get clean;
2935

3036
COPY database-entrypoint.sh /bin/entrypoint.d/
3137
COPY appctl.sh /bin/

0 commit comments

Comments
 (0)