~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.h

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2000-2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
15
 
20
16
#ifndef DRIZZLE_SERVER_SQL_LEX_H
21
17
#define DRIZZLE_SERVER_SQL_LEX_H
24
20
  @defgroup Semantic_Analysis Semantic Analysis
25
21
*/
26
22
 
27
 
#include "sql_udf.h"
28
 
 
29
23
/* YACC and LEX Definitions */
30
24
 
31
25
/* These may not be declared yet */
39
33
  YYSTYPE before including this file
40
34
*/
41
35
 
42
 
#include <drizzled/set_var.h>
 
36
#include "set_var.h"
43
37
 
44
38
#ifdef DRIZZLE_YACC
45
39
#define LEX_YYSTYPE void *
72
66
  SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_STATUS,
73
67
  SQLCOM_SHOW_ENGINE_LOGS, SQLCOM_SHOW_ENGINE_STATUS, SQLCOM_SHOW_ENGINE_MUTEX,
74
68
  SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
75
 
  SQLCOM_SHOW_CREATE,
76
 
  SQLCOM_SHOW_CREATE_DB,
77
 
  SQLCOM_SHOW_TABLE_STATUS,
 
69
  SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS,
 
70
  SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_TABLE_STATUS,
78
71
  SQLCOM_LOAD,SQLCOM_SET_OPTION,SQLCOM_LOCK_TABLES,SQLCOM_UNLOCK_TABLES,
79
72
  SQLCOM_CHANGE_DB, SQLCOM_CREATE_DB, SQLCOM_DROP_DB, SQLCOM_ALTER_DB,
80
73
  SQLCOM_REPAIR, SQLCOM_REPLACE, SQLCOM_REPLACE_SELECT,
88
81
  SQLCOM_RENAME_TABLE,  
89
82
  SQLCOM_RESET, SQLCOM_PURGE, SQLCOM_PURGE_BEFORE, SQLCOM_SHOW_BINLOGS,
90
83
  SQLCOM_SHOW_OPEN_TABLES,
91
 
  SQLCOM_DELETE_MULTI, SQLCOM_UPDATE_MULTI,
92
 
  SQLCOM_SHOW_WARNS,
93
 
  SQLCOM_EMPTY_QUERY,
94
 
  SQLCOM_SHOW_ERRORS,
 
84
  SQLCOM_SHOW_SLAVE_HOSTS, SQLCOM_DELETE_MULTI, SQLCOM_UPDATE_MULTI,
 
85
  SQLCOM_SHOW_BINLOG_EVENTS,
 
86
  SQLCOM_SHOW_WARNS, SQLCOM_EMPTY_QUERY, SQLCOM_SHOW_ERRORS,
95
87
  SQLCOM_CHECKSUM,
96
88
  SQLCOM_BINLOG_BASE64_EVENT,
97
89
  SQLCOM_SHOW_PLUGINS,
133
125
    Enum is used for making it possible to detect if the user
134
126
    changed variable or if it should be left at old value
135
127
   */
136
 
  enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE} heartbeat_opt;
 
128
  enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE}
 
129
    ssl, ssl_verify_server_cert, heartbeat_opt;
 
130
  char *ssl_key, *ssl_cert, *ssl_ca, *ssl_capath, *ssl_cipher;
137
131
  char *relay_log_name;
138
132
  uint32_t relay_log_pos;
139
133
} LEX_MASTER_INFO;
160
154
  Keep in sync with index_hint_type.
161
155
*/
162
156
extern const char * index_hint_type_name[];
163
 
typedef unsigned char index_clause_map;
 
157
typedef uchar index_clause_map;
164
158
 
165
159
/*
166
160
  Bits in index_clause_map : one for each possible FOR clause in
195
189
    key_name.length= length;
196
190
  }
197
191
 
198
 
  void print(Session *session, String *str);
 
192
  void print(THD *thd, String *str);
199
193
}; 
200
194
 
201
195
/* 
374
368
  virtual TableList* get_table_list();
375
369
  virtual List<Item>* get_item_list();
376
370
  virtual uint32_t get_table_join_options();
377
 
  virtual TableList *add_table_to_list(Session *session, Table_ident *table,
 
371
  virtual TableList *add_table_to_list(THD *thd, Table_ident *table,
378
372
                                        LEX_STRING *alias,
379
373
                                        uint32_t table_options,
380
374
                                        thr_lock_type flags= TL_UNLOCK,
394
388
   SELECT_LEX_UNIT - unit of selects (UNION, INTERSECT, ...) group 
395
389
   SELECT_LEXs
396
390
*/
397
 
