diff --git a/phalcon/DataMapper/Query/AbstractConditions.zep b/phalcon/DataMapper/Query/AbstractConditions.zep index 6572eec9adc..82e1f12588e 100644 --- a/phalcon/DataMapper/Query/AbstractConditions.zep +++ b/phalcon/DataMapper/Query/AbstractConditions.zep @@ -270,7 +270,6 @@ abstract class AbstractConditions extends AbstractQuery * * @return string */ - protected function buildLimitCommon() -> string { string limit = ""; diff --git a/phalcon/Db/Adapter/AbstractAdapter.zep b/phalcon/Db/Adapter/AbstractAdapter.zep index fbb6e1a020c..2927f57b824 100644 --- a/phalcon/Db/Adapter/AbstractAdapter.zep +++ b/phalcon/Db/Adapter/AbstractAdapter.zep @@ -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; diff --git a/phalcon/Db/Adapter/AdapterInterface.zep b/phalcon/Db/Adapter/AdapterInterface.zep index 4ad8aeaeee3..a8bff191534 100644 --- a/phalcon/Db/Adapter/AdapterInterface.zep +++ b/phalcon/Db/Adapter/AdapterInterface.zep @@ -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 diff --git a/tests/database/Db/Adapter/Pdo/DeleteCest.php b/tests/database/Db/Adapter/Pdo/DeleteCest.php new file mode 100644 index 00000000000..c438338543f --- /dev/null +++ b/tests/database/Db/Adapter/Pdo/DeleteCest.php @@ -0,0 +1,61 @@ + + * + * 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 + * @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()); + } +} diff --git a/tests/database/Db/Adapter/Pdo/QueryCest.php b/tests/database/Db/Adapter/Pdo/QueryCest.php index 2e4367fe768..cebf6be0e0c 100644 --- a/tests/database/Db/Adapter/Pdo/QueryCest.php +++ b/tests/database/Db/Adapter/Pdo/QueryCest.php @@ -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);