Drizzled Public API Documentation

Runtime Environment

Defines

#define MY_YACC_INIT   1000
#define MY_YACC_MAX   32000

Functions

const std::string & drizzled::getCommandName (const enum_server_command &command)
void drizzled::init_update_queries (void)
bool drizzled::dispatch_command (enum_server_command command, Session *session, char *packet, uint32_t packet_length)
static bool drizzled::_schema_select (Session *session, Select_Lex *sel, const string &schema_table_name)
int drizzled::prepare_new_schema_table (Session *session, LEX &lex, const string &schema_table_name)
static int drizzled::execute_command (Session *session)
bool drizzled::execute_sqlcom_select (Session *session, TableList *all_tables)
bool drizzled::my_yyoverflow (short **a, ParserType **b, ulong *yystacksize)
void drizzled::init_select (LEX *lex)
bool drizzled::new_select (LEX *lex, bool move_down)
void drizzled::create_select_for_variable (Session *session, const char *var_name)
void drizzled::parse (Session *session, const char *inBuf, uint32_t length)
bool drizzled::add_field_to_list (Session *session, LEX_STRING *field_name, enum enum_field_types type, char *length, char *decimal, uint32_t type_modifier, enum column_format_type column_format, Item *default_value, Item *on_update_value, LEX_STRING *comment, char *change, List< String > *interval_list, const CHARSET_INFO *const cs)
void drizzled::add_join_natural (TableList *a, TableList *b, List< String > *using_fields, Select_Lex *lex)
bool drizzled::check_simple_select (Session::pointer session)
Item * drizzled::all_any_subquery_creator (Item *left_expr, chooser_compare_func_creator cmp, bool all, Select_Lex *select_lex)
bool drizzled::update_precheck (Session *session, TableList *)
bool drizzled::insert_precheck (Session *session, TableList *)
Item * drizzled::negate_expression (Session *session, Item *expr)
bool drizzled::check_string_char_length (LEX_STRING *str, const char *err_msg, uint32_t max_char_length, const CHARSET_INFO *const cs, bool no_error)
bool drizzled::check_identifier_name (LEX_STRING *str, error_t err_code, uint32_t max_char_length, const char *param_for_err_msg)
static bool drizzled::parse_sql (Session *session, Lex_input_stream *lip)

Variables

size_t drizzled::my_thread_stack_size = 0
const CHARSET_INFO * drizzled::character_set_filesystem
const char * drizzled::xa_state_names []
bitset< CF_BIT_SIZE > drizzled::sql_command_flags [SQLCOM_END+1]

Function Documentation

static bool drizzled::_schema_select ( Session *  session,
Select_Lex *  sel,
const string &  schema_table_name 
) [static]

Create a TableList object for an INFORMATION_SCHEMA table.

This function is used in the parser to convert a SHOW or DESCRIBE table_name command to a SELECT from INFORMATION_SCHEMA. It prepares a Select_Lex and a TableList object to represent the given command as a SELECT parse tree.

Parameters:
sessionthread handle
lexcurrent lex
table_identtable alias if it's used
schema_table_namethe name of the INFORMATION_SCHEMA table to be created
Note:
Due to the way this function works with memory and LEX it cannot be used outside the parser (parse tree transformations outside the parser break PS and SP).
Return values:
0success
1out of memory or SHOW commands are not allowed in this version of the server.

Definition at line 398 of file sql_parse.cc.

bool drizzled::add_field_to_list ( Session *  session,
LEX_STRING *  field_name,
enum_field_types  type,
char *  length,
char *  decimals,
uint32_t  type_modifier,
enum column_format_type  column_format,
Item *  default_value,
Item *  on_update_value,
LEX_STRING *  comment,
char *  change,
List< String > *  interval_list,
const CHARSET_INFO *const  cs 
)

Store field definition for create.

Returns:
Return 0 if ok

Definition at line 846 of file sql_parse.cc.

References drizzled::CreateField::init(), and drizzled::null_lex_str.

void drizzled::add_join_natural ( TableList *  a,
TableList *  b,
List< String > *  using_fields,
Select_Lex *  lex 
)

Create a fake Select_Lex for a unit.

The method create a fake Select_Lex object for a unit. This object is created for any union construct containing a union operation and also for any single select union construct of the form

    (SELECT ... ORDER BY order_list [LIMIT n]) ORDER BY ...
    @endvarbatim
    or of the form
    @varbatim
    (SELECT ... ORDER BY LIMIT n) ORDER BY ...
    @endvarbatim

  @param session_arg		   thread handle

  @note
    The object is used to retrieve rows from the temporary table
    where the result on the union is obtained.

  @retval
    1     on failure to create the object
  @retval
    0     on success
*/

bool Select_Lex_Unit::add_fake_select_lex(Session *session_arg)
{
  Select_Lex *first_sl= first_select();
  assert(!fake_select_lex);

  if (!(fake_select_lex= new (session_arg->mem_root) Select_Lex()))
      return(1);
  fake_select_lex->include_standalone(this,
                                      (Select_Lex_Node**)&fake_select_lex);
  fake_select_lex->select_number= INT_MAX;
  fake_select_lex->parent_lex= &session_arg->lex(); /* Used in init_query. */
  fake_select_lex->make_empty_select();
  fake_select_lex->linkage= GLOBAL_OPTIONS_TYPE;
  fake_select_lex->select_limit= 0;

  fake_select_lex->context.outer_context=first_sl->context.outer_context;
  /* allow item list resolving in fake select for ORDER BY */
  fake_select_lex->context.resolve_in_select_list= true;
  fake_select_lex->context.select_lex= fake_select_lex;

  if (!is_union())
  {
    /*
      This works only for
      (SELECT ... ORDER BY list [LIMIT n]) ORDER BY order_list [LIMIT m],
      (SELECT ... LIMIT n) ORDER BY order_list [LIMIT m]
      just before the parser starts processing order_list
    */
    global_parameters= fake_select_lex;
    fake_select_lex->no_table_names_allowed= 1;
    session_arg->lex().current_select= fake_select_lex;
  }
  session_arg->lex().pop_context();
  return(0);
}


/**
  Push a new name resolution context for a JOIN ... ON clause to the
  context stack of a query block.

    Create a new name resolution context for a JOIN ... ON clause,
    set the first and last leaves of the list of table references
    to be used for name resolution, and push the newly created
    context to the stack of contexts of the query.

  @param session       pointer to current thread
  @param left_op   left  operand of the JOIN
  @param right_op  rigth operand of the JOIN

  @retval
    false  if all is OK
  @retval
    true   if a memory allocation error occured
*/

bool
push_new_name_resolution_context(Session *session,
                                 TableList *left_op, TableList *right_op)
{
  Name_resolution_context *on_context;
  if (!(on_context= new (session->mem_root) Name_resolution_context))
    return true;
  on_context->init();
  on_context->first_name_resolution_table=
    left_op->first_leaf_for_name_resolution();
  on_context->last_name_resolution_table=
    right_op->last_leaf_for_name_resolution();
  return session->lex().push_context(on_context);
}


/**
  Add an ON condition to the second operand of a JOIN ... ON.

    Add an ON condition to the right operand of a JOIN ... ON clause.

  @param b     the second operand of a JOIN ... ON
  @param expr  the condition to be added to the ON clause

  @retval
    false  if there was some error
  @retval
    true   if all is OK
*/

void add_join_on(TableList *b, Item *expr)
{
  if (expr)
  {
    if (!b->on_expr)
      b->on_expr= expr;
    else
    {
      /*
        If called from the parser, this happens if you have both a
        right and left join. If called later, it happens if we add more
        than one condition to the ON clause.
      */
      b->on_expr= new Item_cond_and(b->on_expr,expr);
    }
    b->on_expr->top_level_item();
  }
}


/**
  Mark that there is a NATURAL JOIN or JOIN ... USING between two
  tables.

    This function marks that table b should be joined with a either via
    a NATURAL JOIN or via JOIN ... USING. Both join types are special
    cases of each other, so we treat them together. The function
    setup_conds() creates a list of equal condition between all fields
    of the same name for NATURAL JOIN or the fields in 'using_fields'
    for JOIN ... USING. The list of equality conditions is stored
    either in b->on_expr, or in JOIN::conds, depending on whether there
    was an outer join.

  EXAMPLE
  @verbatim
    SELECT * FROM t1 NATURAL LEFT JOIN t2
     <=>
    SELECT * FROM t1 LEFT JOIN t2 ON (t1.i=t2.i and t1.j=t2.j ... )

    SELECT * FROM t1 NATURAL JOIN t2 WHERE <some_cond>
     <=>
    SELECT * FROM t1, t2 WHERE (t1.i=t2.i and t1.j=t2.j and <some_cond>)

    SELECT * FROM t1 JOIN t2 USING(j) WHERE <some_cond>
     <=>
    SELECT * FROM t1, t2 WHERE (t1.j=t2.j and <some_cond>)
   
Parameters:
aLeft join argument
bRight join argument
using_fieldsField names from USING clause

Definition at line 1463 of file sql_parse.cc.

References drizzled::TableList::natural_join.

Item * drizzled::all_any_subquery_creator ( Item *  left_expr,
chooser_compare_func_creator  cmp,
bool  all,
Select_Lex *  select_lex 
)

Construct ALL/ANY/SOME subquery Item.

Parameters:
left_exprpointer to left expression
cmpcompare function creator
alltrue if we create ALL subquery
select_lexpointer on parsed subquery structure
Returns:
constructed Item (or 0 if out of memory)

Definition at line 1507 of file sql_parse.cc.

bool drizzled::check_simple_select ( Session::pointer  session)

Check if the select is a simple select (not an union).

Return values:
0ok
1error ; In this case the error messege is sent to the client

Definition at line 1480 of file sql_parse.cc.

References drizzled::Session::m_lip, and drizzled::Lex_input_stream::yylval.

void drizzled::create_select_for_variable ( Session *  session,
const char *  var_name 
)

Create a select to return the same output as 'SELECT @var_name'.

Used for SHOW COUNT(*) [ WARNINGS | ERROR].

This will crash with a core dump if the variable doesn't exists.

Parameters:
var_nameVariable name

Definition at line 746 of file sql_parse.cc.

bool drizzled::dispatch_command ( enum_server_command  command,
Session *  session,
char *  packet,
uint32_t  packet_length 
)

Perform one connection-level (COM_XXXX) command.

Parameters:
commandtype of command to perform
sessionconnection handle
packetdata for the command, packet is always null-terminated
packet_lengthlength of packet + 1 (to show that data is null-terminated) except for COM_SLEEP, where it can be zero.
Todo:

set session->lex().sql_command to SQLCOM_END here.

The following has to be changed to an 8 byte integer

Return values:
0ok
1request of thread shutdown, i. e. if command is COM_QUIT/COM_SHUTDOWN

Definition at line 182 of file sql_parse.cc.

References drizzled::TransactionServices::autocommitOrRollback(), drizzled::Diagnostics_area::can_overwrite_status, drizzled::Session::close_thread_tables(), drizzled::Session::command, drizzled::Diagnostics_area::disable_status(), drizzled::memory::Root::free_root(), drizzled::Session::is_error(), drizzled::Diagnostics_area::is_sent, drizzled::kill_drizzle(), drizzled::Session::mem_root, drizzled::Session::my_eof(), drizzled::Session::my_ok(), drizzled::parse(), drizzled::Session::readAndStoreQuery(), drizzled::Session::set_proc_info(), drizzled::Session::setQueryId(), drizzled::Session::status_var, and drizzled::session::Transactions::stmt.

Referenced by drizzled::Session::executeStatement().

static int drizzled::execute_command ( Session *  session) [static]

Execute command saved in session and lex->sql_command.

Before every operation that can request a write lock for a table wait if a global read lock exists. However do not wait if this thread has locked tables already. No new locks can be requested until the other locks are released. The thread that requests the global read lock waits for write locked tables to become unlocked.

Note that wait_if_global_read_lock() sets a protection against a new global read lock when it succeeds. This needs to be released by start_waiting_global_read_lock() after the operation.

Parameters:
sessionThread handle
Todo:
  • Invalidate the table in the query cache if something changed after unlocking when changes become visible. TODO: this is workaround. right way will be move invalidating in the unlock procedure.
  • TODO: use check_change_password()
  • JOIN is not supported yet. TODO
  • SUSPEND and FOR MIGRATE are not supported yet. TODO
Return values:
falseOK
trueError

Definition at line 466 of file sql_parse.cc.

References drizzled::TransactionContext::hasModifiedNonTransData(), drizzled::Session::inTransaction(), drizzled::Session::is_error(), drizzled::Session::row_count_func, drizzled::Session::set_proc_info(), drizzled::sql_command_flags, and drizzled::session::Transactions::stmt.

Referenced by drizzled::parse().

bool drizzled::insert_precheck ( Session *  session,
TableList *   
)

simple INSERT query pre-check.

Parameters:
sessionThread handler
tablesGlobal table list
Return values:
falseOK
trueerror

Definition at line 1578 of file sql_parse.cc.

Referenced by drizzled::statement::ReplaceSelect::execute(), drizzled::statement::InsertSelect::execute(), drizzled::statement::Replace::execute(), and drizzled::statement::Insert::execute().

Item * drizzled::negate_expression ( Session *  session,
Item *  expr 
)

negate given expression.

Parameters:
sessionthread handler
exprexpression for negation
Returns:
negated expression

Definition at line 1603 of file sql_parse.cc.

void drizzled::parse ( Session *  session,
const char *  inBuf,
uint32_t  length 
)

Parse a query.

Parameters:
sessionCurrent thread
inBufBegining of the query text
lengthLength of the query text

Definition at line 781 of file sql_parse.cc.

References drizzled::Session::cleanup_after_query(), drizzled::Session::end_statement(), drizzled::execute_command(), drizzled::Session::is_error(), drizzled::parse_sql(), drizzled::Session::reset_for_next_command(), and drizzled::Session::set_proc_info().

Referenced by drizzled::dispatch_command().

static bool drizzled::parse_sql ( Session *  session,
Lex_input_stream *  lip 
) [static]

This is a wrapper of DRIZZLEparse(). All the code should call parse_sql() instead of DRIZZLEparse().

Parameters:
sessionThread context.
lipLexer context.
Returns:
Error status.
Return values:
falseon success.
trueon parsing error.

Definition at line 1715 of file sql_parse.cc.

References drizzled::Session::is_error(), drizzled::Session::is_fatal_error, and drizzled::Session::m_lip.

Referenced by drizzled::parse().

bool drizzled::update_precheck ( Session *  session,
TableList *   
)

Update query pre-check.

Parameters:
sessionThread handler
tablesGlobal/local table list (have to be the same)
Return values:
falseOK
trueError

Definition at line 1539 of file sql_parse.cc.

Referenced by drizzled::statement::Update::execute().


Variable Documentation

bitset<CF_BIT_SIZE> drizzled::sql_command_flags[SQLCOM_END+1]

Mark all commands that somehow changes a table.

This is used to check number of updates / hour.

sql_command is actually set to SQLCOM_END sometimes so we need the +1 to include it in the array.

See COMMAND_FLAG_xxx for different type of commands 2 - query that returns meaningful ROW_COUNT() - a number of modified rows

Definition at line 117 of file sql_parse.cc.

Referenced by drizzled::execute_command().

const char * drizzled::xa_state_names
Initial value:
{
  "NON-EXISTING", "ACTIVE", "IDLE", "PREPARED"
}

Definition at line 101 of file sql_parse.cc.