class Session;
 
391
class THD;
398
392
class select_result;
399
393
class JOIN;
400
394
class select_union;
440
434
  /* not NULL if unit used in subselect, point to subselect item */
441
435
  Item_subselect *item;
442
436
  /* thread handler */
443
 
  Session *session;
 
437
  THD *thd;
444
438
  /*
445
439
    SELECT_LEX for hidden SELECT in onion which process global
446
440
    ORDER BY and LIMIT
455
449
  st_select_lex* outer_select();
456
450
  st_select_lex* first_select()
457
451
  {
458
 
    return reinterpret_cast<st_select_lex*>(slave);
 
452
    return my_reinterpret_cast(st_select_lex*)(slave);
459
453
  }
460
454
  st_select_lex_unit* next_unit()
461
455
  {
462
 
    return reinterpret_cast<st_select_lex_unit*>(next);
 
456
    return my_reinterpret_cast(st_select_lex_unit*)(next);
463
457
  }
464
458
  st_select_lex* return_after_parsing() { return return_to; }
465
459
  void exclude_level();
466
460
  void exclude_tree();
467
461
 
468
462
  /* UNION methods */
469
 
  bool prepare(Session *session, select_result *result, uint32_t additional_options);
 
463
  bool prepare(THD *thd, select_result *result, uint32_t additional_options);
470
464
  bool exec();
471
465
  bool cleanup();
472
466
  inline void unclean() { cleaned= 0; }
474
468
 
475
469
  void print(String *str, enum_query_type query_type);
476
470
 
477
 
  bool add_fake_select_lex(Session *session);
478
 
  void init_prepare_fake_select_lex(Session *session);
 
471
  bool add_fake_select_lex(THD *thd);
 
472
  void init_prepare_fake_select_lex(THD *thd);
479
473
  bool change_result(select_result_interceptor *result,
480
474
                     select_result_interceptor *old_result);
481
475
  void set_limit(st_select_lex *values);
482
 
  void set_session(Session *session_arg) { session= session_arg; }
 
476
  void set_thd(THD *thd_arg) { thd= thd_arg; }
483
477
  inline bool is_union (); 
484
478
 
485
 
  friend void lex_start(Session *session);
 
479
  friend void lex_start(THD *thd);
486
480
  friend int subselect_union_engine::exec();
487
481
 
488
482
  List<Item> *get_unit_column_types();
582
576
  bool subquery_in_having;
583
577
  /* true <=> this SELECT is correlated w.r.t. some ancestor select */
584
578
  bool is_correlated;
 
579
  /*
 
580
    This variable is required to ensure proper work of subqueries and
 
581
    stored procedures. Generally, one should use the states of
 
582
    Query_arena to determine if it's a statement prepare or first
 
583
    execution of a stored procedure. However, in case when there was an
 
584
    error during the first execution of a stored procedure, the SP body
 
585
    is not expelled from the SP cache. Therefore, a deeply nested
 
586
    subquery might be left unoptimized. So we need this per-subquery
 
587
    variable to inidicate the optimization/execution state of every
 
588
    subquery. Prepared statements work OK in that regard, as in
 
589
    case of an error during prepare the PS is not created.
 
590
  */
 
591
  bool first_execution;
 
592
  bool first_cond_optimization;
585
593
  /* exclude this select from check of unique_table() */
586
594
  bool exclude_from_table_unique_test;
587
595
  /* List of fields that aren't under an aggregate function */
642
650
  bool inc_in_sum_expr();
643
651
  uint32_t get_in_sum_expr();
644
652
 
645
 
  bool add_item_to_list(Session *session, Item *item);
646
 
  bool add_group_to_list(Session *session, Item *item, bool asc);
647
 
  bool add_order_to_list(Session *session, Item *item, bool asc);
648
 
  TableList* add_table_to_list(Session *session, Table_ident *table,
 
653
  bool add_item_to_list(THD *thd, Item *item);
 
654
  bool add_group_to_list(THD *thd, Item *item, bool asc);
 
655
  bool add_order_to_list(THD *thd, Item *item, bool asc);
 
656
  TableList* add_table_to_list(THD *thd, Table_ident *table,
649
657
                                LEX_STRING *alias,
650
658
                                uint32_t table_options,
651
659
                                thr_lock_type flags= TL_UNLOCK,
652
660
                                List<Index_hint> *hints= 0,
653
661
                                LEX_STRING *option= 0);
654
662
  TableList* get_table_list();
655
 
  bool init_nested_join(Session *session);
656
 
  TableList *end_nested_join(Session *session);
657
 
  TableList *nest_last_join(Session *session);
 
663
  bool init_nested_join(THD *thd);
 
664
  TableList *end_nested_join(THD *thd);
 
665
  TableList *nest_last_join(THD *thd);
658
666
  void add_joined_table(TableList *table);
659
667
  TableList *convert_right_join();
660
668
  List<Item>* get_item_list();
664
672
  {
665
673
    order_list.elements= 0;
666
674
    order_list.first= 0;
667
 
    order_list.next= (unsigned char**) &order_list.first;
 
675
    order_list.next= (uchar**) &order_list.first;
668
676
  }
669
677
  /*
670
678
    This method created for reiniting LEX in mysql_admin_table() and can be
675
683
  void cut_subtree() { slave= 0; }
676
684
  bool test_limit();
677
685
 
678
 
  friend void lex_start(Session *session);
 
686
  friend void lex_start(THD *thd);
679
687
  st_select_lex() : n_sum_items(0), n_child_sum_items(0) {}
680
688
  void make_empty_select()
681
689
  {
682
690
    init_query();
683
691
    init_select();
684
692
  }
685
 
  bool setup_ref_array(Session *session, uint32_t order_group_num);
686
 
  void print(Session *session, String *str, enum_query_type query_type);
 
693
  bool setup_ref_array(THD *thd, uint32_t order_group_num);
 
694
  void print(THD *thd, String *str, enum_query_type query_type);
687
695
  static void print_order(String *str,
688
696
                          order_st *order,
689
697
                          enum_query_type query_type);
690
 
  void print_limit(Session *session, String *str, enum_query_type query_type);
691
 
  void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
 
698
  void print_limit(THD *thd, String *str, enum_query_type query_type);
 
699
  void fix_prepare_information(THD *thd, Item **conds, Item **having_conds);
692
700
  /*
693
701
    Destroy the used execution plan (JOIN) of this subtree (this
694
702
    SELECT_LEX and all nested SELECT_LEXes and SELECT_LEX_UNITs).
706
714
   Add a index hint to the tagged list of hints. The type and clause of the
707
715
   hint will be the current ones (set by set_index_hint()) 
708
716
  */
709
 
  bool add_index_hint (Session *session, char *str, uint32_t length);
 
717
  bool add_index_hint (THD *thd, char *str, uint32_t length);
710
718
 
711
719
  /* make a list to hold index hints */
712
 
  void alloc_index_hints (Session *session);
 
720
  void alloc_index_hints (THD *thd);
713
721
  /* read and clear the index hints */
714
722
  List<Index_hint>* pop_index_hints(void) 
715
723
  {
856
864
    in which it was right after query parsing.
857
865
  */
858
866
  SQL_LIST sroutines_list;
859
 
  unsigned char    **sroutines_list_own_last;
 
867
  uchar    **sroutines_list_own_last;
860
868
  uint32_t     sroutines_list_own_elements;
861
869
 
862
870
  /*
1001
1009
class Lex_input_stream
1002
1010
{
1003
1011
public:
1004
 
  Lex_input_stream(Session *session, const char* buff, unsigned int length);
 
1012
  Lex_input_stream(THD *thd, const char* buff, unsigned int length);
1005
1013
  ~Lex_input_stream();
1006
1014
 
1007
1015
  /**
1229
1237
    return m_body_utf8_ptr - m_body_utf8;
1230
1238
  }
1231
1239
 
1232
 
  void body_utf8_start(Session *session, const char *begin_ptr);
 
1240
  void body_utf8_start(THD *thd, const char *begin_ptr);
1233
1241
  void body_utf8_append(const char *ptr);
1234
1242
  void body_utf8_append(const char *ptr, const char *end_ptr);
1235
 
  void body_utf8_append_literal(Session *session,
 
1243
  void body_utf8_append_literal(THD *thd,
1236
1244
                                const LEX_STRING *txt,
1237
1245
                                const CHARSET_INFO * const txt_cs,
1238
1246
                                const char *end_ptr);
1239
1247
 
1240
1248
  /** Current thread. */
1241
 
  Session *m_session;
 
1249
  THD *m_thd;
1242
1250
 
1243
1251
  /** Current line number. */
1244
1252
  uint32_t yylineno;
1328
1336
  const char *found_semicolon;
1329
1337
 
1330
1338
  /** Token character bitmaps, to detect 7bit strings. */
1331
 
  unsigned char tok_bitmap;
 
1339
  uchar tok_bitmap;
1332
1340
 
1333
1341
  /** SQL_MODE = IGNORE_SPACE. */
1334
1342
  bool ignore_space;
1340
1348
    Starting position of the TEXT_STRING or IDENT in the pre-processed
1341
1349
    buffer.
1342
1350
 
1343
 
    NOTE: this member must be used within DRIZZLElex() function only.
 
1351
    NOTE: this member must be used within MYSQLlex() function only.
1344
1352
  */
1345
1353
  const char *m_cpp_text_start;
1346
1354
 
1348
1356
    Ending position of the TEXT_STRING or IDENT in the pre-processed
1349
1357
    buffer.
1350
1358
 
1351
 
    NOTE: this member must be used within DRIZZLElex() function only.
 
1359
    NOTE: this member must be used within MYSQLlex() function only.
1352
1360
    */
1353
1361
  const char *m_cpp_text_end;
1354
1362
 
1355
1363
  /**
1356
1364
    Character set specified by the character-set-introducer.
1357
1365
 
1358
 
    NOTE: this member must be used within DRIZZLElex() function only.
 
1366
    NOTE: this member must be used within MYSQLlex() function only.
1359
1367
  */
1360
1368
  const CHARSET_INFO *m_underscore_cs;
1361
1369
};
1362
1370
 
1363
1371
 
1364
 
/* The state of the lex parsing. This is saved in the Session struct */
 
1372
/* The state of the lex parsing. This is saved in the THD struct */
1365
1373
 
1366
1374
typedef struct st_lex : public Query_tables_list
1367
1375
{
1376
1384
  LEX_STRING name;
1377
1385
  char *help_arg;
1378
1386
  char* to_log;                                 /* For PURGE MASTER LOGS TO */
 
1387
  char* x509_subject,*x509_issuer,*ssl_cipher;
1379
1388
  String *wild;
1380
1389
  sql_exchange *exchange;
1381
1390
  select_result *result;
1382
1391
  Item *default_value, *on_update_value;
1383
1392
  LEX_STRING comment, ident;
1384
1393
  XID *xid;
1385
 
  unsigned char* yacc_yyss, *yacc_yyvs;
1386
 
  Session *session;
1387
 
  virtual_column_info *vcol_info;
 
1394
  uchar* yacc_yyss, *yacc_yyvs;
 
1395
  THD *thd;
1388
1396
 
1389
1397
  /* maintain a list of used plugins for this LEX */
1390
1398
  DYNAMIC_ARRAY plugins;
1447
1455
    syntax error back.
1448
1456
  */
1449
1457
  bool expr_allows_subselect;
1450
 
  /*
1451
 
    A special command "PARSE_VCOL_EXPR" is defined for the parser 
1452
 
    to translate an expression statement of a virtual column \
1453
 
    (stored in the *.frm file as a string) into an Item object.
1454
 
    The following flag is used to prevent other applications to use 
1455
 
    this command.
1456
 
  */
1457
 
  bool parse_vcol_expr;
1458
1458
 
1459
1459
  thr_lock_type lock_option;
1460
1460
  enum enum_duplicates duplicates;
1474
1474
  enum Foreign_key::fk_match_opt fk_match_option;
1475
1475
  enum Foreign_key::fk_option fk_update_opt;
1476
1476
  enum Foreign_key::fk_option fk_delete_opt;
1477
 
  uint32_t slave_session_opt, start_transaction_opt;
 
1477
  uint32_t slave_thd_opt, start_transaction_opt;
1478
1478
  int nest_level;
1479
1479
  /*
1480
1480
    In LEX representing update which were transformed to multi-update
1559
1559
    return context_stack.head();
1560
1560
  }
1561
1561
  /*
1562
 
    Restore the LEX and Session in case of a parse error.
 
1562
    Restore the LEX and THD in case of a parse error.
1563
1563
  */
1564
 
  static void cleanup_lex_after_parse_error(Session *session);
 
1564
  static void cleanup_lex_after_parse_error(THD *thd);
1565
1565
 
1566
1566
  void reset_n_backup_query_tables_list(Query_tables_list *backup);
1567
1567
  void restore_backup_query_tables_list(Query_tables_list *backup);
1611
1611
 
1612
1612
extern void lex_init(void);
1613
1613
extern void lex_free(void);
1614
 
extern void lex_start(Session *session);
 
1614
extern void lex_start(THD *thd);
1615
1615
extern void lex_end(LEX *lex);
1616
1616
 
1617
1617
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);