From cc2e2507194298b89ad7ca7a6304423d86e3a87b Mon Sep 17 00:00:00 2001 From: Hamish Friedlander Date: Wed, 29 Aug 2012 15:08:26 +1200 Subject: [PATCH] NEW Allow querying if a field exists on a table --- model/Database.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/model/Database.php b/model/Database.php index d76f73853..7e32cd114 100644 --- a/model/Database.php +++ b/model/Database.php @@ -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.