diff --git a/webdata/scripts/news-raw-tables.php b/webdata/scripts/news-raw-tables.php index f07bfa3..489930e 100644 --- a/webdata/scripts/news-raw-tables.php +++ b/webdata/scripts/news-raw-tables.php @@ -5,14 +5,9 @@ * to create 12 tables for NewsRaw */ $theTime = mktime(); -$str = "CREATE TABLE IF NOT EXISTS `news_raw_%s` ( - `news_id` int(11) NOT NULL, - `time` int(11) NOT NULL, - `raw` text NOT NULL, - PRIMARY KEY (`news_id`,`time`) -) ENGINE=InnoDB;"; +$str = 'CREATE TABLE IF NOT EXISTS `news_raw_%s` LIKE news_raw'; $db = NewsRaw::getDb(); for ($i = 0; $i < 12; $i++) { $db->query(sprintf($str, date('Ym', $theTime))); $theTime = strtotime('+1 month', $theTime); -} \ No newline at end of file +} diff --git a/webdata/scripts/table-build.php b/webdata/scripts/table-build.php index c756de5..b264817 100644 --- a/webdata/scripts/table-build.php +++ b/webdata/scripts/table-build.php @@ -11,7 +11,18 @@ $p = pathinfo($m); $o = new $p['filename']; if($o instanceof Pix_Table) { - $o->dropTable(); + try { + $o->dropTable(); + } catch (Pix_Table_Exception $e) { + echo 'Unable to drop table "'.$p['filename'].'". '; + if (preg_match('/^Table: \w+SQL Error: \(1051\)Unknown table/', + $e->getMessage())) { + echo 'Table missing. Ignored.'."\n"; + } else { + echo "\n"; + die($e->getMessage()); + } + } $o->createTable(); } -} \ No newline at end of file +} diff --git a/webdata/stdlibs/pixframework/Pix/Table/Db/Adapter/MysqlCommon.php b/webdata/stdlibs/pixframework/Pix/Table/Db/Adapter/MysqlCommon.php index 1a62db6..0552af2 100644 --- a/webdata/stdlibs/pixframework/Pix/Table/Db/Adapter/MysqlCommon.php +++ b/webdata/stdlibs/pixframework/Pix/Table/Db/Adapter/MysqlCommon.php @@ -12,7 +12,7 @@ abstract class Pix_Table_Db_Adapter_MysqlCommon extends Pix_Table_Db_Adapter_SQL public function createTable($table) { $sql = "CREATE TABLE " . $this->column_quote($table->getTableName()); - $types = array('bigint', 'tinyint', 'int', 'varchar', 'char', 'text', 'float', 'double', 'binary'); + $types = array('bigint', 'tinyint', 'int', 'varchar', 'char', 'text', 'longtext', 'float', 'double', 'binary'); foreach ($table->_columns as $name => $column) { $s = $this->column_quote($name) . ' '; @@ -73,7 +73,7 @@ public function createTable($table) $column_sql[] = $s; } - $sql .= " (\n" . implode(", \n", $column_sql) . ") ENGINE = InnoDB\n"; + $sql .= " (\n" . implode(", \n", $column_sql) . ") ENGINE = InnoDB DEFAULT CHARSET=utf8mb4\n"; return $this->query($sql, $table); }