Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Cache] [PdoAdapter] Fix MySQL 1170 error (blob as primary key) #21323

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

Closed
wants to merge 2 commits into from
Closed

[Cache] [PdoAdapter] Fix MySQL 1170 error (blob as primary key) #21323

wants to merge 2 commits into from

Conversation

akeeman
Copy link
Contributor

@akeeman akeeman commented Jan 17, 2017

Q A
Branch? 3.2
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? n/a
Fixed tickets n/a
License MIT
Doc PR n/a

When using a Doctrine\DBAL\Connection to initialize the PdoAdapter, PdoAdapter::createTable tries to create a table using a blob field as primary key. This is not an option for MySQL, resulting in an exeption: Syntax error or access violation: 1170 BLOB/TEXT column 'item_id' used in key specification without a key length. This commit supplies a way to act like the non-Connection way creates the table does.

Sync up with the non-Connection way of creating a table.
$schema = new Schema();
$table = $schema->createTable($this->table);
$table->addColumn($this->idCol, 'blob', array('length' => 255));
$table->addColumn($this->idCol, $types[$this->driver], array('length' => 255));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just 'mysql' === $this->driver ? 'binary' : 'blog'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I indeed mentioned the MySQL case explicitly. However, the section below differs from the schema, in the sense that none of the statements there define the id column as blob (expecting you mean blob, not blog). Mapping it like this should result in an id column type that matches up with those below.

Copy link
Contributor Author

@akeeman akeeman Jan 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must say that I don't really know why sqlite uses text, but as you wrote it, I hope you do ;). In case this should be varchar too, then sqlite should also use 'string'. Then I would say that something like 'mysql' === $this->driver ? 'binary' : 'string' would be applicable, and I'll change the sqlite line too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took inspiration from https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php#L214

what matters is having a storage of 255 bytes, with collations/charset disabled

Copy link
Contributor Author

@akeeman akeeman Jan 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, given that works I'd suggest to make the end result the same. Using the initially proposed mapping will result that, given doctrine's type mapping. Still I don't know why col type text is needed for sqlite, but probably I've got some catching up to do concerning that...

So, I now propose to keep it like my initial proposition. What about you?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. could you please fix fabbot's failure? then we're done

@fabpot
Copy link
Member

fabpot commented Jan 17, 2017

Thank you @akeeman.

fabpot added a commit that referenced this pull request Jan 17, 2017
… key) (akeeman)

This PR was submitted for the master branch but it was merged into the 3.2 branch instead (closes #21323).

Discussion
----------

[Cache] [PdoAdapter] Fix MySQL 1170 error (blob as primary key)

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | n/a
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

When using a Doctrine\DBAL\Connection to initialize the PdoAdapter, PdoAdapter::createTable tries to create a table using a blob field as primary key. [This is not an option for MySQL](https://techjourney.net/mysql-error-1170-42000-blobtext-column-used-in-key-specification-without-a-key-length/), resulting in an exeption: `Syntax error or access violation: 1170 BLOB/TEXT column 'item_id' used in key specification without a key length`. This commit supplies a way to act like the non-Connection way creates the table does.

Commits
-------

08c6a65 [Cache] [PdoAdapter] Fix MySQL 1170 error (blob as primary key)
@fabpot fabpot closed this Jan 17, 2017
@akeeman akeeman deleted the patch-1 branch January 18, 2017 07:45
@fabpot fabpot mentioned this pull request Feb 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.