Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- `Phalcon\Mvc\Model\Resultset\Simple::__construct` now accepts `Psr\SimpleCache\CacheInterface` for the cache
- `Phalcon\Mvc\Model\Resultset::__construct` now accepts `Psr\SimpleCache\CacheInterface` for the cache
- `Phalcon\Mvc\Model\Resultset::getCache` now returns `Psr\SimpleCache\CacheInterface` [#15471](https://github.com/phalcon/cphalcon/issues/15471)
- Changed `Phalcon\Db\Adapter\AbstractAdapter:delete()` signature of optional parameters. [#15363](https://github.com/phalcon/cphalcon/issues/15363)

## Fixed
- Fixed `Phalcon\Db\Adapter\AbstractAdapter:delete()` when `bindTypes` argument is passed. [#15363](https://github.com/phalcon/cphalcon/issues/15363)

# [5.0.0-alpha.2](https://github.com/phalcon/cphalcon/releases/tag/v5.0.0-alpha.2) (2021-05-05)

Expand Down
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 table
* @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 table
* @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 <team@phalcon.io>
*
* 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 <team@phalcon.io>
* @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