Skip to content

Commit

Permalink
#15363 - Fix Phalcon\Db\Adapter\AbstractAdapter:delete() when `bind…
Browse files Browse the repository at this point in the history
…Types` argument is passed
  • Loading branch information
Jeckerson committed May 10, 2021
1 parent 98690b0 commit ff5c971
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 4 deletions.
1 change: 0 additions & 1 deletion phalcon/DataMapper/Query/AbstractConditions.zep
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ abstract class AbstractConditions extends AbstractQuery
*
* @return string
*/

protected function buildLimitCommon() -> string
{
string limit = "";
Expand Down
9 changes: 8 additions & 1 deletion phalcon/Db/Adapter/AbstractAdapter.zep
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,15 @@ abstract class AbstractAdapter implements AdapterInterface, EventsAwareInterface
* // Next SQL sentence is generated
* DELETE FROM `robots` WHERE `id` = 101
* ```
*
* @param array|string
* @param string|null whereCondition
* @param array placeholders
* @param array dataTypes
*
* @return bool
*/
public function delete(var table, var whereCondition = null, var placeholders = null, var dataTypes = null) -> bool
public function delete(var table, string whereCondition = null, array placeholders = [], array dataTypes = []) -> bool
{
var sql, escapedTable;

Expand Down
9 changes: 8 additions & 1 deletion phalcon/Db/Adapter/AdapterInterface.zep
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,15 @@ interface AdapterInterface

/**
* Deletes data from a table using custom RDBMS SQL syntax
*
* @param array|string
* @param string|null whereCondition
* @param array placeholders
* @param array dataTypes
*
* @return bool
*/
public function delete(var table, whereCondition = null, placeholders = null, dataTypes = null) -> bool;
public function delete(var table, string whereCondition = null, array placeholders = [], array dataTypes = []) -> bool;

/**
* Returns an array of Phalcon\Db\Column objects describing a table
Expand Down
61 changes: 61 additions & 0 deletions tests/database/Db/Adapter/Pdo/DeleteCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types = 1);

namespace Phalcon\Test\Database\Db\Adapter\Pdo;

use DatabaseTester;
use Phalcon\Test\Fixtures\Migrations\InvoicesMigration;
use Phalcon\Test\Fixtures\Traits\DiTrait;
use Phalcon\Test\Models\Invoices;

final class DeleteCest
{
use DiTrait;

public function _before(DatabaseTester $I)
{
$this->setNewFactoryDefault();
$this->setDatabase($I);
}

/**
* Tests Phalcon\Db\Adapter\AbstractAdapter :: delete()
*
* @author Phalcon Team <[email protected]>
* @since 2021-05-10
*
* @group pgsql
* @group mysql
* @group sqlite
*/
public function dbAdapterPdoQuery(DatabaseTester $I)
{
$I->wantToTest('Db\Adapter\Pdo - delete()');

$connection = $I->getConnection();
$db = $this->container->get('db');

$migration = new InvoicesMigration($connection);
$migration->insert(1, 1, 1, 'title 1', 101);
$migration->insert(2, 1, 1, 'title 2', 102);
$migration->insert(3, 1, 1, 'title 3', 103);

$I->assertSame(3, Invoices::count());

$db->delete($migration->getTable(), 'inv_id > :id', [
'id' => 1,
]);

$I->assertSame(1, Invoices::count());
}
}
2 changes: 1 addition & 1 deletion tests/database/Db/Adapter/Pdo/QueryCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function dbAdapterPdoQuery(DatabaseTester $I)
$I->assertTrue(is_object($result));
$I->assertInstanceOf(Pdo::class, $result);

while ($row = $result->fetch()) {
while ($result->fetch()) {
$number++;
}
$I->assertEquals(5, $number);
Expand Down

0 comments on commit ff5c971

Please sign in to comment.