summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/updatedb.sh64
1 files changed, 3 insertions, 61 deletions
diff --git a/bin/updatedb.sh b/bin/updatedb.sh
index 1f5e18434..f504634f1 100755
--- a/bin/updatedb.sh
+++ b/bin/updatedb.sh
@@ -146,20 +146,9 @@ function update_db_schema($package, $version, $file)
global $DB;
// read DDL file
- if ($lines = file($file)) {
- $sql = '';
- foreach ($lines as $line) {
- if (preg_match('/^--/', $line) || trim($line) == '')
- continue;
-
- $sql .= $line . "\n";
- if (preg_match('/(;|^GO)$/', trim($line))) {
- @$DB->query(fix_table_names($sql));
- $sql = '';
- if ($error = $DB->is_error()) {
- return $error;
- }
- }
+ if ($sql = file_get_contents($file)) {
+ if (!$DB->exec_script($sql)) {
+ return $DB->is_error();
}
}
@@ -185,51 +174,4 @@ function update_db_schema($package, $version, $file)
return $DB->is_error();
}
-function fix_table_names($sql)
-{
- global $DB, $RC, $dir;
- static $tables;
- static $sequences;
-
- $prefix = $RC->config->get('db_prefix');
- $engine = $DB->db_provider;
-
- if (empty($prefix)) {
- return $sql;
- }
-
- if ($tables === null) {
- $tables = array();
- $sequences = array();
-
- // read complete schema (initial) file
- $filename = "$dir/../$engine.initial.sql";
- $schema = @file_get_contents($filename);
-
- // find table names
- if (preg_match_all('/CREATE TABLE (\[dbo\]\.|IF NOT EXISTS )?[`"\[\]]*([^`"\[\] \r\n]+)/i', $schema, $matches)) {
- foreach ($matches[2] as $table) {
- $tables[$table] = $prefix . $table;
- }
- }
- // find sequence names
- if ($engine == 'postgres' && preg_match_all('/CREATE SEQUENCE (IF NOT EXISTS )?"?([^" \n\r]+)/i', $schema, $matches)) {
- foreach ($matches[2] as $sequence) {
- $sequences[$sequence] = $prefix . $sequence;
- }
- }
- }
-
- // replace table names
- foreach ($tables as $table => $real_table) {
- $sql = preg_replace("/([^a-zA-Z0-9_])$table([^a-zA-Z0-9_])/", "\\1$real_table\\2", $sql);
- }
- // replace sequence names
- foreach ($sequences as $sequence => $real_sequence) {
- $sql = preg_replace("/([^a-zA-Z0-9_])$sequence([^a-zA-Z0-9_])/", "\\1$real_sequence\\2", $sql);
- }
-
- return $sql;
-}
-
?>