MDL-75977 xmldb: Avoid using null params on built-in DB functions
commiteeaaf131ac699fa7fc77c5657eec13dcba1b4ca9
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 23 Nov 2022 23:58:16 +0000 (24 00:58 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Sat, 26 Nov 2022 15:16:20 +0000 (26 16:16 +0100)
tree400d218acebfcd00f8b7fdd93c1d386bbbffbe09
parent57c1e97bf17ebd43bdd0d7a9d5c26bb2546b693d
MDL-75977 xmldb: Avoid using null params on built-in DB functions

This changes a couple of cases, in postgres and oracle where we
were trying to calculate strlen() on null values (that causes a
PHP 8.1 warning).

Also, at the same time, fixing another case in xmldb_field, it
was detected that it had a bug around precision (being set to the
value of type), being used as object property, when it's not, so
it was also fixed by moving the code logic a little bit.

Note that the bug has been there since inception because there
isn't any code in Moodle using that ->precision property. It
was just detected thanks to PHP 8.2, but that's another story. :-)

Verified that with the patch:
- All DBs can be installed (phpunit install)
- Both DDL and DML pass without any ddl/dml warning (in all DBs).
lib/dml/oci_native_moodle_database.php
lib/dml/pgsql_native_moodle_database.php
lib/xmldb/xmldb_field.php