1: <?php
2:
3: namespace Alchemy\dialect;
4:
5: class SQLiteCompiler extends ANSICompiler {
6:
7: protected static $schema_formats = array(
8: 'Integer' => "INTEGER",
9: 'Index' => "CREATE INDEX %s ON %s (%3$//, /)",
10: 'UniqueKey' => "CREATE UNIQUE INDEX %s ON %s (%3$//, /)",
11: 'PrimaryKey' => "PRIMARY KEY (%3$//, /)",
12: 'Timestamp' => "TIMESTAMP DEFAULT CURRENT_TIMESTAMP");
13:
14:
15: public function Create($obj) {
16: $table = $obj->getTable();
17:
18: $columns = $this->map('Create_Element', $table->listColumns());
19: $queries = array();
20:
21: foreach ($table->listIndexes() as $name => $index) {
22: $sql = $this->Create_Element($index);
23: if ($index->getType() == 'PrimaryKey' ||
24: $index->getType() == 'ForeignKey') {
25: $columns[] = $sql;
26: } else {
27: $queries[] = $sql;
28: }
29: }
30:
31: $columns = implode(', ', $columns);
32: array_unshift($queries,
33: "CREATE TABLE IF NOT EXISTS {$table->getName()} ({$columns})");
34:
35: return $queries;
36: }
37:
38:
39: public function Update($obj) {
40: $this->pushConfig(array('alias_tables' => false));
41: $sql = parent::Update($obj);
42: $this->popConfig();
43:
44: return $sql;
45: }
46: }