}
}
- // Multi-value indexes are advisory and for best portability
- // should be created as separate statements.
+ // Wrap the CREATE TABLE around the main body chunks...
$statements = array();
$statements[] = $this->startCreateTable($name, $def) . "\n" .
implode($sql, ",\n") . "\n" .
$this->endCreateTable($name, $def);
+
+ // Multi-value indexes are advisory and for best portability
+ // should be created as separate statements.
if (!empty($def['indexes'])) {
foreach ($def['indexes'] as $col => $colDef) {
$this->appendCreateIndex($statements, $name, $col, $colDef);
}
}
+ if (!empty($def['fulltext indexes'])) {
+ foreach ($def['fulltext indexes'] as $col => $colDef) {
+ $this->appendCreateFulltextIndex($statements, $name, $col, $colDef);
+ }
+ }
return $statements;
}
*/
function appendForeignKeyDef(array &$sql, $name, array $def)
{
+ if (count($def) != 2) {
+ throw new Exception("Invalid foreign key def for $name: " . var_export($def, true));
+ }
list($refTable, $map) = $def;
$srcCols = array_keys($map);
$refCols = array_values($map);
$statements[] = "CREATE INDEX $name ON $table " . $this->buildIndexList($def);
}
+ /**
+ * Append an SQL statement with an index definition for a full-text search
+ * index over one or more columns on a table.
+ *
+ * @param array $statements
+ * @param string $table
+ * @param string $name
+ * @param array $def
+ */
+ function appendCreateFulltextIndex(array &$statements, $table, $name, array $def)
+ {
+ throw new Exception("Fulltext index not supported in this database");
+ }
+
/**
* Append an SQL statement to drop an index from a table.
*
$this->appendAlterAddForeign($phrase, $keyName, $def['foreign keys'][$keyName]);
}
- $this->appendAlterExtras($phrase, $tableName);
+ $this->appendAlterExtras($phrase, $tableName, $def);
if (count($phrase) > 0) {
$sql = 'ALTER TABLE ' . $tableName . ' ' . implode(",\n", $phrase);
$phrase[] = 'DROP FOREIGN KEY ' . $keyName;
}
- function appendAlterExtras(array &$phrase, $tableName)
+ function appendAlterExtras(array &$phrase, $tableName, array $def)
{
// no-op
}
if (!$cd->nullable) {
$column['not null'] = true;
}
- if ($cd->autoincrement) {
+ if ($cd->auto_increment) {
$column['type'] = 'serial';
}
if ($cd->default) {
*/
function validateDef($tableName, array $def)
{
- if (count($defs) && $defs[0] instanceof ColumnDef) {
- $def = $this->oldToNew($tableName, $defs);
+ if (isset($def[0]) && $def[0] instanceof ColumnDef) {
+ $def = $this->oldToNew($tableName, $def);
}
// A few quick checks :D
if (!isset($def['fields'])) {
- throw new Exceptioni("Invalid table definition for $tableName: no fields.");
+ throw new Exception("Invalid table definition for $tableName: no fields.");
}
return $def;