My Project
Public Types | Public Member Functions | Public Attributes
Prepared_statement Class Reference

List of all members.

Public Types

enum  flag_values { IS_IN_USE = 1, IS_SQL_PREPARE = 2 }

Public Member Functions

 Prepared_statement (THD *thd_arg)
virtual ~Prepared_statement ()
void setup_set_params ()
virtual Query_arena::Type type () const
virtual void cleanup_stmt ()
bool set_name (LEX_STRING *name)
void close_cursor ()
bool is_in_use ()
bool is_sql_prepare () const
void set_sql_prepare ()
bool prepare (const char *packet, uint packet_length)
bool execute_loop (String *expanded_query, bool open_cursor, uchar *packet_arg, uchar *packet_end_arg)
bool execute_server_runnable (Server_runnable *server_runnable)
void deallocate ()

Public Attributes

THD * thd
Select_fetch_protocol_binary result
Item_param ** param_array
Server_side_cursorcursor
uint param_count
uint last_errno
uint flags
char last_error [MYSQL_ERRMSG_SIZE]
bool(* set_params )(Prepared_statement *st, uchar *data, uchar *data_end, uchar *read_pos, String *expanded_query)
bool(* set_params_from_vars )(Prepared_statement *stmt, List< LEX_STRING > &varnames, String *expanded_query)

Detailed Description

Prepared_statement: a statement that can contain placeholders.


Constructor & Destructor Documentation

Destroy this prepared statement, cleaning up all used memory and resources.

This is called from ::deallocate() to handle COM_STMT_CLOSE and DEALLOCATE PREPARE or when THD ends and all prepared statements are freed.


Member Function Documentation

Common part of DEALLOCATE PREPARE and mysqld_stmt_close.

bool Prepared_statement::execute_loop ( String expanded_query,
bool  open_cursor,
uchar *  packet,
uchar *  packet_end 
)

Execute a prepared statement. Re-prepare it a limited number of times if necessary.

Try to execute a prepared statement. If there is a metadata validation error, prepare a new copy of the prepared statement, swap the old and the new statements, and try again. If there is a validation error again, repeat the above, but perform no more than MAX_REPREPARE_ATTEMPTS.

Note:
We have to try several times in a loop since we release metadata locks on tables after prepared statement prepare. Therefore, a DDL statement may sneak in between prepare and execute of a new statement. If this happens repeatedly more than MAX_REPREPARE_ATTEMPTS times, we give up.
Returns:
TRUE if an error, FALSE if success
Return values:
TRUEeither MAX_REPREPARE_ATTEMPTS has been reached, or some general error
FALSEsuccessfully executed the statement, perhaps after having reprepared it a few times.
bool Prepared_statement::prepare ( const char *  packet,
uint  packet_len 
)

Parse statement text, validate the statement, and prepare it for execution.

You should not change global THD state in this function, if at all possible: it may be called from any context, e.g. when executing a COM_* command, and SQLCOM_* command, or a stored procedure.

Parameters:
packetstatement text
packet_len
Note:
Precondition: The caller must ensure that thd->change_list and thd->free_list is empty: this function will not back them up but will free in the end of its execution.
Postcondition: thd->mem_root contains unused memory allocated during validation.

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines