Perform raw sql query
@return bool
964152
public function performQuery()
    {
        //change connection if provide
        if ($this->option('c')) {
            $this->schema->setConnection($this->option('c'));
            $this->schema->switchWrapper();
        }

        $rawQuery = $this->option('r');
        if (empty($rawQuery)) {
            $this->warn('Please provide raw sql query as string (in single/double quote)!');
            return false;
        }

         $result = $this->schema->rawQuery($rawQuery);
        if (!!$result) {
            (new Dumper)->dump($result);
        }
        $this->info('Query executed successfully!');
    }
1136382
public function query()
    {
        $model       = $this->model;

        $this->query = $model->select($this->select)
                            ->where($this->where)
                            ->orderBy($this->orderBy, $this->sortBy)
                            ->take($this->num)
                            ->offset($this->offset);

        $this->sql   = $this->query->getQuery()->toSql();

        $this->data  = $this->query->get()->toArray();

        return $this->data;
    }
957716
protected function executeFilteredQuery()
    {
        $this->logQueryStart();
        $result = new WP_Query($this->getFilters());
        $this->logQueryCompletion($result->request);
        return $result;
    }
26002
public function generate_query() {
        $query = '';
        $this->query->each(function($statement) use(&$query) {
            if (count($statement) == 1) {
                $query .= $statement[0];
            } else {
                if($statement[1] === null){
                    $query .= $statement[0];
                }else{
                    $query .= $statement[0].' "'.$statement[1].'"';
                }
            }
            $query .= ' ';

        });

        $this->raw_query = trim($query);

        return $this->raw_query;
    }
699765
public function executeRawQuery($query)
    {
        $resultSet = null;
        if($this->odbAdapter) {
            if(!empty($query)) {
                $resultSet = $this->getDbAdapter()->query($query, DbAdapter::QUERY_MODE_EXECUTE);

            }
        }


        return $resultSet;
    }
1234932
public function getQuery(): Query
    {
        $bindings = new Bindings();

        if (count($this->data) == 0 && $this->select === null) {
            throw new Exception('Can not execute Insert query, no records to insert');
        }

        if ($this->table === null) {
            throw new Exception('Can not execute Insert query when table name is not set');
        }

        $hasFields = count($this->fields) > 0;

        $query = "INSERT INTO {$this->table}";

        if ($hasFields) {
            $query .= ' (';

            foreach ($this->fields as $field) {
                $query .= $field . ',';
            }

            $query = substr($query, 0, -1) . ')';
        }

        if ($this->select !== null) {
            if ($this->select instanceof Select || $this->select instanceof Query) {
                $query .= "\n(\n\t" . str_replace("\n", "\n\t", $this->select->__toString()) . "\n)";
                $bindings->addBindingsFromInstance($this->select->getBindings());
            } else {
                throw new Exception('Can not use non-Select or non-Query instance in INSERT INTO SELECT statement - use Query instance to pass Select query');
            }
        } else {
            $query .= "\nVALUES\n";
            foreach ($this->data as $i1 => $row) {
                $query .= "\t(";

                if ($hasFields) {

                    foreach ($this->fields as $field) {
                        if (isset($row[$field])) {
                            $val = $row[$field];

                            if ($val instanceof Expr) {
                                $query .= "{$val},";
                            } else {
                                //$key = 'i' . $i1 . Query::getKeyIndex();
	                            $key = $bindings->makeAndSet("i{$i1}", $val);
                                $query .= ":{$key},";
                            }
                        } else {
                            $query .= 'NULL,';
                        }
                    }

                    $query = substr($query, 0, -1);

                } else {
                    $values = array_values($row);

                    foreach ($values as $i2 => $val) {
                        if ($val instanceof Expr) {
                            $query .= "{$val},";
                        } else {
                            //$key = 'i' . $i2 . Query::getKeyIndex();
	                        $key = $bindings->makeAndSet("i{$i2}", $val);
                            $query .= ":{$key},";
                        }
                    }

                    $query = substr($query, 0, -1);
                }

                $query .= "),\n";
            }

            $query = substr($query, 0, -2);
        }

        return new Query($query, $bindings, $this->getAdapterConnection());
    }
320580
protected function sql()
    {
        if ( null === $this->sql )
        {
            $this->sql = new Sql(
                $this->getDbAdapter(),
                $this->getTableInSchema( 'settings' )
            );
        }

        return $this->sql;
    }
1294593
protected function execute_query()
    {
        $query = $this->database->getQueryCollection()->findQuery($this->strQuery);

        if ($query) {
            return $query->result();
        }

        return null;
    }
1122376
public function get_query()
	{
		// Get the columns
		$columns = $this->select(false);

		// Start building the query
		$select = $columns;
		if ($this->use_subquery())
		{
			$select = array();
			foreach ($columns as $c)
			{
				$select[] = $c[0];
			}
		}
		$query = call_fuel_func_array('DB::select', $select);

		// Set the defined connection on the query
		$query->set_connection($this->connection);

		// Set from table
		$query->from(array($this->_table(), $this->alias));

		// Build the query further
		$tmp = $this->build_query($query, $columns);

		return $tmp['query'];
	}
