~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.h

Merge in security refactor.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
44
44
namespace drizzled
45
45
{
46
46
 
47
 
class st_lex_symbol;
48
47
class select_result_interceptor;
49
48
 
50
49
/* YACC and LEX Definitions */
63
62
*/
64
63
 
65
64
#ifdef DRIZZLE_SERVER
66
 
/* set_var should change to set_var here ... */
67
 
# include <drizzled/sys_var.h>
 
65
# include <drizzled/set_var.h>
68
66
# include <drizzled/item/func.h>
69
67
# ifdef DRIZZLE_YACC
70
68
#  define LEX_YYSTYPE void *
250
248
      UNCACHEABLE_EXPLAIN
251
249
      UNCACHEABLE_PREPARE
252
250
  */
253
 
  std::bitset<8> uncacheable;
 
251
  uint8_t uncacheable;
254
252
  enum sub_select_type linkage;
255
253
  bool no_table_names_allowed; /* used for global order by */
256
254
  bool no_error; /* suppress error message (convert it to warnings) */
260
258
    return memory::sql_alloc(size);
261
259
  }
262
260
  static void *operator new(size_t size, memory::Root *mem_root)
263
 
  { return (void*) mem_root->alloc_root((uint32_t) size); }
 
261
  { return (void*) alloc_root(mem_root, (uint32_t) size); }
264
262
  static void operator delete(void *, size_t)
265
263
  {  }
266
264
  static void operator delete(void *, memory::Root *)
285
283
  virtual uint32_t get_in_sum_expr();
286
284
  virtual TableList* get_table_list();
287
285
  virtual List<Item>* get_item_list();
 
286
  virtual uint32_t get_table_join_options();
288
287
  virtual TableList *add_table_to_list(Session *session, Table_ident *table,
289
 
                                       LEX_STRING *alias,
290
 
                                       const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
291
 
                                       thr_lock_type flags= TL_UNLOCK,
292
 
                                       List<Index_hint> *hints= 0,
293
 
                                       LEX_STRING *option= 0);
 
288
                                        LEX_STRING *alias,
 
289
                                        uint32_t table_options,
 
290
                                        thr_lock_type flags= TL_UNLOCK,
 
291
                                        List<Index_hint> *hints= 0,
 
292
                                        LEX_STRING *option= 0);
294
293
  virtual void set_lock_for_tables(thr_lock_type)
295
294
  {}
296
295
 
297
296
  friend class Select_Lex_Unit;
298
 
  friend bool new_select(LEX *lex, bool move_down);
 
297
  friend bool mysql_new_select(LEX *lex, bool move_down);
299
298
private:
300
299
  void fast_exclude();
301
300
};
306
305
*/
307
306
class Session;
308
307
class select_result;
309
 
class Join;
 
308
class JOIN;
310
309
class select_union;
311
310
class Select_Lex_Unit: public Select_Lex_Node {
312
311
protected:
405
404
class Select_Lex: public Select_Lex_Node
406
405
{
407
406
public:
408
 
 
409
 
  Select_Lex() :
410
 
    context(),
411
 
    db(0),
412
 
    where(0),
413
 
    having(0),
414
 
    cond_value(),
415
 
    having_value(),
416
 
    parent_lex(0),
417
 
    olap(UNSPECIFIED_OLAP_TYPE),
418
 
    table_list(),
419
 
    group_list(),
420
 
    item_list(),
421
 
    interval_list(),
422
 
    is_item_list_lookup(false),
423
 
    join(0),
424
 
    top_join_list(),
425
 
    join_list(0),
426
 
    embedding(0),
427
 
    sj_nests(),
428
 
    leaf_tables(0),
429
 
    type(optimizer::ST_PRIMARY),
430
 
    order_list(),
431
 
    gorder_list(0),
432
 
    select_limit(0),
433
 
    offset_limit(0),
434
 
    ref_pointer_array(0),
435
 
    select_n_having_items(0),
436
 
    cond_count(0),
437
 
    between_count(0),
438
 
    max_equal_elems(0),
439
 
    select_n_where_fields(0),
440
 
    parsing_place(NO_MATTER),
441
 
    with_sum_func(0),
442
 
    in_sum_expr(0),
443
 
    select_number(0),
444
 
    nest_level(0),
445
 
    inner_sum_func_list(0),
446
 
    with_wild(0),
447
 
    braces(0),
448
 
    having_fix_field(0),
449
 
    inner_refs_list(),
450
 
    n_sum_items(0),
451
 
    n_child_sum_items(0),
452
 
    explicit_limit(0),
453
 
    is_cross(false),
454
 
    subquery_in_having(0),
455
 
    is_correlated(0),
456
 
    exclude_from_table_unique_test(0),
457
 
    non_agg_fields(),
458
 
    cur_pos_in_select_list(0),
459
 
    prev_join_using(0),
460
 
    full_group_by_flag(),
461
 
    current_index_hint_type(INDEX_HINT_IGNORE),
462
 
    current_index_hint_clause(),
463
 
    index_hints(0)
464
 
  {
465
 
  }
466
 
 
467
407
  Name_resolution_context context;
468
408
  char *db;
469
409
  /* An Item representing the WHERE clause */
482
422
  List<Item> item_list;  /* list of fields & expressions */
483
423
  List<String> interval_list;
484
424
  bool is_item_list_lookup;
485
 
  Join *join; /* after Join::prepare it is pointer to corresponding JOIN */
 
425
  JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
486
426
  List<TableList> top_join_list; /* join list of the top level          */
487
427
  List<TableList> *join_list;    /* list for the currently parsed join  */
488
428
  TableList *embedding;          /* table embedding to the above list   */
518
458
  enum_parsing_place parsing_place; /* where we are parsing expression */
519
459
  bool with_sum_func;   /* sum function indicator */
520
460
 
 
461
  uint32_t table_join_options;
521
462
  uint32_t in_sum_expr;
522
463
  uint32_t select_number; /* number of select (used for EXPLAIN) */
523
464
  int8_t nest_level;     /* nesting level of select */
535
476
 
536
477
  /* explicit LIMIT clause was used */
537
478
  bool explicit_limit;
538
 
 
539
 
  /* explicit CROSS JOIN was used */
540
 
  bool is_cross;
541
 
 
542
479
  /*
543
480
    there are subquery in HAVING clause => we can't close tables before
544
481
    query processing end even if we use temporary table
577
514
          defined as SUM_FUNC_USED.
578
515
  */
579
516
  std::bitset<2> full_group_by_flag;
580
 
 
581
517
  void init_query();
582
518
  void init_select();
583
519
  Select_Lex_Unit* master_unit();
615
551
  TableList* add_table_to_list(Session *session,
616
552
                               Table_ident *table,
617
553
                               LEX_STRING *alias,
618
 
                               const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
 
554
                               uint32_t table_options,
619
555
                               thr_lock_type flags= TL_UNLOCK,
620
556
                               List<Index_hint> *hints= 0,
621
557
                               LEX_STRING *option= 0);
626
562
  void add_joined_table(TableList *table);
627
563
  TableList *convert_right_join();
628
564
  List<Item>* get_item_list();
 
565
  uint32_t get_table_join_options();
629
566
  void set_lock_for_tables(thr_lock_type lock_type);
630
567
  inline void init_order()
631
568
  {
634
571
    order_list.next= (unsigned char**) &order_list.first;
635
572
  }
636
573
  /*
637
 
    This method created for reiniting LEX in admin_table() and can be
 
574
    This method created for reiniting LEX in mysql_admin_table() and can be
638
575
    used only if you are going remove all Select_Lex & units except belonger
639
576
    to LEX (LEX::unit & LEX::select, for other purposes there are
640
577
    Select_Lex_Unit::exclude_level & Select_Lex_Unit::exclude_tree
646
583
  bool test_limit();
647
584
 
648
585
  friend void lex_start(Session *session);
 
586
  Select_Lex() : n_sum_items(0), n_child_sum_items(0) {}
649
587
  void make_empty_select()
650
588
  {
651
589
    init_query();
654
592
  bool setup_ref_array(Session *session, uint32_t order_group_num);
655
593
  void print(Session *session, String *str, enum_query_type query_type);
656
594
  static void print_order(String *str,
657
 
                          Order *order,
 
595
                          order_st *order,
658
596
                          enum_query_type query_type);
659
597
  void print_limit(Session *session, String *str, enum_query_type query_type);
660
598
  void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
856
794
  List<Lex_Column>    columns;
857
795
  List<Item>          *insert_list,field_list,value_list,update_list;
858
796
  List<List_item>     many_values;
859
 
  SetVarVector  var_list;
 
797
  List<set_var_base>  var_list;
860
798
  /*
861
799
    A stack of name resolution contexts for the query. This stack is used
862
800
    at parse time to set local name resolution contexts for various parts
904
842
    enum ha_rkey_function ha_rkey_mode;
905
843
    enum xa_option_words xa_opt;
906
844
  };
907
 
  sql_var_t option_type;
 
845
  enum enum_var_type option_type;
908
846
 
909
847
  int nest_level;
910
848
  uint8_t describe;
914
852
  */
915
853
  uint8_t derived_tables;
916
854
 
 
855
  /* Only true when FULL symbol is found (e.g. SHOW FULL PROCESSLIST) */
 
856
  bool verbose;
 
857
  
917
858
  /* Was the IGNORE symbol found in statement */
918
859
  bool ignore;
919
860
 
936
877
     statement in a session. It's re-used by doing lex_end, lex_start
937
878
     in sql_lex.cc
938
879
  */
939
 
  virtual ~LEX();
 
880
  virtual ~LEX()
 
881
  {
 
882
  }
940
883
 
941
884
  TableList *unlink_first_table(bool *link_to_local);
942
885
  void link_first_table_back(TableList *first, bool link_to_local);
943
886
  void first_lists_tables_same();
944
887
 
 
888
  bool only_view_structure();
 
889
  bool need_correct_ident();
 
890
 
945
891
  void cleanup_after_one_table_open();
946
892
 
947
893
  bool push_context(Name_resolution_context *context)
960
906
  {
961
907
    return context_stack.head();
962
908
  }
 
909
  /*
 
910
    Restore the LEX and Session in case of a parse error.
 
911
  */
 
912
  static void cleanup_lex_after_parse_error(Session *session);
963
913
 
964
914
  /**
965
915
    @brief check if the statement is a single-level join
982
932
    }
983
933
    return false;
984
934
  }
985
 
  bool is_cross; // CROSS keyword was used
986
 
  bool isCacheable()
987
 
  {
988
 
    return cacheable;
989
 
  }
990
 
  void setCacheable(bool val)
991
 
  {
992
 
    cacheable= val;
993
 
  }
994
 
 
995
 
  void reset()
996
 
  {
997
 
    sum_expr_used= false;
998
 
    _exists= false;
999
 
  }
1000
 
 
1001
 
  void setSumExprUsed()
1002
 
  {
1003
 
    sum_expr_used= true;
1004
 
  }
1005
 
 
1006
 
  bool isSumExprUsed()
1007
 
  {
1008
 
    return sum_expr_used;
1009
 
  }
1010
 
 
1011
 
  void start(Session *session);
1012
 
  void end();
1013
 
 
1014
 
  message::Table *table()
1015
 
  {
1016
 
    if (not _create_table)
1017
 
      _create_table= new message::Table;
1018
 
 
1019
 
    return _create_table;
1020
 
  }
1021
 
 
1022
 
  message::Table::Field *field()
1023
 
  {
1024
 
    return _create_field;
1025
 
  }
1026
 
 
1027
 
  void setField(message::Table::Field *arg)
1028
 
  {
1029
 
    _create_field= arg;
1030
 
  }
1031
 
 
1032
 
  void setExists()
1033
 
  {
1034
 
    _exists= true;
1035
 
  }
1036
 
 
1037
 
  bool exists() const
1038
 
  {
1039
 
    return _exists;
1040
 
  }
1041
 
 
1042
 
private: 
1043
 
  bool cacheable;
1044
 
  bool sum_expr_used;
1045
 
  message::Table *_create_table;
1046
 
  message::Table::Field *_create_field;
1047
 
  bool _exists;
1048
935
};
1049
936
 
1050
937
extern void lex_start(Session *session);
 
938
extern void lex_end(LEX *lex);
1051
939
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
1052
940
extern bool is_lex_native_function(const LEX_STRING *name);
1053
941
 
1054
 
bool check_for_sql_keyword(drizzled::st_lex_symbol const&);
1055
 
bool check_for_sql_keyword(drizzled::lex_string_t const&);
1056
 
 
1057
942
/**
1058
943
  @} (End of group Semantic_Analysis)
1059
944
*/