Skip to content

Commit

Permalink
Merge branch 'MDL-52544-master' of git://github.com/damyon/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jul 19, 2016
2 parents 9e91ff5 + 87c6f9a commit 74ec2dd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
13 changes: 9 additions & 4 deletions lib/adodb/drivers/adodb-oci8po.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ function _FetchField($fieldOffset = -1)
// 10% speedup to move MoveNext to child class
function MoveNext()
{
if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
$ret = @oci_fetch_array($this->_queryID,$this->fetchMode);
if($ret !== false) {
global $ADODB_ANSI_PADDING_OFF;
$this->fields = $ret;
$this->_currentRow++;
$this->_updatefields();

Expand Down Expand Up @@ -169,10 +171,12 @@ function GetArrayLimit($nrows,$offset=-1)
$arr = array();
return $arr;
}
if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
$ret = @oci_fetch_array($this->_queryID,$this->fetchMode);
if ($ret === false) {
$arr = array();
return $arr;
}
$this->fields = $ret;
$this->_updatefields();
$results = array();
$cnt = 0;
Expand All @@ -188,8 +192,9 @@ function _fetch()
{
global $ADODB_ANSI_PADDING_OFF;

$ret = @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode);
$ret = @oci_fetch_array($this->_queryID,$this->fetchMode);
if ($ret) {
$this->fields = $ret;
$this->_updatefields();

if (!empty($ADODB_ANSI_PADDING_OFF)) {
Expand All @@ -198,7 +203,7 @@ function _fetch()
}
}
}
return $ret;
return $ret !== false;
}

}
1 change: 1 addition & 0 deletions lib/adodb/readme_moodle.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ Our changes:
* Removed random seed initialization from lib/adodb/adodb.inc.php:216 (see 038f546 and MDL-41198).
* MDL-52286 Added muting erros in ADORecordSet::__destruct().
Check if fixed upstream during the next upgrade and remove this note.
* MDL-52544 Pull upstream patch for php7 and ocipo.

skodak, iarenaza, moodler, stronk7, abgreeve
57 changes: 43 additions & 14 deletions lib/dml/oci_native_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,8 @@ private function oracle_dirty_hack ($table, $field, $value) {
return ' ';
} else if (is_bool($value)) {
return (int)$value;
} else if (is_null($value)) {
return '';
} else {
return $value;
}
Expand All @@ -786,6 +788,8 @@ private function oracle_dirty_hack ($table, $field, $value) {
return ' ';
} else if (is_bool($value)) {
return (int)$value;
} else if (is_null($value)) {
return '';
} else {
return $value;
}
Expand Down Expand Up @@ -855,6 +859,9 @@ private function oracle_dirty_hack ($table, $field, $value) {
} 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)!!
Expand Down Expand Up @@ -922,8 +929,7 @@ public function change_database_structure($sql, $tablenames = null) {
return true;
}

