~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Monty Taylor
  • Date: 2010-02-05 08:11:15 UTC
  • mfrom: (1283 build)
  • mto: (1273.13.43 fix_is)
  • mto: This revision was merged to the branch mainline in revision 1300.
  • Revision ID: mordred@inaugust.com-20100205081115-dr82nvrwv4lvw7sd
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
#include "drizzled/internal/m_string.h"
63
63
#include "drizzled/pthread_globals.h"
64
64
#include "drizzled/charset.h"
 
65
#include "drizzled/transaction_services.h"
65
66
 
66
67
#include <map>
67
68
#include <algorithm>
68
69
 
69
70
using namespace std;
70
 
using namespace drizzled;
 
71
 
 
72
namespace drizzled
 
73
{
 
74
 
 
75
namespace internal
 
76
{
 
77
extern bool timed_mutexes;
 
78
}
71
79
 
72
80
extern plugin::StorageEngine *myisam_engine;
73
81
extern bool timed_mutexes;
99
107
static void fix_completion_type(Session *session, sql_var_t type);
100
108
static void fix_max_join_size(Session *session, sql_var_t type);
101
109
static void fix_session_mem_root(Session *session, sql_var_t type);
102
 
static void fix_trans_mem_root(Session *session, sql_var_t type);
103
110
static void fix_server_id(Session *session, sql_var_t type);
104
111
static bool get_unsigned32(Session *session, set_var *var);
105
112
static bool get_unsigned64(Session *session, set_var *var);
189
196
                                                        &SV::query_prealloc_size,
190
197
                                                        false, fix_session_mem_root);
191
198
static sys_var_readonly sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
192
 
static sys_var_session_uint32_t sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
193
 
                                                           &SV::trans_alloc_block_size,
194
 
                                                           false, fix_trans_mem_root);
195
 
static sys_var_session_uint32_t sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
196
 
                                                        &SV::trans_prealloc_size,
197
 
                                                        false, fix_session_mem_root);
198
199
 
199
200
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
200
201
                                             &opt_secure_file_priv);
203
204
 
204
205
static sys_var_session_size_t   sys_sort_buffer(&vars, "sort_buffer_size",
205
206
                                                &SV::sortbuff_size);
206
 
static sys_var_session_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
207
 
                                                               &SV::optimizer_switch);
208
207
 
209
208
static sys_var_session_storage_engine sys_storage_engine(&vars, "storage_engine",
210
209
                                       &SV::storage_engine);
223
222
                                             check_tx_isolation);
224
223
static sys_var_session_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
225
224
                                           &SV::tmp_table_size);
226
 
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
227
 
static sys_var_const_str  sys_version(&vars, "version", drizzled::version().c_str());
 
225
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &internal::timed_mutexes);
 
226
static sys_var_const_str  sys_version(&vars, "version", version().c_str());
228
227
 
229
228
static sys_var_const_str        sys_version_comment(&vars, "version_comment",
230
229
                                            COMPILATION_COMMENT);
303
302
/* Global read-only variable containing hostname */
304
303
static sys_var_const_str        sys_hostname(&vars, "hostname", glob_hostname);
305
304
 
306
 
/* Read only variables */
307
 
 
308
 
extern SHOW_COMP_OPTION have_symlink;
309
 
