~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: lbieber
  • Date: 2009-06-12 17:51:58 UTC
  • mfrom: (1061 staging)
  • mto: (1061.1.3 merge-all)
  • mto: This revision was merged to the branch mainline in revision 1062.
  • Revision ID: lbieber@lbieber-laptop-20090612175158-v6k2st8gvs81z3dn
sync with latest from trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 */
19
19
 
20
20
/**
21
 
  @file
22
 
 
23
 
  @brief
24
 
  Handling of MySQL SQL variables
 
21
  @file Handling of MySQL SQL variables
25
22
 
26
23
  @details
27
24
  To add a new variable, one has to do the following:
126
123
  The variables are linked into the list. A variable is added to
127
124
  it in the constructor (see sys_var class for details).
128
125
*/
129
 
 
130
126
static sys_var_chain vars = { NULL, NULL };
131
127
 
132
128
static sys_var_session_uint64_t
404
400
    return 0;
405
401
 
406
402
  if ((res=(*check_func)(session, var)) < 0)
407
 
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
408
 
             name.c_str(), var->value->str_value.ptr());
 
403
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
409
404
  return res;
410
405
}
411
406
 
463
458
  if (val < 0 || val > 2)
464
459
  {
465
460
    char buf[64];
466
 
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
467
 
             var->var->name.c_str(), llstr(val, buf));
 
461
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->getName().c_str(), llstr(val, buf));
468
462
    return 1;
469
463
  }
470
464
  return 0;
741
735
  /* Don't use bigger value than given with --maximum-variable-name=.. */
742
736
  if ((uint32_t) tmp > max_system_variables.*offset)
743
737
  {
744
 
    throw_bounds_warning(session, true, true, name, (int64_t) tmp);
 
738
    throw_bounds_warning(session, true, true, getName(), (int64_t) tmp);
745
739
    tmp= max_system_variables.*offset;
746
740
  }
747
741
 
750
744
  else if (tmp > UINT32_MAX)
751
745
  {
752
746
    tmp= UINT32_MAX;
753
 
    throw_bounds_warning(session, true, true, name, (int64_t) var->save_result.uint64_t_value);
 
747
    throw_bounds_warning(session, true, true, getName(), (int64_t) var->save_result.uint64_t_value);
754
748
  }
755
749
 
756
750
  if (var->type == OPT_GLOBAL)
1025
1019
      goto err;
1026
1020
    }
1027
1021
 
1028
 
    if (!m_allow_empty_value &&
1029
 
        res->length() == 0)
 
1022
    if (! m_allow_empty_value && res->length() == 0)
1030
1023
    {
1031
1024
      buff[0]= 0;
1032
1025
      goto err;
1050
1043
  {
1051
1044
    uint64_t tmp= var->value->val_int();
1052
1045
 
1053
 
    if (!m_allow_empty_value &&
1054
 
        tmp == 0)
 
1046
    if (! m_allow_empty_value && tmp == 0)
1055
1047
    {
1056
1048
      buff[0]= '0';
1057
1049
      buff[1]= 0;
1294
1286
  else
1295
1287
  {
1296
1288
    session->variables.*offset= var->save_result.charset;
1297
 
    session->update_charset();
1298
1289
  }
1299
1290
  return 0;
1300
1291
}
1307
1298
  else
1308
1299
  {
1309
1300
    session->variables.*offset= global_system_variables.*offset;
1310
 
    session->update_charset();
1311
1301
  }
1312
1302
}
1313
1303
 
1507
1497
unsigned char *sys_var_timestamp::value_ptr(Session *session, enum_var_type,
1508
1498
                                            const LEX_STRING *)
1509
1499
{
1510
 
  session->sys_var_tmp.long_value= (long) session->start_time;
1511
 
  return (unsigned char*) &session->sys_var_tmp.long_value;
 
1500
  session->sys_var_tmp.int32_t_value= (int32_t) session->start_time;
 
1501
  return (unsigned char*) &session->sys_var_tmp.int32_t_value;
1512
1502
}
1513
1503
 
1514
1504
 
1720
1710
    session->variables.*offset= microseconds;
1721
1711
}
1722
1712
 
1723
 
 
1724
 
unsigned char *sys_var_microseconds::value_ptr(Session *session,
1725
 
                                               enum_var_type type,
1726
 
                                               const LEX_STRING *)
1727
 
{
1728
 
  session->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
1729
 
                                   global_system_variables.*offset :
1730
 
                                   session->variables.*offset) / 1000000.0;
1731
 
  return (unsigned char*) &session->tmp_double_value;
1732
 
}
1733
 
 
1734
 
 
1735
1713
/*
1736
1714
  Functions to update session->options bits
1737
1715
*/
1879
1857
  sys_var *var;
1880
1858
  /* A write lock should be held on LOCK_system_variables_hash */
1881
1859
 
1882
 
  for (var= first; var; var= var->next)
 
1860
  for (var= first; var; var= var->getNext())
1883
1861
  {
1884
1862
 
1885
1863
    /* this fails if there is a conflicting variable name. */
1888
1866
      return 1;
1889
1867
    } 
1890
1868
    if (long_options)
1891
 
      var->option_limits= find_option(long_options, var->name.c_str());
 
1869
      var->setOptionLimits(find_option(long_options, var->getName().c_str()));
1892
1870
  }
1893
1871
  return 0;
1894
1872
 
1912
1890
  int result= 0;
1913
1891
 
1914
1892
  /* A write lock should be held on LOCK_system_variables_hash */
1915
 
  for (sys_var *var= first; var; var= var->next)
 
1893
  for (sys_var *var= first; var; var= var->getNext())
1916
1894
  {
1917
1895
    system_variable_hash.remove(var);
1918
1896
  }
1952
1930
        iter++)
1953
1931
    {
1954
1932
      sys_var *var= *iter;
1955
 
      show->name= var->name.c_str();
 
1933
      show->name= var->getName().c_str();
1956
1934
      show->value= (char*) var;
1957
1935
      show->type= SHOW_SYS;
1958
1936
      show++;
1995
1973
{
1996
1974
  uint32_t count= 0;
1997
1975
 
1998
 
  for (sys_var *var=vars.first; var; var= var->next, count++) {};
 
1976
  for (sys_var *var= vars.first; var; var= var->getNext(), count++) {};
1999
1977
 
2000
1978
  if (my_init_dynamic_array(&fixed_show_vars, sizeof(SHOW_VAR),
2001
1979
                            FIXED_VARS_SIZE + 64, 64))
2004
1982
  fixed_show_vars.elements= FIXED_VARS_SIZE;
2005
1983
  memcpy(fixed_show_vars.buffer, fixed_vars, sizeof(fixed_vars));
2006
1984
 
2007
 
  vars.last->next= NULL;
 
1985
  vars.last->setNext(NULL);
2008
1986
  if (mysql_add_sys_var_chain(vars.first, my_long_options))
2009
1987
    goto error;
2010
1988
 
2133
2111
{
2134
2112
  if (var->is_readonly())
2135
2113
  {
2136
 
    my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0),
2137
 
             var->name.c_str(), "read only");
 
2114
    my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->getName().c_str(), "read only");
2138
2115
    return -1;
2139
2116
  }
2140
2117
  if (var->check_type(type))
2141
2118
  {
2142
2119
    int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE;
2143
 
    my_error(err, MYF(0), var->name.c_str());
 
2120
    my_error(err, MYF(0), var->getName().c_str());
2144
2121
    return -1;
2145
2122
  }
2146
2123
  /* value is a NULL pointer if we are using SET ... = DEFAULT */
2148
2125
  {
2149
2126
    if (var->check_default(type))
2150
2127
    {
2151
 
      my_error(ER_NO_DEFAULT, MYF(0), var->name.c_str());
 
2128
      my_error(ER_NO_DEFAULT, MYF(0), var->getName().c_str());
2152
2129
      return -1;
2153
2130
    }
2154
2131
    return 0;
2159
2136
    return -1;
2160
2137
  if (var->check_update_type(value->result_type()))
2161
2138
  {
2162
 
    my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name.c_str());
 
2139
    my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->getName().c_str());
2163
2140
    return -1;
2164
2141
  }
2165
2142
  return var->check(session, this) ? -1 : 0;
2179
2156
*/
2180
2157
int set_var::update(Session *session)
2181
2158
{
2182
 
  if (!value)
 
2159
  if (! value)
2183
2160
    var->set_default(session, type);
2184
2161
  else if (var->update(session, this))
2185
2162
    return -1;                          // should never happen
2186
 
  if (var->after_update)
2187
 
    (*var->after_update)(session, type);
 
2163
  if (var->getAfterUpdateTrigger())
 
2164
    (*var->getAfterUpdateTrigger())(session, type);
2188
2165
  return 0;
2189
2166
}
2190
2167
 
2191
 
 
2192
2168
/*****************************************************************************
2193
2169
  Functions to handle SET @user_variable=const_expr
2194
2170
*****************************************************************************/