summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2007-04-21 18:08:41 +0000
committerDries Buytaert <dries@buytaert.net>2007-04-21 18:08:41 +0000
commit9050e15621523ed306fda50d24f5fe79eaa3ddb0 (patch)
treeb06513cfc48c5a2085f62f42e6199bf162f27df1
parentcf050e5f6e79841f79a29763ba757850d441e281 (diff)
downloadbrdo-9050e15621523ed306fda50d24f5fe79eaa3ddb0.tar.gz
brdo-9050e15621523ed306fda50d24f5fe79eaa3ddb0.tar.bz2
- Patch #137479 by dww: added db_column_exits(). (Yay, the servers are snappy on Saturday evening.)
-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() {