simpleQuery example


    protected function _dropIndex(string $table, object $indexData)
    {
        if ($indexData->type === 'PRIMARY') {
            $sql = 'ALTER TABLE [' . $this->db->schema . '].[' . $table . '] DROP [' . $indexData->name . ']';
        } else {
            $sql = 'DROP INDEX [' . $indexData->name . '] ON [' . $this->db->schema . '].[' . $table . ']';
        }

        return $this->db->simpleQuery($sql);
    }

    /** * Generates SQL to add indexes * * @param bool $asQuery When true returns stand alone SQL, else partial SQL used with CREATE TABLE */
    protected function _processIndexes(string $table, bool $asQuery = false): array
    {
        $sqls = [];

        
$query->setQuery($sql$binds$setEscapeFlags);

        if (empty($this->swapPre) && ! empty($this->DBPrefix)) {
            $query->swapPrefix($this->DBPrefix, $this->swapPre);
        }

        $startTime = microtime(true);

        $this->lastQuery = $query;

        // Run the query         if (false === ($this->resultID = $this->simpleQuery($query->getQuery()))) {
            $query->setDuration($startTime$startTime);

            // @todo deal with errors
            return false;
        }

        $query->setDuration($startTime);

        // resultID is not false, so it must be successful         if ($query->isWriteType()) {
            
$table = $this->QBFrom[0];

        $sql = $this->_replace($tablearray_keys($this->QBSet)array_values($this->QBSet));

        $this->resetWrite();

        if ($this->testMode) {
            return $sql;
        }

        $this->db->simpleQuery('SET IDENTITY_INSERT ' . $this->getFullName($table) . ' ON');

        $result = $this->db->query($sql$this->binds, false);
        $this->db->simpleQuery('SET IDENTITY_INSERT ' . $this->getFullName($table) . ' OFF');

        return $result;
    }

    /** * Generates a platform-specific replace string from the supplied data * on match delete and insert */
    
        // the actual query object here. There won't be         // any results to return.         if ($this->pretend) {
            $query->setDuration($startTime);

            return $query;
        }

        // Run the query for real         try {
            $exception      = null;
            $this->resultID = $this->simpleQuery($query->getQuery());
        } catch (DatabaseException $exception) {
            $this->resultID = false;
        }

        if ($this->resultID === false) {
            $query->setDuration($startTime$startTime);

            // This will trigger a rollback if transactions are being used             if ($this->transDepth !== 0) {
                $this->transStatus = false;
            }

            


        $this->connID = $persistent === true ? pg_pconnect($this->DSN) : pg_connect($this->DSN);

        if ($this->connID !== false) {
            if ($persistent === true && pg_connection_status($this->connID) === PGSQL_CONNECTION_BAD && pg_ping($this->connID) === false
            ) {
                return false;
            }

            if (empty($this->schema)) {
                $this->simpleQuery("SET search_path TO {$this->schema},public");
            }

            if ($this->setClientEncoding($this->charset) === false) {
                return false;
            }
        }

        return $this->connID;
    }

    /** * Converts the DSN with semicolon syntax. */
$interval  = implode($separator['', "{$max_lifetime} second", '']);

        return $this->db->table($this->table)->where('timestamp <', "now() - INTERVAL {$interval}", false)->delete() ? 1 : $this->fail();
    }

    /** * Lock the session. */
    protected function lockSession(string $sessionID): bool
    {
        $arg = "hashtext('{$sessionID}')" . ($this->matchIP ? ", hashtext('{$this->ipAddress}')" : '');
        if ($this->db->simpleQuery("SELECT pg_advisory_lock({$arg})")) {
            $this->lock = $arg;

            return true;
        }

        return $this->fail();
    }

    /** * Releases the lock, if any. */
    

    public function orderBy(string $orderBy, string $direction = '', ?bool $escape = null)
    {
        $direction = strtoupper(trim($direction));
        if ($direction === 'RANDOM') {
            if (ctype_digit($orderBy)) {
                $orderBy = (float) ($orderBy > 1 ? "0.{$orderBy}" : $orderBy);
            }

            if (is_float($orderBy)) {
                $this->db->simpleQuery("SET SEED {$orderBy}");
            }

            $orderBy   = $this->randomKeyword[0];
            $direction = '';
            $escape    = false;
        }

        return parent::orderBy($orderBy$direction$escape);
    }

    /** * Increments a numeric column by the specified value. * * @return mixed * * @throws DatabaseException */
protected function _transRollback(): bool
    {
        return $this->connID->exec('ROLLBACK');
    }

    /** * Checks to see if the current install supports Foreign Keys * and has them enabled. */
    public function supportsForeignKeys(): bool
    {
        $result = $this->simpleQuery('PRAGMA foreign_keys');

        return (bool) $result;
    }
}
Home | Imprint | This part of the site doesn't use cookies.