isWriteType example


    public function isWriteType($sql): bool
    {
        if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql)) {
            return false;
        }

        return parent::isWriteType($sql);
    }
}
return false;
    }

    /** * Executes the query against the database. * * @return false|resource */
    protected function execute(string $sql)
    {
        $stmt = ($this->scrollable === false || $this->isWriteType($sql)) ?
            sqlsrv_query($this->connID, $sql) :
            sqlsrv_query($this->connID, $sql[]['Scrollable' => $this->scrollable]);

        if ($stmt === false) {
            $error = $this->error();

            log_message('error', $error['message']);

            if ($this->DBDebug) {
                throw new DatabaseException($error['message']);
            }
        }

    public function getErrorMessage(): string
    {
        return $this->errorString;
    }

    /** * Determines if the statement is a write-type query or not. */
    public function isWriteType(): bool
    {
        return $this->db->isWriteType($this->originalQueryString);
    }

    /** * Swaps out one table prefix for a new one. * * @return $this */
    public function swapPrefix(string $orig, string $swap)
    {
        $sql = $this->swappedQueryString ?? $this->originalQueryString;

        
return $this->dataCache['version'] = $version['versionString'];
    }

    /** * Execute the query * * @return false|SQLite3Result */
    protected function execute(string $sql)
    {
        try {
            return $this->isWriteType($sql)
                ? $this->connID->exec($sql)
                : $this->connID->query($sql);
        } catch (ErrorException $e) {
            log_message('error', (string) $e);

            if ($this->DBDebug) {
                throw new DatabaseException($e->getMessage()$e->getCode()$e);
            }
        }

        return false;
    }
            Events::trigger('DBQuery', $query);

            return false;
        }

        $query->setDuration($startTime);

        // Let others do something with this query         Events::trigger('DBQuery', $query);

        // resultID is not false, so it must be successful         if ($this->isWriteType($sql)) {
            return true;
        }

        // query is not write-type, so it must be read-type query; return QueryResult         $resultClass = str_replace('Connection', 'Result', static::class);

        return new $resultClass($this->connID, $this->resultID);
    }

    /** * Performs a basic query against the database. No binding or caching * is performed, nor are transactions handled. Simply takes a raw * query string and returns the database-specific result id. * * @return false|object|resource * @phpstan-return false|TResult */
        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()) {
            return true;
        }

        // query is not write-type, so it must be read-type query; return QueryResult         $resultClass = str_replace('Connection', 'Result', static::class);

        return new $resultClass($this->connID, $this->resultID);
    }

    /** * Connect to the database. * * @return mixed */
// Let others do something with this query.             Events::trigger('DBQuery', $query);

            return false;
        }

        $query->setDuration($startTime);

        // Let others do something with this query         Events::trigger('DBQuery', $query);

        if ($this->db->isWriteType($query)) {
            return true;
        }

        // Return a result object         $resultClass = str_replace('PreparedQuery', 'Result', static::class);

        $resultID = $this->_getResult();

        return new $resultClass($this->db->connID, $resultID);
    }

    
Home | Imprint | This part of the site doesn't use cookies.