1250373
protected function query ( $sql )
	{
		$sql = $this->sql_printf(func_get_args());
		if (!($res = mysqli_query( $this->conn, $sql)))
		{
			$this->sql_errcheck($sql);
		}
		if (!is_bool($res))
		{
			((mysqli_free_result($res) || (is_object($res) && (get_class($res) == "mysqli_result"))) ? true : false);
		}
	}
650445
public function process()
    {
        $value = $this->value();
        if (!is_scalar($value)) {
            return false;
        }

        if (is_string($value)) {
            $value = strtolower($value);
        }

        $bool = null;
        if (in_array($value, $this->getConfig('truthy'), true)) {
            $bool = true;
        } elseif (in_array($value, $this->getConfig('falsy'), true)) {
            $bool = false;
        }

        if ($bool !== null) {
            if (!$this->manager()->getRepository() instanceof Table) {
                foreach ($this->fields() as $field) {
                    $this->getQuery()->where([
                        $field => $bool,
                    ]);
                }

                return true;
            }

            $conditions = [];
            foreach ($this->fields() as $field) {
                $conditions[] = [$field => $bool];
            }

            $this->getQuery()->andWhere([$this->getConfig('mode') => $conditions]);
        }

        return false;
    }
547448
public function performsql()
    {
        $oAuthUser = oxNew(\OxidEsales\Eshop\Application\Model\User::class);
        $oAuthUser->loadAdminUser();
        if ($oAuthUser->oxuser__oxrights->value === "malladmin") {
            $sUpdateSQL = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("updatesql");
            $sUpdateSQLFile = $this->_processFiles();

            if ($sUpdateSQLFile && strlen($sUpdateSQLFile) > 0) {
                if (isset($sUpdateSQL) && strlen($sUpdateSQL)) {
                    $sUpdateSQL .= ";\r\n" . $sUpdateSQLFile;
                } else {
                    $sUpdateSQL = $sUpdateSQLFile;
                }
            }

            $sUpdateSQL = trim(stripslashes($sUpdateSQL));
            $oStr = getStr();
            $iLen = $oStr->strlen($sUpdateSQL);
            if ($this->_prepareSQL($sUpdateSQL, $iLen)) {
                $aQueries = $this->aSQLs;
                $this->_aViewData["aQueries"] = [];
                $aPassedQueries = [];
                $aQAffectedRows = [];
                $aQErrorMessages = [];
                $aQErrorNumbers = [];

                if (!empty($aQueries) && is_array($aQueries)) {
                    $blStop = false;
                    $oDB = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
                    $iQueriesCounter = 0;
                    for ($i = 0; $i < count($aQueries); $i++) {
                        $sUpdateSQL = $aQueries[$i];
                        $sUpdateSQL = trim($sUpdateSQL);

                        if ($oStr->strlen($sUpdateSQL) > 0) {
                            $aPassedQueries[$iQueriesCounter] = nl2br(\OxidEsales\Eshop\Core\Str::getStr()->htmlentities($sUpdateSQL));
                            if ($oStr->strlen($aPassedQueries[$iQueriesCounter]) > 200) {
                                $aPassedQueries[$iQueriesCounter] = $oStr->substr($aPassedQueries[$iQueriesCounter], 0, 200) . "...";
                            }

                            while ($sUpdateSQL[$oStr->strlen($sUpdateSQL) - 1] == ";") {
                                $sUpdateSQL = $oStr->substr($sUpdateSQL, 0, ($oStr->strlen($sUpdateSQL) - 1));
                            }

                            $aQAffectedRows [$iQueriesCounter] = null;
                            $aQErrorMessages[$iQueriesCounter] = null;
                            $aQErrorNumbers [$iQueriesCounter] = null;

                            try {
                                $aQAffectedRows[$iQueriesCounter] = $oDB->execute($sUpdateSQL);
                            } catch (Exception $exception) {
                                // Report errors
                                $aQErrorMessages[$iQueriesCounter] = \OxidEsales\Eshop\Core\Str::getStr()->htmlentities($exception->getMessage());
                                $aQErrorNumbers[$iQueriesCounter] = \OxidEsales\Eshop\Core\Str::getStr()->htmlentities($exception->getCode());
                                // Trigger breaking the loop
                                $blStop = true;
                            }

                            $iQueriesCounter++;

                            // stopping on first error..
                            if ($blStop) {
                                break;
                            }
                        }
                    }
                }
                $this->_aViewData["aQueries"] = $aPassedQueries;
                $this->_aViewData["aAffectedRows"] = $aQAffectedRows;
                $this->_aViewData["aErrorMessages"] = $aQErrorMessages;
                $this->_aViewData["aErrorNumbers"] = $aQErrorNumbers;
            }
            $this->_iDefEdit = 1;
        }
    }
