Get field from table

@param  array|null   $field
@param  string|null  $sqlQuery
@rturn  array
426336
public function get($fields = null, $sqlQuery = false)
    {
        $sql = $this->buildQuery('select', $fields);
        if($sqlQuery === true) {
            return $this->getQuery();
        }
        $result = $this->executeQuery($sql);
        $data = $result->fetch_array(MYSQLI_ASSOC);
        return $data;
    }
634483
public function num_rows($sqlQuery = false)
    {
        $sql = $this->buildQuery('select');
        if($sqlQuery === true) {
            return $this->getQuery();
        }
        $result = $this->executeQuery($sql);
        return $result->num_rows;
    }
179121
protected function readFields(string $sql): array
    {
        if (trim($sql) === '') {
            throw new Exception\EmptyQueryException('Cannot read fields for an empty query');
        }

        $sql = $this->getEmptiedQuery($sql);
        $stmt = $this->mysqli->prepare($sql);

        if ($stmt === false) {
            $message = $this->mysqli->error;
            throw new Exception\InvalidQueryException(
                sprintf('Invalid query: %s (%s)', $sql, $message)
            );
        }
        $stmt->execute();

        $result = $stmt->result_metadata();
        if ($result === false) {
            $message = $this->mysqli->error;
            throw new Exception\InvalidQueryException(
                sprintf('Cannot get metadata: %s (%s)', $sql, $message)
            );
        }

        $metaFields = $result->fetch_fields();

        if ($metaFields === false) {
            $result->close();
            $message = $this->mysqli->error;
            throw new Exception\InvalidQueryException(
                sprintf('Cannot fetch metadata fields: %s (%s)', $sql, $message)
            );
        }

        $result->close();
        $stmt->close();

        return $metaFields;
    }
1054662
public function select($field, string $as = null, bool $reset = true): self
    {
        $reset && $this->reset();

        // handle trivial selects
        if ($field === 1 || $field === '1') {
            return $this->push('select', '1');
        } elseif ($field === true) {
            return $this->push('select', 'TRUE');
        }

        // handle other query object
        if ($field instanceof Builder || $field instanceof Sql) {
            if ($as == null) {
                throw new BuilderException('Alias required!');
            }
            return $this->push('select', '('. $field->toString() .') AS '. $this->agent->quoteField($as));
        }

        $field = $this->prepareField($field);
        if ($as != null) {
            $field = $field .' AS '. $this->agent->quoteField($as);
        }

        return $this->push('select', $field);
    }
510001
function FetchField($offset = -1)
	{
		$o= new ADOFieldObject();
		$o->name = @db2_field_name($this->_queryID,$offset);
		$o->type = @db2_field_type($this->_queryID,$offset);
		$o->max_length = db2_field_width($this->_queryID,$offset);
		if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name);
		else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name);
		return $o;
	}
9447
public function selectQuery($fields = null)
    {
        /**/$this->app->pr->start('selectQuery/getActualF');

        $actual_fields = $fields ?: $this->getActualFields();

        if ($this->fast && $this->_selectQuery) {
            return $this->_selectQuery();
        }

        $this->_selectQuery = $select = $this->_dsql()->del('fields');

        /**/$this->app->pr->next('selectQuery/addSystemFields');
        // add system fields into select
        foreach ($this->elements as $el) {
            if ($el instanceof Field) {
                if ($el->system() && !in_array($el->short_name, $actual_fields)) {
                    $actual_fields[] = $el->short_name;
                }
            }
        }
        /**/$this->app->pr->next('selectQuery/updateQuery');

        // add actual fields
        foreach ($actual_fields as $field) {
            /** @type Field $field */
            $field = $this->hasElement($field);
            if (!$field) {
                continue;
            }

            $field->updateSelectQuery($select);
        }
        /**/$this->app->pr->stop();

        return $select;
    }
354820
function buildQuery( $sql = NULL ) {
		if( !isset( $this->query ) OR empty( $sql ) ) {
			return FALSE;
		}

		$this->query .= $sql;

		return $this->query;
	}
267231
function select($fields,$filter=NULL,array $options=NULL,$ttl=0) {
		list($sql,$args)=$this->stringify($fields,$filter,$options);
		$result=$this->db->exec($sql,$args,$ttl);
		$out=[];
		foreach ($result as &$row) {
			foreach ($row as $field=>&$val) {
				if (array_key_exists($field,$this->fields)) {
					if (!is_null($val) || !$this->fields[$field]['nullable'])
						$val=$this->db->value(
							$this->fields[$field]['pdo_type'],$val);
				}
				unset($val);
			}
			$out[]=$this->factory($row);
			unset($row);
		}
		return $out;
	}
