MDL-52544 oracle: small tweaks

This commit just:

- Moves the null => '' to better place, restricting it to PHP >= 7.0
  (bug https://bugs.php.net/bug.php?id=72524)
- Adds a couple of notes here and there.
- Changes some small details to keep the file using the same coding.
This commit is contained in:
Eloy Lafuente (stronk7) 2016-07-19 01:48:02 +02:00
parent 74ec2dd63d
commit 5281e6a082

View File

@ -774,8 +774,6 @@ class oci_native_moodle_database extends moodle_database {
return ' ';
} else if (is_bool($value)) {
return (int)$value;
} else if (is_null($value)) {
return '';
} else {
return $value;
}
@ -788,8 +786,6 @@ class oci_native_moodle_database extends moodle_database {
return ' ';
} else if (is_bool($value)) {
return (int)$value;
} else if (is_null($value)) {
return '';
} else {
return $value;
}
@ -859,9 +855,6 @@ class oci_native_moodle_database extends moodle_database {
} else if (gettype($value) == 'integer') {
return '0'; // Transform 0 to '0' that evaluates the same for PHP
} else if (is_null($value)) {
return '';
} else if ($value === '') {
return ' '; // Transform '' to ' ' that DON'T EVALUATE THE SAME
// (we'll transform back again on get_records_XXX functions and others)!!
@ -929,7 +922,7 @@ class oci_native_moodle_database extends moodle_database {
return true;
}
protected function bind_params($stmt, array & $params=null, $tablename=null, array & $descriptors = null) {
protected function bind_params($stmt, array &$params=null, $tablename=null, array &$descriptors = null) {
if ($params) {
$columns = array();
if ($tablename) {
@ -1015,6 +1008,12 @@ class oci_native_moodle_database extends moodle_database {
default: // Bind as CHAR (applying dirty hack)
// TODO: Optimise
$params[$key] = $this->oracle_dirty_hack($tablename, $columnname, $params[$key]);
// Because of PHP7 bug (https://bugs.php.net/bug.php?id=72524) it seems that it's
// impossible to bind NULL values in a reliable way, let's use empty string
// instead in the mean time.
if ($params[$key] === null && version_compare(PHP_VERSION, '7.0.0', '>=')) {
$params[$key] = '';
}
oci_bind_by_name($stmt, $key, $params[$key]);
}
}
@ -1024,7 +1023,10 @@ class oci_native_moodle_database extends moodle_database {
protected function free_descriptors($descriptors) {
foreach ($descriptors as $descriptor) {
// Because all descriptors used in the driver come from LOB::writeTemporary() calls
// we can safely close them here unconditionally.
$descriptor->close();
// Free resources.
oci_free_descriptor($descriptor);
}
}
@ -1061,7 +1063,7 @@ class oci_native_moodle_database extends moodle_database {
list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_UPDATE);
$stmt = $this->parse_query($sql);
$descriptors = [];
$descriptors = array();
$this->bind_params($stmt, $params, null, $descriptors);
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);
@ -1127,7 +1129,7 @@ class oci_native_moodle_database extends moodle_database {
list($rawsql, $params) = $this->tweak_param_names($rawsql, $params);
$this->query_start($rawsql, $params, SQL_QUERY_SELECT);
$stmt = $this->parse_query($rawsql);
$descriptors = [];
$descriptors = array();
$this->bind_params($stmt, $params, null, $descriptors);
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);
@ -1164,7 +1166,7 @@ class oci_native_moodle_database extends moodle_database {
list($rawsql, $params) = $this->tweak_param_names($rawsql, $params);
$this->query_start($rawsql, $params, SQL_QUERY_SELECT);
$stmt = $this->parse_query($rawsql);
$descriptors = [];
$descriptors = array();
$this->bind_params($stmt, $params, null, $descriptors);
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);
@ -1205,7 +1207,7 @@ class oci_native_moodle_database extends moodle_database {
list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_SELECT);
$stmt = $this->parse_query($sql);
$descriptors = [];
$descriptors = array();
$this->bind_params($stmt, $params, null, $descriptors);
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);
@ -1274,7 +1276,7 @@ class oci_native_moodle_database extends moodle_database {
if ($returning) {
oci_bind_by_name($stmt, ":oracle_id", $id, 10, SQLT_INT);
}
$descriptors = [];
$descriptors = array();
$this->bind_params($stmt, $params, $table, $descriptors);
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);
@ -1389,7 +1391,7 @@ class oci_native_moodle_database extends moodle_database {
// list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_UPDATE);
$stmt = $this->parse_query($sql);
$descriptors = [];
$descriptors = array();
$this->bind_params($stmt, $params, $table, $descriptors);
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);
@ -1480,7 +1482,7 @@ class oci_native_moodle_database extends moodle_database {
list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_UPDATE);
$stmt = $this->parse_query($sql);
$descriptors = [];
$descriptors = array();
$this->bind_params($stmt, $params, $table, $descriptors);
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);
@ -1512,7 +1514,7 @@ class oci_native_moodle_database extends moodle_database {
list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_UPDATE);
$stmt = $this->parse_query($sql);
$descriptors = [];
$descriptors = array();
$this->bind_params($stmt, $params, null, $descriptors);
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);