Skip to content

Commit 1cb7e5b

Browse files
committed
feat: Abstract method and database dependants versions of the "close" method
1 parent fd3b230 commit 1cb7e5b

File tree

7 files changed

+92
-11
lines changed

7 files changed

+92
-11
lines changed

phpstan-baseline.neon.dist

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,15 @@ parameters:
256256
path: system/Database/MySQLi/PreparedQuery.php
257257

258258
-
259-
message: "#^Property CodeIgniter\\\\Database\\\\BasePreparedQuery\\:\\:\\$statement \\(object\\|resource\\) in isset\\(\\) is not nullable\\.$#"
259+
message: "#^Cannot call method close\\(\\) on object\\|resource\\.$#"
260260
count: 1
261261
path: system/Database/MySQLi/PreparedQuery.php
262262

263+
-
264+
message: "#^Property CodeIgniter\\\\Database\\\\BasePreparedQuery\\:\\:\\$statement \\(object\\|resource\\) in isset\\(\\) is not nullable\\.$#"
265+
count: 2
266+
path: system/Database/MySQLi/PreparedQuery.php
267+
263268
-
264269
message: "#^Cannot access property \\$field_count on object\\|resource\\|false\\.$#"
265270
count: 1
@@ -307,7 +312,7 @@ parameters:
307312

308313
-
309314
message: "#^Property CodeIgniter\\\\Database\\\\BasePreparedQuery\\:\\:\\$statement \\(object\\|resource\\) in isset\\(\\) is not nullable\\.$#"
310-
count: 1
315+
count: 2
311316
path: system/Database/Postgre/PreparedQuery.php
312317

313318
-
@@ -322,7 +327,7 @@ parameters:
322327

323328
-
324329
message: "#^Property CodeIgniter\\\\Database\\\\BasePreparedQuery\\:\\:\\$statement \\(object\\|resource\\) in isset\\(\\) is not nullable\\.$#"
325-
count: 1
330+
count: 2
326331
path: system/Database/SQLSRV/PreparedQuery.php
327332

328333
-
@@ -391,10 +396,15 @@ parameters:
391396
path: system/Database/SQLite3/PreparedQuery.php
392397

393398
-
394-
message: "#^Property CodeIgniter\\\\Database\\\\BasePreparedQuery\\:\\:\\$statement \\(object\\|resource\\) in isset\\(\\) is not nullable\\.$#"
399+
message: "#^Cannot call method close\\(\\) on object\\|resource\\.$#"
395400
count: 1
396401
path: system/Database/SQLite3/PreparedQuery.php
397402

403+
-
404+
message: "#^Property CodeIgniter\\\\Database\\\\BasePreparedQuery\\:\\:\\$statement \\(object\\|resource\\) in isset\\(\\) is not nullable\\.$#"
405+
count: 2
406+
path: system/Database/SQLite3/PreparedQuery.php
407+
398408
-
399409
message: "#^Cannot call method columnName\\(\\) on object\\|resource\\|false\\.$#"
400410
count: 2

system/Database/BasePreparedQuery.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,18 @@ abstract public function _execute(array $data): bool;
140140
abstract public function _getResult();
141141

142142
/**
143-
* Explicitly closes the statement.
143+
* Explicitly closes the prepared statement.
144144
*/
145-
public function close()
145+
public function close(): bool
146146
{
147-
if (! is_object($this->statement) || ! method_exists($this->statement, 'close')) {
148-
return;
149-
}
150-
151-
$this->statement->close();
147+
return $this->_close();
152148
}
153149

150+
/**
151+
* The database dependant version of the close method.
152+
*/
153+
abstract public function _close(): bool;
154+
154155
/**
155156
* Returns the SQL that has been prepared.
156157
*/

system/Database/MySQLi/PreparedQuery.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,18 @@ public function _getResult()
8484
{
8585
return $this->statement->get_result();
8686
}
87+
88+
/**
89+
* Deallocate prepared statements
90+
*/
91+
public function _close(): bool
92+
{
93+
$error = true;
94+
if (isset($this->statement)) {
95+
$error = $this->statement->close();
96+
unset($this->statement);
97+
}
98+
99+
return $error;
100+
}
87101
}

system/Database/OCI8/PreparedQuery.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ public function _getResult()
9393
return $this->statement;
9494
}
9595

96+
/**
97+
* Deallocate prepared statements
98+
*/
99+
public function _close(): bool
100+
{
101+
$error = true;
102+
if (null !== $this->statement) {
103+
$error = oci_free_statement($this->statement);
104+
unset($this->statement);
105+
}
106+
107+
return $error;
108+
}
109+
96110
/**
97111
* Replaces the ? placeholders with :0, :1, etc parameters for use
98112
* within the prepared query.

system/Database/Postgre/PreparedQuery.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ public function _getResult()
9393
return $this->result;
9494
}
9595

96+
/**
97+
* Deallocate prepared statements
98+
*/
99+
public function _close(): bool
100+
{
101+
$error = true;
102+
if (isset($this->statement)) {
103+
$error = (bool) pg_query($this->db->connID, 'DEALLOCATE ' . $this->name);
104+
unset($this->statement);
105+
}
106+
107+
return $error;
108+
}
109+
96110
/**
97111
* Replaces the ? placeholders with $1, $2, etc parameters for use
98112
* within the prepared query.

system/Database/SQLSRV/PreparedQuery.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ public function _getResult()
9595
return $this->result;
9696
}
9797

98+
/**
99+
* Deallocate prepared statements
100+
*/
101+
public function _close(): bool
102+
{
103+
$error = true;
104+
if (isset($this->statement)) {
105+
$error = sqlsrv_free_stmt($this->statement);
106+
unset($this->statement);
107+
}
108+
109+
return $error;
110+
}
111+
98112
/**
99113
* Handle parameters
100114
*/

system/Database/SQLite3/PreparedQuery.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,18 @@ public function _getResult()
8888
{
8989
return $this->result;
9090
}
91+
92+
/**
93+
* Deallocate prepared statements
94+
*/
95+
public function _close(): bool
96+
{
97+
$error = true;
98+
if (isset($this->statement)) {
99+
$error = $this->statement->close();
100+
unset($this->statement);
101+
}
102+
103+
return $error;
104+
}
91105
}

0 commit comments

Comments
 (0)