Skip to content

Commit 9d09059

Browse files
committed
bug symfony#21323 [Cache] [PdoAdapter] Fix MySQL 1170 error (blob as primary key) (akeeman)
This PR was submitted for the master branch but it was merged into the 3.2 branch instead (closes symfony#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)
2 parents 84d0da2 + 08c6a65 commit 9d09059

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Symfony/Component/Cache/Adapter/PdoAdapter.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,20 @@ public function createTable()
108108
$conn = $this->getConnection();
109109

110110
if ($conn instanceof Connection) {
111+
$types = array(
112+
'mysql' => 'binary',
113+
'sqlite' => 'text',
114+
'pgsql' => 'string',
115+
'oci' => 'string',
116+
'sqlsrv' => 'string',
117+
);
118+
if (!isset($types[$this->driver])) {
119+
throw new \DomainException(sprintf('Creating the cache table is currently not implemented for PDO driver "%s".', $this->driver));
120+
}
121+
111122
$schema = new Schema();
112123
$table = $schema->createTable($this->table);
113-
$table->addColumn($this->idCol, 'blob', array('length' => 255));
124+
$table->addColumn($this->idCol, $types[$this->driver], array('length' => 255));
114125
$table->addColumn($this->dataCol, 'blob', array('length' => 16777215));
115126
$table->addColumn($this->lifetimeCol, 'integer', array('unsigned' => true, 'notnull' => false));
116127
$table->addColumn($this->timeCol, 'integer', array('unsigned' => true, 'foo' => 'bar'));

0 commit comments

Comments
 (0)