~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Henrik Ingo
  • Date: 2011-09-23 06:14:37 UTC
  • mfrom: (2425 drizzle)
  • mto: This revision was merged to the branch mainline in revision 2439.
  • Revision ID: henrik.ingo@avoinelama.fi-20110923061437-ct1wedkb9s47uy2t
Merge newest trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
#include <drizzled/system_variables.h>
60
60
#include <drizzled/session/times.h>
61
61
#include <drizzled/session/transactions.h>
 
62
#include <drizzled/create_field.h>
 
63
#include <drizzled/lex_input_stream.h>
62
64
 
63
65
#include <limits.h>
64
66
 
88
90
 
89
91
namespace
90
92
{
91
 
 
92
 
static const std::string command_name[COM_END+1]={
93
 
  "Sleep",
94
 
  "Quit",
95
 
  "Init DB",
96
 
  "Query",
97
 
  "Shutdown",
98
 
  "Connect",
99
 
  "Ping",
100
 
  "Kill",
101
 
  "Error"  // Last command number
102
 
};
103
 
 
 
93
  static const std::string command_name[]=
 
94
  {
 
95
    "Sleep",
 
96
    "Quit",
 
97
    "Init DB",
 
98
    "Query",
 
99
    "Shutdown",
 
100
    "Connect",
 
101
    "Ping",
 
102
    "Kill",
 
103
    "Error"  // Last command number
 
104
  };
104
105
}
105
106
 
106
 
const char *xa_state_names[]={
 
107
const char *xa_state_names[]=
 
108
{
107
109
  "NON-EXISTING", "ACTIVE", "IDLE", "PREPARED"
108
110
};
109
111
 
 
112
 
110
113
/**
111
114
  Mark all commands that somehow changes a table.
112
115
 
189
192
                      const char* packet, uint32_t packet_length)
190
193
{
191
194
  bool error= false;
192
 
  Query_id &query_id= Query_id::get_query_id();
 
195
  Query_id& query_id= Query_id::get_query_id();
193
196
 
194
197
  DRIZZLE_COMMAND_START(session->thread_id, command);
195
198
 
198
201
  session->times.set_time();
199
202
  session->setQueryId(query_id.value());
200
203
 
201
 
  switch (command)
 
204
  if (command != COM_PING)
202
205
  {
203
 
  /* Ignore these statements. */
204
 
  case COM_PING:
205
 
    break;
206
 
 
207
 
  /* Increase id and count all other statements. */
208
 
  default:
 
206
    // Increase id and count all other statements
209
207
    session->status_var.questions++;
210
208
    query_id.next();
211
209
  }
218
216
    // We should do something about an error...
219
217
  }
220
218
 
221
 
  session->server_status&=
222
 
           ~(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED);
 
219
  session->server_status&= ~(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED);
223
220
 
224
221
  switch (command)
