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 mysql QueryBuilder boolean type #9324

Closed
wants to merge 2 commits into from
Closed

Fix mysql QueryBuilder boolean type #9324

wants to merge 2 commits into from

Conversation

mj4444ru
Copy link

@mj4444ru mj4444ru commented Aug 5, 2015

The problem is that yii type boolean type is considered mysql bit (1), and in QueryBuilder it is incorrect. When we create a migration using Schema :: TYPE_BOOLEAN, database type we get Schema :: TYPE_SMALLINT, and the model of type integer.

/framework/db/mysql/Schema.php

if ($column->size === 1 && $type === 'bit') {
$column->type = 'boolean';
}

/framework/db/mysql/QueryBuilder.php

public $typeMap = [
...
Schema::TYPE_BOOLEAN => 'tinyint(1)',
...
];

@samdark
Copy link
Member

samdark commented Aug 5, 2015

What is the problem currently?

@mj4444ru
Copy link
Author

mj4444ru commented Aug 5, 2015

The problem is that yii type boolean type is considered mysql bit (1), and in QueryBuilder it is incorrect. When we create a migration using Schema :: TYPE_BOOLEAN, database type we get Schema :: TYPE_SMALLINT, and the model of type integer.

Sorry that just has not. I do not have time to issue.

@samdark
Copy link
Member

samdark commented Aug 5, 2015

What do you mean by "in QueryBuilder it is incorrect"?

@mj4444ru
Copy link
Author

mj4444ru commented Aug 5, 2015

public $typeMap = [
...
Schema::TYPE_BOOLEAN => 'tinyint(1)',
...
];

@samdark
Copy link
Member

samdark commented Aug 5, 2015

Why tinyint(1) is incorrect?

@Faryshta
Copy link
Contributor

Faryshta commented Aug 5, 2015

@samdark its not wrong to use tinyint(1) simply 'bit(1)` requires less space in disk and can get lesser possible values. For example using tinyint you can insert a value equal 2.

The problem I think would be if all SQL engines support it to avoid generating problems when migrating from one db engine to another

@cebe
Copy link
Member

cebe commented Aug 5, 2015

the mysql synonym for boolean is tinyint(1):

BOOL, BOOLEAN

These types are synonyms for TINYINT(1). A value of zero is considered false. Nonzero values are considered true:

https://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html

@cebe cebe closed this Aug 5, 2015
@mj4444ru
Copy link
Author

mj4444ru commented Aug 6, 2015

Why the alias MySQL? yii type boolean considers the type bit (1).

@cebe
Copy link
Member

cebe commented Aug 6, 2015

it considers bit(1) and tinyint(1), what is the problem?

@mj4444ru
Copy link
Author

mj4444ru commented Aug 6, 2015

The problem is that yii in accordance with the mysql Schema said type boolean type mysql bit(1).

Code file /framework/db/mysql/Schema.php

if ($column->size === 1 && $ type === 'bit') {
     $column->type = 'boolean';
}

At this time, /framework/db/mysql/QueryBuilder.php said boolean type tinyint(1).

Thus QueryBuilder.php contradicts Schema.php.

It does not matter what's in the mysql alias type boolean.
It is important to consider that type of boolean the core yii.

@cebe
Copy link
Member

cebe commented Aug 6, 2015

this line should cover the tinyint(1) case too then. https://github.com/yiisoft/yii2/blob/master/framework/db/mysql/Schema.php#L160 I thought it was already doing this...

@cebe cebe reopened this Aug 6, 2015
@cebe cebe added the status:to be verified Needs to be reproduced and validated. label Aug 6, 2015
@mj4444ru
Copy link
Author

mj4444ru commented Aug 6, 2015

@cebe So can not be done
tinyint(1) - a number from -127 to 127 (in practice)
tinyint(1) - a number from 0 to 9 (in theory)

@cebe cebe added this to the 2.1.x milestone Aug 6, 2015
@cebe cebe modified the milestones: 2.1.0, 2.1.x Dec 9, 2016
@cebe
Copy link
Member

cebe commented Dec 9, 2016

closing this in favor of #9339

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:to be verified Needs to be reproduced and validated.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants