View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0006976 | OXID eShop (all versions) | 4.01. Database handling | public | 2019-05-02 17:24 | 2024-06-12 10:33 |
| Reporter | leofonic | Assigned To | |||
| Priority | normal | Severity | minor | Reproducibility | always |
| Status | resolved | Resolution | fixed | ||
| Product Version | 6.1.3 | ||||
| Fixed in Version | 6.0.3 | ||||
| Summary | 0006976: Database methods like "getAll" do not work sometimes | ||||
| Description | In class database there is a wrapper for methods getOne and getAll. There is a check whether the statement is a select query that has an output or an action which has no output. This check, method "doesStatementProduceOutput", looks for the first word in the statement. If the statement is a union statement that begins with a bracket, the first word is recognized as "(SELECT", which is not in the list of known words, therefore the return of "getAll" is an empty array. | ||||
| Steps To Reproduce | Use "getAll" in a module with a select statement with "union" and starting with a bracket. | ||||
| Tags | No tags attached. | ||||
| Theme | Not defined | ||||
| Browser | Not defined | ||||
| PHP Version | Not defined | ||||
| Database Version | Not defined | ||||
|
|
$db = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
$result = $db->getAll('(select oxtitle from oxarticles limit 1) union (select oxtitle from oxcategories limit 1)');
var_dump($result);
Results in: /var/www/html/source/index.php:13: array (size=0) empty Expected an array with values like this: MySQL [oxid]> (select oxtitle from oxarticles limit 2) union (select oxtitle from oxcategories limit 2); +---------------------+ | oxtitle | +---------------------+ | | | Trapez ION MADTRIXX | | Bindungen | | Trapeze | +---------------------+ 4 rows in set (0.00 sec) MySQL [oxid]> -MK |
|
|
same for getOne |
|
|
With the QueryBuilder not reproducible anymore:$db = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
$result = $db->getAll('(select oxtitle from oxarticles limit 1) union (select oxtitle from oxcategories limit 1)');
var_dump($result);
$container = \OxidEsales\EshopCommunity\Internal\Container\ContainerFactory::getInstance()->getContainer();
$queryBuilderFactory = $container->get(\OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface::class);
$queryBuilder = $queryBuilderFactory->create();
$result = $queryBuilder->select('(select oxtitle from oxarticles limit 1) union (select oxtitle from oxcategories limit 1)')->execute()->fetchAllAssociative();
var_dump($result);Result: array(0) {
}
array(2) {
[0]=>
array(1) {
["(select oxtitle from oxarticles limit 1)"]=>
string(0) ""
}
[1]=>
array(1) {
["(select oxtitle from oxarticles limit 1)"]=>
string(9) "Bindungen"
}
}Directly on the database: MySQL [oxid]> (select oxtitle from oxarticles limit 1) union (select oxtitle from oxcategories limit 1); +-----------+ | oxtitle | +-----------+ | | | Bindungen | +-----------+ 2 rows in set (0.001 sec) MySQL [oxid]> |
|
|
Fixed with the introduction of the QueryBuilder in v6.0.3 |