From 7cbbb010e552a3df3a145e5d9b5706ff5e4c5b22 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Mon, 23 Dec 2024 08:25:21 -0800 Subject: [PATCH 1/3] recognize new mariadb specific queries in WordPressDbStatement --- classes/WpMatomo/Db/WordPress.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/classes/WpMatomo/Db/WordPress.php b/classes/WpMatomo/Db/WordPress.php index ebca7f7fe..3002d5bf4 100644 --- a/classes/WpMatomo/Db/WordPress.php +++ b/classes/WpMatomo/Db/WordPress.php @@ -279,7 +279,10 @@ public function query( $sql, $bind = array() ) { $test_sql = trim( $test_sql ); } - if ( preg_match( '/^\s*(select)\s/i', $test_sql ) ) { + if ( + preg_match( '/^\s*(select)\s/i', $test_sql ) + || preg_match( '/\sfor select\s/i', $test_sql ) + ) { // WordPress does not fetch any result when doing a query w/ a select... it's only supposed to be used for things like // insert / update / drop ... $result = $this->fetchAll( $sql, $bind ); From 3144cf7105e5c182a0d42de93cd18297b797b859 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Mon, 23 Dec 2024 09:58:22 -0800 Subject: [PATCH 2/3] stub test for change --- tests/phpunit/wpmatomo/db/test-wordpress.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/phpunit/wpmatomo/db/test-wordpress.php b/tests/phpunit/wpmatomo/db/test-wordpress.php index a2de4d6e5..59fd812b8 100644 --- a/tests/phpunit/wpmatomo/db/test-wordpress.php +++ b/tests/phpunit/wpmatomo/db/test-wordpress.php @@ -271,6 +271,10 @@ public function test_update_sets_null_values_correctly_when_all_params_are_null( $this->assertNull( $row['message'] ); } + public function test_query_recognizes_mariadb_set_for_queries() { + throw new \Exception( 'unimplemented' ); + } + private function insert_many_values() { $this->insert_access( 'foo', 'view' ); $this->insert_access( 'bar', 'write' ); From f038b2e6c930c9c59db827a1b1e92c717163faf6 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Wed, 25 Dec 2024 11:15:50 -0800 Subject: [PATCH 3/3] add test to ensure SET STATEMENT FOR MariaDB specific SQL works properly in MWP --- tests/phpunit/wpmatomo/db/test-wordpress.php | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/wpmatomo/db/test-wordpress.php b/tests/phpunit/wpmatomo/db/test-wordpress.php index 59fd812b8..a6e708e87 100644 --- a/tests/phpunit/wpmatomo/db/test-wordpress.php +++ b/tests/phpunit/wpmatomo/db/test-wordpress.php @@ -272,7 +272,26 @@ public function test_update_sets_null_values_correctly_when_all_params_are_null( } public function test_query_recognizes_mariadb_set_for_queries() { - throw new \Exception( 'unimplemented' ); + \Piwik\Config::getInstance()->database['schema'] = 'Mariadb'; + \Piwik\Db\Schema::unsetInstance(); + + $params = new \Piwik\ArchiveProcessor\Parameters( + new \Piwik\Site( 1 ), + \Piwik\Period\Factory::build( 'day', 'today' ), + new \Piwik\Segment( '', [ 1 ] ) + ); + $log_aggregator = new \Piwik\DataAccess\LogAggregator( $params ); + + $sql = $log_aggregator->getQueryByDimensionSql( [], false, [], false, false, false, 120, false ); + + // make sure SQL we're testing has MariaDB specific SQL + $this->assertStringContainsString( 'SET STATEMENT max_statement_time', $sql['sql'] ); + + // test that the query works in MWP + $statement = $log_aggregator->queryVisitsByDimension( [], false, [], false, false, false, 120, false ); + $row = $statement->fetch(); + + $this->assertIsArray( $row ); } private function insert_many_values() {