Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 14708 tinyint #14709

Merged
merged 7 commits into from
Jan 14, 2020
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
9 changes: 8 additions & 1 deletion CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# [4.0.1](https://github.com/phalcon/cphalcon/releases/tag/v4.0.1) (2020-01-11)
# [4.0.3](https://github.com/phalcon/cphalcon/releases/tag/v4.0.3) (XXX-XX-XX)
## Added

## Changed

## Fixed
- Fixed `Phalcon\Db\Adapter\Pdo\Mysql` Tinyint(1) is handled as boolean under MySql [#14708](https://github.com/phalcon/cphalcon/issues/14708)

# [4.0.1](https://github.com/phalcon/cphalcon/releases/tag/v4.0.1) (2020-01-11)

## Changed
- Changed the logic when logging times for `Phalcon\Logger` to use `DateTimeImmutable` so as to handle microseconds if necessary. [#2893](https://github.com/phalcon/cphalcon/issues/2893)
- Changed `Phalcon\Http\Cookie::send` and `Phalcon\Http\Cookie::delete` to allow for `samesite` to be passed in the `options` when using PHP > 7.3 [#14627](https://github.com/phalcon/cphalcon/issues/14627)
Expand Down
13 changes: 0 additions & 13 deletions phalcon/Db/Adapter/Pdo/Mysql.zep
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,6 @@ class Mysql extends PdoAdapter
*/

switch true {
/**
* BOOL
*/
case starts_with(columnType, "tinyint(1)", true):
/**
* tinyint(1) is boolean
*/
let definition["type"] = Column::TYPE_BOOLEAN,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_BOOL;

break;

/**
* BIGINT
*/
Expand Down
8 changes: 4 additions & 4 deletions tests/_data/fixtures/Traits/Db/MysqlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected function getColumns(): array
],
6 => [
'columnName' => 'field_boolean',
'type' => Column::TYPE_BOOLEAN,
'type' => Column::TYPE_TINYINTEGER,
'isNumeric' => true,
'size' => 1,
'default' => null,
Expand All @@ -188,11 +188,11 @@ protected function getColumns(): array
'primary' => false,
'first' => false,
'after' => 'field_bigint_default',
'bindType' => Column::BIND_PARAM_BOOL,
'bindType' => Column::BIND_PARAM_INT,
],
7 => [
'columnName' => 'field_boolean_default',
'type' => Column::TYPE_BOOLEAN,
'type' => Column::TYPE_TINYINTEGER,
'isNumeric' => true,
'size' => 1,
'default' => 1,
Expand All @@ -202,7 +202,7 @@ protected function getColumns(): array
'primary' => false,
'first' => false,
'after' => 'field_boolean',
'bindType' => Column::BIND_PARAM_BOOL,
'bindType' => Column::BIND_PARAM_INT,
],
8 => [
'columnName' => 'field_char',
Expand Down
19 changes: 16 additions & 3 deletions tests/integration/Mvc/Model/SaveCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,14 @@ public function mvcModelSaveAfterFetchingRelatedWithMagicGetter(IntegrationTeste
*
* @author Phalcon Team <team@phalcon.io>
* @since 2019-08-02
* @dataProvider tinyintProvider
*/
public function mvcModelSaveWithTinyInt(IntegrationTester $I)
public function mvcModelSaveWithTinyInt(IntegrationTester $I, \Codeception\Example $example)
{
$I->wantToTest('Mvc\Model::save() with a tinyint(1)');

$referenceModel = new TinyIntTest();
$referenceModel->test = 0;
$referenceModel->test = $example['value'];

$I->assertTrue(
$referenceModel->save()
Expand All @@ -484,11 +485,23 @@ public function mvcModelSaveWithTinyInt(IntegrationTester $I)

$storedModel = TinyIntTest::findFirstById($id);
$I->assertEquals(
'0',
$example['value'],
$storedModel->test
);
}

/**
* @return array
*/
protected function tinyintProvider()
{
return [
['value' => "1"],
['value' => "0"],
['value' => "250"]
];
}

/**
* Tests Phalcon\Mvc\Model\ :: save() with schema
*
Expand Down