Skip to content

Instantly share code, notes, and snippets.

@fitoria
Created January 6, 2010 20:59
Show Gist options
  • Select an option

  • Save fitoria/270653 to your computer and use it in GitHub Desktop.

Select an option

Save fitoria/270653 to your computer and use it in GitHub Desktop.
<?
require "app.class.php";
function genSQL($object) {
$o = $object . "Table";
$data = new $o;
$sql = "CREATE TABLE $data->name (\n";
$i = 0;
foreach($data->definition as $column) {
unset($size);
if ($type == 'external') next($data->definition);
if ($i) $sql .= " ,\n";
$type = $column['type'];
if ($type == 'file' || $type == 'image' || $type == 'autoimage') {
$type = 'varchar';
$size = '500';
}
if ($type == 'order') $type = 'serial NULL';
if (!$size) $size = $column['size'];
$size = preg_replace("/\./", ",", $size);
$sql .= " ".$column['name']." ".$type;
if ($size) $sql .= " (".$size.")";
if ($column['name'] == $data->key) $sql .= " PRIMARY KEY";
if ($column['references']) $sql .= " REFERENCES ".$column['references'];
++$i;
}
$sql .= "\n);\n\n";
print $sql;
}
$tables = array('catbebida', 'catcomida', 'tipocomida', 'prioridad', 'rango', 'comida', 'detallecomida', 'bebida', 'catevento', 'evento', 'sala', 'pelicula', 'tanda', 'catartista', 'artista','politica');
foreach($tables as $key)
genSQL($key);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment