PMCORE-1882 Suggest Field doesn't show records when we use an alias in a Query

This commit is contained in:
Roly Rudy Gutierrez Pinto
2020-08-21 00:44:20 -04:00
parent 9d3b85724a
commit bd09154369
3 changed files with 82 additions and 4 deletions

View File

@@ -60,7 +60,8 @@
"league/oauth2-google": "^3.0",
"tecnickcom/tcpdf": "6.3.*",
"fzaninotto/faker": "^1.7",
"predis/predis": "1.1.1"
"predis/predis": "1.1.1",
"phpmyadmin/sql-parser": "^5.3"
},
"require-dev": {
"guzzlehttp/guzzle": "^6.3",

72
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "da3512db89554c0bf1626fe310fd8254",
"content-hash": "c2797ee5f1a7edd412479d5495731149",
"packages": [
{
"name": "bshaffer/oauth2-server-php",
@@ -2663,17 +2663,83 @@
"description": "PHPMailer is a full-featured email creation and transfer class for PHP",
"time": "2018-11-15T22:32:31+00:00"
},
{
"name": "phpmyadmin/sql-parser",
"version": "5.3.1",
"source": {
"type": "git",
"url": "https://github.com/phpmyadmin/sql-parser.git",
"reference": "11457e9bbedc182b48c04db3a2621d17b58b0808"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpmyadmin/sql-parser/zipball/11457e9bbedc182b48c04db3a2621d17b58b0808",
"reference": "11457e9bbedc182b48c04db3a2621d17b58b0808",
"shasum": ""
},
"require": {
"php": "^7.1",
"symfony/polyfill-mbstring": "^1.3"
},
"conflict": {
"phpmyadmin/motranslator": "<3.0"
},
"require-dev": {
"phpmyadmin/coding-standard": "^1.0",
"phpmyadmin/motranslator": "^4.0 || ^5.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.3",
"phpstan/phpstan-phpunit": "^0.12.1",
"phpunit/php-code-coverage": "*",
"phpunit/phpunit": "^7.4 || ^8 || ^9"
},
"suggest": {
"ext-mbstring": "For best performance",
"phpmyadmin/motranslator": "Translate messages to your favorite locale"
},
"bin": [
"bin/highlight-query",
"bin/lint-query",
"bin/tokenize-query"
],
"type": "library",
"autoload": {
"psr-4": {
"PhpMyAdmin\\SqlParser\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0-or-later"
],
"authors": [
{
"name": "The phpMyAdmin Team",
"email": "developers@phpmyadmin.net",
"homepage": "https://www.phpmyadmin.net/team/"
}
],
"description": "A validating SQL lexer and parser with a focus on MySQL dialect.",
"homepage": "https://github.com/phpmyadmin/sql-parser",
"keywords": [
"analysis",
"lexer",
"parser",
"sql"
],
"time": "2020-03-21T00:25:34+00:00"
},
{
"name": "predis/predis",
"version": "v1.1.1",
"source": {
"type": "git",
"url": "https://github.com/nrk/predis.git",
"url": "https://github.com/predis/predis.git",
"reference": "f0210e38881631afeafb56ab43405a92cafd9fd1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nrk/predis/zipball/f0210e38881631afeafb56ab43405a92cafd9fd1",
"url": "https://api.github.com/repos/predis/predis/zipball/f0210e38881631afeafb56ab43405a92cafd9fd1",
"reference": "f0210e38881631afeafb56ab43405a92cafd9fd1",
"shasum": ""
},

View File

@@ -1,5 +1,6 @@
<?php
use PhpMyAdmin\SqlParser\Parser;
use ProcessMaker\Core\System;
use ProcessMaker\BusinessModel\DynaForm\SuggestTrait;
use ProcessMaker\BusinessModel\Cases;
@@ -1044,6 +1045,16 @@ class PmDynaform
$dt[$key]["alias"] = "";
}
if ($key == 0) {
//compatibility with table name alias when uses the sentence 'AS'
if (strtoupper($dt[$key]["alias"]) === 'AS') {
$parser = new Parser($sql);
if (isset($parser->statements[$key]) && isset($parser->statements[$key]->from[$key])) {
$obj1 = $parser->statements[$key]->from[$key];
if (!empty($obj1->alias)) {
$dt[$key]["alias"] = $dt[$key]["alias"] . ' ' . $obj1->alias;
}
}
}
$from .= $dt[$key]["table"]
. ($dt[$key]["table"] == $dt[$key]["alias"] ? "" : " " . $dt[$key]["alias"]);
} else {