Platform independent LIKE statement builder.

@param string|null $prefix
@param string      $column
@param string|null $not
@param string      $bind
@param bool        $caseSensitive

@return string
550353
protected function platformPrepareLikeStatement(
        $prefix = null,
        $column,
        $not = null,
        $bind,
        $caseSensitive = false
    ) {
        $likeStatement = "{$prefix} {$column} {$not} LIKE :{$bind}";

        if ($caseSensitive === true) {
            $likeStatement = "{$prefix} LOWER({$column}) {$not} LIKE :{$bind}";
        }

        return $likeStatement;
    }
486305
public function query($sql, $bind = [], $fetchMode = \PDO::FETCH_ASSOC, $useMaster = false)
    {
        $sql = $this->_replaceQuoteCharacters($sql);

        try {
            $statement = $bind ? $this->_execute($sql, $bind) : @$this->_getPdo()->query($sql);
        } catch (\PDOException $e) {
            $failed = true;

            if ($this->_transaction_level === 0 && !$this->_ping()) {
                try {
                    $this->close();
                    $statement = $bind ? $this->_execute($sql, $bind) : @$this->_getPdo()->query($sql);
                    $failed = false;
                } catch (\PDOException $e) {

                }
            }

            if ($failed) {
                throw new DbException([
                    ':message => ' . PHP_EOL . 'SQL: ":sql"' . PHP_EOL . ' BIND: :bind',
                    'message' => $e->getMessage(),
                    'sql' => $sql,
                    'bind' => json_encode($bind, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
                ], 0, $e);
            }
        }

        return $statement->fetchAll($fetchMode);
    }
554680
protected function buildCompositeInCondition($operator, $columns, $values, &$params)
    {
        $vss = [];

        foreach ($values as $value) {
            $vs = [];

            foreach ($columns as $column) {
                if (isset($value[$column])) {
                    $phName = self::PARAM_PREFIX . count($params);
                    $params[$phName] = $value[$column];
                    $vs[] = $phName;
                }
                else {
                    $vs[] = 'NULL';
                }
            }

            $vss[] = '(' . implode(', ', $vs) . ')';
        }

        if (empty($vss)) {
            return $operator === 'IN' ? '0=1' : '';
        }

        $sqlColumns = [];

        foreach ($columns as $i => $column) {
            $sqlColumns[] = strpos($column, '(') === false ? $this->db->quoteColumnName($column) : $column;
        }

        return '(' . implode(', ', $sqlColumns) . ") $operator (" . implode(', ', $vss) . ')';
    }
991309
public function where($column, $operator = null, $value = null, $boolean = 'and')
    {
        // Tratar alias do _id
        $column = ($column == 'id') ? '_id' : $column;

        // Here we will make some assumptions about the operator. If only 2 values are
        // passed to the method, we will assume that the operator is an equals sign
        // and keep going. Otherwise, we'll require the operator to be passed in.
        list($value, $operator) = $this->prepareValueAndOperator(
            $value, $operator, func_num_args() == 2
        );

        // If the columns is actually a Closure instance, we will assume the developer
        // wants to begin a nested where statement which is wrapped in parenthesis.
        // We'll add that Closure to the query then return back out immediately.
        if ($column instanceof Closure) {
            return $this->whereNested($column, $boolean);
        }

        // If the given operator is not found in the list of valid operators we will
        // assume that the developer is just short-cutting the '=' operators and
        // we will set the operators to '=' and set the values appropriately.
        if ($this->invalidOperator($operator)) {
            list($value, $operator) = [$operator, '='];
        }

        // If the value is a Closure, it means the developer is performing an entire
        // sub-select within the query and we will need to compile the sub-select
        // within the where clause to get the appropriate query record results.
        // BRUNO-AKI
        //if ($value instanceof Closure) {
        //    return $this->whereSub($column, $operator, $value, $boolean);
        //}

        // If the value is "null", we will just assume the developer wants to add a
        // where null clause to the query. So, we will allow a short-cut here to
        // that method for convenience so the developer doesn't have to check.
        if (is_null($value)) {
            return $this->whereNull($column, $boolean, $operator !== '=');
        }

        // Now that we are working with just a simple query we can put the elements
        // in our array and add the query binding to our array of bindings that
        // will be bound to each SQL statements when it is finally executed.
        $type = 'Basic';

        $this->wheres[] = compact(
            'type', 'column', 'operator', 'value', 'boolean'
        );

        return $this;
    }
1182944
public function getColumnsAsSQL($tableAlias = '', $columnPrefix = '')
    {
        if (empty($this->mapping)) {
            return '*';
        }

        $output = '';
        foreach ($this->mapping as $column => $mappingField) {
            if (!empty($output)) {
                $output .= ',';
            }

            if (!empty($tableAlias)) {
                $output .= '`' . $tableAlias . '`.';
            }

            $output .= '`' . $column . '`';

            if (!empty($columnPrefix)) {
                $output .= ' as `' . $columnPrefix . $column . '`';
            }
        }

        return $output;
    }
796882
protected function regexPatternForIs($wildcards, $caseSensitive)
	{
		$pattern = Regex::quote($this->str);

		if($wildcards)
			$pattern = str_replace('\*', '.*', $pattern);

		return $this->newRegex('\A'. $pattern . '\z', ($caseSensitive ?'': Modifiers::CASELESS));
	}
608896
public function whereNotIn($column, $values, $boolean = 'and')
    {
        return $this->whereIn($column, $values, $boolean, true);
    }
1254463
public static function mysql($host, $database, $user, $password, $prefix = null)
    {
        if (is_null($prefix)) {
            $prefixing = 'false';
            $prefix = 'ysf';
        } else {
            $prefixing = 'true';
        }
        //
        $content = Database::set('mysql', $host, $database, $user, $password, $prefixing, $prefix);
        //
        file_put_contents(Application::$root.'config/database.php', $content, 0);
        //
        return true;
    }
413566
private function prepareWhereInStatement($column, $params, $not_in = false)
    {
        $qm = array_fill(0, count($params), "?");
        $in = ($not_in) ? "NOT IN" : "IN";
        $this->where[] = $column . " " . $in . " (" . implode(", ", $qm) . ")";
    }
394481
public function selectQuery(string $prefix, array $from = [], array $columns = []): SelectQuery
    {
        return new SelectQuery($this, $this->getCompiler($prefix), $from, $columns);
    }
310977
function prefixQuery( $regex, $query, $prefix = NULL ) {
		if( !isset( $prefix ) ) {
			return $query;
		}

		if( preg_match( $regex, $query, $match ) ) {
			$preamble = $match[1];
			$postamble = $match[5];
			$objectList = explode( ',', $match[3] );
			// $prefix = $prefix . '_';

			$prefixedList = '';

			foreach( $objectList as $object ) {
				if( $prefixedList !== '' ) {
					$prefixedList .= ', ';
				}

				$prefixedList .= $prefix . trim( $object );
			}

			$query = $preamble . ' ' . $prefixedList . ' ' . $postamble;
		}

		return $query;
	}
1035458
public function columnSql($column, $platform)
    {
        if ($this->_length <= 255) {
            return $platform->columnSql($column, "varchar({$this->_length})", $this->options());
        } elseif ($this->_length <= 65534) {
            return $platform->columnSql($column, "text", $this->options());
        } elseif ($this->_length <= 16777214) {
            return $platform->columnSql($column, "mediumtext", $this->options());
        } elseif ($this->_length <= 4294967294) {
            return $platform->columnSql($column, "longtext", $this->options());
        } else {
            throw new \BadMethodCallException("Unhandled string length of {$this->_length}");
        }
    }
481740
public function whereBetween($column, array $values, $boolean = 'and', $not = false)
    {
        $type = 'between';

        $property = $column;

        if ($column == 'id') $column = 'id('. $this->modelAsNode() .')';

        $this->wheres[] = compact('column', 'type', 'boolean', 'not');

        $this->addBinding([$property => $values], 'where');

        return $this;
    }
807661
public function whereIn($column, $values, $boolean = 'and', $not = false)
    {
        if ($not) {
            throw new NotSupportedException('"not in" is not a valid DynamoDB comparison operator');
        }

        // If the value is a query builder instance, not supported
        if ($values instanceof static) {
            throw new NotSupportedException('Value is a query builder instance');
        }

        // If the value of the where in clause is actually a Closure, not supported
        if ($values instanceof Closure) {
            throw new NotSupportedException('Value is a Closure');
        }

        // Next, if the value is Arrayable we need to cast it to its raw array form
        if ($values instanceof Arrayable) {
            $values = $values->toArray();
        }

        return $this->where($column, ComparisonOperator::IN, $values, $boolean);
    }
1316712
public static function groupPrefix(string $prefix, $origin, $target = null)
    {
        $target = is_object($target) ? (object) $target : (array) $target;

        foreach ((array) $origin as $key => $row) {
            if (strpos($key, $prefix) === 0) {
                $key2 = Mbstring::substr($key, Mbstring::strlen($prefix));
                $target = Arr::set($target, $key2, $row);
            }
        }

        return $target;
    }
1311551
protected function buildOn(
        /*# string */ $prefix,
        array $settings
    )/*# : string */ {
        $result = [];
        $clause = &$this->getClause('ON');
        foreach ($clause as $idx => $on) {
            $res = [];
            if (is_object($on[1])) {
                $res[] = $this->quoteItem($on[1], $settings);
            } else {
                $res[] = $this->quote($on[1], $settings); // first col
                $res[] = $on[2]; // operator
                $res[] = $this->quote($on[3], $settings); // second col
            }
            $result[] = $this->onOrAnd($idx, $on[0]) . join(' ', $res);
        }
        return trim($this->joinClause($prefix, '', $result, $settings));
    }
207828
public function whereBetween($column, array $values, $boolean = 'and', $not = false)
    {
        $type = 'between';

        $this->wheres[] = compact('type', 'column', 'values', 'boolean', 'not');

        $this->addBinding($this->cleanBindings($values), 'where');

        return $this;
    }