# HG changeset patch # User Matti Hamalainen # Date 1558038349 -10800 # Node ID a5f52e54c9daab982d903290de8e92173e3e65df # Parent ac3bd4e94555b25a2d15ab7d80f0b9495af32d60 Improve stDBGetTableSchema(). diff -r ac3bd4e94555 -r a5f52e54c9da msitegen.inc.php --- a/msitegen.inc.php Thu May 16 21:59:44 2019 +0300 +++ b/msitegen.inc.php Thu May 16 23:25:49 2019 +0300 @@ -742,46 +742,62 @@ } -function stDBGetTableSchema($dbh, $data) +function stDBGetTableSchema($dbh, $schema) { - $res = array(); + $res = []; $driver = $dbh->getAttribute(PDO::ATTR_DRIVER_NAME); - foreach ($data as $col) + // Go through the table schema, definition by definition + foreach ($schema as $scol) { - $tmp = array(); + $tmp = []; + // And each element of the one definition + // (like 'foo INTEGER AUTOINCREMENT') + foreach ($scol as $elem) switch ($driver) { case "pgsql": - foreach ($col as $elem) + switch ($elem) { - // For Postgres, use SERIAL for autoincrement - if ($elem == "AUTOINCREMENT") + case "AUTOINCREMENT": + // For Postgres, use SERIAL for autoincrement and + // "cleverly" replace the 2nd element with SERIAL + // assuming that it is INTEGER or such. $tmp[1] = "SERIAL"; - else + break; + + case "DATETIME": + $tmp[] = "TIMESTAMPTZ"; + break; + + default: $tmp[] = $elem; + break; } break; case "mysql": - foreach ($col as $elem) + switch ($elem) { - if ($elem == "AUTOINCREMENT") + case "AUTOINCREMENT": $tmp[] = "AUTO_INCREMENT"; - else + break; + + default: $tmp[] = $elem; + break; } break; case "sqlite": - $tmp = $col; + $tmp[] = $elem; break; - + default: - die("Don't know how to handle PDO driver '".$driver."' yet.\n"); + die("Don't know how to handle PDO driver '".$driver."'.\n"); } - + $res[] = implode(" ", $tmp); }