58820
public static function ExecuteEach()
	{
		$arguments = func_get_args();
		$executeQueryBuilders = is_array($arguments[0])? $arguments[0] : $arguments;

		$db = self::connect();
		$db->beginTransaction();
		
		try
		{
			$results = null;

			foreach($executeQueryBuilders as $executeQueryBuilder)
			{				
				$executeQuery = $executeQueryBuilder($results);
				$query = $db->prepare($executeQuery["statement"]);
			
				foreach($executeQuery["parameters"] as $key => $parameter)
				{
					if(!isset($parameter["type"]))
						$parameter["type"] = PDO::PARAM_STR;
						
					$query->bindParam($key,$parameter["value"],$parameter["type"]);
				}
					
				$query->execute();
				$rowsAffected = $query->rowCount();
				$lastID = $db->lastInsertId();

				$results = (object) array(
					DatabaseReturn::RowsAffected => $rowsAffected,
					DatabaseReturn::LastInsertID => $lastID
				);
			}
		}
		catch (PDOException $e)
		{
			$db->rollBack();
			$exception = "Sorry, there was a problem with query execution. ({$e->getMessage()})";
		}

		if($exception) throw new \Exception($exception);
		
		$db->commit();
		return $results;
	}
1285497
public function execute()
    {
        $request = $this->request->getCurrentRequest();

        $iTotalRecords = $this->queryBuilder->getTotalRecords();
        $iTotalDisplayRecords = $this->queryBuilder->getTotalDisplayRecords();

        list($data, $objects) = $this->queryBuilder->getData($this->multiple);

        $id_index = array_search('_identifier_', array_keys($this->getFields()));
        $ids = array();

        array_walk($data, function($val, $key) use ($id_index, &$ids) {
            $ids[$key] = $val[$id_index];
        });

        if (!is_null($this->fixedData)) {
            $this->fixedData = array_reverse($this->fixedData);
            foreach ($this->fixedData as $item) {
                array_unshift($data, $item);
            }
        }

        if (!is_null($this->renderer)) {
            array_walk($data, $this->renderer);
        }

        if (!is_null($this->rendererObj)) {
            $this->rendererObj->applyTo($data, $objects);
        }

        if (!empty($this->multiple)) {
            array_walk($data,
                    function($val, $key) use(&$data, $ids) {
                array_unshift($val, sprintf('<input type="checkbox" name="dataTables[actions][]" value="%s" />', $ids[$key]));
                $data[$key] = $val;
            });
        }

        $output = array(
            "draw" => $request->query->getInt('draw'),
            "recordsTotal" => $iTotalRecords,
            "recordsFiltered" => $iTotalDisplayRecords,
            "data" => $data
        );

        return new JsonResponse($output);
    }
599575
public function exec(): bool
    {
        /* @var $sqlStmt \PDOStatement */
        $sqlStmt = $this->getConnection()->prepare($this->getQuery());

        if ($sqlStmt === false) {
            return $this->execFails($sqlStmt, ErrorType::CONNECTION_ERROR);
        }

        // Bind input
        foreach ($this->bindedValues as /* @var $i int */
                 $i => $bindedValue) {
            $type = $this->getPDOType($bindedValue);

            if ($type === false) {
                throw new \Exception('Invalid type of binded value at position ' . ($i + 1) . '.');
            }

            $bindParamsResult = $sqlStmt->bindValue($i + 1, $bindedValue, $type);

            if ($bindParamsResult === false) {
                return $this->execFails($sqlStmt, ErrorType::BINDING_ERROR);
            }
        }

        // Exec query
        $result = $sqlStmt->execute();

        if ($result == false) {
            return $this->execFails($sqlStmt, ErrorType::STATEMENT_ERROR);
        }

        $this->result = new MPDOResult($sqlStmt);

        $sqlStmt->closeCursor();

        return true;
    }
1306863
protected function rawQuery($query)
	{
		$start = microtime(TRUE);
		$res   = mysqli_query($this->conn, $query);
		$timer = microtime(TRUE) - $start;

		$this->stats[] = array(
			'query' => $query,
			'start' => $start,
			'timer' => $timer,
		);
		if (!$res)
		{
			$error = mysqli_error($this->conn);
			
			end($this->stats);
			$key = key($this->stats);
			$this->stats[$key]['error'] = $error;
			$this->cutStats();
			
			$this->error("$error. Full query: [$query]");
		}
		$this->cutStats();
		return $res;
	}
537120
public function raw($query, $return = false, $fetchMode = null, $fetchClass = null)
    {
        if (! $return) {
            return $this->exec($query);
        }

        $fetchMode = Database::normalizeFetchType($fetchMode);

        $statement = $this->query($query);

        if ($fetchMode === Database::FETCH_CLASS) {
            $statement->setFetchMode($fetchMode, $fetchClass);
        } else {
            $statement->setFetchMode($fetchMode);
        }

        return $statement->fetchAll();
    }