Throws an exception if no records are found / affected
@param PDOStatement $statement
@param \Exception $exceptionToThrow
@return boolean
@throws NoRecordsAffectedException
328304
public function checkAffected(PDOStatement $statement, \Exception $exceptionToThrow = null)
    {
        if (!$exceptionToThrow instanceof \Exception) {
            $exceptionToThrow = new NoRecordsAffectedException();
        }
        if (!boolval($statement->rowCount()) && $this->getIsStrict()) {
            throw $exceptionToThrow;
        }
        return true;
    }
1064268
public static function get_record_by_contextid($contextid, $exception = true) {
        global $DB;

        if (!$record = $DB->get_record(self::TABLE, array('contextid' => $contextid))) {
            if (!$exception) {
                return false;
            } else {
                throw new \dml_missing_record_exception(self::TABLE);
            }
        }

        return new static(0, $record);
    }
361043
protected function logExceptionAndThrow($exception, LogOperation $log = null)
    {
        if ($this->shouldLog($log) && is_null($log->getStartTime())) {
            $this->logStart($log);
        }
        if ($this->shouldLog($log)) {
            $log->setError($exception->getMessage());
        }

        throw $exception;
    }
219541
public void doSet(Rec record) throws DBException
    {
        super.doSet(record);
        if (m_arrayCache != null)
            if (m_iLogicalIndex != NO_INDEX)
            {
                m_arrayCache.set(m_iLogicalIndex, this.getDataSource());    // Show the current record as deleted.
            }
    }
261497
protected void executeUpdateSilently(String statement) {
        logger.trace(statement);
        try (Statement alter = conn.createStatement()) {
            alter.execute(statement);
        } catch (final SQLException e) {
            logger.debug("Could not execute {}.", statement, e);
        }
    }
1245880
public function destroy(): int
    {
        $pk = static::$primaryKey;

        if (is_array($pk)) {
            $where = [];
            $data = $this->getData();
            foreach ($pk as $field) {
                if (!isset($data[$field])) {
                    throw new Exception("Can not destroy row from database when object doesn't contain '{$field}' in loaded data");
                }
                $where[$field] = $data[$field];
            }

            return static::delete($where);
        } else if (!isset($this->data[$pk])) {
            throw new Exception('Can not destroy row from database when object doesn\'t contain primary key\'s value');
        } else {
            return static::delete($this->data[$pk]);
        }
    }
723441
private boolean isOptimisticLockingException(DbOperation failedOperation, Throwable cause) {

    boolean isConstraintViolation = ExceptionUtil.checkForeignKeyConstraintViolation(cause);
    boolean isVariableIntegrityViolation = ExceptionUtil.checkVariableIntegrityViolation(cause);

    if (isVariableIntegrityViolation) {

      return true;
    } else if (
      isConstraintViolation
      && failedOperation instanceof DbEntityOperation
      && ((DbEntityOperation) failedOperation).getEntity() instanceof HasDbReferences
      && (failedOperation.getOperationType().equals(DbOperationType.INSERT)
      || failedOperation.getOperationType().equals(DbOperationType.UPDATE))
      ) {

      DbEntity entity = ((DbEntityOperation) failedOperation).getEntity();
      for (Map.Entry<String, Class> reference : ((HasDbReferences)entity).getReferencedEntitiesIdAndClass().entrySet()) {
        DbEntity referencedEntity = this.persistenceSession.selectById(reference.getValue(), reference.getKey());
        if (referencedEntity == null) {

          return true;
        }
      }
    }

    return false;
  }
50721
private void throwIfStatementForbidden(PreparedStatement statement) {
        if (mOnlyAllowReadOnlyOperations && !statement.mReadOnly) {
            throw new com.couchbase.lite.internal.database.sqlite.exception.SQLiteException(
                    "Cannot execute this statement because it "
                    + "might modify the database but the connection is read-only.");
        }
    }
320768
public static function bindToStatement(PDOStatement $statement, array $bindings=[])
    {
        foreach ($bindings as $key=>$value) {

            $casted = is_bool($value) ? (int)$value : $value;

            $statement->bindValue(
                is_string($key) ? $key : $key + 1,
                $casted,
                is_int($casted) ? PDO::PARAM_INT : ($casted === null ? PDO::PARAM_NULL : PDO::PARAM_STR)
            );

        }
    }
236739
public function affectedRows()
	{
		try {
			return $this->_statement->rowCount();
		} catch ( PDOException $e ) {
			throw new MW_DB_Exception( $e->getMessage(), $e->getCode(), $e->errorInfo );
		}
	}
177378
private function getResult(BaseQueryObjectInterface $queryObject, PDOStatement $statement)
    {
        $result = $this->getNormalizedResult($statement);

        if ($queryObject instanceof SingleScalarResultQueryObjectInterface) {
            return $this->getSingleScalarResult($result);
        } elseif ($queryObject instanceof SingleResultQueryObjectInterface) {
            return $this->getSingleResult($result);
        }

        return $result;
    }
1232324
public static void warnedUpdate (
        Statement stmt, String query, int expectedCount)
        throws SQLException
    {
        int modified = stmt.executeUpdate(query);
        if (modified != expectedCount) {
            log.warning("Statement did not modify expected number of rows", "stmt", stmt,
                        "expected", expectedCount, "modified", modified);
        }
    }
709645
public static void checkedUpdate (PreparedStatement stmt, int expectedCount)
        throws SQLException, PersistenceException
    {
        int modified = stmt.executeUpdate();
        if (modified != expectedCount) {
            String err = "Statement did not modify expected number of rows [stmt=" + stmt +
                ", expected=" + expectedCount + ", modified=" + modified + "]";
            throw new PersistenceException(err);
        }
    }
335114
protected function _executeStatement($statement, $sql, $params) {
        if ((!$statement->execute($params))) {
            throw new DbException($this->_pdoObject->errorInfo(), $sql, $params, $this->_errorReporting);
        }

        if ($statement->errorCode() == '00000') {
            return;
        }
        throw new DbException($statement->errorInfo(), $sql, $params, $this->_errorReporting);
    }
1367876
public boolean hasNext() throws DBException
    {
        if (m_iCurrentRecord >= m_iRecordsAccessed)
            return true;
        Object record = this.next();
        if (record == null)
            return false;
        else
        {
            m_iRecordsAccessed--;   // Offically this record has not been accessed
            return true;
        }
    }
613537
public function exceptionSampleRate(\Exception $toLog)
    {
        $sampleRate = 1.0;
        if (count($this->exceptionSampleRates) == 0) {
            return $sampleRate;
        }
        
        $exceptionClasses = array();
        
        $class = get_class($toLog);
        while ($class) {
            $exceptionClasses []= $class;
            $class = get_parent_class($class);
        }
        $exceptionClasses = array_reverse($exceptionClasses);
        
        foreach ($exceptionClasses as $exceptionClass) {
            if (isset($this->exceptionSampleRates["$exceptionClass"])) {
                $sampleRate = $this->exceptionSampleRates["$exceptionClass"];
            }
        }
        
        return $sampleRate;
    }
413507
@Override
    public boolean previous() throws SQLException {
        checkClosed();
        if (cursorPosition == Position.afterLast) {
            return last();
        }
        if (cursorPosition == Position.beforeFirst || table.getActiveRowIndex() <= 0) {
            beforeFirst();
            return false;
        }
        try {
            int tempRowIndex = table.getActiveRowIndex();
            table.resetRowPosition();
            table.advanceToRow(0);
            return table.advanceToRow(tempRowIndex - 1);
        } catch (Exception x) {
            throw SQLError.get(x);
        }
    }