async fn query(&mut self, sql: String) -> Result<State, io::Error> {
        // Parse first before doing any transaction checking.
        let stmts = match parse_sql(&sql) {
            Ok(stmts) => stmts,
            Err(err) => {
                self.error(err).await?;
                return self.ready().await;
            }
        };

        let num_stmts = stmts.len();

        // Compare with postgres' backend/tcop/postgres.c exec_simple_query.
        for stmt in stmts {
            // In an aborted transaction, reject all commands except COMMIT/ROLLBACK.
            if self.is_aborted_txn() && !is_txn_exit_stmt(Some(&stmt)) {
                self.aborted_txn_error().await?;
                break;
            }

            // Start an implicit transaction if we aren't in any transaction and there's
            // more than one statement. This mirrors the `use_implicit_block` variable in
            // postgres.
            //
            // This needs to be done in the loop instead of once at the top because
            // a COMMIT/ROLLBACK statement needs to start a new transaction on next
            // statement.
            self.start_transaction(Some(num_stmts)).await;

            match self.one_query(stmt).await? {
                State::Ready => (),
                State::Drain => break,
                State::Done => return Ok(State::Done),
            }
        }

        // Implicit transactions are closed at the end of a Query message.
        {
            if self.coord_client.session().transaction().is_implicit() {
                self.commit_transaction().await?;
            }
        }

        if num_stmts == 0 {
            self.conn.send(BackendMessage::EmptyQueryResponse).await?;
        }

        self.ready().await
    }
// See "Multiple Statements in a Simple Query" which documents how implicit
// transactions are handled.
// From https://www.postgresql.org/docs/current/protocol-flow.html
See "Multiple Statements in a Simple Query" which documents how implicit
transactions are handled.
See " Multiple Statements in a Simple Query " which documents how implicit transactions are handled .
async fn query(&mut self, sql: String) -> Result<State, io::Error> {
        // Parse first before doing any transaction checking.
        let stmts = match parse_sql(&sql) {
            Ok(stmts) => stmts,
            Err(err) => {
                self.error(err).await?;
                return self.ready().await;
            }
        };
        let num_stmts = stmts.len();
        // Compare with postgres' backend/tcop/postgres.c exec_simple_query.
        for stmt in stmts {
            // In an aborted transaction, reject all commands except COMMIT/ROLLBACK.
            if self.is_aborted_txn() && !is_txn_exit_stmt(Some(&stmt)) {
                self.aborted_txn_error().await?;
                break;
            }
            // Start an implicit transaction if we aren't in any transaction and there's
            // more than one statement. This mirrors the `use_implicit_block` variable in
            // postgres.
            //
            // This needs to be done in the loop instead of once at the top because
            // a COMMIT/ROLLBACK statement needs to start a new transaction on next
            // statement.
            self.start_transaction(Some(num_stmts)).await;
            match self.one_query(stmt).await? {
                State::Ready => (),
                State::Drain => break,
                State::Done => return Ok(State::Done),
            }
        }
        // Implicit transactions are closed at the end of a Query message.
        {
            if self.coord_client.session().transaction().is_implicit() {
                self.commit_transaction().await?;
            }
        }
        if num_stmts == 0 {
            self.conn.send(BackendMessage::EmptyQueryResponse).await?;
        }
        self.ready().await
    }
async fn query ( & mut self , sql : String ) -> Result < State , io :: Error > { // Parse first before doing any transaction checking. let stmts = match parse_sql ( & sql ) { Ok ( stmts ) => stmts , Err ( err ) => { self . error ( err ) . await ? ; return self . ready ( ) . await ; } } ; let num_stmts = stmts . len ( ) ; // Compare with postgres' backend/tcop/postgres.c exec_simple_query. for stmt in stmts { // In an aborted transaction, reject all commands except COMMIT/ROLLBACK. if self . is_aborted_txn ( ) && ! is_txn_exit_stmt ( Some ( & stmt ) ) { self . aborted_txn_error ( ) . await ? ; break ; } // Start an implicit transaction if we aren't in any transaction and there's // more than one statement. This mirrors the `use_implicit_block` variable in // postgres. // // This needs to be done in the loop instead of once at the top because // a COMMIT/ROLLBACK statement needs to start a new transaction on next // statement. self . start_transaction ( Some ( num_stmts ) ) . await ; match self . one_query ( stmt ) . await ? { State :: Ready => ( ) , State :: Drain => break , State :: Done => return Ok ( State :: Done ) , } } // Implicit transactions are closed at the end of a Query message. { if self . coord_client . session ( ) . transaction ( ) . is_implicit ( ) { self . commit_transaction ( ) . await ? ; } } if num_stmts == 0 { self . conn . send ( BackendMessage :: EmptyQueryResponse ) . await ? ; } self . ready ( ) . await }
See "Multiple Statements in a Simple Query" which documents how implicit
transactions are handled.
See " Multiple Statements in a Simple Query " which documents how implicit transactions are handled .
&mut self
sql
String
&mut self
sql
String