summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/database.mysql.inc7
-rw-r--r--includes/database.mysqli.inc7
-rw-r--r--includes/database.pgsql.inc7
3 files changed, 21 insertions, 0 deletions
diff --git a/includes/database.mysql.inc b/includes/database.mysql.inc
index 4617ca125..72f3a4c7a 100644
--- a/includes/database.mysql.inc
+++ b/includes/database.mysql.inc
@@ -422,6 +422,13 @@ function db_table_exists($table) {
}
/**
+ * Check if a column exists in the given table.
+ */
+function db_column_exists($table, $column) {
+ return db_num_rows(db_query("SHOW COLUMNS FROM {%s} LIKE '%s'", $table, $column));
+}
+
+/**
* Wraps the given table.field entry with a DISTINCT(). The wrapper is added to
* the SELECT list entry of the given query and the resulting query is returned.
* This function only applies the wrapper if a DISTINCT doesn't already exist in
diff --git a/includes/database.mysqli.inc b/includes/database.mysqli.inc
index 5e829fbd3..04f8cc9aa 100644
--- a/includes/database.mysqli.inc
+++ b/includes/database.mysqli.inc
@@ -402,6 +402,13 @@ function db_table_exists($table) {
}
/**
+ * Check if a column exists in the given table.
+ */
+function db_column_exists($table, $column) {
+ return db_num_rows(db_query("SHOW COLUMNS FROM {%s} LIKE '%s'", $table, $column));
+}
+
+/**
* Wraps the given table.field entry with a DISTINCT(). The wrapper is added to
* the SELECT list entry of the given query and the resulting query is returned.
* This function only applies the wrapper if a DISTINCT doesn't already exist in
diff --git a/includes/database.pgsql.inc b/includes/database.pgsql.inc
index 56a30ee9a..be5e4447a 100644
--- a/includes/database.pgsql.inc
+++ b/includes/database.pgsql.inc
@@ -395,6 +395,13 @@ function db_table_exists($table) {
}
/**
+ * Check if a column exists in the given table.
+ */
+function db_column_exists($table, $column) {
+ return db_result(db_query("SELECT COUNT(pg_attribute.attname) FROM pg_class, pg_attribute WHERE pg_attribute.attrelid = pg_class.oid AND pg_class.relname = '{". db_escape_table($table) ."}' AND attname='%s'", $column));
+}
+
+/**
* Verify if the database is set up correctly.
*/
function db_check_setup() {