Play Script queries

@param bool $executeQueries
@throws Migration\Exception
@throws \Exception
@return void
761097
private function playQueries($executeQueries = false)
    {
        foreach ($this->migration->getQueries() as $idx => $query) {
            try {
                $this->runQuery($query, $executeQueries);
            } catch (\Exception $e) {
                // Only throw if more than one query is played
                if ($idx >= 1) {
                    throw new Exception($e->getMessage());
                }

                throw $e;
            }
        }
    }
1336882
protected function loadQueries($sqlQueriesFile) {
        // Read the sql queries file
        if (!file_exists($sqlQueriesFile))
            throw new \Exception("File with mysql queries not found at expected location: $sqlQueriesFile");

        if (!($this->queries = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($sqlQueriesFile))))
            throw new \Exception("Could not parse yaml file with mysql queries: $sqlQueriesFile");
    }
676434
public function exec($query)
    {
        if ($this->isConnected()) {
            try {
                return $this->pdo->exec($query);
            } catch (PDOException $e) {
                throw new \Exception($e->getMessage());
                return false;
            }
        } else {
            return false;
        }
    }
890090
protected function _runQueries()
    {
        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        $aQueries = $this->getQueries();
        $bSuccess = true;
        foreach ($aQueries as $sQuery) {
            try {
                $oDb->execute($sQuery);
            } catch (\OxidEsales\Eshop\Core\Exception\StandardException $exception) {
                \OxidEsales\Eshop\Core\Registry::getLogger()->error($exception->getMessage(), [$exception]);
                $bSuccess = false;
            }
        }

        return $bSuccess;
    }
511797
public function run(Migration $migration, $executeQueries = false, $forcedRollback = false)
    {
        $this->migration = $migration;

        try {
            $this->playQueries($executeQueries);
            if ($forcedRollback) {
                $this->playRollbackQueries($executeQueries);
            }
        } catch (Exception $e) {
            $this->playRollbackQueries($executeQueries);

            throw $e;
        }
    }
757211
public function findByType($type, $executeQuery = true)
    {
        $queryBuilder = $this->createQueryBuilder('w')
            ->andWhere($this->getWigetInstanceString($type))
        ;

        return $executeQuery ? $queryBuilder->getQuery()->getResult() : $queryBuilder->getQuery();
    }
316255
private static function executeSQLs($aSQLs)
    {
        if (count($aSQLs) > 0) {
            foreach ($aSQLs as $sSQL) {
                self::executeSQL($sSQL);
            }
        }
    }
707058
protected function execute(string $query, array $bindings = [])
    {
        $query = N1qlQuery::fromString($query);
        $query->consistency($this->consistency);
        $query->crossBucket($this->crossBucket);
        $query->positionalParams($bindings);
        $result = $this->executeQuery($query);
        $this->metrics = $result->metrics ?? [];

        return $result;
    }
251652
public static function sql(...$messages): void
    {
        static::init();

        if (!static::isTemporaryDisabled('sql')) {
            foreach (static::$adapters as $adapter) {
                /* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
                if ($adapter->isLevelEnabled(self::SQL)) {
                    $adapter->sql((new Message(self::SQL))->setMessages($messages));
                }
            }
        }
    }
883338
@Override
    public boolean execute(String sql, String[] columnNames) throws SQLException
    {
        checkClosed();
        throw SQLError.noSupport();
    }
892313
protected function configureQuery(SelectQuery $query, bool $loadColumns = true): SelectQuery
    {
        //Clarifying table name
        $query->from("{$this->getTable()} AS {$this->getAlias()}");

        //Columns to be loaded for primary model
        if ($loadColumns) {
            $this->mountColumns($query, true, '', true);
        }

        return parent::configureQuery($query, $loadColumns);
    }
712237
protected function run( $query, $bindings, Closure $callback ) {
		$start = microtime( true );

		// Prevent showing the errors.
		$suppress_errors = $this->wpdb->suppress_errors;
		$this->wpdb->suppress_errors( true );

		// Here we will run this query. If an exception occurs we'll determine if it was
		// caused by a connection that has been lost. If that is the cause, we'll try
		// to re-establish connection and re-run the query with a fresh connection.
		try {
			$result = $this->runQueryCallback( $query, $bindings, $callback );
		} catch ( \Exception $e ) {
			$result = $this->handleQueryException( $e, $query, $bindings );
		}

		// Once we have run the query we will calculate the time that it took to run and
		// then log the query, bindings, and execution time so we will report them on
		// the event that the developer needs them. We'll log time in milliseconds.
		$this->logQuery( $query, $bindings, $this->getElapsedTime( $start ) );

		$this->wpdb->suppress_errors( $suppress_errors );

		return $result;
	}
222875
protected function handleQueryException( $e, $query, $bindings ) {
		if ( $result = apply_filters( 'awethemes.database.handle_query_exception', null, $e, $query, $bindings ) ) {
			return $result;
		}

		throw $e;
	}
461372
public static function batchQuery(AbstractDatabaseDriver $db, $queries)
    {
        if (is_string($queries)) {
            $queries = $db->splitSql($queries);
        }

        foreach ((array) $queries as $query) {
            if (!trim($query, " \n\r\t;")) {
                continue;
            }

            $db->setQuery($query)->execute();
        }

        return true;
    }
254272
private function execute()
    {
        // Let the generator do his work now,
        if ($this->queryType !== self::QUERY_INSERT && $this->queryType !== self::QUERY_UPDATE && $this->queryType !== self::QUERY_DELETE) {
            throw new QueryException("Can only do apply() on INSERT and UPDATE mode!", 0, $this->exception); // @codeCoverageIgnore
        }

        // Validate all variables
        if ($this->queryType === self::QUERY_INSERT) {
            // We should have the table, all required data.
            if (count($this->changeData) === 0 || empty($this->table)) {
                throw new QueryException("When inserting you should at least give a table and the inserting data!", 0, $this->exception); // @codeCoverageIgnore
            }
        }
        if ($this->queryType === self::QUERY_UPDATE) {
            // We should have a where with at least one condition, data, and a table
            if (count($this->whereConditions) === 0 || count($this->changeData) === 0 || empty($this->table)) {
                throw new QueryException("When updating you should at least give a table, at least one where condition and the updating data!", 0, $this->exception); // @codeCoverageIgnore
            }
        }
        if ($this->queryType === self::QUERY_DELETE) {
            // We should have a where and table
            if (count($this->whereConditions) === 0 || empty($this->table)) {
                throw new QueryException("When deleting you should at least give a table and at least one where condition!", 0, $this->exception); // @codeCoverageIgnore
            }
        }

        $this->bindValues = array();
        $this->bindTypes = array();

        // Generate parts
        if ($this->queryType === self::QUERY_INSERT) {
            $this->generator->generateInsert($this->columnOrder, $this->changeData, $this->start, $this->data, $this->bindValues, $this->bindTypes);
        }

        if ($this->queryType === self::QUERY_UPDATE) {
            $this->generator->generateJoin($this->joinTables, $this->join);
            $this->generator->generateUpdate($this->changeData, $this->data, $this->bindValues, $this->bindTypes);
            $this->generator->generateWhere($this->whereConditions, $this->where, $this->bindValues, $this->bindTypes);
        }

        if ($this->queryType === self::QUERY_DELETE) {
            $this->generator->generateJoin($this->joinTables, $this->join);
            $this->generator->generateWhere($this->whereConditions, $this->where, $this->bindValues, $this->bindTypes);
        }

        $this->query = "";
        $this->combineQuery();

        // Verify if bind has same number as the number of question marks in the query
        // TODO: Implement this when stable
        //$this->verifyQuery();

        $connection = ConnectionManager::getConnection();
        $query = $connection->prepare($this->query);

        // Bind all values
        $idx = 1;
        foreach ($this->bindValues as $key => $value) {
            $query->bindValue($idx, $value, $this->bindTypes[$key]);
            $idx++;
        }

        // Execute
        $status = $query->execute();

        if ($status && $this->queryType === self::QUERY_INSERT) {
            return $connection->lastInsertId();
        }
        return $status;
    }
1029647
public function addQueries(array $queries = array()) {
	    foreach($queries as $queryInfo) {
	        $batchAction = (isset($queryInfo[1])) ? $queryInfo[1] : null;
	        $this->addQuery($queryInfo[0], $batchAction);
	    }
	}
65485
public function addQuery(ClientAction $query, $resultObject = null)
    {
        if (isset($resultObject)) {
            $queryId = $query->getId();
            $this->resultObjects[$queryId] = $resultObject;
        }
        $this->queries[] = $query;
    }