protected function bind_params($stmt, array $params=null, $tablename=null) {
$descriptors = array();
protected function bind_params($stmt, array & $params=null, $tablename=null, array & $descriptors = null) {
if ($params) {
$columns = array();
if ($tablename) {
Expand All @@ -943,15 +949,21 @@ protected function bind_params($stmt, array $params=null, $tablename=null) {
if (is_array($value)) { // Let's go to bind special cases (lob descriptors)
if (isset($value['clob'])) {
$lob = oci_new_descriptor($this->oci, OCI_DTYPE_LOB);
if ($descriptors === null) {
throw new coding_exception('moodle_database::bind_params() $descriptors not specified for clob');
}
$descriptors[] = $lob;
oci_bind_by_name($stmt, $key, $lob, -1, SQLT_CLOB);
$lob->writeTemporary($this->oracle_dirty_hack($tablename, $columnname, $params[$key]['clob']), OCI_TEMP_CLOB);
$descriptors[] = $lob;
continue; // Column binding finished, go to next one
} else if (isset($value['blob'])) {
$lob = oci_new_descriptor($this->oci, OCI_DTYPE_LOB);
if ($descriptors === null) {
throw new coding_exception('moodle_database::bind_params() $descriptors not specified for clob');
}
$descriptors[] = $lob;
oci_bind_by_name($stmt, $key, $lob, -1, SQLT_BLOB);
$lob->writeTemporary($params[$key]['blob'], OCI_TEMP_BLOB);
$descriptors[] = $lob;
continue; // Column binding finished, go to next one
}
} else {
Expand All @@ -961,9 +973,12 @@ protected function bind_params($stmt, array $params=null, $tablename=null) {
// conditions and other raw SQLs not covered by the above function.
if (strlen($value) > 4000) {
$lob = oci_new_descriptor($this->oci, OCI_DTYPE_LOB);
if ($descriptors === null) {
throw new coding_exception('moodle_database::bind_params() $descriptors not specified for clob');
}
$descriptors[] = $lob;
oci_bind_by_name($stmt, $key, $lob, -1, SQLT_CLOB);
$lob->writeTemporary($this->oracle_dirty_hack($tablename, $columnname, $params[$key]), OCI_TEMP_CLOB);
$descriptors[] = $lob;
continue; // Param binding finished, go to next one.
}
}
Expand Down Expand Up @@ -1009,6 +1024,7 @@ protected function bind_params($stmt, array $params=null, $tablename=null) {

protected function free_descriptors($descriptors) {
foreach ($descriptors as $descriptor) {
$descriptor->close();
oci_free_descriptor($descriptor);
}
}
Expand Down Expand Up @@ -1045,8 +1061,10 @@ public function execute($sql, array $params=null) {
list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_UPDATE);
$stmt = $this->parse_query($sql);
$this->bind_params($stmt, $params);
$descriptors = [];
$this->bind_params($stmt, $params, null, $descriptors);
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);
$this->query_end($result, $stmt);
oci_free_statement($stmt);

Expand Down Expand Up @@ -1109,8 +1127,10 @@ public function get_recordset_sql($sql, array $params=null, $limitfrom=0, $limit
list($rawsql, $params) = $this->tweak_param_names($rawsql, $params);
$this->query_start($rawsql, $params, SQL_QUERY_SELECT);
$stmt = $this->parse_query($rawsql);
$this->bind_params($stmt, $params);
$descriptors = [];
$this->bind_params($stmt, $params, null, $descriptors);
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);
$this->query_end($result, $stmt);

return $this->create_recordset($stmt);
Expand Down Expand Up @@ -1144,8 +1164,10 @@ public function get_records_sql($sql, array $params=null, $limitfrom=0, $limitnu
list($rawsql, $params) = $this->tweak_param_names($rawsql, $params);
$this->query_start($rawsql, $params, SQL_QUERY_SELECT);
$stmt = $this->parse_query($rawsql);
$this->bind_params($stmt, $params);
$descriptors = [];
$this->bind_params($stmt, $params, null, $descriptors);
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);
$this->query_end($result, $stmt);

$records = null;
Expand Down Expand Up @@ -1183,8 +1205,10 @@ public function get_fieldset_sql($sql, array $params=null) {
list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_SELECT);
$stmt = $this->parse_query($sql);
$this->bind_params($stmt, $params);
$descriptors = [];
$this->bind_params($stmt, $params, null, $descriptors);
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);
$this->query_end($result, $stmt);

$records = null;
Expand Down Expand Up @@ -1241,16 +1265,17 @@ public function insert_record_raw($table, $params, $returnid=true, $bulk=false,
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
$sql .= $returning;

$id = null;
$id = 0;

// note we don't need tweak_param_names() here. Placeholders are safe column names. MDL-28080
// list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_INSERT);
$stmt = $this->parse_query($sql);
$descriptors = $this->bind_params($stmt, $params, $table);
if ($returning) {
oci_bind_by_name($stmt, ":oracle_id", $id, 10, SQLT_INT);
}
$descriptors = [];
$this->bind_params($stmt, $params, $table, $descriptors);
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);
$this->query_end($result, $stmt);
Expand Down Expand Up @@ -1364,7 +1389,8 @@ public function update_record_raw($table, $params, $bulk=false) {
// list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_UPDATE);
$stmt = $this->parse_query($sql);
$descriptors = $this->bind_params($stmt, $params, $table);
$descriptors = [];
$this->bind_params($stmt, $params, $table, $descriptors);
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);
$this->query_end($result, $stmt);
Expand Down Expand Up @@ -1454,7 +1480,8 @@ public function set_field_select($table, $newfield, $newvalue, $select, array $p
list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_UPDATE);
$stmt = $this->parse_query($sql);
$descriptors = $this->bind_params($stmt, $params, $table);
$descriptors = [];
$this->bind_params($stmt, $params, $table, $descriptors);
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);
$this->query_end($result, $stmt);
Expand Down Expand Up @@ -1485,8 +1512,10 @@ public function delete_records_select($table, $select, array $params=null) {
list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_UPDATE);
$stmt = $this->parse_query($sql);
$this->bind_params($stmt, $params);
$descriptors = [];
$this->bind_params($stmt, $params, null, $descriptors);
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);
$this->query_end($result, $stmt);
oci_free_statement($stmt);

Expand Down

0 comments on commit 74ec2dd

Please sign in to comment.