-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
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)); |
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Thank you @akeeman. |
… 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)
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.