Merge pull request #3345 from annando/1704-db-update-error
Print out database error messages
This commit is contained in:
commit
afa70bf74e
1 changed files with 23 additions and 8 deletions
|
@ -158,6 +158,21 @@ function print_structure($database) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print out database error messages
|
||||||
|
*
|
||||||
|
* @param object $db Database object
|
||||||
|
* @param string $message Message to be added to the error message
|
||||||
|
*
|
||||||
|
* @return string Error message
|
||||||
|
*/
|
||||||
|
function print_update_error($db, $message) {
|
||||||
|
echo sprintf(t("\nError %d occured during database update:\n%s\n"),
|
||||||
|
$db->errorno, $db->error);
|
||||||
|
|
||||||
|
return t('Errors encountered performing database changes: ').$message.EOL;
|
||||||
|
}
|
||||||
|
|
||||||
function update_structure($verbose, $action, $tables=null, $definition=null) {
|
function update_structure($verbose, $action, $tables=null, $definition=null) {
|
||||||
global $a, $db;
|
global $a, $db;
|
||||||
|
|
||||||
|
@ -207,7 +222,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
|
||||||
if (!isset($database[$name])) {
|
if (!isset($database[$name])) {
|
||||||
$r = db_create_table($name, $structure["fields"], $verbose, $action, $structure['indexes']);
|
$r = db_create_table($name, $structure["fields"], $verbose, $action, $structure['indexes']);
|
||||||
if (!dbm::is_result($r)) {
|
if (!dbm::is_result($r)) {
|
||||||
$errors .= t('Errors encountered creating database tables.').$name.EOL;
|
$errors .= print_update_error($db, $name);
|
||||||
}
|
}
|
||||||
$is_new_table = True;
|
$is_new_table = True;
|
||||||
} else {
|
} else {
|
||||||
|
@ -364,33 +379,33 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
|
||||||
} else {
|
} else {
|
||||||
$r = $db->q("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
|
$r = $db->q("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
|
||||||
if (!dbm::is_result($r)) {
|
if (!dbm::is_result($r)) {
|
||||||
$errors .= t('Errors encountered performing database changes.').$sql3.EOL;
|
$errors .= print_update_error($db, $sql3);
|
||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = @$db->q($sql3);
|
$r = @$db->q($sql3);
|
||||||
if (!dbm::is_result($r))
|
if (!dbm::is_result($r)) {
|
||||||
$errors .= t('Errors encountered performing database changes.').$sql3.EOL;
|
$errors .= print_update_error($db, $sql3);
|
||||||
|
}
|
||||||
if ($is_unique) {
|
if ($is_unique) {
|
||||||
if ($ignore != "") {
|
if ($ignore != "") {
|
||||||
$db->q("SET session old_alter_table=0;");
|
$db->q("SET session old_alter_table=0;");
|
||||||
} else {
|
} else {
|
||||||
$r = $db->q("INSERT INTO `".$temp_name."` SELECT * FROM `".$name."`".$group_by.";");
|
$r = $db->q("INSERT INTO `".$temp_name."` SELECT * FROM `".$name."`".$group_by.";");
|
||||||
if (!dbm::is_result($r)) {
|
if (!dbm::is_result($r)) {
|
||||||
$errors .= t('Errors encountered performing database changes.').$sql3.EOL;
|
$errors .= print_update_error($db, $sql3);
|
||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
$r = $db->q("DROP TABLE `".$name."`;");
|
$r = $db->q("DROP TABLE `".$name."`;");
|
||||||
if (!dbm::is_result($r)) {
|
if (!dbm::is_result($r)) {
|
||||||
$errors .= t('Errors encountered performing database changes.').$sql3.EOL;
|
$errors .= print_update_error($db, $sql3);
|
||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
$r = $db->q("RENAME TABLE `".$temp_name."` TO `".$name."`;");
|
$r = $db->q("RENAME TABLE `".$temp_name."` TO `".$name."`;");
|
||||||
if (!dbm::is_result($r)) {
|
if (!dbm::is_result($r)) {
|
||||||
$errors .= t('Errors encountered performing database changes.').$sql3.EOL;
|
$errors .= print_update_error($db, $sql3);
|
||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue