~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
 
17
17
/* Basic functions needed by many modules */
18
 
#include <config.h>
 
18
#include "config.h"
19
19
#include <assert.h>
20
20
 
21
21
#include <signal.h>
30
30
#  include <time.h>
31
31
# endif
32
32
#endif
33
 
#include <drizzled/internal/my_pthread.h>
34
 
#include <drizzled/internal/thread_var.h>
 
33
#include "drizzled/internal/my_pthread.h"
 
34
#include "drizzled/internal/thread_var.h"
35
35
 
36
36
#include <drizzled/sql_select.h>
37
37
#include <drizzled/error.h>
44
44
#include <drizzled/check_stack_overrun.h>
45
45
#include <drizzled/lock.h>
46
46
#include <drizzled/plugin/listen.h>
47
 
#include <drizzled/cached_directory.h>
 
47
#include "drizzled/cached_directory.h"
48
48
#include <drizzled/field/epoch.h>
49
49
#include <drizzled/field/null.h>
50
 
#include <drizzled/sql_table.h>
51
 
#include <drizzled/global_charset_info.h>
52
 
#include <drizzled/pthread_globals.h>
53
 
#include <drizzled/internal/iocache.h>
54
 
#include <drizzled/drizzled.h>
55
 
#include <drizzled/plugin/authorization.h>
56
 
#include <drizzled/table/temporary.h>
57
 
#include <drizzled/table/placeholder.h>
58
 
#include <drizzled/table/unused.h>
59
 
#include <drizzled/plugin/storage_engine.h>
60
 
#include <drizzled/session.h>
 
50
#include "drizzled/sql_table.h"
 
51
#include "drizzled/global_charset_info.h"
 
52
#include "drizzled/pthread_globals.h"
 
53
#include "drizzled/internal/iocache.h"
 
54
#include "drizzled/drizzled.h"
 
55
#include "drizzled/plugin/authorization.h"
 
56
#include "drizzled/table/temporary.h"
 
57
#include "drizzled/table/placeholder.h"
 
58
#include "drizzled/table/unused.h"
 
59
#include "drizzled/plugin/storage_engine.h"
61
60
 
62
61
#include <drizzled/refresh_version.h>
63
62
 
148
147
  if (sort.io_cache)
149
148
  {
150
149
    sort.io_cache->close_cached_file();
151
 
    safe_delete(sort.io_cache);
 
150
    delete sort.io_cache;
 
151
    sort.io_cache= 0;
152
152
  }
153
153
}
154
154
 
807
807
 
808
808
  if (not table::Cache::singleton().insert(table))
809
809
  {
810
 
    safe_delete(table);
 
810
    delete table;
811
811
 
812
812
    return NULL;
813
813
  }
1598
1598
     * table/schema information via error messages
1599
1599
     */
1600
1600
    identifier::Table the_table(tables->getSchemaName(), tables->getTableName());
1601
 
    if (not plugin::Authorization::isAuthorized(*user(), the_table))
 
1601
    if (not plugin::Authorization::isAuthorized(user(), the_table))
1602
1602
    {
1603
1603
      result= -1;                               // Fatal error
1604
1604
      break;
1929
1929
                           const char *name, uint32_t , Item **,
1930
1930
                           bool, TableList **actual_table)
