/** * Returns a Field object. If the column is NOT in the table, a * Error is thrown by the Field constructor * @param string $column_name Name of the column in this table * @param string $alias Query alias used when referencing this field * @return Field */ public function getField($column_name, $alias = null) { if (!$this->db->allowed($column_name)) { throw new \Exception(t('Improper column name "%s"', $column_name)); } $field = new Field($this, $column_name, $alias); if (!($field->allowSplat() && $column_name == '*') && (DATABASE_CHECK_COLUMNS && !$this->columnExists($column_name))) { throw new \Exception(t('Column does not exist in %s "%s"', get_class($this), $this->getFullName())); } return $field; }
/** * Constructs a new column object * @param string $name Name of the column * @param \Database\Resource $resource * @param boolean $check_existence If true, check to see if column exists * before creating */ public function __construct(\Database\Resource $resource, $name, $check_existence = null) { $check_existance = empty($check_existance) ? DATABASE_CHECK_COLUMNS : $check_existance; if (!\Database\DB::allowed($name)) { throw new \Exception(t('Bad column name')); } $this->name = new \Variable\Attribute($name, 'name'); $this->resource = $resource; if ($check_existence && !$this->resource->columnExists($name)) { throw new \Exception(t('Column "%s" does not exist in %s "%s"', $name, get_class($resource), $this->resource->getFullName(false))); } }