~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Olaf van der Spek
  • Date: 2011-11-09 19:27:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2457.
  • Revision ID: olafvdspek@gmail.com-20111109192744-xgu8uyi2f89ebwd1
Refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <drizzled/abort_exception.h>
22
22
#include <drizzled/error.h>
23
23
#include <drizzled/nested_join.h>
 
24
#include <drizzled/query_id.h>
24
25
#include <drizzled/transaction_services.h>
25
26
#include <drizzled/sql_parse.h>
26
27
#include <drizzled/data_home.h>
87
88
extern size_t my_thread_stack_size;
88
89
extern const charset_info_st *character_set_filesystem;
89
90
 
90
 
static atomic<uint64_t> g_query_id;
91
 
 
92
91
namespace
93
92
{
94
93
  static const std::string command_name[]=
193
192
                      const char* packet, uint32_t packet_length)
194
193
{
195
194
  bool error= false;
 
195
  Query_id& query_id= Query_id::get_query_id();
196
196
 
197
197
  DRIZZLE_COMMAND_START(session->thread_id, command);
198
198
 
199
199
  session->command= command;
200
200
  session->lex().sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
201
201
  session->times.set_time();
202
 
  session->setQueryId(g_query_id.increment());
 
202
  session->setQueryId(query_id.value());
203
203
 
204
204
  if (command != COM_PING)
205
205
  {
206
206
    // Increase id and count all other statements
207
207
    session->status_var.questions++;
 
208
    query_id.next();
208
209
  }
209
210
 
210
211
  /* @todo set session->lex().sql_command to SQLCOM_END here */
908
909
 
909
910
  if (not table->is_derived_table() && table->db.data())
910
911
  {
911
 
    files_charset_info->casedn_str(table->db.str_);
 
912
    my_casedn_str(files_charset_info, table->db.str_);
912
913
    if (not schema::check(*session, identifier::Schema(table->db)))
913
914
    {
914
915
      my_error(ER_WRONG_DB_NAME, MYF(0), table->db.data());
957
958
    TableList *first_table= (TableList*) table_list.first;
958
959
    for (TableList *tables= first_table; tables; tables= tables->next_local)
959
960
    {
960
 
      if (not table_alias_charset->strcasecmp(alias_str, tables->alias) &&
961
 
        not system_charset_info->strcasecmp(ptr->getSchemaName(), tables->getSchemaName()))
 
961
      if (not my_strcasecmp(table_alias_charset, alias_str, tables->alias) &&
 
962
        not my_strcasecmp(system_charset_info, ptr->getSchemaName(), tables->getSchemaName()))
962
963
      {
963
964
        my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str);
964
965
        return NULL;
973
974
      element
974
975
      We don't use the offsetof() macro here to avoid warnings from gcc
975
976
    */
976
 
    previous_table_ref= (TableList*) ((char*) table_list.next - ((char*) &(ptr->next_local) - (char*) ptr));
 
977
    previous_table_ref= (TableList*) ((char*) table_list.next -
 
978
                                       ((char*) &(ptr->next_local) -
 
979
                                        (char*) ptr));
977
980
    /*
978
981
      Set next_name_resolution_table of the previous table reference to point
979
982
      to the current table reference. In effect the list
1046
1049
    - 0, otherwise
1047
1050
*/
1048
1051
 
1049
 
TableList *Select_Lex::end_nested_join()
 
1052
TableList *Select_Lex::end_nested_join(Session *)
1050
1053
{
 
1054
  TableList *ptr;
 
1055
  NestedJoin *nested_join;
 
1056
 
1051
1057
  assert(embedding);
1052
 
  TableList* ptr= embedding;
 
1058
  ptr= embedding;
1053
1059
  join_list= ptr->getJoinList();
1054
1060
  embedding= ptr->getEmbedding();
1055
 
  NestedJoin* nested_join= ptr->getNestedJoin();
 
1061
  nested_join= ptr->getNestedJoin();
1056
1062
  if (nested_join->join_list.size() == 1)
1057
1063
  {
1058
1064
    TableList *embedded= &nested_join->join_list.front();
1060
1066
    embedded->setJoinList(join_list);
1061
1067
    embedded->setEmbedding(embedding);
1062
1068
    join_list->push_front(embedded);
1063
 
    return embedded;
 
1069
    ptr= embedded;
1064
1070
  }
1065
 
  else if (not nested_join->join_list.size())
 
1071
  else if (nested_join->join_list.size() == 0)
1066
1072
  {
1067
1073
    join_list->pop();
1068
 
    return NULL;
 
1074
    ptr= NULL;                                     // return value
1069
1075
  }
1070
1076
  return ptr;
1071
1077
}
1196
1202
 
1197
1203
void Select_Lex::set_lock_for_tables(thr_lock_type lock_type)
1198
1204
{
1199
 
  for (TableList *tables= (TableList*) table_list.first; tables; tables= tables->next_local)
 
1205
  for (TableList *tables= (TableList*) table_list.first;
 
1206
       tables;
 
1207
       tables= tables->next_local)
1200
1208
  {
1201
1209
    tables->lock_type= lock_type;
1202
1210
  }