/** * Get the columns from database table. * * @return array An array of the field names, or false if an error occurs. * * @since 2.0 * @throws \UnexpectedValueException */ public function getFields() { if ($this->fields === null) { // Lookup the fields for this table only once. $fields = $this->db->getTable($this->table)->getColumnDetails(true); if (empty($fields)) { throw new \UnexpectedValueException(sprintf('No columns found for %s table', $this->table)); } $this->fields = $fields; } return $this->fields; }
/** * Batch update some data. * * @param string $table Table name. * @param array $data Data you want to update. * @param mixed $conditions Where conditions, you can use array or Compare object. * Example: * - `array('id' => 5)` => id = 5 * - `new GteCompare('id', 20)` => 'id >= 20' * - `new Compare('id', '%Flower%', 'LIKE')` => 'id LIKE "%Flower%"' * * @return boolean True if update success. */ public function updateBatch($table, $data, $conditions = array()) { $query = $this->db->getQuery(true); // Build conditions $query = QueryHelper::buildWheres($query, $conditions); // Build update values. $fields = array_keys($this->db->getTable($table)->getColumns()); $hasField = false; foreach ((array) $data as $field => $value) { if (!in_array($field, $fields)) { continue; } $query->set($query->format('%n = %q', $field, $value)); $hasField = true; } if (!$hasField) { return false; } $query->update($table); return $this->db->setQuery($query)->execute(); }
/** * getFilterFields * * @return array */ public function getSelectFields() { $fields = array(); $i = 0; foreach ($this->tables as $alias => $table) { $columns = $this->db->getTable($table['name'])->getColumns(); foreach ($columns as $column) { $prefix = $table['prefix']; if ($i === 0) { $prefix = $prefix === null ? false : true; } else { $prefix = $prefix === null ? true : false; } if ($prefix === true) { $fields[] = $this->db->quoteName("{$alias}.{$column} AS {$alias}_{$column}"); } else { $fields[] = $this->db->quoteName("{$alias}.{$column} AS {$column}"); } } $i++; } return $fields; }
/** * Get table fields. * * @param string $table Table name. * * @return array */ public function getFields($table) { return $this->db->getTable($table)->getColumns(); }