'autoinc' => 'INT(11) NOT NULL AUTO_INCREMENT',
'timestamp' => 'datetime',
'blob' => 'longtext', // eak what blob is stored?
+ 'integer'
);
// assume we need to create database..
return null;
}
-
+ // may as well rewrite this.. as we have too loop throug hit anyway..
+ function createTable(MTrackDBSchema_Table $table)
+ {
+ echo "Create $table->name\n";
+
+ $pri_key = null;
+
+ $sql = array();
+ foreach ($table->fields as $f) {
+ if ($f->type == 'autoinc') {
+ $pri_key = $f->name;
+ if (!$table->keys) {
+ $table->keys = array(
+ (object)array(
+ 'type' => 'primary',
+ 'fields' => array($f->name)
+ )
+ );
+ }
+ }
+ $str = $this->computeFieldCreate($f);
+ $sql[] = $str;
+ }
+
+ if (is_array($table->keys)) {
+
+ foreach ($table->keys as $k) {
+ if ($k->type != 'primary') continue;
+ if ($pri_key !== null) continue;
+ $sql[] = "\tprimary key (" . join(', ', $k->fields) . ")";
+ }
+ }
+
+ $sql = "CREATE TABLE $table->name (\n" .
+ join(",\n", $sql) .
+ ")\n";
+
+ echo $sql;
+
+ $this->db->exec($sql);
+
+ if (is_array($table->keys)) foreach ($table->keys as $k) {
+ if ($k->type == 'primary') continue;
+ $this->db->exec($this->computeIndexCreate($table, $k));
+ }
+ }
function alterTable(MTrackDBSchema_Table $from, MTrackDBSchema_Table $to)
{