Skip to content
Snippets Groups Projects
Commit 9050e156 authored by Dries Buytaert's avatar Dries Buytaert
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
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -421,6 +421,13 @@ function db_table_exists($table) { ...@@ -421,6 +421,13 @@ function db_table_exists($table) {
return db_num_rows(db_query("SHOW TABLES LIKE '{". db_escape_table($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 * 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. * the SELECT list entry of the given query and the resulting query is returned.
......
...@@ -401,6 +401,13 @@ function db_table_exists($table) { ...@@ -401,6 +401,13 @@ function db_table_exists($table) {
return db_num_rows(db_query("SHOW TABLES LIKE '{". db_escape_table($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 * 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. * the SELECT list entry of the given query and the resulting query is returned.
......
...@@ -394,6 +394,13 @@ function db_table_exists($table) { ...@@ -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) ."}'")); 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. * Verify if the database is set up correctly.
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment