~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sys_var.cc

merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
#include "config.h"
47
47
#include "drizzled/option.h"
48
 
#include <drizzled/error.h>
49
 
#include <drizzled/gettext.h>
50
 
#include <drizzled/tztime.h>
51
 
#include <drizzled/data_home.h>
52
 
#include <drizzled/set_var.h>
53
 
#include <drizzled/session.h>
54
 
#include <drizzled/sql_base.h>
55
 
#include <drizzled/lock.h>
56
 
#include <drizzled/item/uint.h>
57
 
#include <drizzled/item/null.h>
58
 
#include <drizzled/item/float.h>
59
 
#include <drizzled/plugin.h>
 
48
#include "drizzled/error.h"
 
49
#include "drizzled/gettext.h"
 
50
#include "drizzled/tztime.h"
 
51
#include "drizzled/data_home.h"
 
52
#include "drizzled/set_var.h"
 
53
#include "drizzled/session.h"
 
54
#include "drizzled/sql_base.h"
 
55
#include "drizzled/lock.h"
 
56
#include "drizzled/item/uint.h"
 
57
#include "drizzled/item/null.h"
 
58
#include "drizzled/item/float.h"
 
59
#include "drizzled/item/string.h"
 
60
#include "drizzled/plugin.h"
60
61
#include "drizzled/version.h"
61
62
#include "drizzled/strfunc.h"
62
63
#include "drizzled/internal/m_string.h"
63
64
#include "drizzled/pthread_globals.h"
64
65
#include "drizzled/charset.h"
65
66
#include "drizzled/transaction_services.h"
 
67
#include "drizzled/constrained_value.h"
66
68
 
67
69
#include <cstdio>
68
70
#include <map>
128
130
*/
129
131
static sys_var_session_uint64_t
130
132
sys_auto_increment_increment("auto_increment_increment",
131
 
                             &system_variables::auto_increment_increment);
 
133
                             &drizzle_system_variables::auto_increment_increment);
132
134
static sys_var_session_uint64_t
133
135
sys_auto_increment_offset("auto_increment_offset",
134
 
                          &system_variables::auto_increment_offset);
 
136
                          &drizzle_system_variables::auto_increment_offset);
135
137
 
136
138
static sys_var_fs_path sys_basedir("basedir", basedir);
137
139
static sys_var_fs_path sys_pid_file("pid_file", pid_file);
139
141
 
140
142
static sys_var_size_t_ptr sys_thread_stack_size("thread_stack",
141
143
                                                      &my_thread_stack_size);
142
 
static sys_var_uint32_t_ptr sys_back_log("back_log", &back_log);
 
144
static sys_var_constrained_value<uint32_t> sys_back_log("back_log", back_log);
143
145
 
144
146
static sys_var_session_uint64_t sys_bulk_insert_buff_size("bulk_insert_buffer_size",
145
 
                                                          &system_variables::bulk_insert_buff_size);
 
147
                                                          &drizzle_system_variables::bulk_insert_buff_size);
146
148
static sys_var_session_uint32_t sys_completion_type("completion_type",
147
 
                                                    &system_variables::completion_type,
 
149
                                                    &drizzle_system_variables::completion_type,
148
150
                                                    check_completion_type,
149
151
                                                    fix_completion_type);
150
152
static sys_var_collation_sv
151
 
sys_collation_server("collation_server", &system_variables::collation_server, &default_charset_info);
 
153
sys_collation_server("collation_server", &drizzle_system_variables::collation_server, &default_charset_info);
152
154
static sys_var_fs_path       sys_datadir("datadir", getDataHome());
153
155
 
154
156
static sys_var_session_uint64_t sys_join_buffer_size("join_buffer_size",
155
 
                                                     &system_variables::join_buff_size);
 
157
                                                     &drizzle_system_variables::join_buff_size);
156
158
static sys_var_session_uint32_t sys_max_allowed_packet("max_allowed_packet",
157
 
                                                       &system_variables::max_allowed_packet);
 
159
                                                       &drizzle_system_variables::max_allowed_packet);
158
160
static sys_var_uint64_t_ptr     sys_max_connect_errors("max_connect_errors",
159
161
                                               &max_connect_errors);
160
162
static sys_var_session_uint64_t sys_max_error_count("max_error_count",
161
 
                                                  &system_variables::max_error_count);
 
163
                                                  &drizzle_system_variables::max_error_count);
162
164
static sys_var_session_uint64_t sys_max_heap_table_size("max_heap_table_size",
163
 
                                                        &system_variables::max_heap_table_size);
 
165
                                                        &drizzle_system_variables::max_heap_table_size);
164
166
static sys_var_session_uint64_t sys_pseudo_thread_id("pseudo_thread_id",
165
 
                                              &system_variables::pseudo_thread_id,
 
167
                                              &drizzle_system_variables::pseudo_thread_id,
166
168
                                              0, check_pseudo_thread_id);
167
169
static sys_var_session_ha_rows  sys_max_join_size("max_join_size",
168
 
                                                  &system_variables::max_join_size,
 
170
                                                  &drizzle_system_variables::max_join_size,
169
171
                                                  fix_max_join_size);
170
172
static sys_var_session_uint64_t sys_max_seeks_for_key("max_seeks_for_key",
171
 
                                                      &system_variables::max_seeks_for_key);
 
173
                                                      &drizzle_system_variables::max_seeks_for_key);
172
174
static sys_var_session_uint64_t   sys_max_length_for_sort_data("max_length_for_sort_data",
173
 
                                                               &system_variables::max_length_for_sort_data);
 
175
                                                               &drizzle_system_variables::max_length_for_sort_data);
174
176
static sys_var_session_size_t   sys_max_sort_length("max_sort_length",
175
 
                                                    &system_variables::max_sort_length);
 
177
                                                    &drizzle_system_variables::max_sort_length);
176
178
static sys_var_uint64_t_ptr     sys_max_write_lock_count("max_write_lock_count",
177
179
                                                 &max_write_lock_count);
178
180
static sys_var_session_uint64_t sys_min_examined_row_limit("min_examined_row_limit",
179
 
                                                           &system_variables::min_examined_row_limit);
 
181
                                                           &drizzle_system_variables::min_examined_row_limit);
180
182
 
181
183
/* these two cannot be static */
182
184
static sys_var_session_bool sys_optimizer_prune_level("optimizer_prune_level",
183
 
                                                      &system_variables::optimizer_prune_level);
 
185
                                                      &drizzle_system_variables::optimizer_prune_level);
184
186
static sys_var_session_uint32_t sys_optimizer_search_depth("optimizer_search_depth",
185
 
                                                           &system_variables::optimizer_search_depth);
 
187
                                                           &drizzle_system_variables::optimizer_search_depth);
186
188
 
187
189
static sys_var_session_uint64_t sys_preload_buff_size("preload_buffer_size",
188
 
                                                      &system_variables::preload_buff_size);
 
190
                                                      &drizzle_system_variables::preload_buff_size);
189
191
static sys_var_session_uint32_t sys_read_buff_size("read_buffer_size",
190
 
                                                   &system_variables::read_buff_size);
 
192
                                                   &drizzle_system_variables::read_buff_size);
191
193
static sys_var_session_uint32_t sys_read_rnd_buff_size("read_rnd_buffer_size",
192
 
                                                       &system_variables::read_rnd_buff_size);
 
194
                                                       &drizzle_system_variables::read_rnd_buff_size);
193
195
static sys_var_session_uint32_t sys_div_precincrement("div_precision_increment",
194
 
                                                      &system_variables::div_precincrement);
 
196
                                                      &drizzle_system_variables::div_precincrement);
195
197
 
196
198
static sys_var_session_size_t   sys_range_alloc_block_size("range_alloc_block_size",
197
 
                                                           &system_variables::range_alloc_block_size);
 
199
                                                           &drizzle_system_variables::range_alloc_block_size);
198
200
static sys_var_session_uint32_t sys_query_alloc_block_size("query_alloc_block_size",
199
 
                                                           &system_variables::query_alloc_block_size,
 
201
                                                           &drizzle_system_variables::query_alloc_block_size,
200
202
                                                           NULL, fix_session_mem_root);
201
203
static sys_var_session_uint32_t sys_query_prealloc_size("query_prealloc_size",
202
 
                                                        &system_variables::query_prealloc_size,
 
204
                                                        &drizzle_system_variables::query_prealloc_size,
203
205
                                                        NULL, fix_session_mem_root);
204
206
static sys_var_readonly sys_tmpdir("tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
205
207
 
213
215
                                           fix_server_id);
214
216
 
215
217
static sys_var_session_size_t   sys_sort_buffer("sort_buffer_size",
216
 
                                                &system_variables::sortbuff_size);
 
218
                                                &drizzle_system_variables::sortbuff_size);
217
219
 
218
220
static sys_var_session_size_t sys_transaction_message_threshold("transaction_message_threshold",
219
 
                                                                &system_variables::transaction_message_threshold);
 
221
                                                                &drizzle_system_variables::transaction_message_threshold);
220
222
 
221
223
static sys_var_session_storage_engine sys_storage_engine("storage_engine",
222
 
                                       &system_variables::storage_engine);
 
224
                                       &drizzle_system_variables::storage_engine);
223
225
static sys_var_const_str        sys_system_time_zone("system_time_zone",
224
226
                                             system_time_zone);
225
227
static sys_var_size_t_ptr       sys_table_def_size("table_definition_cache",
229
231
static sys_var_uint64_t_ptr     sys_table_lock_wait_timeout("table_lock_wait_timeout",
230
232
                                                    &table_lock_wait_timeout);
231
233
static sys_var_session_enum     sys_tx_isolation("tx_isolation",
232
 
                                             &system_variables::tx_isolation,
 
234
                                             &drizzle_system_variables::tx_isolation,
233
235
                                             &tx_isolation_typelib,
234
236
                                             fix_tx_isolation,
235
237
                                             check_tx_isolation);
236
238
static sys_var_session_uint64_t sys_tmp_table_size("tmp_table_size",
237
 
                                           &system_variables::tmp_table_size);
 
239
                                           &drizzle_system_variables::tmp_table_size);
238
240
static sys_var_bool_ptr  sys_timed_mutexes("timed_mutexes", &internal::timed_mutexes);
239
241
static sys_var_const_str  sys_version("version", version().c_str());
240
242
 
274
276
/* Local state variables */
275
277
 
276
278
static sys_var_session_ha_rows  sys_select_limit("sql_select_limit",
277
 
                                                 &system_variables::select_limit);
 
279
                                                 &drizzle_system_variables::select_limit);
278
280
static sys_var_timestamp sys_timestamp("timestamp");
279
281
static sys_var_last_insert_id
280
282
sys_last_insert_id("last_insert_id");
308
310
                                          get_warning_count);
309
311
 
310
312
sys_var_session_uint64_t sys_group_concat_max_len("group_concat_max_len",
311
 
                                                  &system_variables::group_concat_max_len);
 
313
                                                  &drizzle_system_variables::group_concat_max_len);
312
314
 
313
315
sys_var_session_time_zone sys_time_zone("time_zone");
314
316
 
1547
1549
  Initialize the system variables
1548
1550
 
1549
1551
  SYNOPSIS
1550
 
    set_var_init()
 
1552
    sys_var_init()
1551
1553
 
1552
1554
  RETURN VALUES
1553
1555
    0           SUCCESS
1554
1556
    otherwise   FAILURE
1555
1557
*/
1556
1558
 
1557
 
int set_var_init()
 
