8000 adjust sqlite table definition · symfony/symfony@6f5748e · GitHub
[go: up one dir, main page]

Skip to content

Commit 6f5748e

Browse files
committed
adjust sqlite table definition
1 parent 5978fcf commit 6f5748e

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ public function createTable()
180180

181181
switch ($this->driver) {
182182
case 'mysql':
183-
$sql = "CREATE TABLE $this->table ($this->idCol VARCHAR(128) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol MEDIUMINT NOT NULL, $this->timeCol INTEGER NOT NULL) ENGINE = InnoDB";
183+
$sql = "CREATE TABLE $this->table ($this->idCol VARCHAR(128) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol MEDIUMINT NOT NULL, $this->timeCol INTEGER UNSIGNED NOT NULL) ENGINE = InnoDB";
184184
break;
185185
case 'sqlite':
186-
$sql = "CREATE TABLE $this->table ($this->idCol VARCHAR(128) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol MEDIUMINT NOT NULL, $this->timeCol INTEGER NOT NULL)";
186+
$sql = "CREATE TABLE $this->table ($this->idCol TEXT NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)";
187187
break;
188188
case 'pgsql':
189189
$sql = "CREATE TABLE $this->table ($this->idCol VARCHAR(128) NOT NULL PRIMARY KEY, $this->dataCol BYTEA NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)";

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,28 @@ public function testReadWriteReadWithNullByte()
135135
$this->assertSame($sessionData, $readData, 'Written value can be read back correctly');
136136
}
137137

138+
public function testReadingRequiresExactlySameId()
139+
{
140+
$storage = new PdoSessionHandler($this->getMemorySqlitePdo());
141+
$storage->open('', 'sid');
142+
$storage->write('id', 'data');
143+
$storage->write('test', 'data');
144+
$storage->write('space ', 'data');
145+
$storage->close();
146+
147+
$storage->open('', 'sid');
148+
$readDataCaseSensitive = $storage->read('ID');
149+
$readDataNoCharFolding = $storage->read('tést');
150+
$readDataKeepSpace = $storage->read('space ');
151+
$readDataExtraSpace = $storage->read('space ');
152+
$storage->close();
153+
154+
$this->assertSame('', $readDataCaseSensitive, 'Retrieval by ID should be case-sensitive (collation setting)');
155+
$this->assertSame('', $readDataNoCharFolding, 'Retrieval by ID should not do character folding (collation setting)');
156+
$this->assertSame('data', $readDataKeepSpace, 'Retrieval by ID requires spaces as-is');
157+
$this->assertSame('', $readDataExtraSpace, 'Retrieval by ID requires spaces as-is');
158+
}
159+
138160
/**
139161
* Simulates session_regenerate_id(true) which will require an INSERT or UPDATE (replace)
140162
*/

0 commit comments

Comments
 (0)
0