| | 325 | |
|---|
| | 326 | function install_sqlupdate( $file ) |
|---|
| | 327 | { |
|---|
| | 328 | global $db; |
|---|
| | 329 | global $dryrun; |
|---|
| | 330 | |
|---|
| | 331 | out("-> Running SQL script ".UPGRADE_DIR."/".$version."/".$file); |
|---|
| | 332 | // run sql script |
|---|
| | 333 | $fd = fopen(UPGRADE_DIR."/".$version."/".$file, "r"); |
|---|
| | 334 | $data = ""; |
|---|
| | 335 | while (!feof($fd)) { |
|---|
| | 336 | $data .= fread($fd, 1024); |
|---|
| | 337 | } |
|---|
| | 338 | fclose($fd); |
|---|
| | 339 | |
|---|
| | 340 | preg_match_all("/((SELECT|INSERT|UPDATE|DELETE|CREATE|DROP|ALTER).*);\s*\n/Us", $data, $matches); |
|---|
| | 341 | |
|---|
| | 342 | foreach ($matches[1] as $sql) { |
|---|
| | 343 | debug($sql); |
|---|
| | 344 | if (!$dryrun) { |
|---|
| | 345 | $result = $db->query($sql); |
|---|
| | 346 | if(DB::IsError($result)) { |
|---|
| | 347 | fatal($result->getDebugInfo()."\" while running ".$file."\n"); |
|---|
| | 348 | } |
|---|
| | 349 | } |
|---|
| | 350 | } |
|---|
| | 351 | } |
|---|
| | 352 | |
|---|
| 336 | | if (strtolower(substr($file,-4)) == ".sql") { |
|---|
| 337 | | out("-> Running SQL script ".UPGRADE_DIR."/".$version."/".$file); |
|---|
| 338 | | // run sql script |
|---|
| 339 | | $fd = fopen(UPGRADE_DIR."/".$version."/".$file, "r"); |
|---|
| 340 | | $data = ""; |
|---|
| 341 | | while (!feof($fd)) { |
|---|
| 342 | | $data .= fread($fd, 1024); |
|---|
| 343 | | } |
|---|
| 344 | | fclose($fd); |
|---|
| 345 | | |
|---|
| 346 | | preg_match_all("/((SELECT|INSERT|UPDATE|DELETE|CREATE|DROP|ALTER).*);\s*\n/Us", $data, $matches); |
|---|
| 347 | | |
|---|
| 348 | | foreach ($matches[1] as $sql) { |
|---|
| 349 | | debug($sql); |
|---|
| 350 | | if (!$dryrun) { |
|---|
| 351 | | $result = $db->query($sql); |
|---|
| 352 | | if(DB::IsError($result)) { |
|---|
| 353 | | fatal($result->getDebugInfo()."\" while running ".$file."\n"); |
|---|
| 354 | | } |
|---|
| 355 | | } |
|---|
| 356 | | } |
|---|
| | 367 | if ( (strtolower(substr($file,-4)) == ".sqlite") && ($db_engine == "sqlite") ) { |
|---|
| | 368 | install_sqlupdate( $file ); |
|---|
| | 369 | } |
|---|
| | 370 | elseif ((strtolower(substr($file,-4)) == ".sql") && ( ($db_engine == "mysql") || ($db_engine == "pgsql")) ) { |
|---|
| | 371 | install_sqlupdate( $file ); |
|---|