863 Commits

Author SHA1 Message Date
Srdjan
fa0eecd6bf MDL-69451 dml: use same temptables for both rw and ro database handle
moodle_read_slave_trait: when creating another handle, restore temptables
property that is clobbered by raw_connect().

Also a better condition for temptable related queries detection in
pgsql_native_moodle_database.

dml_pgsql_read_slave_test::test_temp_table(): use real db connection
if possible, otherwise skip the test.
2021-08-06 10:00:20 +10:00
Eloy Lafuente (stronk7)
75dcac4716 Merge branch 'MDL-71463' of https://github.com/paulholden/moodle 2021-05-03 19:00:19 +02:00
Paul Holden
586cc05bce MDL-71463 dml: escape square brackets for SQL Server LIKE operator. 2021-04-29 13:49:43 +01:00
Marina Glancy
badf442ec7 MDL-70965 core_dml: php8 related changes:
1. pg_connection_status(false) fails on PHP8 because the argument is not a stream
2. skipeed the unittest that expected that pg_query() does not show an error if the resource is invalid
see also MDL-71482
2021-04-28 12:42:07 +02:00
Srdjan
ebf19a7085 MDL-70965 core_dml: read_slave - mock db handles as resources
So they comply with the type hints.
2021-04-28 12:38:32 +02:00
Eloy Lafuente (stronk7)
ba5b6089d5 MDL-71036 phpunit: Renamed various regexp-related assertions
In PHPUnit 9.1, the following regexp-related assertions
have been deprecated and there are new alternatives for
all them:
    - assertRegExp()     -> assertMatchesRegularExpression()
    - assertNotRegExp()  -> assertDoesNotMatchRegularExpression()

This is about to, simply, move all cases to the new alternatives.

Source: https://github.com/sebastianbergmann/phpunit/blob/9.1.0/ChangeLog-9.1.md

Regexp to find all them:

    ag 'assertRegExp|assertNotRegExp' -li
2021-03-11 19:22:24 +01:00
Eloy Lafuente (stronk7)
ece2fe5da1 Merge branch 'MDL-70899-master' of git://github.com/marinaglancy/moodle 2021-03-01 20:20:46 +01:00
Eloy Lafuente (stronk7)
6cf59943ca Merge branch 'MDL-52817' of git://github.com/paulholden/moodle 2021-02-23 19:07:56 +01:00
Marina Glancy
f4fb91aecb MDL-70920 core: prevent calls to call_user_fun_array() with assoc array 2021-02-21 22:22:21 +01:00
Paul Holden
b2d19cc29f MDL-52817 dml: implement driver methods for SQL group concatenation. 2021-02-19 15:31:00 +00:00
Marina Glancy
6f90758721 MDL-70899 dml: set_db_handle() definition not compatible with parent 2021-02-15 16:25:15 +01:00
Ruslan Kabalin
536fdb0c2f MDL-70055 pgsql DML: Support large number of SQL-IN parameters.
This patch adds a solution for Postgres that allows overriding IN
statement limit of 16bit (65535 values) by wrapping items in VALUES
list. This only takes place in number of items exceeds 65535, otherwise
parent class get_in_or_equal() function is used.
2020-12-24 14:39:21 +00:00
Tim Hunt
dc72bc6ac5 MDL-54907 dml: Correct incorrect PHPdoc 2020-11-27 14:57:36 +00:00
Eloy Lafuente (stronk7)
533c35ff99 MDL-69973 xmldb: Fix problem with MariaDB >= 10.2.7 metadata defaults
With MariaDB 10.2.7 the driver was incorrectly returning '' (empty
string) as default for all the columns having null (meaning, no
default).

Also, cover the case in unit tests, it seems that we were already
testing other defaults but not the null case.
2020-10-30 19:27:11 +01:00
Eloy Lafuente (stronk7)
3a5641cb74 MDL-67673 phpunit: Remove deprecated assertEquals() params
The optional parameters of assertEquals() and assertNotEquals()
are deprecated in PHPUnit 8 (to be removed in PHPUnit 9):

- delta => use assertEqualsWithDelta()
- canonicalize => use assertEqualsCanonicalizing()
- ignoreCase => use assertEqualsIgnoringCase
- maxDepth => removed without replacement.

More info @ https://github.com/sebastianbergmann/phpunit/issues/3341

Initial search done with:

ag 'assert(Not)?Equals\(.*,.*,' --php

