This commit is contained in:
Jun Pataleta 2022-11-30 10:03:39 +08:00 committed by Ilya Tregubov
commit 85e8177eac
3 changed files with 24 additions and 24 deletions

View File

@ -689,15 +689,13 @@ class oci_native_moodle_database extends moodle_database {
if (is_bool($value)) { // Always, convert boolean to int
$value = (int)$value;
} else if ($column->meta_type == 'B') { // BLOB detected, we return 'blob' array instead of raw value to allow
if (!is_null($value)) { // binding/executing code later to know about its nature
$value = array('blob' => $value);
}
} else if ($column->meta_type == 'B' && !is_null($value)) {
// Not null BLOB detected, we return 'blob' array instead for later handing on binding.
$value = array('blob' => $value);
} else if ($column->meta_type == 'X' && strlen($value) > 4000) { // CLOB detected (>4000 optimisation), we return 'clob'
if (!is_null($value)) { // array instead of raw value to allow binding/
$value = array('clob' => (string)$value); // executing code later to know about its nature
}
} else if ($column->meta_type == 'X' && !is_null($value) && strlen($value) > 4000) {
// Not null CLOB detected (>4000 optimisation), we return 'clob' array instead for later handing on binding.
$value = array('clob' => (string)$value);
} else if ($value === '') {
if ($column->meta_type == 'I' or $column->meta_type == 'F' or $column->meta_type == 'N') {
@ -962,7 +960,7 @@ class oci_native_moodle_database extends moodle_database {
// passed in an arbitrary sql (not processed by normalise_value() ever,
// and let's handle it as such. This will provide proper binding of CLOBs in
// conditions and other raw SQLs not covered by the above function.
if (strlen($value) > 4000) {
if (!is_null($value) && 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');

View File

@ -545,7 +545,7 @@ class pgsql_native_moodle_database extends moodle_database {
$tablename = $this->prefix.$table;
$sql = "SELECT a.attnum, a.attname AS field, t.typname AS type, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef,
CASE WHEN a.atthasdef THEN pg_catalog.pg_get_expr(d.adbin, d.adrelid) END AS adsrc
CASE WHEN a.atthasdef THEN pg_catalog.pg_get_expr(d.adbin, d.adrelid) ELSE '' END AS adsrc
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace as ns ON ns.oid = c.relnamespace
JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid

View File

@ -116,25 +116,27 @@ class xmldb_field extends xmldb_object {
*/
public function set_attributes($type, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $default=null, $previous=null) {
$this->type = $type;
/// Try to split the precision into length and decimals and apply
/// each one as needed
$precisionarr = explode(',', $precision);
if (isset($precisionarr[0])) {
$this->length = trim($precisionarr[0]);
// LOBs (BINARY OR TEXT) don't support any precision (neither length or decimals).
if ($type == XMLDB_TYPE_BINARY || $this->type == XMLDB_TYPE_TEXT) {
$this->length = null;
$this->decimals = null;
} else if (!is_null($precision)) {
// Try to split the not null precision into length and decimals and apply each one as needed.
$precisionarr = explode(',', $precision);
if (isset($precisionarr[0])) {
$this->length = trim($precisionarr[0]);
}
if (isset($precisionarr[1])) {
$this->decimals = trim($precisionarr[1]);
}
}
if (isset($precisionarr[1])) {
$this->decimals = trim($precisionarr[1]);
}
$this->precision = $type;
$this->notnull = !empty($notnull) ? true : false;
$this->sequence = !empty($sequence) ? true : false;
$this->setDefault($default);
if ($this->type == XMLDB_TYPE_BINARY || $this->type == XMLDB_TYPE_TEXT) {
$this->length = null;
$this->decimals = null;
}
$this->previous = $previous;
}