MySQL 8.4.2
Source Code Documentation
Ed_connection Class Referencefinal

#include <ed_connection.h>

Public Member Functions

 Ed_connection (THD *thd)
 Construct a new "execute direct" connection. More...
 
bool execute_direct (LEX_STRING sql_text)
 Execute one SQL statement. More...
 
bool execute_direct (Server_runnable *server_runnable)
 Same as the previous, but takes an instance of Server_runnable instead of SQL statement text. More...
 
const char * get_last_error () const
 The following three members are only valid if execute_direct() or move_to_next_result() returned an error. More...
 
unsigned int get_last_errno () const
 
Ed_result_setget_result_sets ()
 
 ~Ed_connection ()
 

Private Member Functions

void free_old_result ()
 Free all result sets of the previous statement, if any, and reset warnings and errors. More...
 
void add_result_set (Ed_result_set *ed_result_set)
 A helper method that is called only during execution. More...
 
 Ed_connection (const Ed_connection &)
 
Ed_connectionoperator= (Ed_connection &)
 

Private Attributes

Diagnostics_area m_diagnostics_area
 
THDm_thd
 Execute direct interface does not support multi-statements, only multi-results. More...
 
Ed_result_setm_rsets
 
Ed_result_setm_current_rset
 

Friends

class Protocol_local
 

Constructor & Destructor Documentation

◆ Ed_connection() [1/2]

Ed_connection::Ed_connection ( THD thd)

Construct a new "execute direct" connection.

Create a new "execute direct" connection.

The connection can be used to execute SQL statements. If the connection failed to initialize, the error will be returned on the attempt to execute a statement.

Precondition
thd must have no open tables while the connection is used. However, Ed_connection works okay in LOCK TABLES mode. Other properties of THD, such as the current warning information, errors, etc. do not matter and are preserved by Ed_connection. One thread may have many Ed_connections created for it.

◆ ~Ed_connection()

Ed_connection::~Ed_connection ( )
inline

◆ Ed_connection() [2/2]

Ed_connection::Ed_connection ( const Ed_connection )
private

Member Function Documentation

◆ add_result_set()

void Ed_connection::add_result_set ( Ed_result_set ed_result_set)
private

A helper method that is called only during execution.

Although Ed_connection doesn't support multi-statements, a statement may generate many result sets. All subsequent result sets are appended to the end.

Precondition
This is called only by Protocol_local.

◆ execute_direct() [1/2]

bool Ed_connection::execute_direct ( LEX_STRING  sql_text)

Execute one SQL statement.

A simple wrapper that uses a helper class to execute SQL statements.

Until this method is executed, no other methods of Ed_connection can be used. Life cycle of Ed_connection is:

Initialized -> a statement has been executed -> look at result, move to next result -> look at result, move to next result -> ... moved beyond the last result == Initialized.

This method can be called repeatedly. Once it's invoked, results of the previous execution are lost.

A result of execute_direct() can be either:

  • success, no result set rows. In this case get_field_count() returns 0. This happens after execution of INSERT, UPDATE, DELETE, DROP and similar statements. Some other methods, such as get_affected_rows() can be used to retrieve additional result information.
  • success, there are some result set rows (maybe 0). E.g. happens after SELECT. In this case get_field_count() returns the number of columns in a result set and store_result() can be used to retrieve a result set..
  • an error, methods to retrieve error information can be used.
Returns
execution status
Return values
falsesuccess, use get_field_count() to determine what to do next.
trueerror, use get_last_error() to see the error number.

◆ execute_direct() [2/2]

bool Ed_connection::execute_direct ( Server_runnable server_runnable)

Same as the previous, but takes an instance of Server_runnable instead of SQL statement text.

Execute a fragment of server functionality without an effect on thd, and store results in memory.

Returns
execution status
Return values
falsesuccess, use get_field_count() if your code fragment is supposed to return a result set
truefailure

Conventions:

  • the code fragment must finish with OK, EOF or ERROR.
  • the code fragment doesn't have to close thread tables, free memory, commit statement transaction or do any other cleanup that is normally done in the end of dispatch_command().
Parameters
server_runnableA code fragment to execute.

◆ free_old_result()

void Ed_connection::free_old_result ( )
private

Free all result sets of the previous statement, if any, and reset warnings and errors.

Called before execution of the next query.

◆ get_last_errno()

unsigned int Ed_connection::get_last_errno ( ) const
inline

◆ get_last_error()

const char * Ed_connection::get_last_error ( ) const
inline

The following three members are only valid if execute_direct() or move_to_next_result() returned an error.

They never fail, but if they are called when there is no result, or no error, the result is not defined.

◆ get_result_sets()

Ed_result_set * Ed_connection::get_result_sets ( )
inline

◆ operator=()

Ed_connection & Ed_connection::operator= ( Ed_connection )
private

Friends And Related Function Documentation

◆ Protocol_local

friend class Protocol_local
friend

Member Data Documentation

◆ m_current_rset

Ed_result_set* Ed_connection::m_current_rset
private

◆ m_diagnostics_area

Diagnostics_area Ed_connection::m_diagnostics_area
private

◆ m_rsets

Ed_result_set* Ed_connection::m_rsets
private

◆ m_thd

THD* Ed_connection::m_thd
private

Execute direct interface does not support multi-statements, only multi-results.

So we never have a situation when we have a mix of result sets and OK or error packets. We either have a single result set, a single error, or a single OK, or we have a series of result sets, followed by an OK or error.


The documentation for this class was generated from the following files: