Added sql dump maker
This commit is contained in:
parent
c2165dd617
commit
165edd75bd
|
@ -22,3 +22,31 @@ $writer->save("data/current.ods");
|
|||
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
unset($spreadsheet);
|
||||
|
||||
$db = new SQLite3(dirname(__FILE__)."/db");
|
||||
$db->busyTimeout(5000);
|
||||
|
||||
$sql="";
|
||||
|
||||
$tables=$db->query("SELECT name FROM sqlite_master WHERE type ='table' AND name NOT LIKE 'sqlite_%';");
|
||||
|
||||
while ($table=$tables->fetchArray(SQLITE3_NUM)) {
|
||||
$sql.=$db->querySingle("SELECT sql FROM sqlite_master WHERE name = '{$table[0]}'").";\n\n";
|
||||
$rows=$db->query("SELECT * FROM {$table[0]}");
|
||||
$sql.="INSERT INTO {$table[0]} (";
|
||||
$columns=$db->query("PRAGMA table_info({$table[0]})");
|
||||
$fieldnames=array();
|
||||
while ($column=$columns->fetchArray(SQLITE3_ASSOC)) {
|
||||
$fieldnames[]=$column["name"];
|
||||
}
|
||||
$sql.=implode(",",$fieldnames).") VALUES";
|
||||
while ($row=$rows->fetchArray(SQLITE3_ASSOC)) {
|
||||
foreach ($row as $k=>$v) {
|
||||
$row[$k]="'".SQLite3::escapeString($v)."'";
|
||||
}
|
||||
$sql.="\n(".implode(",",$row)."),";
|
||||
}
|
||||
$sql=rtrim($sql,",").";\n\n";
|
||||
}
|
||||
|
||||
file_put_contents("data/current.sql",$sql);
|
||||
|
|
Reference in New Issue
Block a user