format table alias for fields or where
@param  mixed  $data      array|string
@param  string $table_alias table alias name
@param  array  $in_fields
@return mixed  array|string
501132
static public function formatQueryTableAlias($data=null, $table_alias=null, $in_fields=null)
    {
        if ($data && isset($table_alias)) {
            if (is_array($data)) {
                foreach ($data as $k => $v) {
                    if (!is_numeric($k) && strpos($k, '.') === false) {
                        if(isset($in_fields) && !in_array($k, $in_fields)) continue;
                        
                        $data[$table_alias . '.' . $k] = $v;
                        unset($data[$k]);
                    }
                }
            } elseif (strpos($data, ',')) {
                $data = explode(',', $data);
                foreach ($data as $k => $v) {
                    $v = trim($v);
                    if(isset($in_fields) && !in_array($v, $in_fields)) continue;
                    
                    $data[$k] = $table_alias . '.' . $v;
                }
                $data = implode(',', $data);
            } elseif (strpos($data, '.') === false) {
                $data = trim($data);
                if(isset($in_fields) && in_array($data, $in_fields)) {
                    $data = $table_alias . '.' . $data;
                }
            }
        }
        
        return $data;
    }
928891
public function findIn($table_name, $column_name, array $in_array) {
            $params = $this->getEnumeratedParameterList($table_name . '_' . $column_name, $in_array);

            $query = "SELECT * FROM $table_name WHERE $column_name IN (" . $this->keyList($params) . ')';
            $records = $this->query($query, $params);

            return $records;
        }
972595
public function fieldSelectAll($table, $fields, $where, $orderBy = null)
    {
        $table = $this->getTableName($table);

        $query = "SELECT ";

        $query .= $this->selectFields($fields);

        $query .= " FROM " . $table . " ";

        $params = null;
        if ($where !== self::NO_WHERE_CLAUSE) {
            $query .= "WHERE " . $this->where($where, $params);
        }

        if ($orderBy) {
            $query .= $this->orderBy($orderBy) . " ";
        }

        return $this->query($query, $params);
    }
181865
public function aliasRelationshipWhere($column, $tableAlias, $pivotAlias, $pivot)
    {
        //first explode the string on "." in case it was given with the table already included
        $split = explode('.', $column);

        //if the second split item exists, there was a "."
        if (isset($split[1])) {
            //if the table name is the pivot table, append the pivot alias
            if ($split[0] === $pivot) {
                return $pivotAlias.'.'.$split[1];
            }
            //otherwise append the table alias
            else {
                return $tableAlias.'.'.$split[1];
            }
        } else {
            return $tableAlias.'.'.$column;
        }
    }
933861
public function update($table, array $data = [], $where = null): array
    {
        if (\is_array($table)) {
            $data = $table[SQL::SET] ?? $table[SQL::VALUES];
            $where = $table;
            $table = $this->getTable($table, SQL::UPDATE);
        } elseif ($where) {
            $where = [SQL::WHERE => $where];
        }

        $fields = [];
        $map = [];

        foreach ($data as $key => $value) {
            $column = $this->columnQuote(\preg_replace("/(\s*\[(\+|\-|\*|\/)\]$)/i", '', $key));

            if ($raw = $this->buildRaw($value, $map)) {
                $fields[] = $column . ' = ' . $raw;
                continue;
            }

            $mapKey = $this->mapKey();
            \preg_match('/(?<column>\w+)(\[(?<operator>\+|\-|\*|\/)\])?/i', $key, $match);

            if (isset($match['operator'])) {
                if (\is_numeric($value)) {
                    $fields[] = $column . ' = ' . $column . ' ' . $match['operator'] . ' ' . $value;
                }
            } else {
                $fields[] = $column . ' = ' . $mapKey;
                $map[$mapKey] = $this->typeMap($value, \gettype($value));
            }
        }

        $sql = 'UPDATE ' . $this->tableQuote($table) . ' SET ' . \implode(', ', $fields) .
            $this->suffixClause($where, $map);

        return [$sql, $map];
    }
228629
public function in ($fieldName, $fieldArray = [])
    {
        $fieldArray = array_map(function($v) { return sprintf('"%s"', $v); }, $fieldArray);
        $tableName  = '';

        if (strpos($fieldName, '.') === false) {
            $tableName = $this->table() . '.';
        }

        if (!empty($fieldArray)) {
            $this->setIn($tableName . $fieldName . ' IN (' . implode(', ', $fieldArray) . ')');
        }

        return $this;
    }
401870
function record_exists($table, $data) {
		if (!empty($this->prefix) && !(substr_count($table,$this->prefix) > 0)) {
			$table = $this->prefix."_".$table;
        }
		$pairs = array();
		foreach($data as $key => $value) {
			if (!is_numeric($value)) {
				$pairs[] = $this->encapsulate_column_name($key)." = '".$this->escape($value)."'";
			} else {
				$pairs[] = $this->encapsulate_column_name($key)." = $value";
			}
		}
		$where = implode(" AND ", $pairs);
		$records = $this->select("*",$table,$data);
		if ($records->num_rows > 0) {
			return $records;
		} else {
			return false;
		}
	}
385622
public function buildInsertBatchSQL($table = null, $data = array())
	{
		$keys = array_keys($data[0]);
		$values = array();
		foreach($data as $item)
		{
			$params = array();
			foreach($keys as $key)
			{
				$paramName = ':' . $this->getParamName();
				$this->bindValue($paramName, $item[$key]);
				$params[] = $paramName;
			}
			$values[] = '(' . implode(',', $params) . ')';
		}
		$this->operationOption['params'] = array();
		return 'insert into ' . $this->parseTable($table) . ' (' . implode(',',array_map(array($this,'parseKeyword'),$keys)) . ') values ' . implode(',', $values) . $this->parseLock();
	}
