summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2022-01-05 19:28:27 +0100
committerAndrey Andreev <narf@devilix.net>2022-01-05 19:28:27 +0100
commitf43bd73f6360f9d15a89527614c9ff696825ce99 (patch)
tree66d2009ccd98c7df4b3d97c86ec9e3c23156923e /system
parent3d9c9e6f9fed47332a094cc6a359e4f377357804 (diff)
[ci skip] An attempt at a better solution for #5896
Diffstat (limited to 'system')
-rw-r--r--system/database/drivers/oci8/oci8_driver.php44
-rw-r--r--system/database/drivers/oci8/oci8_result.php15
2 files changed, 50 insertions, 9 deletions
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index 8617a4ebe..16646efea 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -85,6 +85,26 @@ class CI_DB_oci8_driver extends CI_DB {
*/
public $limit_used = FALSE;
+ /**
+ * Error cache
+ *
+ * Cached error info about failed queries.
+ * Used so that statement IDs can be released immediately.
+ *
+ * @var array|false
+ */
+ protected $_error = FALSE;
+
+ /**
+ * Affected rows
+ *
+ * Cached result of oci_num_rows().
+ * Used so that statement IDs can be released immediately.
+ *
+ * @var int|false
+ */
+ protected $_affected_rows = FALSE;
+
// --------------------------------------------------------------------
/**
@@ -257,12 +277,17 @@ class CI_DB_oci8_driver extends CI_DB {
*/
$this->result_id = oci_parse($this->conn_id, $sql);
oci_set_prefetch($this->result_id, 1000);
- if (oci_execute($this->result_id, $this->commit_mode))
+ $result = oci_execute($this->result_id, $this->commit_mode);
+ $this->_error = oci_error($this->result_id);
+ $this->is_write_type($sql) && $this->_affected_rows = oci_num_rows($this->result_id);
+
+ if ($this->is_write_type($sql) OR $result === FALSE)
{
- return $this->result_id;
+ oci_free_statement($this->result_id);
+ return $result;
}
- return FALSE;
+ return $this->result_id;
}
// --------------------------------------------------------------------
@@ -314,7 +339,7 @@ class CI_DB_oci8_driver extends CI_DB {
*/
public function affected_rows()
{
- return oci_num_rows($this->result_id);
+ return $this->_affected_rows;
}
// --------------------------------------------------------------------
@@ -447,14 +472,15 @@ class CI_DB_oci8_driver extends CI_DB {
*/
public function error()
{
+ if ( ! empty($this->_error))
+ {
+ return $this->_error;
+ }
+
// oci_error() returns an array that already contains
// 'code' and 'message' keys, but it can return false
// if there was no error ....
- if (is_resource($this->result_id))
- {
- $error = oci_error($this->result_id);
- }
- elseif (is_resource($this->conn_id))
+ if (is_resource($this->conn_id))
{
$error = oci_error($this->conn_id);
}
diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php
index cf0b33d26..0d57d9428 100644
--- a/system/database/drivers/oci8/oci8_result.php
+++ b/system/database/drivers/oci8/oci8_result.php
@@ -196,4 +196,19 @@ class CI_DB_oci8_result extends CI_DB_result {
return $class_name;
}
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Destructor
+ *
+ * Attempt to free remaining statement IDs.
+ *
+ * @see https://github.com/bcit-ci/CodeIgniter/pull/5896
+ * @return void
+ */
+ public function __destruct()
+ {
+ $this->free_result();
+ }
}