225
222
  {
401
398
*/
402
399
static bool _schema_select(Session& session, Select_Lex& sel, const string& schema_table_name)
403
400
{
404
 
  LEX_STRING db, table;
 
401
  lex_string_t db, table;
405
402
  bitset<NUM_OF_TABLE_OPTIONS> table_options;
406
403
  /*
407
404
     We have to make non const db_name & table_name
408
405
     because of lower_case_table_names
409
406
  */
410
 
  session.make_lex_string(&db, "data_dictionary", sizeof("data_dictionary"), false);
411
 
  session.make_lex_string(&table, schema_table_name, false);
 
407
  session.make_lex_string(&db, str_ref("data_dictionary"));
 
408
  session.make_lex_string(&table, schema_table_name);
412
409
  return not sel.add_table_to_list(&session, new Table_ident(db, table), NULL, table_options, TL_READ);
413
410
}
414
411
 
730
727
  LEX& lex= session->lex();
731
728
  init_select(&lex);
732
729
  lex.sql_command= SQLCOM_SELECT;
733
 
  LEX_STRING tmp;
 
730
  lex_string_t tmp;
734
731
  tmp.str= (char*) var_name;
735
732
  tmp.length=strlen(var_name);
736
 
  LEX_STRING null_lex_string;
 
733
  lex_string_t null_lex_string;
737
734
  memset(&null_lex_string.str, 0, sizeof(null_lex_string));
738
735
  /*
739
736
    We set the name of Item to @@session.var_name because that then is used
744
741
    char buff[MAX_SYS_VAR_LENGTH*2+4+8];
745
742
    char *end= buff;
746
743
    end+= snprintf(buff, sizeof(buff), "@@session.%s", var_name);
747
 
    var->set_name(buff, end-buff, system_charset_info);
 
744
    var->set_name(buff, end-buff);
748
745
    session->add_item_to_list(var);
749
746
  }
750
747
}
804
801
    Return 0 if ok
805
802
*/
806
803
 
807
 
bool add_field_to_list(Session *session, LEX_STRING *field_name, enum_field_types type,
808
 
                       char *length, char *decimals,
 
804
bool add_field_to_list(Session *session, lex_string_t *field_name, enum_field_types type,
 
805
                       const char *length, const char *decimals,
809
806
                       uint32_t type_modifier,
810
807
                       enum column_format_type column_format,
811
808
                       Item *default_value, Item *on_update_value,
812
 
                       LEX_STRING *comment,
813
 
                       char *change,
 
809
                       lex_string_t *comment,
 
810
                       const char *change,
814
811
                       List<String> *interval_list, const charset_info_st * const cs)
815
812
{
816
813
  register CreateField *new_field;
824
821
  {
825
822
    Key *key;
826
823
    lex->col_list.push_back(new Key_part_spec(*field_name, 0));
827
 
    key= new Key(Key::PRIMARY, null_lex_str,
 
824
    key= new Key(Key::PRIMARY, null_lex_string(),
828
825
                      &default_key_create_info,
829
826
                      0, lex->col_list);
830
827
    statement->alter_info.key_list.push_back(key);
834
831
  {
835
832
    Key *key;
836
833
    lex->col_list.push_back(new Key_part_spec(*field_name, 0));
837
 
    key= new Key(Key::UNIQUE, null_lex_str,
 
834
    key= new Key(Key::UNIQUE, null_lex_string(),
838
835
                 &default_key_create_info, 0,
839
836
                 lex->col_list);
840
837
    statement->alter_info.key_list.push_back(key);
913
910
 
914
911
TableList *Select_Lex::add_table_to_list(Session *session,
915
912
                                         Table_ident *table,
916
 
                                         LEX_STRING *alias,
 
913
                                         lex_string_t *alias,
917
914
                                         const bitset<NUM_OF_TABLE_OPTIONS>& table_options,
918
915
                                         thr_lock_type lock_type,
919
916
                                         List<Index_hint> *index_hints_arg,
920
 
                                         LEX_STRING *option)
 
917
                                         lex_string_t *option)
921
918
{
922
919
  TableList *previous_table_ref; /* The table preceding the current one. */
923
 
  char *alias_str;
924
920
  LEX *lex= &session->lex();
925
921
 
926
922
  if (!table)
927
923
    return NULL;                                // End of memory
928
 
  alias_str= alias ? alias->str : table->table.str;
 
924
  const char* alias_str= alias ? alias->str : table->table.str;
929
925
  if (! table_options.test(TL_OPTION_ALIAS) &&
930
926
      check_table_name(table->table.str, table->table.length))
931
927
  {
940
936
    identifier::Schema schema_identifier(string(table->db.str));
941
937
    if (not schema::check(*session, schema_identifier))
942
938
    {
943
 
 
944
939
      my_error(ER_WRONG_DB_NAME, MYF(0), table->db.str);
945
940
      return NULL;
946
941
    }
950
945
  {
951
946
    if (table->sel)
952
947
    {
953
 
      my_message(ER_DERIVED_MUST_HAVE_ALIAS,
954
 
                 ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0));
 
948
      my_message(ER_DERIVED_MUST_HAVE_ALIAS, ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0));
955
949
      return NULL;
956
950
    }
957
951
    alias_str= (char*) session->mem.memdup(alias_str,table->table.length+1);
958
952
  }
959
953
  TableList *ptr = (TableList *) session->mem.calloc(sizeof(TableList));
960
954
 
 
955
  char* name;
 
956
  size_t name_size;
961
957
  if (table->db.str)
962
958
  {
963
959
    ptr->setIsFqtn(true);
964
960
    ptr->setSchemaName(table->db.str);
965
 
    ptr->db_length= table->db.length;
966
961
  }
967
 
  else if (lex->copy_db_to(ptr->getSchemaNamePtr(), &ptr->db_length))
 
962
  else if (lex->session->copy_db_to(name, name_size))
968
963
    return NULL;
969
964
  else
 
965
  {
970
966
    ptr->setIsFqtn(false);
 
967
    ptr->setSchemaName(name);
 
968
  }
971
969
 
972
970
  ptr->alias= alias_str;
973
971
  ptr->setIsAlias(alias ? true : false);
974
972
  ptr->setTableName(table->table.str);
975
 
  ptr->table_name_length=table->table.length;
976
973
  ptr->lock_type=   lock_type;
977
974
  ptr->force_index= table_options.test(TL_OPTION_FORCE_INDEX);
978
975
  ptr->ignore_leaves= table_options.test(TL_OPTION_IGNORE_LEAVES);
984
981
  if (lock_type != TL_IGNORE)
985
982
  {
986
983
    TableList *first_table= (TableList*) table_list.first;
987
 
    for (TableList *tables= first_table ;
988
 
         tables ;
989
 
         tables=tables->next_local)
 
984
    for (TableList *tables= first_table; tables; tables= tables->next_local)
990
985
    {
991
986
      if (not my_strcasecmp(table_alias_charset, alias_str, tables->alias) &&
992
 
          not my_strcasecmp(system_charset_info, ptr->getSchemaName(), tables->getSchemaName()))
 
987
        not my_strcasecmp(system_charset_info, ptr->getSchemaName(), tables->getSchemaName()))
993
988
      {
994
 
        my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str);
995
 
        return NULL;
 
989
        my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str);
 
990
        return NULL;
996
991
      }
997
992
    }
998
993
  }
1578
1573
*/
1579
1574
 
1580
1575
 
1581
 
bool check_string_char_length(LEX_STRING *str, const char *err_msg,
 
1576
bool check_string_char_length(lex_string_t *str, const char *err_msg,
1582
1577
                              uint32_t max_char_length, const charset_info_st * const cs,
1583
1578
                              bool no_error)
1584
1579
{
1595
1590
}
1596
1591
 
1597
1592
 
1598
 
bool check_identifier_name(LEX_STRING *str, error_t err_code,
 
1593
bool check_identifier_name(lex_string_t *str, error_t err_code,
1599
1594
                           uint32_t max_char_length,
1600
1595
                           const char *param_for_err_msg)
1601
1596
{