Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix SQLitePlateform again

  • Loading branch information...
commit c19bfc6b97bd3d23c3de3a60602d0801bbdb39ac 1 parent eaeca74
@willdurand willdurand authored
View
15 src/Propel/Generator/Platform/SqlitePlatform.php
@@ -66,10 +66,8 @@ public function getAddTableDDL(Table $table)
$lines[] = $this->getColumnDDL($column);
}
- if ($table->hasPrimaryKey()) {
- if (1 < count($table->getPrimaryKey())) {
- $lines[] = $this->getPrimaryKeyDDL($table);
- }
+ if (null !== $primaryKeyDDL = $this->getPrimaryKeyDDL($table)) {
+ $lines[] = $primaryKeyDDL;
}
foreach ($table->getUnices() as $unique) {
@@ -100,9 +98,12 @@ public function getAddTableDDL(Table $table)
*/
public function getPrimaryKeyDDL(Table $table)
{
- if ($table->hasPrimaryKey()) {
- // SQLite doesn't support multiple PRIMARY KEYS
- return 'UNIQUE (' . $this->getColumnListDDL($table->getPrimaryKey()) . ')';
+ if ($table->hasPrimaryKey() && 1 < count($table->getPrimaryKey())) {
+ if ($table->hasAutoIncrementPrimaryKey()) {
+ return 'UNIQUE (' . $this->getColumnListDDL($table->getPrimaryKey()) . ')';
+ }
+
+ return 'PRIMARY KEY (' . $this->getColumnListDDL($table->getPrimaryKey()) . ')';
}
}
View
12 tests/Propel/Tests/Generator/Behavior/I18n/I18nBehaviorTest.php
@@ -48,7 +48,7 @@ public function testModifyDatabaseOverridesDefaultLocale()
(
id INTEGER NOT NULL,
locale VARCHAR(5) DEFAULT 'fr_FR' NOT NULL,
- UNIQUE (id,locale)
+ PRIMARY KEY (id,locale)
);
EOF;
$this->assertContains($expected, $builder->getSQL());
@@ -82,7 +82,7 @@ public function testModifyDatabaseDoesNotOverrideTableLocale()
(
id INTEGER NOT NULL,
locale VARCHAR(5) DEFAULT 'pt_PT' NOT NULL,
- UNIQUE (id,locale)
+ PRIMARY KEY (id,locale)
);
EOF;
$this->assertContains($expected, $builder->getSQL());
@@ -184,7 +184,7 @@ public function testModifyTableMovesI18nColumns($schema)
id INTEGER NOT NULL,
locale VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
bar VARCHAR(100),
- UNIQUE (id,locale)
+ PRIMARY KEY (id,locale)
);
EOF;
$this->assertContains($expected, $builder->getSQL());
@@ -232,7 +232,7 @@ public function testModiFyTableUsesCustomI18nTableName()
(
id INTEGER NOT NULL,
locale VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
- UNIQUE (id,locale)
+ PRIMARY KEY (id,locale)
);
EOF;
$this->assertContains($expected, $builder->getSQL());
@@ -263,7 +263,7 @@ public function testModiFyTableUsesCustomLocaleColumnName()
(
id INTEGER NOT NULL,
culture VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
- UNIQUE (id,culture)
+ PRIMARY KEY (id,culture)
);
EOF;
$this->assertContains($expected, $builder->getSQL());
@@ -294,7 +294,7 @@ public function testModiFyTableUsesCustomLocaleDefault()
(
id INTEGER NOT NULL,
locale VARCHAR(5) DEFAULT 'fr_FR' NOT NULL,
- UNIQUE (id,locale)
+ PRIMARY KEY (id,locale)
);
EOF;
$this->assertContains($expected, $builder->getSQL());
View
12 tests/Propel/Tests/Generator/Behavior/Versionable/VersionableBehaviorTest.php
@@ -186,7 +186,7 @@ public function testModifyTableAddsVersionColumnForForeignKeysIfForeignTableIsVe
foreign_id INTEGER,
version INTEGER DEFAULT 0 NOT NULL,
foreign_id_version INTEGER DEFAULT 0,
- UNIQUE (id,version)
+ PRIMARY KEY (id,version)
);
-- SQLite does not support foreign keys; this is just for reference
@@ -232,7 +232,7 @@ public function testModifyTableAddsVersionColumnForReferrersIfForeignTableIsVers
version INTEGER DEFAULT 0 NOT NULL,
versionable_behavior_test_0_ids MEDIUMTEXT,
versionable_behavior_test_0_versions MEDIUMTEXT,
- UNIQUE (id,version)
+ PRIMARY KEY (id,version)
);
-- SQLite does not support foreign keys; this is just for reference
@@ -260,7 +260,7 @@ public function testModifyTableAddsVersionTable($schema)
id INTEGER NOT NULL,
bar INTEGER,
version INTEGER DEFAULT 0 NOT NULL,
- UNIQUE (id,version)
+ PRIMARY KEY (id,version)
);
-- SQLite does not support foreign keys; this is just for reference
@@ -296,7 +296,7 @@ public function testModifyTableAddsVersionTableCustomName()
id INTEGER NOT NULL,
bar INTEGER,
version INTEGER DEFAULT 0 NOT NULL,
- UNIQUE (id,version)
+ PRIMARY KEY (id,version)
);
-- SQLite does not support foreign keys; this is just for reference
@@ -421,7 +421,7 @@ public function testModifyTableAddsVersionTableLogColumns($schema)
version_created_at TIMESTAMP,
version_created_by VARCHAR(100),
version_comment VARCHAR(255),
- UNIQUE (id,version)
+ PRIMARY KEY (id,version)
);
-- SQLite does not support foreign keys; this is just for reference
@@ -453,7 +453,7 @@ public function testDatabaseLevelBehavior()
id INTEGER NOT NULL,
bar INTEGER,
version INTEGER DEFAULT 0 NOT NULL,
- UNIQUE (id,version)
+ PRIMARY KEY (id,version)
);
-- SQLite does not support foreign keys; this is just for reference
View
22 tests/Propel/Tests/Generator/Platform/SqlitePlatformTest.php
@@ -165,7 +165,7 @@ public function testGetAddTableDDLCompositePK($schema)
foo INTEGER NOT NULL,
bar INTEGER NOT NULL,
baz VARCHAR(255) NOT NULL,
- UNIQUE (foo,bar)
+ PRIMARY KEY (foo,bar)
);
";
$this->assertEquals($expected, $this->getPlatform()->getAddTableDDL($table));
@@ -222,13 +222,21 @@ public function testGetColumnDDLCustomSqlType()
$this->assertEquals($expected, $this->getPlatform()->getColumnDDL($column));
}
- public function testGetPrimaryKeyDDLSimpleKey()
+ public function testGetPrimaryKeyDDLCompositeKeyWithAutoIncrement()
{
$table = new Table('foo');
- $column = new Column('bar');
- $column->setPrimaryKey(true);
- $table->addColumn($column);
- $expected = 'UNIQUE (bar)';
+ $table->setIdMethod(IdMethod::NATIVE);
+
+ $column1 = new Column('bar');
+ $column1->setPrimaryKey(true);
+ $table->addColumn($column1);
+
+ $column2 = new Column('baz');
+ $column2->setPrimaryKey(true);
+ $column2->setAutoIncrement(true);
+ $table->addColumn($column2);
+
+ $expected = 'UNIQUE (bar,baz)';
$this->assertEquals($expected, $this->getPlatform()->getPrimaryKeyDDL($table));
}
@@ -241,7 +249,7 @@ public function testGetPrimaryKeyDDLCompositeKey()
$column2 = new Column('bar2');
$column2->setPrimaryKey(true);
$table->addColumn($column2);
- $expected = 'UNIQUE (bar1,bar2)';
+ $expected = 'PRIMARY KEY (bar1,bar2)';
$this->assertEquals($expected, $this->getPlatform()->getPrimaryKeyDDL($table));
}
Please sign in to comment.
Something went wrong with that request. Please try again.