From 910c43db3b3ef144be0325e55116f72c72fdbe88 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Mon, 7 Aug 2023 00:34:39 +0100 Subject: [PATCH 1/2] Fix: Cannot execute stored procedure with SELECT using the SQL tab Signed-off-by: Kamil Tekiela --- libraries/classes/Display/Results.php | 4 ++-- libraries/classes/Sql.php | 8 ++------ test/classes/Controllers/Import/ImportControllerTest.php | 3 ++- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/libraries/classes/Display/Results.php b/libraries/classes/Display/Results.php index caf82be001..33941a03cb 100644 --- a/libraries/classes/Display/Results.php +++ b/libraries/classes/Display/Results.php @@ -4191,7 +4191,7 @@ class Results // display the Export link). if ( ($analyzedSqlResults['querytype'] === self::QUERY_TYPE_SELECT) - && empty($analyzedSqlResults['procedure']) + && empty($analyzedSqlResults['is_procedure']) ) { if (count($analyzedSqlResults['select_tables']) === 1) { $urlParams['single_table'] = 'true'; @@ -4227,7 +4227,7 @@ class Results } return [ - 'has_procedure' => ! empty($analyzedSqlResults['procedure']), + 'has_procedure' => ! empty($analyzedSqlResults['is_procedure']), 'has_geometry' => $geometryFound, 'has_print_link' => $printLink == '1', 'has_export_link' => $analyzedSqlResults['querytype'] === self::QUERY_TYPE_SELECT, diff --git a/libraries/classes/Sql.php b/libraries/classes/Sql.php index 2070592775..36109558a6 100644 --- a/libraries/classes/Sql.php +++ b/libraries/classes/Sql.php @@ -1061,7 +1061,7 @@ class Sql $response = ResponseRenderer::getInstance(); $response->addJSON($extraData ?? []); - if (empty($analyzedSqlResults['is_select']) || isset($extraData['error'])) { + if (($result instanceof ResultInterface && $result->numFields() === 0) || isset($extraData['error'])) { return $queryMessage; } @@ -1125,7 +1125,7 @@ class Sql 'db' => $db, 'table' => $table, 'sql_query' => $sqlQuery, - 'is_procedure' => ! empty($analyzedSqlResults['procedure']), + 'is_procedure' => ! empty($analyzedSqlResults['is_procedure']), ]); } @@ -1724,10 +1724,6 @@ class Sql $extraData ); - if ($this->dbi->moreResults()) { - $this->dbi->nextResult(); - } - $warningMessages = $this->operations->getWarningMessagesArray(); // No rows returned -> move back to the calling page diff --git a/test/classes/Controllers/Import/ImportControllerTest.php b/test/classes/Controllers/Import/ImportControllerTest.php index 31a731d76e..34a0559172 100644 --- a/test/classes/Controllers/Import/ImportControllerTest.php +++ b/test/classes/Controllers/Import/ImportControllerTest.php @@ -41,7 +41,8 @@ class ImportControllerTest extends AbstractTestCase $this->dummyDbi->addResult( 'SELECT A.* FROM table1 A WHERE A.nomEtablissement = \'Saint-Louis - Châteaulin\'' . ' AND foo = 4 AND `:a` IS NULL LIMIT 0, 25', - [] + [], + ['nomEtablissement', 'foo'] ); $this->dummyDbi->addResult( From 5d3b9185123c8c8a4c908ff5e1037b0224b5d545 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 8 Aug 2023 15:35:35 +0100 Subject: [PATCH 2/2] Adjust Selenium tests Signed-off-by: Kamil Tekiela --- test/selenium/CreateDropDatabaseTest.php | 3 ++- test/selenium/Database/EventsTest.php | 3 ++- test/selenium/Database/OperationsTest.php | 3 ++- test/selenium/Database/ProceduresTest.php | 3 ++- test/selenium/Database/StructureTest.php | 3 ++- test/selenium/Database/TriggersTest.php | 3 ++- test/selenium/Table/OperationsTest.php | 3 ++- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/test/selenium/CreateDropDatabaseTest.php b/test/selenium/CreateDropDatabaseTest.php index ad8f543a5d..febc47ad10 100644 --- a/test/selenium/CreateDropDatabaseTest.php +++ b/test/selenium/CreateDropDatabaseTest.php @@ -82,7 +82,8 @@ class CreateDropDatabaseTest extends TestBase $this->dbQuery( 'SHOW DATABASES LIKE \'' . $this->databaseName . '\';', function (): void { - $this->assertFalse($this->isElementPresent('className', 'table_results')); + $this->assertTrue($this->isElementPresent('className', 'table_results')); + $this->assertFalse($this->isElementPresent('cssSelector', '.table_results tbody tr')); } ); } diff --git a/test/selenium/Database/EventsTest.php b/test/selenium/Database/EventsTest.php index 828f3580d8..126d3fa867 100644 --- a/test/selenium/Database/EventsTest.php +++ b/test/selenium/Database/EventsTest.php @@ -215,7 +215,8 @@ class EventsTest extends TestBase 'USE `' . $this->databaseName . '`;' . 'SHOW EVENTS WHERE Db=\'' . $this->databaseName . '\' AND Name=\'test_event\';', function (): void { - $this->assertFalse($this->isElementPresent('className', 'table_results')); + $this->assertTrue($this->isElementPresent('className', 'table_results')); + $this->assertFalse($this->isElementPresent('cssSelector', '.table_results tbody tr')); } ); } diff --git a/test/selenium/Database/OperationsTest.php b/test/selenium/Database/OperationsTest.php index c7e2504610..d09efb6e6b 100644 --- a/test/selenium/Database/OperationsTest.php +++ b/test/selenium/Database/OperationsTest.php @@ -86,7 +86,8 @@ class OperationsTest extends TestBase $this->dbQuery( 'SHOW DATABASES LIKE \'' . $this->databaseName . '\'', function (): void { - $this->assertFalse($this->isElementPresent('className', 'table_results')); + $this->assertTrue($this->isElementPresent('className', 'table_results')); + $this->assertFalse($this->isElementPresent('cssSelector', '.table_results tbody tr')); } ); diff --git a/test/selenium/Database/ProceduresTest.php b/test/selenium/Database/ProceduresTest.php index 5c07d7804f..36e980ab2e 100644 --- a/test/selenium/Database/ProceduresTest.php +++ b/test/selenium/Database/ProceduresTest.php @@ -216,7 +216,8 @@ class ProceduresTest extends TestBase $this->dbQuery( "SHOW PROCEDURE STATUS WHERE Db='" . $this->databaseName . "'", function (): void { - $this->assertFalse($this->isElementPresent('className', 'table_results')); + $this->assertTrue($this->isElementPresent('className', 'table_results')); + $this->assertFalse($this->isElementPresent('cssSelector', '.table_results tbody tr')); } ); } diff --git a/test/selenium/Database/StructureTest.php b/test/selenium/Database/StructureTest.php index 0eaed7fd7b..6785051e5a 100644 --- a/test/selenium/Database/StructureTest.php +++ b/test/selenium/Database/StructureTest.php @@ -90,7 +90,8 @@ class StructureTest extends TestBase $this->dbQuery( 'SHOW TABLES FROM `' . $this->databaseName . '`;', function (): void { - $this->assertFalse($this->isElementPresent('className', 'table_results')); + $this->assertTrue($this->isElementPresent('className', 'table_results')); + $this->assertFalse($this->isElementPresent('cssSelector', '.table_results tbody tr')); } ); } diff --git a/test/selenium/Database/TriggersTest.php b/test/selenium/Database/TriggersTest.php index 21ee8df0bb..5a773f2be5 100644 --- a/test/selenium/Database/TriggersTest.php +++ b/test/selenium/Database/TriggersTest.php @@ -200,7 +200,8 @@ class TriggersTest extends TestBase $this->dbQuery( 'SHOW TRIGGERS FROM `' . $this->databaseName . '`;', function (): void { - $this->assertFalse($this->isElementPresent('className', 'table_results')); + $this->assertTrue($this->isElementPresent('className', 'table_results')); + $this->assertFalse($this->isElementPresent('cssSelector', '.table_results tbody tr')); } ); } diff --git a/test/selenium/Table/OperationsTest.php b/test/selenium/Table/OperationsTest.php index 5088e65669..91ff84fa66 100644 --- a/test/selenium/Table/OperationsTest.php +++ b/test/selenium/Table/OperationsTest.php @@ -226,7 +226,8 @@ class OperationsTest extends TestBase 'USE `' . $this->databaseName . '`;' . 'SHOW TABLES', function (): void { - $this->assertFalse($this->isElementPresent('className', 'table_results')); + $this->assertTrue($this->isElementPresent('className', 'table_results')); + $this->assertFalse($this->isElementPresent('cssSelector', '.table_results tbody tr')); } ); }