Skip to content
This repository
Browse code

NEW Allow querying if a field exists on a table

  • Loading branch information...
commit cc2e2507194298b89ad7ca7a6304423d86e3a87b 1 parent abbce15
Hamish Friedlander authored August 29, 2012

Showing 1 changed file with 13 additions and 1 deletion. Show diff stats Hide diff stats

  1. 14  model/Database.php
14  model/Database.php
@@ -143,7 +143,7 @@ function clearCachedFieldlist($tableName=false){
143 143
 	 * Returns true if the given table exists in the database
144 144
 	 */
145 145
 	abstract function hasTable($tableName);
146  
-	
  146
+
147 147
 	/**
148 148
 	 * Returns the enum values available on the given field
149 149
 	 */
@@ -440,6 +440,18 @@ function requireIndex($table, $index, $spec) {
440 440
 	}
441 441
 
442 442
 	/**
  443
+	 * Return true if the table exists and already has a the field specified
  444
+	 * @param string $tableName - The table to check
  445
+	 * @param string $fieldName - The field to check
  446
+	 * @return bool - True if the table exists and the field exists on the table
  447
+	 */
  448
+	function hasField($tableName, $fieldName) {
  449
+		if (!$this->hasTable($tableName)) return false;
  450
+		$fields = $this->fieldList($tableName);
  451
+		return array_key_exists($fieldName, $fields);
  452
+	}
  453
+
  454
+	/**
443 455
 	 * Generate the given field on the table, modifying whatever already exists as necessary.
444 456
 	 * @param string $table The table name.
445 457
 	 * @param string $field The field name.

0 notes on commit cc2e250

Please sign in to comment.
Something went wrong with that request. Please try again.