Commit 78e2faa5 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Fixes #9074 - QFQ query with nested QFQ query failed if the outer QFQ query is...

Fixes #9074 - QFQ query with nested QFQ query failed if the outer QFQ query is a multi column query ( ='{{!' ). Fixed.
parent feb839b8
Pipeline #2348 passed with stages
in 3 minutes and 4 seconds
......@@ -159,6 +159,7 @@ class Evaluate {
$debugLocal[] = $debugIndent . "Parse: $result";
$posFirstClose = strpos($result, $this->endDelimiter);
$posLastClose = strrpos($result, $this->endDelimiter);
// Variables like 'fillStoreVar' might contain SQL statements. Put them in store in case a DB exception is thrown.
$this->store::setVar(SYSTEM_SQL_RAW, $line, STORE_SYSTEM);
......@@ -176,7 +177,8 @@ class Evaluate {
$post = substr($result, $posFirstClose + $this->endDelimiterLength);
$match = substr($result, $posMatchOpen + $this->startDelimiterLength, $posFirstClose - $posMatchOpen - $this->startDelimiterLength);
$evaluated = $this->substitute($match, $foundInStore, $sqlMode);
$tmpSqlMode = ($posFirstClose == $posLastClose) ? $sqlMode : ROW_IMPLODE_ALL;
$evaluated = $this->substitute($match, $foundInStore, $tmpSqlMode);
// newline
$debugLocal[] = '';
......
......@@ -9,7 +9,6 @@
namespace IMATHUZH\Qfq\Tests\Unit\Core;
use IMATHUZH\Qfq\Core\Evaluate;
use IMATHUZH\Qfq\Core\Store\Store;
use IMATHUZH\Qfq\Tests\Unit\Core\Database\AbstractDatabaseTest;
......@@ -75,20 +74,22 @@ class EvaluateTest extends AbstractDatabaseTest {
// Get 2 row Array
$expected = [
[
'id' => '1',
'name' => 'Doe',
],
[
'id' => '2',
'name' => 'Smith',
],
['id' => '1', 'name' => 'Doe',],
['id' => '2', 'name' => 'Smith',],
];
$this->assertEquals($expected, $eval->parse('{{!SELECT id, name FROM Person WHERE id < 3 ORDER BY id}}'));
// Get 2 row Array with nested query
$expected = [
['id' => 1, 'name' => 'Doe', 'cnt' => 1],
['id' => 2, 'name' => 'Smith', 'cnt' => 1],
];
$this->assertEquals($expected, $eval->parse('{{!SELECT id, name, {{SELECT 1 }} AS cnt FROM Person WHERE id < 3 ORDER BY id}}'));
// Get empty array
$this->assertEquals(array(), $eval->parse('{{!SELECT id, name FROM Person WHERE id=0}}'));
// INSERT: Use 'Eval' to write a record
$eval->parse('{{INSERT INTO Person (name, firstname) VALUES (\'Sinatra\', \'Frank\')}}');
$this->assertEquals('Frank Sinatra', $eval->parse('{{SELECT firstname, " ", name FROM Person WHERE name="Sinatra" AND firstname="Frank"}}'));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment