Commit d2238f09 authored by Gábor Hojtsy's avatar Gábor Hojtsy

#986682 by pkiraly: improve code documentation for db_table_exists() and db_column_exists()

parent 3f7a4816
......@@ -177,6 +177,7 @@ function db_fetch_array($result) {
*
* @param $result
* A database query result resource, as returned from db_query().
*
* @return
* The resulting field or FALSE.
*/
......@@ -345,6 +346,12 @@ function db_unlock_tables() {
/**
* Check if a table exists.
*
* @param $table
* The name of the table.
*
* @return
* TRUE if the table exists, and FALSE if the table does not exist.
*/
function db_table_exists($table) {
return (bool) db_fetch_object(db_query("SHOW TABLES LIKE '{". db_escape_table($table) ."}'"));
......@@ -352,6 +359,14 @@ function db_table_exists($table) {
/**
* Check if a column exists in the given table.
*
* @param $table
* The name of the table.
* @param $column
* The name of the column.
*
* @return
* TRUE if the column exists, and FALSE if the column does not exist.
*/
function db_column_exists($table, $column) {
return (bool) db_fetch_object(db_query("SHOW COLUMNS FROM {". db_escape_table($table) ."} LIKE '". db_escape_table($column) ."'"));
......
......@@ -346,6 +346,12 @@ function db_unlock_tables() {
/**
* Check if a table exists.
*
* @param $table
* The name of the table.
*
* @return
* TRUE if the table exists, and FALSE if the table does not exist.
*/
function db_table_exists($table) {
return (bool) db_fetch_object(db_query("SHOW TABLES LIKE '{". db_escape_table($table) ."}'"));
......@@ -353,6 +359,14 @@ function db_table_exists($table) {
/**
* Check if a column exists in the given table.
*
* @param $table
* The name of the table.
* @param $column
* The name of the column.
*
* @return
* TRUE if the column exists, and FALSE if the column does not exist.
*/
function db_column_exists($table, $column) {
return (bool) db_fetch_object(db_query("SHOW COLUMNS FROM {". db_escape_table($table) ."} LIKE '". db_escape_table($column) ."'"));
......
......@@ -383,6 +383,12 @@ function db_unlock_tables() {
/**
* Check if a table exists.
*
* @param $table
* The name of the table.
*
* @return
* TRUE if the table exists, and FALSE if the table does not exist.
*/
function db_table_exists($table) {
return (bool) db_result(db_query("SELECT COUNT(*) FROM pg_class WHERE relname = '{". db_escape_table($table) ."}'"));
......@@ -390,6 +396,14 @@ function db_table_exists($table) {
/**
* Check if a column exists in the given table.
*
* @param $table
* The name of the table.
* @param $column
* The name of the column.
*
* @return
* TRUE if the column exists, and FALSE if the column does not exist.
*/
function db_column_exists($table, $column) {
return (bool) 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 = '". db_escape_table($column) ."'"));
......
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