Commit 9050e156 authored by Dries's avatar Dries
Browse files

- Patch #137479 by dww: added db_column_exits(). (Yay, the servers are snappy...

- Patch #137479 by dww: added db_column_exits().  (Yay, the servers are snappy on Saturday evening.)
parent cf050e5f
......@@ -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.
......
......@@ -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.
......
......@@ -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.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment