Adding batch loads

This commit is contained in:
2019-09-07 12:59:44 +02:00
parent 1d9576856b
commit 4b9d9e713a

View File

@@ -121,6 +121,44 @@ class Db extends PhpObject
//Create tables //Create tables
@array_walk($this->getInstallQueries(), array($this, 'setQuery')); @array_walk($this->getInstallQueries(), array($this, 'setQuery'));
} }
public function loadFile($sFilePath) {
set_time_limit(0);
$bResult = false;
if(file_exists($sFilePath))
{
$sContent = file_get_contents($sFilePath);
$sContent = ToolBox::fixEOL($sContent);
if(str_replace(ToolBox::FILE_EOL, '', $sContent)!='')
{
$asLines = explode(ToolBox::FILE_EOL, $sContent);
$sSql = '';
foreach ($asLines as $sLine)
{
$sSql .= trim($sLine);
if(substr($sSql, -1)==';') //Multi line SQL
{
$asResult = $this->setQuery($sSql);
if($asResult === false)
{
$this->addError('SQL failed with error: '.$this->db->error, $sSql);
$bResult = false;
break;
}
$bResult = true;
$sSql = '';
}
else $sSql .= " ";
}
}
else $this->addError('File is empty: '.basename($sFilePath));
}
else $this->addError('File not found: '.$sFilePath);
return $bResult;
}
//For debug purposes //For debug purposes
public function getFullInstallQuery() public function getFullInstallQuery()