1931
1931
{
1932
 
  List<Natural_join_column>::iterator
1933
 
    field_it(table_ref->join_columns->begin());
 
1932
  List_iterator_fast<Natural_join_column>
 
1933
    field_it(*(table_ref->join_columns));
1934
1934
  Natural_join_column *nj_col, *curr_nj_col;
1935
1935
  Field *found_field;
1936
1936
 
2145
2145
    */
2146
2146
    if (table_name && table_name[0])
2147
2147
    {
2148
 
      List<TableList>::iterator it(table_list->getNestedJoin()->join_list.begin());
 
2148
      List_iterator<TableList> it(table_list->getNestedJoin()->join_list);
2149
2149
      TableList *table;
2150
2150
      while ((table= it++))
2151
2151
      {
2295
2295
        fields.
2296
2296
      */
2297
2297
      {
2298
 
        Select_Lex *current_sel= session->getLex()->current_select;
 
2298
        Select_Lex *current_sel= session->lex->current_select;
2299
2299
        Select_Lex *last_select= table_ref->select_lex;
2300
2300
        /*
2301
2301
          If the field was an outer referencee, mark all selects using this
2444
2444
                  find_item_error_report_type report_error,
2445
2445
                  enum_resolution_type *resolution)
2446
2446
{
2447
 
  List<Item>::iterator li(items.begin());
 
2447
  List_iterator<Item> li(items);
2448
2448
  Item **found=0, **found_unaliased= 0, *item;
2449
2449
  const char *db_name=0;
2450
2450
  const char *field_name=0;
2647
2647
static bool
2648
2648
test_if_string_in_list(const char *find, List<String> *str_list)
2649
2649
{
2650
 
  List<String>::iterator str_list_it(str_list->begin());
 
2650
  List_iterator<String> str_list_it(*str_list);
2651
2651
  String *curr_str;
2652
2652
  size_t find_length= strlen(find);
2653
2653
  while ((curr_str= str_list_it++))
2981
2981
  if (using_fields && found_using_fields < using_fields->elements)
2982
2982
  {
2983
2983
    String *using_field_name;
2984
 
    List<String>::iterator using_fields_it(using_fields->begin());
 
2984
    List_iterator_fast<String> using_fields_it(*using_fields);
2985
2985
    while ((using_field_name= using_fields_it++))
2986
2986
    {
2987
2987
      const char *using_field_name_ptr= using_field_name->c_ptr();
2988
 
      List<Natural_join_column>::iterator
2989
 
        it(natural_using_join->join_columns->begin());
 
2988
      List_iterator_fast<Natural_join_column>
 
2989
        it(*(natural_using_join->join_columns));
2990
2990
      Natural_join_column *common_field;
2991
2991
 
2992
2992
      for (;;)
3068
3068
  /* Call the procedure recursively for each nested table reference. */
3069
3069
  if (table_ref->getNestedJoin())
3070
3070
  {
3071
 
    List<TableList>::iterator nested_it(table_ref->getNestedJoin()->join_list.begin());
 
3071
    List_iterator_fast<TableList> nested_it(table_ref->getNestedJoin()->join_list);
3072
3072
    TableList *same_level_left_neighbor= nested_it++;
3073
3073
    TableList *same_level_right_neighbor= NULL;
3074
3074
    /* Left/right-most neighbors, possibly at higher levels in the join tree. */
3122
3122
  {
3123
3123
    assert(table_ref->getNestedJoin() &&
3124
3124
           table_ref->getNestedJoin()->join_list.elements == 2);
3125
 
    List<TableList>::iterator operand_it(table_ref->getNestedJoin()->join_list.begin());
 
3125
    List_iterator_fast<TableList> operand_it(table_ref->getNestedJoin()->join_list);
3126
3126
    /*
3127
3127
      Notice that the order of join operands depends on whether table_ref
3128
3128
      represents a LEFT or a RIGHT join. In a RIGHT join, the operands are
3222
3222
  if (from_clause->elements == 0)
3223
3223
    return false; /* We come here in the case of UNIONs. */
3224
3224
 
3225
 
  List<TableList>::iterator table_ref_it(from_clause->begin());
 
3225
  List_iterator_fast<TableList> table_ref_it(*from_clause);
3226
3226
  TableList *table_ref; /* Current table reference. */
3227
3227
  /* Table reference to the left of the current. */
3228
3228
  TableList *left_neighbor;
3272
3272
    return 0;
3273
3273
 
3274
3274
  Item *item;
3275
 
  List<Item>::iterator it(fields.begin());
 
3275
  List_iterator<Item> it(fields);
3276
3276
 
3277
 
  session->getLex()->current_select->cur_pos_in_select_list= 0;
 
3277
  session->lex->current_select->cur_pos_in_select_list= 0;
3278
3278
  while (wild_num && (item= it++))
3279
3279
  {
3280
3280
    if (item->type() == Item::FIELD_ITEM &&
3284
3284
    {
3285
3285
      uint32_t elem= fields.elements;
3286
3286
      bool any_privileges= ((Item_field *) item)->any_privileges;
3287
 
      Item_subselect *subsel= session->getLex()->current_select->master_unit()->item;
 
3287
      Item_subselect *subsel= session->lex->current_select->master_unit()->item;
3288
3288
      if (subsel &&
3289
3289
          subsel->substype() == Item_subselect::EXISTS_SUBS)
3290
3290
      {
3315
3315
      wild_num--;
3316
3316
    }
3317
3317
    else
3318
 
      session->getLex()->current_select->cur_pos_in_select_list++;
 
3318
      session->lex->current_select->cur_pos_in_select_list++;
3319
3319
  }
3320
 
  session->getLex()->current_select->cur_pos_in_select_list= UNDEF_POS;
 
3320
  session->lex->current_select->cur_pos_in_select_list= UNDEF_POS;
3321
3321
 
3322
3322
  return 0;
3323
3323
}
3332
3332
{
3333
3333
  register Item *item;
3334
3334
  enum_mark_columns save_mark_used_columns= session->mark_used_columns;
3335
 
  nesting_map save_allow_sum_func= session->getLex()->allow_sum_func;
3336
 
  List<Item>::iterator it(fields.begin());
 
3335
  nesting_map save_allow_sum_func= session->lex->allow_sum_func;
 
3336
  List_iterator<Item> it(fields);
3337
3337
  bool save_is_item_list_lookup;
3338
3338
 
3339
3339
  session->mark_used_columns= mark_used_columns;
3340
3340
  if (allow_sum_func)
3341
 
    session->getLex()->allow_sum_func|= 1 << session->getLex()->current_select->nest_level;
 
3341
    session->lex->allow_sum_func|= 1 << session->lex->current_select->nest_level;
3342
3342
  session->setWhere(Session::DEFAULT_WHERE);
3343
 
  save_is_item_list_lookup= session->getLex()->current_select->is_item_list_lookup;
3344
 
  session->getLex()->current_select->is_item_list_lookup= 0;
 
3343
  save_is_item_list_lookup= session->lex->current_select->is_item_list_lookup;
 
3344
  session->lex->current_select->is_item_list_lookup= 0;
3345
3345
 
3346
3346
  /*
3347
3347
    To prevent fail on forward lookup we fill it with zerows,
3359
3359
  }
3360
3360
 
3361
3361
  Item **ref= ref_pointer_array;
3362
 
  session->getLex()->current_select->cur_pos_in_select_list= 0;
 
3362
  session->lex->current_select->cur_pos_in_select_list= 0;
3363
3363
  while ((item= it++))
3364
3364
  {
3365
3365
    if ((!item->fixed && item->fix_fields(session, it.ref())) || (item= *(it.ref()))->check_cols(1))
3366
3366
    {
3367
 
      session->getLex()->current_select->is_item_list_lookup= save_is_item_list_lookup;
3368
 
      session->getLex()->allow_sum_func= save_allow_sum_func;
 
3367
      session->lex->current_select->is_item_list_lookup= save_is_item_list_lookup;
 
3368
      session->lex->allow_sum_func= save_allow_sum_func;
3369
3369
      session->mark_used_columns= save_mark_used_columns;
3370
3370
      return true;
3371
3371
    }
3375
3375
        sum_func_list)
3376
3376
      item->split_sum_func(session, ref_pointer_array, *sum_func_list);
3377
3377
    session->used_tables|= item->used_tables();
3378
 
    session->getLex()->current_select->cur_pos_in_select_list++;
 
3378
    session->lex->current_select->cur_pos_in_select_list++;
3379
3379
  }
3380
 
  session->getLex()->current_select->is_item_list_lookup= save_is_item_list_lookup;
3381
 
  session->getLex()->current_select->cur_pos_in_select_list= UNDEF_POS;
 
3380
  session->lex->current_select->is_item_list_lookup= save_is_item_list_lookup;
 
3381
  session->lex->current_select->cur_pos_in_select_list= UNDEF_POS;
3382
3382
 
3383
 
  session->getLex()->allow_sum_func= save_allow_sum_func;
 
3383
  session->lex->allow_sum_func= save_allow_sum_func;
3384
3384
  session->mark_used_columns= save_mark_used_columns;
3385
3385
  return(test(session->is_error()));
3386
3386
}
3549
3549
 
3550
3550
bool
3551
3551
insert_fields(Session *session, Name_resolution_context *context, const char *db_name,
3552
 
              const char *table_name, List<Item>::iterator *it,
 
3552
              const char *table_name, List_iterator<Item> *it,
3553
3553
              bool )
3554
3554
{
3555
3555
  Field_iterator_table_ref field_iterator;
3656
3656
        session->used_tables|= item->used_tables();
3657
3657
      }
3658
3658
 
3659
 
      session->getLex()->current_select->cur_pos_in_select_list++;
 
3659
      session->lex->current_select->cur_pos_in_select_list++;
3660
3660
    }
3661
3661
    /*
3662
3662
      In case of stored tables, all fields are considered as used,
3709
3709
int Session::setup_conds(TableList *leaves, COND **conds)
3710
3710
{
3711
3711
  Session *session= this;
3712
 
  Select_Lex *select_lex= session->getLex()->current_select;
 
3712
  Select_Lex *select_lex= session->lex->current_select;
3713
3713
  TableList *table= NULL;       // For HP compilers
3714
3714
  void *save_session_marker= session->session_marker;
3715
3715
  /*
3767
3767
  }
3768
3768
  session->session_marker= save_session_marker;
3769
3769
 
3770
 
  session->getLex()->current_select->is_item_list_lookup= save_is_item_list_lookup;
 
3770
  session->lex->current_select->is_item_list_lookup= save_is_item_list_lookup;
3771
3771
  return(test(session->is_error()));
3772
3772
 
3773
3773
err_no_arena:
3805
3805
bool
3806
3806
fill_record(Session *session, List<Item> &fields, List<Item> &values, bool ignore_errors)
3807
3807
{
3808
 
  List<Item>::iterator f(fields.begin());
3809
 
  List<Item>::iterator v(values.begin());
 
3808
  List_iterator_fast<Item> f(fields),v(values);
3810
3809
  Item *value;
3811
3810
  Item_field *field;
3812
3811
  Table *table;
3824
3823
    field= static_cast<Item_field *>(f++);
3825
3824
    table= field->field->getTable();
3826
3825
    table->auto_increment_field_not_null= false;
3827
 
    f= fields.begin();
 
3826
    f.rewind();
3828
3827
  }
3829
3828
 
3830
3829
  while ((field= static_cast<Item_field *>(f++)))
3871
3870
 
3872
3871
bool fill_record(Session *session, Field **ptr, List<Item> &values, bool)
3873
3872
{
3874
 
  List<Item>::iterator v(values.begin());
 
3873
  List_iterator_fast<Item> v(values);
3875
3874
  Item *value;
3876
3875
  Table *table= 0;
3877
3876
  Field *field;