NEW Allow querying if a field exists on a table

This commit is contained in:
Hamish Friedlander 2012-08-29 15:08:26 +12:00
parent abbce151d9
commit cc2e250719

View File

@ -143,7 +143,7 @@ abstract class SS_Database {
* Returns true if the given table exists in the database
*/
abstract function hasTable($tableName);
/**
* Returns the enum values available on the given field
*/
@ -439,6 +439,18 @@ abstract class SS_Database {
}
}
/**
* Return true if the table exists and already has a the field specified
* @param string $tableName - The table to check
* @param string $fieldName - The field to check
* @return bool - True if the table exists and the field exists on the table
*/
function hasField($tableName, $fieldName) {
if (!$this->hasTable($tableName)) return false;
$fields = $this->fieldList($tableName);
return array_key_exists($fieldName, $fields);
}
/**
* Generate the given field on the table, modifying whatever already exists as necessary.
* @param string $table The table name.