static sys_var_have_variable sys_have_symlink(&vars, "have_symlink", &have_symlink);
310
305
/*
311
306
  Additional variables (not derived from sys_var class, not accessible as
312
307
  @@varname in SELECT or SET). Sorted in alphabetical order to facilitate
318
313
static SHOW_VAR fixed_vars[]= {
319
314
  {"back_log",                (char*) &back_log,                SHOW_INT},
320
315
  {"language",                language,                         SHOW_CHAR},
321
 
  {"locked_in_memory",        (char*) &locked_in_memory,        SHOW_MY_BOOL},
322
316
  {"pid_file",                (char*) pidfile_name,             SHOW_CHAR},
323
317
  {"plugin_dir",              (char*) opt_plugin_dir,           SHOW_CHAR},
324
318
  {"thread_stack",            (char*) &my_thread_stack_size,    SHOW_INT},
395
389
  if (val < 0 || val > 2)
396
390
  {
397
391
    char buf[64];
398
 
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->getName().c_str(), llstr(val, buf));
 
392
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->getName().c_str(), internal::llstr(val, buf));
399
393
    return 1;
400
394
  }
401
395
  return 0;
411
405
}
412
406
 
413
407
 
414
 
static void fix_trans_mem_root(Session *session, sql_var_t type)
415
 
{
416
 
  if (type != OPT_GLOBAL)
417
 
    reset_root_defaults(&session->transaction.mem_root,
418
 
                        session->variables.trans_alloc_block_size,
419
 
                        session->variables.trans_prealloc_size);
420
 
}
421
 
 
422
 
 
423
408
static void fix_server_id(Session *, sql_var_t)
424
409
{
425
410
}
433
418
    char buf[22];
434
419
 
435
420
    if (unsignd)
436
 
      ullstr((uint64_t) val, buf);
 
421
      internal::ullstr((uint64_t) val, buf);
437
422
    else
438
 
      llstr(val, buf);
 
423
      internal::llstr(val, buf);
439
424
 
440
425
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
441
426
                        ER_TRUNCATED_WRONG_VALUE,
601
586
}
602
587
 
603
588
 
604
 
bool sys_var_enum::update(Session *, set_var *var)
605
 
{
606
 
  *value= (uint32_t) var->save_result.uint32_t_value;
607
 
  return 0;
608
 
}
609
 
 
610
 
 
611
 
unsigned char *sys_var_enum::value_ptr(Session *, sql_var_t, const LEX_STRING *)
612
 
{
613
 
  return (unsigned char*) enum_names->type_names[*value];
614
 
}
615
 
 
616
 
 
617
 
unsigned char *sys_var_enum_const::value_ptr(Session *, sql_var_t,
618
 
                                             const LEX_STRING *)
619
 
{
620
 
  return (unsigned char*) enum_names->type_names[global_system_variables.*offset];
621
 
}
622
 
 
623
589
/*
624
590
  32 bit types for session variables
625
591
*/
894
860
    uint64_t tmp=var->value->val_int();
895
861
    if (tmp >= enum_names->count)
896
862
    {
897
 
      llstr(tmp,buff);
 
863
      internal::llstr(tmp,buff);
898
864
      value=buff;                               // Wrong value is here
899
865
      goto err;
900
866
    }
908
874
}
909
875
 
910
876
 
911
 
bool sys_var::check_set(Session *, set_var *var, TYPELIB *enum_names)
912
 
{
913
 
  bool not_used;
914
 
  char buff[STRING_BUFFER_USUAL_SIZE], *error= 0;
915
 
  uint32_t error_len= 0;
916
 
  String str(buff, sizeof(buff), system_charset_info), *res;
917
 
 
918
 
  if (var->value->result_type() == STRING_RESULT)
919
 
  {
920
 
    if (!(res= var->value->val_str(&str)))
921
 
    {
922
 
      strcpy(buff, "NULL");
923
 
      goto err;
924
 
    }
925
 
 
926
 
    if (! m_allow_empty_value && res->length() == 0)
927
 
    {
928
 
      buff[0]= 0;
929
 
      goto err;
930
 
    }
931
 
 
932
 
    var->save_result.uint32_t_value= ((uint32_t)
933
 
                                      find_set(enum_names, res->c_ptr(),
934
 
                                               res->length(),
935
 
                                               NULL,
936
 
                                               &error, &error_len,
937
 
                                               &not_used));
938
 
    if (error_len)
939
 
    {
940
 
      size_t len = min((uint32_t)(sizeof(buff) - 1), error_len);
941
 
      strncpy(buff, error, len);
942
 
      buff[len]= '\0';
943
 
      goto err;
944
 
    }
945
 
  }
946
 
  else
947
 
  {
948
 
    uint64_t tmp= var->value->val_int();
949
 
 
950
 
    if (! m_allow_empty_value && tmp == 0)
951
 
    {
952
 
      buff[0]= '0';
953
 
      buff[1]= 0;
954
 
      goto err;
955
 
    }
956
 
 
957
 
    /*
958
 
      For when the enum is made to contain 64 elements, as 1ULL<<64 is
959
 
      undefined, we guard with a "count<64" test.
960
 
    */
961
 
    if (unlikely((tmp >= ((1UL) << enum_names->count)) &&
962
 
                 (enum_names->count < 64)))
963
 
    {
964
 
      llstr(tmp, buff);
965
 
      goto err;
966
 
    }
967
 
    var->save_result.uint32_t_value= (uint32_t) tmp;  // Save for update
968
 
  }
969
 
  return 0;
970
 
 
971
 
err:
972
 
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), buff);
973
 
  return 1;
974
 
}
975
 
 
976
 
 
977
877
/**
978
878
  Return an Item for a variable.
979
879
 
1173
1073
    if (!(tmp=get_charset((int) var->value->val_int())))
1174
1074
    {
1175
1075
      char buf[20];
1176
 
      int10_to_str((int) var->value->val_int(), buf, -10);
 
1076
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
1177
1077
      my_error(ER_UNKNOWN_COLLATION, MYF(0), buf);
1178
1078
      return 1;
1179
1079
    }
1348
1248
    if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
1349
1249
    {
1350
1250
      char buf[20];
1351
 
      int10_to_str((int) var->value->val_int(), buf, -10);
 
1251
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
1352
1252
      my_printf_error(ER_UNKNOWN_ERROR, "Unknown locale: '%s'", MYF(0), buf);
1353
1253
      return 1;
1354
1254
    }
1481
1381
      session->options&= ~(uint64_t) (OPTION_BEGIN);
1482
1382
      session->transaction.all.modified_non_trans_table= false;
1483
1383
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
1484
 
      if (ha_commit(session))
1485
 
        return 1;
 
1384
      TransactionServices &transaction_services= TransactionServices::singleton();
 
1385
      if (transaction_services.ha_commit_trans(session, true))
 
1386
        return 1;
1486
1387
    }
1487
1388
    else
1488
1389
    {
2031
1932
  return 0;
2032
1933
}
2033
1934
 
2034
 
bool
2035
 
sys_var_session_optimizer_switch::
2036
 
symbolic_mode_representation(Session *session, uint32_t val, LEX_STRING *rep)
2037
 
{
2038
 
  char buff[STRING_BUFFER_USUAL_SIZE*8];
2039
 
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
2040
 
 
2041
 
  tmp.length(0);
2042
 
 
2043
 
  for (uint32_t i= 0; val; val>>= 1, i++)
2044
 
  {
2045
 
    if (val & 1)
2046
 
    {
2047
 
      tmp.append(optimizer_switch_typelib.type_names[i],
2048
 
                 optimizer_switch_typelib.type_lengths[i]);
2049
 
      tmp.append(',');
2050
 
    }
2051
 
  }
2052
 
 
2053
 
  if (tmp.length())
2054
 
    tmp.length(tmp.length() - 1); /* trim the trailing comma */
2055
 
 
2056
 
  rep->str= session->strmake(tmp.ptr(), tmp.length());
2057
 
 
2058
 
  rep->length= rep->str ? tmp.length() : 0;
2059
 
 
2060
 
  return rep->length != tmp.length();
2061
 
}
2062
 
 
2063
 
 
2064
 
unsigned char *sys_var_session_optimizer_switch::value_ptr(Session *session,
2065
 
                                                           sql_var_t type,
2066
 
                                                           const LEX_STRING *)
2067
 
{
2068
 
  LEX_STRING opts;
2069
 
  uint32_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
2070
 
                  session->variables.*offset);
2071
 
  (void) symbolic_mode_representation(session, val, &opts);
2072
 
  return (unsigned char *) opts.str;
2073
 
}
2074
 
 
2075
 
 
2076
 
void sys_var_session_optimizer_switch::set_default(Session *session, sql_var_t type)
2077
 
{
2078
 
  if (type == OPT_GLOBAL)
2079
 
    global_system_variables.*offset= 0;
2080
 
  else
2081
 
    session->variables.*offset= global_system_variables.*offset;
2082
 
}
 
1935
} /* namespace drizzled */