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

Schema Builder: collaction() should be wrapped by quotes #23944

Closed
rentalhost opened this issue Apr 19, 2018 · 2 comments
Closed

Schema Builder: collaction() should be wrapped by quotes #23944

rentalhost opened this issue Apr 19, 2018 · 2 comments

Comments

@rentalhost
Copy link
Contributor

rentalhost commented Apr 19, 2018

  • Laravel Version: 5.6.17 (lastest)
  • PHP Version: 7.2.2 ZTS MSVC15 (Visual C++ 2017) x64
  • Database Driver & Version: MariaDB 10.1.14

Description:

Else, ->collection('binary') could fails in some cases, because of the generated code is something like addressable_type varchar(255) collate binary not null (the correct is addressable_type varchar(255) collate "binary" not null).

I think that it should be applied to both: collaction and charset.

It affects MariaDB 10.1, but I don't know if it affects other DBMS and which versions.

I am not the best person to PR that, so if someone could do that, it will be very useful.

Steps to reproduce

Full test case:

Schema::create('addresses', function (Blueprint $blueprint) {
    $blueprint->string('addressable_type')->collation(static::COLLATION_BINARY);
});

Code generated:

create table `platform_addresses` (`addressable_type` varchar(255) collate binary
  not null) default character set utf8mb4 collate utf8mb4_unicode_ci

Code manually fixed:

create table `platform_addresses` (`addressable_type` varchar(255) collate "binary"
  not null) default character set utf8mb4 collate utf8mb4_unicode_ci
@staudenmeir
Copy link
Contributor

Do you know a case where the charset doesn't work without quotes?

@rentalhost
Copy link
Contributor Author

rentalhost commented Apr 24, 2018

Both charset and collation supports binary as value. And binary is a reserved word for both MySQL and MariaDB, at least. But, binary could be used as value for character set as-in, but for collate it should be wrapped.

The code below should works:

Schema::create('example', function (Blueprint $blueprint) {
    $blueprint->collation = '"binary"'; // Need be wrapped!
    $blueprint->charset   = 'binary';   // Do not need be wrapped.

    $blueprint->increments('id');
});

Generated working SQL (beautified):

create table `example` 
    (`id` int unsigned not null auto_increment primary key) 

default character set binary 
        collate "binary"

So, I think that the wrapper should be applied only to collation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants