Renombra una consulta (nombre de tabla y campos)
@param Query $query query a renombrar
@param null|string $tableName nombre de la tabla
@param null|array $columnNames columnas de la tabla
509124
protected function renameQuery (Query $query, $tableName = null, $columnNames = null) {
        $originalSource = $this->renameSource($query, $tableName);

        if($columnNames == null) {
            $columnNames = $this->getColumnNames();
        }

        if ($query instanceof SelectQuery) {
            $hasFieldMappings = $this->hasFieldMappings($columnNames);
            if (!empty($columnNames)) {
                //si $hasFieldMappings == false llamo igual para el caso de select * que complete solo son lo indicado en columnNames
                $this->renameSelectFields($query, $columnNames, $originalSource);

                if ($hasFieldMappings) {
                    if ($query->hasWhereConditions()) {
                        $this->renameConditionFields($query->getWhereConditionGroup(), $columnNames, $originalSource, $query->getTable());
                    }

                    $this->renameOrderByFields($query, $columnNames, $originalSource);
                    $this->renameGroupByFields($query, $columnNames, $originalSource);
                    $this->renameJoinFields($query, $columnNames, $originalSource);
                }
            }
        }
        else if ($query instanceof UpdateQuery) {
            $hasFieldMappings = $this->hasFieldMappings($columnNames);
            if ($hasFieldMappings) {
                if ($query->hasWhereConditions()) {
                    $this->renameConditionFields($query->getWhereConditionGroup(), $columnNames, $originalSource, $query->getTable());
                }
                $this->renameSetFields($query, $columnNames, $originalSource, $query->getTable());
            }
        }
        else if ($query instanceof InsertQuery) {
            $hasFieldMappings = $this->hasFieldMappings($columnNames);
            if ($hasFieldMappings) {
                $this->renameSetFields($query, $columnNames, $originalSource, $query->getTable());
            }
        }
        else if ($query instanceof DeleteQuery) {
            $hasFieldMappings = $this->hasFieldMappings($columnNames);
            if ($hasFieldMappings) {
                if ($query->hasWhereConditions()) {
                    $this->renameConditionFields($query->getWhereConditionGroup(), $columnNames, $originalSource, $query->getTable());
                }
            }
        }
    }
60989
protected function parseTable(Query $query, $tables)
    {
        $item    = [];
        $options = $query->getOptions();

        foreach ((array) $tables as $key => $table) {
            if (!is_numeric($key)) {
                $key    = $this->connection->parseSqlTable($key);
                $item[] = $this->parseKey($query, $key) . ' ' . $this->parseKey($query, $table);
            } else {
                $table = $this->connection->parseSqlTable($table);

                if (isset($options['alias'][$table])) {
                    $item[] = $this->parseKey($query, $table) . ' ' . $this->parseKey($query, $options['alias'][$table]);
                } else {
                    $item[] = $this->parseKey($query, $table);
                }
            }
        }

        return implode(',', $item);
    }
852202
private function renameSource(Query $query, string $tableName = null):string {
        if($tableName == null) {
            $tableName = $this->getTableName();
        }
        $previusSource = $query->getTable();
        if(!empty($tableName)) {
            $query->table($tableName);
        }
        return $previusSource;
    }
672870
public function setQuery($query = null)
    {
        $this->query = [];
        return ($query === null)
            ? $this
            : $this->addQueryData($query);
    }
1370142
public function processQuery(Query $query, $knownTables): Query
    {
        foreach ($this->getTables($query) as $table) {
            $knownTables[] = $table;
        }

        return parent::processQuery($query, $knownTables);
    }
408585
public function bind_and_run( $query, $bindings = [] )
	{
		$new_query = $this->bind_params( $query, $bindings );

		$result = $this->db->query( $new_query );

		if ( $result === false || $this->db->last_error ) {
			throw new QueryException( $new_query, $bindings, new \Exception( $this->db->last_error ) );
		}

		return (array) $result;
	}
855922
public function removeParametersFromColumnName($columnName = null)
    {
        if (null !== $columnName) {
            $newParams = [];
            $parameters = $this->getParameters();
            foreach ($parameters as $key => $parameter) {
                if ($parameter['column'] != $columnName) {
                    $newParams[$key] = $parameter;
                }
            }

            $this->setParameters($newParams);
        }
    }
480704
protected function scopeQueryToWhereModelIsMissing($query, $modelName)
    {
        $model = new $modelName;
        $table = $this->abilitiesTable();

        $query->where("{$table}.entity_type", $modelName);

        $query->whereNotIn("{$table}.entity_id", function ($query) use ($modelName) {
            $model = new $modelName;
            $table = $model->getTable();

            $query->from($table)->select($table.'.'.$model->getKeyName());
        });
    }
786114
public function insert ($table_name, $columns) {
		$column_keys = array();
		foreach ($columns as $key => $value) {
			$column_keys[$key] = ":" . $key;
		}

		$query = "INSERT INTO " . $table_name . " (" . implode(", ", array_keys($column_keys)) . ") VALUES (" . implode(", ", array_values($column_keys)) . ")";
		$this -> query($query, $columns, false);
		return $this -> getLastInsertedID();
	}
