MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Ed_connection Class Reference

Public Member Functions

 Ed_connection (THD *thd)
bool execute_direct (LEX_STRING sql_text)
bool execute_direct (Server_runnable *server_runnable)
ulong get_field_count () const
ulonglong get_affected_rows () const
ulonglong get_last_insert_id () const
ulong get_warn_count () const
const char * get_last_error () const
unsigned int get_last_errno () const
const char * get_last_sqlstate () const
Ed_result_setuse_result_set ()
Ed_result_setstore_result_set ()
bool has_next_result () const
bool move_to_next_result ()

Friends

class Protocol_local

Detailed Description

Definition at line 135 of file sql_prepare.h.

Constructor & Destructor Documentation

Ed_connection::Ed_connection ( THD *  thd)

Construct 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.

Create a new "execute direct" connection.

Definition at line 4141 of file sql_prepare.cc.

Member Function Documentation

bool Ed_connection::execute_direct ( LEX_STRING  sql_text)

Execute one SQL statement.

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.

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

Definition at line 4177 of file sql_prepare.cc.

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.

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

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

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.

Definition at line 4199 of file sql_prepare.cc.

ulonglong Ed_connection::get_affected_rows ( ) const
inline

Get the number of affected (deleted, updated) rows for the current statement. Can be used for statements with get_field_count() == 0.

See Also
Documentation for C API function mysql_affected_rows().

Definition at line 230 of file sql_prepare.h.

ulong Ed_connection::get_field_count ( ) const
inline

Get the number of result set fields.

This method is valid only if we have a result: execute_direct() has been called. Otherwise the returned value is undefined.

See Also
Documentation for C API function mysql_field_count()

Definition at line 217 of file sql_prepare.h.

const char* Ed_connection::get_last_error ( ) const
inline

The following 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.

Definition at line 264 of file sql_prepare.h.

ulonglong Ed_connection::get_last_insert_id ( ) const
inline

Get the last insert id, if any.

See Also
Documentation for mysql_insert_id().

Definition at line 240 of file sql_prepare.h.

ulong Ed_connection::get_warn_count ( ) const
inline

Get the total number of warnings for the last executed statement. Note, that there is only one warning list even if a statement returns multiple results.

See Also
Documentation for C API function mysql_num_warnings().

Definition at line 253 of file sql_prepare.h.

bool Ed_connection::has_next_result ( ) const
inline

If the query returns multiple results, this method can be checked if there is another result beyond the next one. Never fails.

Definition at line 292 of file sql_prepare.h.

bool Ed_connection::move_to_next_result ( )
inline

Only valid to call if has_next_result() returned true. Otherwise the result is undefined.

Definition at line 297 of file sql_prepare.h.

Ed_result_set * Ed_connection::store_result_set ( )

Provided get_field_count() is not 0, this never fails. You must free the returned result set. This can be called only once after execute_direct(). Should be used when you would like to get the results and destroy the connection.

Release ownership of the current result set to the client.

Since we use a simple linked list for result sets, this method uses a linear search of the previous result set to exclude the released instance from the list.

Todo:
Use double-linked list, when this is really used.

XXX: This has never been tested with more than one result set!

Precondition
There must be a result set.

Definition at line 4269 of file sql_prepare.cc.

Ed_result_set* Ed_connection::use_result_set ( )
inline

Provided get_field_count() is not 0, this never fails. You don't need to free the result set, this is done automatically when you advance to the next result set or destroy the connection. Not returning const because of List iterator not accepting Should be used when you would like Ed_connection to manage result set memory for you.

Definition at line 276 of file sql_prepare.h.


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