1559
int sys_var_init()
1558
1560
{
1559
1561
  try
1560
1562
  {
1685
1687
}
1686
1688
 
1687
1689
 
1688
 
/**
1689
 
  Execute update of all variables.
1690
 
 
1691
 
  First run a check of all variables that all updates will go ok.
1692
 
  If yes, then execute all updates, returning an error if any one failed.
1693
 
 
1694
 
  This should ensure that in all normal cases none all or variables are
1695
 
  updated.
1696
 
 
1697
 
  @param Session                Thread id
1698
 
  @param var_list       List of variables to update
1699
 
 
1700
 
  @retval
1701
 
    0   ok
1702
 
  @retval
1703
 
    1   ERROR, message sent (normally no variables was updated)
1704
 
  @retval
1705
 
    -1  ERROR, message not sent
1706
 
*/
1707
 
 
1708
 
int sql_set_variables(Session *session, List<set_var_base> *var_list)
1709
 
{
1710
 
  int error;
1711
 
  List_iterator_fast<set_var_base> it(*var_list);
1712
 
 
1713
 
  set_var_base *var;
1714
 
  while ((var=it++))
1715
 
  {
1716
 
    if ((error= var->check(session)))
1717
 
      goto err;
1718
 
  }
1719
 
  if (!(error= test(session->is_error())))
1720
 
  {
1721
 
    it.rewind();
1722
 
    while ((var= it++))
1723
 
      error|= var->update(session);         // Returns 0, -1 or 1
1724
 
  }
1725
 
 
1726
 
err:
1727
 
  free_underlaid_joins(session, &session->lex->select_lex);
1728
 
  return(error);
1729
 
}
1730
 
 
1731
 
 
1732
 
/*****************************************************************************
1733
 
  Functions to handle SET mysql_internal_variable=const_expr
1734
 
*****************************************************************************/
1735
 
 
1736
 
int set_var::check(Session *session)
1737
 
{
1738
 
  if (var->is_readonly())
1739
 
  {
1740
 
    my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->getName().c_str(), "read only");
1741
 
    return -1;
1742
 
  }
1743
 
  if (var->check_type(type))
1744
 
  {
1745
 
    int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE;
1746
 
    my_error(err, MYF(0), var->getName().c_str());
1747
 
    return -1;
1748
 
  }
1749
 
  /* value is a NULL pointer if we are using SET ... = DEFAULT */
1750
 
  if (!value)
1751
 
  {
1752
 
    if (var->check_default(type))
1753
 
    {
1754
 
      my_error(ER_NO_DEFAULT, MYF(0), var->getName().c_str());
1755
 
      return -1;
1756
 
    }
1757
 
    return 0;
1758
 
  }
1759
 
 
1760
 
  if ((!value->fixed &&
1761
 
       value->fix_fields(session, &value)) || value->check_cols(1))
1762
 
    return -1;
1763
 
  if (var->check_update_type(value->result_type()))
1764
 
  {
1765
 
    my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->getName().c_str());
1766
 
    return -1;
1767
 
  }
1768
 
  return var->check(session, this) ? -1 : 0;
1769
 
}
1770
 
 
1771
 
/**
1772
 
  Update variable
1773
 
 
1774
 
  @param   session    thread handler
1775
 
  @returns 0|1    ok or ERROR
1776
 
 
1777
 
  @note ERROR can be only due to abnormal operations involving
1778
 
  the server's execution evironment such as
1779
 
  out of memory, hard disk failure or the computer blows up.
1780
 
  Consider set_var::check() method if there is a need to return
1781
 
  an error due to logics.
1782
 
*/
1783
 
int set_var::update(Session *session)
1784
 
{
1785
 
  if (! value)
1786
 
    var->set_default(session, type);
1787
 
  else if (var->update(session, this))
1788
 
    return -1;                          // should never happen
1789
 
  if (var->getAfterUpdateTrigger())
1790
 
    (*var->getAfterUpdateTrigger())(session, type);
1791
 
  return 0;
1792
 
}
1793
 
 
1794
 
/*****************************************************************************
1795
 
  Functions to handle SET @user_variable=const_expr
1796
 
*****************************************************************************/
1797
 
 
1798
 
int set_var_user::check(Session *session)
1799
 
{
1800
 
  /*
1801
 
    Item_func_set_user_var can't substitute something else on its place =>
1802
 
    0 can be passed as last argument (reference on item)
1803
 
  */
1804
 
  return (user_var_item->fix_fields(session, (Item**) 0) ||
1805
 
          user_var_item->check(0)) ? -1 : 0;
1806
 
}
1807
 
 
1808
 
 
1809
 
int set_var_user::update(Session *)
1810
 
{
1811
 
  if (user_var_item->update())
1812
 
  {
1813
 
    /* Give an error if it's not given already */
1814
 
    my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY), MYF(0));
1815
 
    return -1;
1816
 
  }
1817
 
  return 0;
1818
 
}
1819
 
 
1820
1690
/****************************************************************************
1821
1691
 Functions to handle table_type
1822
1692
****************************************************************************/