From 9050e15621523ed306fda50d24f5fe79eaa3ddb0 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 21 Apr 2007 18:08:41 +0000 Subject: - Patch #137479 by dww: added db_column_exits(). (Yay, the servers are snappy on Saturday evening.) --- includes/database.mysql.inc | 7 +++++++ includes/database.mysqli.inc | 7 +++++++ includes/database.pgsql.inc | 7 +++++++ 3 files changed, 21 insertions(+) (limited to 'includes') 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 @@ -421,6 +421,13 @@ function db_table_exists($table) { return db_num_rows(db_query("SHOW TABLES LIKE '{". db_escape_table($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. 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 @@ -401,6 +401,13 @@ function db_table_exists($table) { return db_num_rows(db_query("SHOW TABLES LIKE '{". db_escape_table($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. 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 @@ -394,6 +394,13 @@ function db_table_exists($table) { return db_num_rows(db_query("SELECT relname FROM pg_class WHERE relname = '{". db_escape_table($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. */ -- cgit v1.2.3