Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

NEW Allow querying if a field exists on a table

  • Loading branch information...
commit cc2e2507194298b89ad7ca7a6304423d86e3a87b 1 parent abbce15
@hafriedlander hafriedlander authored
Showing with 13 additions and 1 deletion.
  1. +13 −1 model/Database.php
View
14 model/Database.php
@@ -143,7 +143,7 @@ function clearCachedFieldlist($tableName=false){
* Returns true if the given table exists in the database
*/
abstract function hasTable($tableName);
-
+
/**
* Returns the enum values available on the given field
*/
@@ -440,6 +440,18 @@ function requireIndex($table, $index, $spec) {
}
/**
+ * 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.
* @param string $field The field name.
Please sign in to comment.
Something went wrong with that request. Please try again.