Skip to content

Commit

Permalink
added data insert
Browse files Browse the repository at this point in the history
  • Loading branch information
mihailshumilovsms committed Feb 19, 2014
1 parent ab082d8 commit 2bc2807
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions convertor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@

$oXml = simplexml_load_file($iFilePath);


ob_start();
$aDBs = (array)$oXml->{'database'};


foreach ($aDBs['table_structure'] as $key => $val) {
$tableName = (string)$val->attributes()->name;
$oData[$tableName] = array("fields" => array(), "types" => array(), "key" => array(), "primary" => array());
Expand Down Expand Up @@ -103,6 +106,29 @@
}
}

foreach ($aDBs['table_data'] as $k => $tableData) {
$tableName = (string)$tableData->attributes()->name;
if (isset($tableData->row)) {

foreach ($tableData->row as $row) {
$fieldData = (array)$row->field;
unset($fieldData['@attributes']);
array_walk(
$fieldData,
function (&$tv, $tk) {
$tv = addslashes($tv);
if ("0000-00-00 00:00:00" == $tv) {
$tv = "1971-01-01 00:00:01";
}
}
);
echo "INSERT INTO $tableName VALUES(E'" . join("',E'", $fieldData) . "');\n";
}

}
echo "VACUUM FULL $tableName;\n";
}

$dumpData = ob_get_contents();
ob_end_clean();

Expand Down

0 comments on commit 2bc2807

Please sign in to comment.