Then, running tests and fixing remaining cases.
2020-10-21 12:46:00 +02:00
Eloy Lafuente (stronk7)
40de097e65 MDL-67673 phpunit: Remove deprecated assertContains() uses on strings
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: https://github.com/sebastianbergmann/phpunit/issues/3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
2020-10-21 12:46:00 +02:00
Eloy Lafuente (stronk7)
f94195c320 MDL-67673 phpunit: Remove deprecated assertInternalType()
While this is not strictly required, because removal will
happen in PHPUnit 9.0, we are already getting rid of all
uses in core.

From release notes:https://phpunit.de/announcements/phpunit-8.html

assertInternalType() is deprecated and will be removed in
PHPUnit 9. Refactor your test to use assertIsArray(), assertIsBool(),
assertIsFloat(), assertIsInt(), assertIsNumeric(), assertIsObject(),
assertIsResource(), assertIsString(), assertIsScalar(),
assertIsCallable(), or assertIsIterable() instead.
2020-10-21 12:45:59 +02:00
Eloy Lafuente (stronk7)
f6711bb394 MDL-67673 phpunit: Fix the return type of template methods
All the setup/teardown/pre/post/conditions template methods
now are required to return void. This was warned with phpunit 7
and now is enforced.

At the same time, fix a few wrong function names,
provider data and param types, return statements...
2020-10-21 12:45:59 +02:00
sam marshall
edb5cd0de4 MDL-69687 DB: Add API for deleting data based on subquery
The new API works on normal databases (by deleting data based on the
subquery) and also on MySQL (by deleting the data using a weird join
on the subquery).
2020-10-16 18:20:23 +01:00
Eloy Lafuente (stronk7)
5374c768f3 Merge branch 'MDL-67394' of https://github.com/paulholden/moodle into master 2020-08-13 00:28:51 +02:00
Eloy Lafuente (stronk7)
27738e1c07 MDL-69356 unit tests: make some assertions dir separator agnostic 2020-08-07 02:09:15 +02:00
Paul Holden
42fcf7d5da MDL-67394 dml: improve thrown exception when Oracle can't parse query. 2020-07-30 16:21:01 +01:00
Brendan Heywood
ef4145dd1a MDL-68874 dml: Add SQL stacktrace debugging mode 2020-07-15 20:32:43 +10:00
Charles Fulton
66ba391e82 MDL-58931 dml: add support for aurora mysql 2020-07-01 22:56:20 +02:00
Srdjan
317432cacc MDL-19711 dml: call mysqli::real_connect() with @ 2020-05-19 18:09:14 +10:00
Srdjan
3612d0b8b9 MDL-19711 dml: Fix undefined $dberr
In mysqli_native_moodle_database::raw_connect()
2020-05-19 17:02:05 +10:00
Srdjan
46cfde3d95 MDL-19711 dml: Enable use of readonly slave database handles
Implemented with moodle_read_slave_trait

Functionality is triggered by supplying config dboption['readonly'].
See config-dist.php for more info on supported dboptions.

pgsql and mysqli drivers are using this feature. Also added support for
connection timeout for these two drivers.
2020-05-19 11:50:42 +10:00
Shamim Rezaie
b4d062c6be MDL-58584 core: remove duplications from get_columns functions 2020-02-03 15:07:15 +11:00
Matteo Scaramuccia
a8a4eac163 MDL-67414 database: Fixed PostgreSQL 12.x support 2020-01-26 09:37:17 +01:00
Matteo Scaramuccia
aa0a602b10 MDL-65811 database: Fix subsetting in MSSQL 2019-10-25 23:00:32 +02:00
Andrew Nicols
fe0944987e MDL-66011 test: remove magic @covers lines 2019-10-04 09:40:34 +08:00
sam marshall
46875866c6 MDL-63315 DB: Postgres - Clear cursors in persistent connection
If there is a PHP fatal error and destructors do not run (this can
happen in out-of-memory errors, and maybe if there is an error in a
previous destructor) then Postgres cursors may be left open.

Usually this does not cause a problem because the connection is
closed anyway, but if using persistent connections, a future
request may reuse the connection with a cursor open. It then gets
errors when it tries to create a new cursor with the same name.

