Releases: rkrx/php-mysql-query-builder
Allow MySQL::quoteExpression to take less arguments than necessary
Allow MySQL::quoteExpression
to take less arguments than necessary. If more arguments are required than available, the last given argument is used to fill the remaining placeholders.
Enhanced MySQLExceptionInterpreter::throwMoreConcreteException
MySQLExceptionInterpreter::throwMoreConcreteException
now handles SQL-Error-Codes 1452
Enhanced MySQLExceptionInterpreter::throwMoreConcreteException
MySQLExceptionInterpreter::throwMoreConcreteException
now handles SQL-Error-Codes 1216, 1217
Enhanced MySQLExceptionInterpreter::throwMoreConcreteException
MySQLExceptionInterpreter::throwMoreConcreteException
now handles SQL-Error-Codes 1022, 1169, 1586
Support simple arrays like [1, 2, 3, 4, 5] as table-names which will result in a UNION-chain-subquery
Example:
$select
->field('a.value')
->from('a', range(1, 9))
->asString();
SELECT
a.value
FROM
(SELECT '1' AS `value`
UNION
SELECT '2' AS `value`
UNION
SELECT '3' AS `value`
UNION
SELECT '4' AS `value`
UNION
SELECT '5' AS `value`
UNION
SELECT '6' AS `value`
UNION
SELECT '7' AS `value`
UNION
SELECT '8' AS `value`
UNION
SELECT '9' AS `value`) a
Now PHP will moan about non-optional parameters of virtual tables
When using parameterized virtual tables without parameters, PHP will now moan about the missing parameter when not defined as optional.
Added support for parameterized virtual tables
Parameterized virtual tables
When you need parameterized sub-selects, you can use the Helperclass Kir\MySQL\Tools\VirtualTable
to add parameters to a table-name:
Definition:
use Kir\MySQL\Databases\MySQL;
$db = new MySQL($pdo);
$vt1 = $db->select()
->field('a.field1')
->from('a', 'tableA');
$db->getVirtualTables()->add('virt_table1', $vt1);
// Lazy evaluated; parameterized
$db->getVirtualTables()->add('virt_table2', function (array $args) {
return $db->select()
->field('a.field1')
->from('a', 'tableA')
->where(new DBExprFilter('a.active=?', $args, 'active'));
});
Then use it as needed:
$query = $db->select()
->field('t.field1')
->field('vt1.fieldN')
->field('vt2.fieldN')
->from('t', 'test')
->joinInner('vt1', 'virt_table1', 'vt1.field1=t.field1')
->joinInner('vt2', new VirtualTable('virt_table2', ['active' => 1]), 'vt2.field2=t.field2');
The definition of a virtual table can now be set as a closure
The definition of a virtual table can now be set as a closure, which is lazy evaluated:
use Kir\MySQL\Databases\MySQL;
$db = new MySQL($pdo);
$vt1 = $db->select()
->field('a.field1')
->from('a', 'tableA');
$db->getVirtualTables()->add('virt_table1', $vt1);
// Lazy evaluated
$db->getVirtualTables()->add('virt_table2', function () {
return $db->select()
->field('a.field1')
->from('a', 'tableA');
});
$query = $db->select()
->field('t.field1')
->field('vt1.fieldN')
->field('vt2.fieldN')
->from('t', 'test')
->joinInner('vt1', 'virt_table1', 'vt1.field1=t.field1')
->joinInner('vt2', 'virt_table2', 'vt2.field2=t.field2');
Added Support for Virtual Tables
You can now use virtual tables, which are basically just sub-selects referenced by a identifier.
First define virtual tables somewhere in your bootstrap:
use Kir\MySQL\Databases\MySQL;
$db = new MySQL($pdo);
$vt1 = $db->select()
->field('a.field1')
->from('a', 'tableA');
$vt2 = $db->select()
->field('a.field1')
->from('a', 'tableA');
$db->getVirtualTables()->add('virt_table1', $vt1);
$db->getVirtualTables()->add('virt_table2', $vt2);
Then use it as needed:
$query = $db->select()
->field('t.field1')
->field('vt1.fieldN')
->field('vt2.fieldN')
->from('t', 'test')
->joinInner('vt1', 'virt_table1', 'vt1.field1=t.field1')
->joinInner('vt2', 'virt_table2', 'vt2.field2=t.field2');
Fixed various problems introduced after last release
- Fixed various problems with default parameters after last release
- Fixed
MySQL::dryRun
where PHP7-\Errors caused rollbacks on transactions - Fixed
MySQL::transaction
where tries were not handled correctly