891023
public function collStats(Query $query)
    {
        $options = $query->getOptions();

        $cmd     = ['collStats' => $options['table']];
        $command = new Command($cmd);

        $this->log('cmd', 'collStats', $cmd);

        return $command;
    }
976615
public function createQueryColumn(
        $query_name = "",
        $table_name = "table_name",
        $column_name = "column_name",
        $column_type = "string",
        $column_length = 0,
        $column_mask = "MASK",
        $in_select = true
    ) {
        // Default Query Column Name to Datbase Column Name ( if not set )

        $this->columns[] = new QueryColumn
        (
            $query_name,
            $table_name,
            $column_name,
            $column_type,
            $column_length,
            $column_mask,
            $in_select
        );
        end($this->columns);
        $ky = key($this->columns);
        $this->display_order_set["itemno"][] = count($this->columns);
        $this->display_order_set["column"][] = &$this->columns[$ky];
    }
625852
function parse_query($query) {
		$operations = array('SELECT','INSERT','UPDATE','DELETE','REPLACE','RENAME','SHOW','SET','DROP','CREATE INDEX','CREATE TABLE','EXPLAIN','DESCRIBE');

		$query_ex = '/(?P<operation>'.implode("|",$operations).')\s*(?P<columns>.?)\s*(FROM|INTO)\s*(?P<table>`?.*?`?)\s*(WHERE)?\s*?(?P<where>.*?)\s*?(ORDER BY)?\s*?(?P<order>.*?)?\s*?(LIMIT)?(?P<limit>.*?)?$/i';
		preg_match($query_ex, $query, $retn);
		return $retn;	
    }
109536
public function GetTableColumnsMeta($tableName, $columnNames) {
        $tableColumnsMetadata = array();
        foreach ($columnNames as $columnName) {
            $this->setDbConfigList(array());
            $dbConfig = new \Puzzlout\Framework\Dal\DbStatementConfig(null, \Puzzlout\Framework\Dal\DbExecutionType::COLUMNMETAS, new \Puzzlout\Framework\Dal\DbQueryFilters());
            $dbConfig->setQuery("SHOW COLUMNS FROM `$tableName` WHERE `Field` = '$columnName';");
            $this->addDbConfigItem($dbConfig);
            $tableColumnsMetadata[$columnName] = $this->BindParametersAndExecute();
        }
        return $tableColumnsMetadata;
    }
1050238
public function select($query)
    {
        $clause = 'SELECT @DISTINCT';

        if ($query->operation['type'] & AnDomainQuery::QUERY_SELECT_DEFAULT) {
            $description = $query->getRepository()->getDescription();
            $columns = AnDomainQueryHelper::parseColumns($query, $query->columns);
            foreach ($description->getProperty() as $name => $property) {
                if (isset($columns[$name])) {
                    $result = AnDomainQueryHelper::parseColumn($query, $name);
                    if ($result['columns'] instanceof AnDomainResourceColumn) {
                        $columns[] = $columns[$name].' AS '.$this->_store->quoteValue($result['columns']->key());
                        unset($columns[$name]);
                    }
                } elseif ($property->isAttribute()) {
                    $columns[] = $property->getColumn();
                } elseif ($property->isRelationship() && $property->isManyToOne()) {
                    $columns = array_merge($columns, array_values(AnConfig::unbox($property->getColumns())));
                }
            }

            if ($description->getInheritanceColumn()) {
                $columns[] = $description->getInheritanceColumn();
            }

            foreach ($columns as $key => $column) {
                if ($column instanceof AnDomainResourceColumn) {
                    if ($column->resource->getLink()) {
                        $columns[$key] = $column.' AS '.$this->_store->quoteValue((string) $column);
                        continue;
                    } else {
                        $columns[$key] = (string) $column;
                    }
                }
                if (!is_numeric($key)) {
                    $columns[$key] = $column.' AS '.$this->_store->quoteValue($key);
                }
            }
            $clause .= ' '.implode(' , ', $columns);
        } else {
            $columns = (array) $query->operation['value'];
            $columns = AnDomainQueryHelper::parseColumns($query, $columns);
            $clause .= ' '.implode(' , ', $columns);
        }

        return $clause;
    }
1321993
protected static function checkColumn($tableName, $columnName, $con=NULL)
    {
        $connection = self::checkConnection($con);

            $result = $connection->prepare("SELECT {$columnName} FROM {$tableName}");
            $result->execute();
            if (! $result->columnCount())
            {
                throw new ColumnNotExistExeption();
            }
            return $columnName;
    }
500872
public function select( $query, $bindings = [] )
	{
		$query = $this->bind_params( $query, $bindings );

		$result = $this->db->get_results( $query );

		if ( $result === false || $this->db->last_error ) {
			throw new QueryException( $query, $bindings, new \Exception( $this->db->last_error ) );
		}

		return $result;
	}
222876
public function applyToModelQuery($query, $table = null)
    {
        if (is_null($this->scope) || $this->onlyScopeRelations) {
            return $query;
        }

        if (is_null($table)) {
            $table = $query->getModel()->getTable();
        }

        return $this->applyToQuery($query, $table);
    }