This change closes all cursors at the start of a persistent
connection.
2019-09-02 14:08:57 +01:00
Jun Pataleta
669de78352 MDL-66110 dml: Undo table name fix when table name's used as parameter 2019-08-22 16:16:08 +08:00
Ryan Wyllie
f12c591807 MDL-66110 dml: use fix_table_name for all mysql table names
Changed all of the places that were manually prefixing the table
name to instead fix the table name with the fix_table_name
function.
2019-08-22 16:03:33 +08:00
Jun Pataleta
ff6a7345f7 Merge branch 'MDL-66110-master' of https://github.com/ryanwyllie/moodle 2019-08-21 09:57:49 +08:00
Ryan Wyllie
30d2b9cd31 MDL-66110 dml: Fix MySQL v8 compatibility with groups table
MySQL v8 has added "groups" to the reserved word list. That is used
as a table name in Moodle so we have to quote it with backticks in the
SQL so that MySQL knows it's being used as an identifier.
2019-08-13 09:35:19 +08:00
Andrew Nicols
66fa73d84e MDL-66327 pgsql DML: Update get_records_sql to consume less memory
It's more memory efficient to use `pg_fetch_assoc` for each row than to
call `pg_fetch_all` and release memory immediately. This is because we
can treat the assoc fetch like an iterator and it only fetches the
current record into memory one at a time, whilst the all fetch fetches
all records and never unsets them. Attempting to unset them is extremely
time consuming.
2019-08-08 15:48:12 +08:00
Eloy Lafuente (stronk7)
87f196af93 MDL-65204 phpunit: more isEqual() strict string fixes
This is a followup of 85f47ba, where we were relaxing
the (new since phpunit 7.x) strict (===) isEqual()
comparison for strings. Copying the explanations for
easier understanding.

Link: https://github.com/sebastianbergmann/phpunit/issues/3185
Solution here is one of:
  a) Return to the previous situation, making the comparison
     softer. That can achieved by forcing different types, so
     float == string works.
  b) Changing APIs (both forms and database return strings) to
     perform some conversion to floats. That would make float
     comparison (with floats or strings) to work too.
The patch here follows the a) approach. Changing all the internals
for proper float handling sounds excesive when it has been working
perfectly since ever. So we went the easier route, just getting
rid of the new === comparisons when needed by changing expectation
types to float.
2019-04-03 22:08:16 +02:00
Andrew Nicols
71cbc0550f MDL-65168 dml: Move preload SQL functions to self-contained class 2019-03-25 23:05:22 +01:00
Ryan Wyllie
a30570c555 MDL-64820 dml: add object preloading helpers 2019-03-22 09:24:04 +08:00
Tim Hunt
a0536c410a MDL-64981 dml tests: pgsql_native_recordset_testcase port number 2019-03-01 11:12:40 +00:00
Eloy Lafuente (stronk7)
0de29dbf35 MDL-63020 tests: ensure that searching for is null values also works ok 2018-09-24 17:38:10 +02:00
Tim Hunt
eb6c769a8c MDL-63020 dml: improve the unit tests 2018-09-24 11:41:25 +01:00
Tim Hunt
5abc431335 MDL-63020 ddl: fix nullable unique indexes in OCI and MS SQL
This works-around the default non-standard behaviour of these DB engines.
2018-09-20 17:41:22 +01:00
Tim Hunt
54b2b1d27f MDL-63020 xmldb: Improve PHPdoc comments for better IDE autocomplete 2018-09-20 17:41:22 +01:00
Matteo Scaramuccia
82c2d98fa2 MDL-61702 dml: MariaDB 10.3 supports only the Barracuda file format.
More details about this change also in https://tracker.moodle.org/browse/MDL-59099

Ref.: https://mariadb.com/kb/en/library/mariadb-1031-release-notes/#other-variables
2018-05-31 22:55:00 +02:00
David Monllao
17ed12eb17 Merge branch 'm35_MDL-59596_DDL_Issues_With_MariaDB_10p2_SQLMode' of https://github.com/scara/moodle 2018-05-28 08:15:09 +02:00
Jake Dallimore
48c3e99599 MDL-59581 database: remove mssql specific code from lib/dml 2018-04-09 01:58:26 +02:00
Matteo Scaramuccia
f6b16e95a8 MDL-59596 ddl: Added has_breaking_change_sqlmode() 2018-03-26 23:12:36 +02:00
David Monllao
c2e970779d MDL-53226 search_simpledb: Refine the patch
- Clumsy fallback only when there is no full-text search support
- Mimic solr tests
- pgsql tokenization using simple configuration
- workaround for mysql '*' search issue
- total results proper calculation
- SQL server FTS support
- Standarize dml full-text search checkings
- Upgrade note about the new dml method
- Set search_simpledb as default engine if no solr config
2018-03-20 18:49:38 +01:00