983203
public function table($table, $alias = null)
    {
        $database = null;

        // Check if the table is an object, this means
        // we have an subselect inside the table
        if (is_object($table) && ($table instanceof \Closure)) 
        {
            // we have to check if an alias isset 
            // otherwise throw an exception to prevent the 
            // "Every derived table must have its own alias" error
            if (is_null($alias))
            {
                throw new Exception('You must define an alias when working with subselects.');
            }

            $table = array($alias => $table);
        } 

        // Check if the $table is an array and the value is an closure
        // that we can pass a new query object as subquery 
        if (is_array($table) && is_object(reset($table)) && (reset($table) instanceof \Closure)) 
        {
            $alias = key($table);
            $table = reset($table);

            // create new query object
            $subquery = new Select;

            // run the closure callback on the sub query
            call_user_func_array($table, array(&$subquery));

            // set the table 
            // IMPORTANT: Only if we have a closure as table
            // we set the alias as key. This might cause some confusion
            // but only this way we can keep the normal ['table' => 'alias'] syntax
            $table = array($alias => $subquery);
        } 

        // other wise normally try to split the table and database name
        elseif (is_string($table) && strpos($table, '.') !== false)
        {
            $selection = explode('.', $table);

            if (count($selection) !== 2)
            {
                throw new Exception( 'Invalid argument given. You can only define one seperator.' );
            }

            list($database, $table) = $selection;
        }

        // the table might include an alias we need to parse that one out 
        if (is_string($table) && strpos($table, ' as ') !== false)
        {
            $tableParts = explode(' as ', $table);
            $table = array($tableParts[0] => $tableParts[1]);
        }

        // assing the result
        $this->database = $database;
        $this->table = $table;

        // return self
        return $this;
    }
1346397
public static function format($data, $access=null, $fields=null) {
        return [
            'user' => $data->User->URLSegment,
            'token' => $data->Token
        ];
    }
66726
public function getFieldWithTableAlias($name, $table_alias = null)
    {
        $replace = $table_alias === null ? '' : sprintf("%s.", $table_alias);

        return $this->replaceToken($this->checkFieldExist($name)->fields[$name], $replace);
    }
263841
public function field_format_value($fields, $data) 
    {
        if (!$fields || !$data || !is_array($data)) {
            return $data;
        }
        foreach ($fields as $field) {
            $obj = $this->get($field['fieldtype']);
            if (!$obj) {
                continue;
            }
            if ($field['fieldtype'] === 'Group') {
                continue;
            }
            $data = $obj->output_data($data, $field);
        }
        return $data;
    }
548229
protected static function data_prepare ($data, $tag, &$in, &$attributes) {
		if (isset($data['in'])) {
			if ($data['in'] === false) {
				return false;
			}
			$in = trim($data['in']);
			unset($data['in']);
		}
		if ($tag == 'img' && !isset($data['alt'])) {
			$data['alt'] = '';
		}
		if (isset($data['src'])) {
			$data['src'] = static::prepare_url($data['src']);
		}
		if (isset($data['href'])) {
			if ($tag != 'a') {
				$data['href'] = static::prepare_url($data['href']);
			} elseif ($data['href'][0] == '#') {
				$data['href'] = static::url_with_hash($data['href']);
			}
		}
		static::data_prepare_normalize_attributes($data);
		ksort($data);
		foreach ($data as $key => $value) {
			if ($value === false) {
				continue;
			}
			if ($value === true) {
				$attributes .= " $key";
			} else {
				$value      = static::prepare_attr_value($value);
				$attributes .= " $key=\"$value\"";
			}
		}
		return true;
	}
1209847
public function andWhere($field, $operation, $value = null, $alias = self::DEFAULT_TABLE_ALIAS)
    {
        if (strpos($field, '.') > 0) {
            //monta os joins
            $this->fieldValue = [
                'value'     => $value,
                'operation' => $operation,
            ];
            $newAliasField = $this->associationQueryFields($field);
            $alias = $newAliasField['alias'];
            $field = $newAliasField['field'];
        }
        $this->queryBuilder->andWhere($this->makeExpression($field, $operation, $value, $alias));

        return $this;
    }
313482
public function aliasedColumn($query, $columnName, $tableName = null)
    {
        return $this->alias(
            $this->quoteColumn($columnName, $tableName),
            $this->quoteIdentifier(
                ($tableName ? $tableName . '_' : '') .
                $columnName
            )
        );
    }
646834
public static function input ($in = [], $data = []) {
		if (isset($in['insert']) || isset($data['insert'])) {
			return static::__callStatic_internal(__FUNCTION__, func_get_args());
		}
		if ($in === false) {
			return '';
		}
		$in = static::input_merge($in, $data);
		if (static::is_array_indexed($in) && is_array($in[0])) {
			return static::__callStatic_internal(__FUNCTION__, [$in, $data]);
		}
		if (isset($in['type']) && $in['type'] == 'radio') {
			return static::input_radio($in);
		}
		return static::input_other($in);
	}
395297
public function get_sql_filter($data) {
        $field  = $this->field;
        if (is_array($field)) {
            $res = " {$field[0]} = {$field[1]} ";
        } else {
            $res = " {$field} = 0 ";
        }
        return array($res, array());
    }