114933
protected function getColumnSql(\SimpleXMLElement $field)
	{
		// TODO Incorporate into parent class and use $this.
		$blobs = array('text', 'smalltext', 'mediumtext', 'largetext');

		$fName    = (string) $field['Field'];
		$fType    = (string) $field['Type'];
		$fNull    = (string) $field['Null'];
		$fDefault = isset($field['Default']) ? (string) $field['Default'] : null;
		$fExtra   = (string) $field['Extra'];

		$sql = $this->db->quoteName($fName) . ' ' . $fType;

		if ($fNull === 'NO')
		{
			if ($fDefault === null || \in_array($fType, $blobs, true))
			{
				$sql .= ' NOT NULL';
			}
			else
			{
				// TODO Don't quote numeric values.
				$sql .= ' NOT NULL DEFAULT ' . $this->db->quote($fDefault);
			}
		}
		else
		{
			if ($fDefault === null)
			{
				$sql .= ' DEFAULT NULL';
			}
			else
			{
				// TODO Don't quote numeric values.
				$sql .= ' DEFAULT ' . $this->db->quote($fDefault);
			}
		}

		if ($fExtra)
		{
			$sql .= ' ' . strtoupper($fExtra);
		}

		return $sql;
	}
134020
public static function dateSql2Text($sqlField)
	{
		$hasTime=false;
		$tmpDate = self::dateTimeSql2PHP($sqlField,$hasTime);
		if ($tmpDate===null) return null;
		if ($hasTime) {
			return $tmpDate->format((strpos($sqlField,'.')!==false) ? self::$dateTimeMicroFormat : self::$dateTimeFormat);
		}  else {
			return $tmpDate->format(self::$dateFormat);
		}
	}
891848
public static function dbField($table, $field, $where) {

        $fldValue = "";
        $row = self::dbRow($table, ['type'=>'num', 'fl'=>$field, 'where'=>$where]);
        if (!empty($row)) {
            list($fldValue) = $row;
        }
        return $fldValue;
    }
17202
public function getRecord($tableName, $field, $value, $fields = array())
    {
        $query = SQLEncoder::encodeGetRecord($tableName, $field, $value, $fields);
        return $this->con->query($query);
    }
521327
public function getRows($fields = null)
    {
        /**/$this->app->pr->start('getRows/selecting');
        $a = $this->selectQuery($fields);
        /**/$this->app->pr->next('getRows/fetching');
        $a = $a->get();
        $this->app->pr->stop();

        return $a;
    }
82963
private static function handleFields(
        $query,
        Fields $fields = null
    ) {
        $type = static::getType();

        if ($fields === null || empty($fields->get($type))) {
            //Use resource model's default fields
            $fields = static::getDefaultFields();

            $attributes =  array_merge(
                $fields->get($type),
                [static::getIdAttribute()] //[static::getTable() . '.' . static::getIdAttribute()]
            );
        } else {
            $attributes = $fields->get($type);

            if ($fields->get($type) !== ['*']) {
                //Get field attributes for this type and force id attribute
                $attributes = array_merge(
                    $fields->get($type),
                    [static::getIdAttribute()]
                );
            }
        }

        //if ($fields !== null && !empty($fields->get($type))) {
        $fields->validate(static::class);

        $attributes = array_unique($attributes);

        /**
         * @param string $column
         * @return string
         */
        $escape = function ($column) {
            if ($column === '*') {
                return $column;
            }

            return sprintf('"%s"', $column);
        };

        /**
         * This method will prepare the attributes by prefixing then with "
         * - * -> *
         * - table.* -> "table".*
         * - id -> "id"
         * - table.id -> "table"."id"
         * and glue them with comma separator
         */
        $queryPart = implode(
            ',',
            array_map(
                function ($attribute) use ($escape) {
                    return implode(
                        '.',
                        array_map($escape, explode('.', $attribute))
                    );
                },
                $attributes
            )
        );
        //}

        $query = str_replace(
            '{{fields}}',
            $queryPart,
            $query
        );

        return $query;
    }
194016
public function getOne($field = null)
    {
        $row = $this->statement->fetch(PDO::FETCH_ASSOC);

        return null === $field ? $row : $row[$field];
    }
1060506
protected function getRowSql($data, $columnFields) {
        $args = [];
        foreach ($data as $key => $item) {
            if (is_null($item)) {
                $args[] = 'NULL';
                continue;
            }
            if (array_key_exists($key, $columnFields) && $columnFields[$key]) {
                $args[] = $item;
                continue;
            }
            $args[] = sprintf('\'%s\'',
                str_replace(
                    ["\r\n", "\r", "\n", '\\\'', '\''],
                    ["\n", '\r\n', '\r\n', '\'', '\\\''], $item));
        }
        return implode(',',$args);
    }
201888
protected static function loadByQuery($query, $fields = null)
    {
        //
        $table = static::getTable();
        $writer = static::getDatabase()->getWriter();
        $alias = static::getClassName();

        //
        $join = null;
        $allFields = $fields ? $fields : static::getDefaultFields();

        // parse SQL select fields
        $selectFields = $writer->selectFields($allFields, $alias, $join);

        //
        $values = [];
        $whereConditions = [];

        //
        if (isset($query['where'])) {
            $whereConditions[] = '('.$query['where'].')';
            unset($query['where']);
        }

        //
        foreach ($query as $field => $value) {
            $token = ':'.$field;
            $whereConditions[] = "{$field} = {$token}";
            $values[$field] = $value;
        }

        //
        $where = implode(' AND ', $whereConditions);

        // prepare SQL query
        $sql = "SELECT {$selectFields} "
             ."FROM {$table} AS {$alias} {$join} "
             ."WHERE {$where} "
             .'LIMIT 1';

        // fetch data on database and return it
        $result = static::fetch(
            $sql,
            $values,
            true,
            is_string($fields),
            is_null($fields)
        );

        return $result;
    }