From 3e6f501bc0ddda1aa09f64f60fa7cba33ba616cf Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Sun, 16 Apr 2017 13:21:49 +0000
Subject: [PATCH 1/2] Print out database error messages

---
 include/dbstructure.php | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/include/dbstructure.php b/include/dbstructure.php
index 373d6ddb00..aea0fdfeda 100644
--- a/include/dbstructure.php
+++ b/include/dbstructure.php
@@ -158,6 +158,13 @@ function print_structure($database) {
 	}
 }
 
+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) {
 	global $a, $db;
 
@@ -207,7 +214,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
 		if (!isset($database[$name])) {
 			$r = db_create_table($name, $structure["fields"], $verbose, $action, $structure['indexes']);
 			if (!dbm::is_result($r)) {
-				$errors .=  t('Errors encountered creating database tables.').$name.EOL;
+				$errors .= print_update_error($db, $name);
 			}
 			$is_new_table = True;
 		} else {
@@ -364,33 +371,33 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
 					} else {
 						$r = $db->q("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
 						if (!dbm::is_result($r)) {
-							$errors .= t('Errors encountered performing database changes.').$sql3.EOL;
+							$errors .= print_update_error($db, $sql3);
 							return $errors;
 						}
 					}
 				}
 
 				$r = @$db->q($sql3);
-				if (!dbm::is_result($r))
-					$errors .= t('Errors encountered performing database changes.').$sql3.EOL;
-
+				if (!dbm::is_result($r)) {
+					$errors .= print_update_error($db, $sql3);
+				}
 				if ($is_unique) {
 					if ($ignore != "") {
 						$db->q("SET session old_alter_table=0;");
 					} else {
 						$r = $db->q("INSERT INTO `".$temp_name."` SELECT * FROM `".$name."`".$group_by.";");
 						if (!dbm::is_result($r)) {
-							$errors .= t('Errors encountered performing database changes.').$sql3.EOL;
+							$errors .= print_update_error($db, $sql3);
 							return $errors;
 						}
 						$r = $db->q("DROP TABLE `".$name."`;");
 						if (!dbm::is_result($r)) {
-							$errors .= t('Errors encountered performing database changes.').$sql3.EOL;
+							$errors .= print_update_error($db, $sql3);
 							return $errors;
 						}
 						$r = $db->q("RENAME TABLE `".$temp_name."` TO `".$name."`;");
 						if (!dbm::is_result($r)) {
-							$errors .= t('Errors encountered performing database changes.').$sql3.EOL;
+							$errors .= print_update_error($db, $sql3);
 							return $errors;
 						}
 					}

From d80a09c9e5f1cdb1bc58a7e5ad9e420f6d1e54c1 Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Sun, 16 Apr 2017 13:37:42 +0000
Subject: [PATCH 2/2] Doxygen header added

---
 include/dbstructure.php | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/dbstructure.php b/include/dbstructure.php
index aea0fdfeda..a0023c7710 100644
--- a/include/dbstructure.php
+++ b/include/dbstructure.php
@@ -158,6 +158,14 @@ 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);