1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
20
#ifndef DRIZZLED_SQL_BASE_H
21
#define DRIZZLED_SQL_BASE_H
24
#include <drizzled/table.h>
28
void table_cache_free(void);
29
bool table_cache_init(void);
30
bool table_def_init(void);
31
void table_def_free(void);
32
void assign_new_table_id(TableShare *share);
33
uint32_t cached_open_tables(void);
34
uint32_t cached_table_definitions(void);
36
void kill_drizzle(void);
39
void set_item_name(Item *item,char *pos,uint32_t length);
40
bool add_field_to_list(Session *session, LEX_STRING *field_name, enum enum_field_types type,
41
char *length, char *decimal,
42
uint32_t type_modifier,
43
enum column_format_type column_format,
44
Item *default_value, Item *on_update_value,
46
char *change, List<String> *interval_list,
47
const CHARSET_INFO * const cs);
48
Create_field * new_create_field(Session *session, char *field_name, enum_field_types type,
49
char *length, char *decimals,
50
uint32_t type_modifier,
51
Item *default_value, Item *on_update_value,
52
LEX_STRING *comment, char *change,
53
List<String> *interval_list, CHARSET_INFO *cs);
54
void store_position_for_column(const char *name);
55
bool add_to_list(Session *session, SQL_LIST &list,Item *group,bool asc);
56
bool push_new_name_resolution_context(Session *session,
59
void add_join_on(TableList *b,Item *expr);
60
void add_join_natural(TableList *a,TableList *b,List<String> *using_fields,
62
void unlink_open_table(Session *session, Table *find, bool unlock);
63
void drop_open_table(Session *session, Table *table, const char *db_name,
64
const char *table_name);
65
void update_non_unique_table_error(TableList *update,
66
const char *operation,
67
TableList *duplicate);
69
SQL_SELECT *make_select(Table *head, table_map const_tables,
70
table_map read_tables, COND *conds,
71
bool allow_null_cond, int *error);
72
extern Item **not_found_item;
75
A set of constants used for checking non aggregated fields and sum
76
functions mixture in the ONLY_FULL_GROUP_BY_MODE.
78
#define NON_AGG_FIELD_USED 1
79
#define SUM_FUNC_USED 2
82
This enumeration type is used only by the function find_item_in_list
83
to return the info on how an item has been resolved against a list
84
of possibly aliased items.
85
The item can be resolved:
86
- against an alias name of the list's element (RESOLVED_AGAINST_ALIAS)
87
- against non-aliased field name of the list (RESOLVED_WITH_NO_ALIAS)
88
- against an aliased field name of the list (RESOLVED_BEHIND_ALIAS)
89
- ignoring the alias name in cases when SQL requires to ignore aliases
90
(e.g. when the resolved field reference contains a table name or
91
when the resolved item is an expression) (RESOLVED_IGNORING_ALIAS)
93
enum enum_resolution_type {
95
RESOLVED_IGNORING_ALIAS,
96
RESOLVED_BEHIND_ALIAS,
97
RESOLVED_WITH_NO_ALIAS,
98
RESOLVED_AGAINST_ALIAS
100
Item ** find_item_in_list(Item *item, List<Item> &items, uint32_t *counter,
101
find_item_error_report_type report_error,
102
enum_resolution_type *resolution);
103
bool get_key_map_from_key_list(key_map *map, Table *table,
104
List<String> *index_list);
105
bool insert_fields(Session *session, Name_resolution_context *context,
106
const char *db_name, const char *table_name,
107
List_iterator<Item> *it, bool any_privileges);
108
bool setup_tables(Session *session, Name_resolution_context *context,
109
List<TableList> *from_clause, TableList *tables,
110
TableList **leaves, bool select_insert);
111
bool setup_tables_and_check_access(Session *session,
112
Name_resolution_context *context,
113
List<TableList> *from_clause,
117
int setup_wild(Session *session, List<Item> &fields,
118
List<Item> *sum_func_list,
120
bool setup_fields(Session *session, Item** ref_pointer_array,
121
List<Item> &item, enum_mark_columns mark_used_columns,
122
List<Item> *sum_func_list, bool allow_sum_func);
123
inline bool setup_fields_with_no_wrap(Session *session, Item **ref_pointer_array,
125
enum_mark_columns mark_used_columns,
126
List<Item> *sum_func_list,
130
res= setup_fields(session, ref_pointer_array, item, mark_used_columns, sum_func_list,
134
int setup_conds(Session *session, TableList *leaves, COND **conds);
135
int setup_ftfuncs(Select_Lex* select);
136
int init_ftfuncs(Session *session, Select_Lex* select, bool no_order);
137
void wait_for_condition(Session *session, pthread_mutex_t *mutex,
138
pthread_cond_t *cond);
139
int open_tables(Session *session, TableList **tables, uint32_t *counter, uint32_t flags);
140
/* open_and_lock_tables with optional derived handling */
141
int open_and_lock_tables_derived(Session *session, TableList *tables, bool derived);
142
/* simple open_and_lock_tables without derived handling */
143
inline int simple_open_n_lock_tables(Session *session, TableList *tables)
145
return open_and_lock_tables_derived(session, tables, false);
147
/* open_and_lock_tables with derived handling */
148
inline int open_and_lock_tables(Session *session, TableList *tables)
150
return open_and_lock_tables_derived(session, tables, true);
152
bool open_normal_and_derived_tables(Session *session, TableList *tables, uint32_t flags);
153
int lock_tables(Session *session, TableList *tables, uint32_t counter, bool *need_reopen);
154
int decide_logging_format(Session *session);
155
Table *open_temporary_table(Session *session, const char *path, const char *db,
156
const char *table_name, bool link_in_list,
157
open_table_mode open_mode);
158
bool rm_temporary_table(StorageEngine *base, char *path);
159
void free_io_cache(Table *entry);
160
void intern_close_table(Table *entry);
161
void close_temporary_tables(Session *session);
162
void close_tables_for_reopen(Session *session, TableList **tables);
163
TableList *find_table_in_list(TableList *table,
164
TableList *TableList::*link,
166
const char *table_name);
167
TableList *unique_table(Session *session, TableList *table, TableList *table_list,
169
Table *find_temporary_table(Session *session, const char *db, const char *table_name);
170
Table *find_temporary_table(Session *session, TableList *table_list);
171
int drop_temporary_table(Session *session, TableList *table_list);
172
void close_temporary_table(Session *session, Table *table, bool free_share,
174
void close_temporary(Table *table, bool free_share, bool delete_table);
175
bool rename_temporary_table(Table *table, const char *new_db, const char *table_name);
176
void remove_db_from_cache(const char *db);
177
bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
179
/* bits for last argument to remove_table_from_cache() */
180
#define RTFC_NO_FLAG 0x0000
181
#define RTFC_OWNED_BY_Session_FLAG 0x0001
182
#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
183
#define RTFC_CHECK_KILLED_FLAG 0x0004
184
bool remove_table_from_cache(Session *session, const char *db, const char *table,
187
#define NORMAL_PART_NAME 0
188
#define TEMP_PART_NAME 1
189
#define RENAMED_PART_NAME 2
191
void mem_alloc_error(size_t size);
193
#define WFRM_WRITE_SHADOW 1
194
#define WFRM_INSTALL_SHADOW 2
195
#define WFRM_PACK_FRM 4
196
#define WFRM_KEEP_SHARE 8
198
bool close_cached_tables(Session *session, TableList *tables,
199
bool wait_for_refresh, bool wait_for_placeholders);
200
void copy_field_from_tmp_record(Field *field,int offset);
201
bool fill_record(Session * session, List<Item> &fields, List<Item> &values, bool ignore_errors);
202
bool fill_record(Session *session, Field **field, List<Item> &values, bool ignore_errors);
203
OPEN_TableList *list_open_tables(const char *db, const char *wild);
205
inline TableList *find_table_in_global_list(TableList *table,
207
const char *table_name)
209
return find_table_in_list(table, &TableList::next_global,
210
db_name, table_name);
213
inline TableList *find_table_in_local_list(TableList *table,
215
const char *table_name)
217
return find_table_in_list(table, &TableList::next_local,
218
db_name, table_name);
220
#endif /* DRIZZLED_SQL_BASE_H */