@since 0.5

@param Statement $statement
@param EditInfo|null $editInfo

@throws InvalidArgumentException
@return bool

@todo allow setting of indexes
969204
public function set( Statement $statement, EditInfo $editInfo = null ) {
		if( $statement->getGuid() === null ) {
			throw new InvalidArgumentException( 'Can not set a statement that does not have a GUID' );
		}

		$params = array(
			'claim' => json_encode( $this->statementSerializer->serialize( $statement ) ),
		);

		$this->api->postRequest( 'wbsetclaim', $params, $editInfo );
		return true;
	}
195964
public function query_statement( Statement $statement, array $data, $options = 0 ) {

		$query = call_user_func_array(
			[ $this->wpdb, 'prepare' ],
			array_merge( [ (string) $statement] , $data )
		);
		$result               = $this->query( $query );
		$this->last_statement = $statement;

		return $result;
	}
806553
public function queryHandle(Statement $statement): \PDOStatement
    {
        // 记录开始时间
        $begin = timeLog();

        // 获取要执行的语句的Prepare和Params
        $prepare = $statement->getPrepare();
        $params = $statement->getParams();

        // 先记日志,以免错误导致无日志
        FileLog::instance()->sqlBefore('queryHandle', $statement->getSql());

        // 从读服务器进行
        $connect = $this->connectRead();

        // 禁止缓存
        $connect->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);

        // 如果绑定参数为空,直接执行就好.
        if (empty($params)) {
            $result = $connect->query($prepare);
        } else {
            $stmt = $connect->prepare($prepare);
            $stmt->execute($params);
            $result = $stmt;
        }

        // 查询完成,再次打开缓存
        $connect->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);

        // 计算耗时
        $interval = timeLog($begin);

        // 记录耗时
        FileLog::instance()->sqlAfter('afterQueryHandle', $statement->getSql(), $result, $interval, $statement->getOperation());

        Debug::setSql('QueryHandle', $prepare, $interval * 1000, $params, $statement->getSql());
        return $result;
    }
684469
public function set( $reference, $target, EditInfo $editInfo = null ) {
		if( $reference instanceof Reference ) {
			$reference = $reference->getHash();
		}
		if( !is_string( $reference ) ) {
			throw new UnexpectedValueException( 'Could not get reference hash from $reference' );
		}

		if( is_string( $target ) ) {
			$guid = $target;
		} else if ( $target instanceof StatementGuid ) {
			$guid = $target->getSerialization();
		} else if ( $target instanceof Statement ) {
			$guid = $target->getGuid();
		} else {
			throw new UnexpectedValueException( 'Could not get statement guid from $target' );
		}
		if( !is_string( $guid ) ) {
			throw new UnexpectedValueException( 'Unexpected statement guid got from $target' );
		}

		$params = array(
			'statement' => $guid,
			'references' => $reference,
		);

		$this->api->postRequest( 'wbremovereferences', $params, $editInfo );
		return true;
	}
816137
public void setStatement(Statement statement, int iType)
    {
        try {
            if (this.getStatement(iType) != null)
                this.getStatement(iType).close();
            if (statement == null)
                this.setLastSQLStatement(null, iType);
        } catch (SQLException e) {
            e.printStackTrace();    // Never
        }

        switch (iType)
        {
        case DBConstants.SQL_UPDATE_TYPE:
        case DBConstants.SQL_INSERT_TABLE_TYPE:
        case DBConstants.SQL_DELETE_TYPE:
            m_updateStatement = statement;
            break;
        case DBConstants.SQL_AUTOSEQUENCE_TYPE:
        case DBConstants.SQL_SEEK_TYPE:
            if (!SHARE_STATEMENTS)
            {
                m_seekStatement = statement;
                break;
            }
        case DBConstants.SQL_SELECT_TYPE:
        case DBConstants.SQL_CREATE_TYPE:
        default:
            m_queryStatement = statement;
        }
    }
116175
public function prepare($statement)
    {
	
        $returnValue = null;
        $this->preparedExec = false;
        $returnValue = $this->getStatement($statement);

		
        return $returnValue;
    }
834441
public T withStatement(Statement statement) {
		PropertyIdValue pid = statement.getMainSnak()
				.getPropertyId();
		ArrayList<Statement> pidStatements = this.statements.get(pid);
		if (pidStatements == null) {
			pidStatements = new ArrayList<Statement>();
			this.statements.put(pid, pidStatements);
		}

		pidStatements.add(statement);
		return getThis();
	}
1183424
public function save( Revision $revision, EditInfo $editInfo = null ) {
		if( !$revision->getContent()->getData() instanceof EntityDocument ) {
			throw new RuntimeException( 'Can only save Content of EntityDocuments' );
		}

		/** @var Item|Property $entity */
		$entity = $revision->getContent()->getData();
		$serialized = $this->entitySerializer->serialize( $entity );

		$params = array(
			'data' => json_encode( $serialized )
		);

		$revId = $revision->getId();
		if( !is_null( $revId ) ) {
			$params['baserevid'] = $revId;
		}

		$entityId = $entity->getId();
		if( !is_null( $entityId ) ) {
			$params['id'] = $entityId->getSerialization();

			// Always clear so that removing elements is possible
			$params['clear'] = 'true';
			// Add more detail to the default "Cleared an entity" summary
			// Note: this is later overridden if a summary is provided in the EditInfo
			$params['summary'] = 'Edited a ' . $entity->getType();

		} else {
			$params['new'] = $entity->getType();
		}

		// If no editInfo is explicitly passed call back to the one in the revision?
		if( $editInfo === null ) {
			$editInfo = $revision->getEditInfo();
		}

		if( $editInfo->getBot() ) {
			$params['bot'] = true;
		}
		if( $editInfo->getMinor() ) {
			$params['minor'] = true;
		}
		$summary = $editInfo->getSummary();
		if( !empty( $summary ) ) {
			$params['summary'] = $summary;
		}

		$result = $this->api->postRequest( 'wbeditentity', $params, $editInfo );
		return $this->entityDeserializer->deserialize( $result['entity'] );
	}
588949
private function bindValues(&$values, $statement, $parameter)
    {
        $count = count($values);
        for ($i = 0; $i < $count; $i++) {
            if (is_object($values[$i])) {
                if ($values[$i] instanceof DateTime) {
                    $values[$i] = $values[$i]->format('Y-m-d H:i:s');
                } else {
                    $values[$i] = (string) $values[$i];
                }
            }
            $type = $this->getPdoType($values[$i]);
            $statement->bindParam($parameter, $values[$i], $type);
            $parameter++;
        }

        return $parameter;
    }
184426
public function exists(string $statement, ...$params): bool
    {
        /**
         * @var string|int|float|bool|null $result
         */
        $result = $this->single($statement, $params);
        return !empty($result);
    }
1204151
public function postSelect(StatementInterface $statement, ResultInterface $result, ResultSetInterface $resultSet)
    {
        if ($this->getDmsColumns())
            // We have used the query with presented Predefined DMS Columns
            // Nothing to do
            return;

        $storedValues = $this->getStoredValues();
        $pkColumn     = $storedValues['pk'];

        $totalResultSet = array();
        foreach($resultSet as $rc)
        {
            if (!$rc instanceof iDataSetConveyor)
                throw new \Exception(sprintf(
                    'ResultSet must instance of iDataSetConveyor to DmsFeature interact to. "%s" given.'
                    , get_class($rc)
                ));

            $rc = $rc->toArray();

            $pk = $rc[$pkColumn]; // get pk column value
            foreach ($rc as $c => $v) {
                // iterate trough result containing duplicated rows because of join over dms values
                if ($c == 'dms__content' || $c == 'dms__field')
                    // dms virtual columns avoided and set as field->content
                    continue;

                if ($c == $pkColumn
                    && (!in_array($pkColumn, $storedValues['columns'])
                        && !in_array('*', $storedValues['columns'])
                    )
                )
                    continue;


                $totalResultSet[$pk][$c] = $v;
            }

            if (isset($rc['dms__content']) && isset($rc['dms__field'])) {
                if (in_array($rc['dms__field'], $storedValues['columns'])
                    || in_array('*', $storedValues['columns'])
                )
                {
                    $column = $rc['dms__field'];
                    $value  = $rc['dms__content'];
                    $totalResultSet[$pk][$column] = $value;
                }

                unset($rc['dms__field']);
                unset($rc['dms__content']);
            }
        }

        $resultSet->initialize($totalResultSet);
    }
1361925
public function bindValues($statement, $bindings)
    {
        foreach ($bindings as $key => $value) {
            $statement->bindParam($key, $bindings[$key]);
        }
    }
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;
    }
997424
public function getSingleResult($statement, $params = array())
    {
        $result = $this->getResults($statement, $params);

        if (!sizeof($result)) {
            return null;
        }

        return $result[0];
    }
300634
public function prepare($statement, $driverOpts = null) {
		if ($driverOpts === null) {
			$driverOpts = [];
		}

		try {
			$stmt = $this->pdo->prepare($statement, $driverOpts);
			return new PreparedStatement($stmt, $this->pdo, $this->exceptionAdapter);
		} catch (PDOException $e) {
			throw $this->exceptionAdapter->adapt($e, $statement);
		}
	}
1057024
public function exec(string $statement): int
    {
        if (null === $this->pdo) {
            $this->connect();
        }

        try {
            return $this->pdo->exec($statement);
        } catch (PDOException $pdoe) {
            throw new DatabaseException($pdoe->getMessage(), $pdoe);
        }
    }
1059063
public function prepare(string $statement) : PreparedStatementInterface
    {
        try {
            $preparedStatement = $this->getConnection()->prepare($statement);
            return new PdoPreparedStatement($preparedStatement);
        } catch (\PDOException $e) {
            throw new ParserRuntimeException('Statement could not be prepared.', 0, $e);
        }
    }