~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

Merged up with build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
#include <drizzled/item/float.h>
60
60
#include <drizzled/plugin.h>
61
61
 
62
 
#include "drizzled/name_map.h"
63
62
#include <map>
64
63
#include <algorithm>
65
64
 
71
70
 
72
71
class sys_var_pluginvar;
73
72
static DYNAMIC_ARRAY fixed_show_vars;
74
 
static NameMap<sys_var *> system_variable_hash;
 
73
typedef map<string, sys_var *> SystemVariableMap;
 
74
static SystemVariableMap system_variable_map;
75
75
extern char *opt_drizzle_tmpdir;
76
76
 
77
77
const char *bool_type_names[]= { "OFF", "ON", NULL };
225
225
static sys_var_session_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
226
226
                                           &SV::tmp_table_size);
227
227
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
228
 
static sys_var_const_str        sys_version(&vars, "version", PANDORA_RELEASE_VERSION);
 
228
static sys_var_const_str  sys_version(&vars, "version", drizzled_version().c_str());
 
229
 
229
230
static sys_var_const_str        sys_version_comment(&vars, "version_comment",
230
231
                                            COMPILATION_COMMENT);
231
232
static sys_var_const_str        sys_version_compile_machine(&vars, "version_compile_machine",
250
251
static sys_var_session_bit      sys_sql_notes(&vars, "sql_notes", 0,
251
252
                                         set_option_bit,
252
253
                                         OPTION_SQL_NOTES);
253
 
static sys_var_session_bit      sys_safe_updates(&vars, "sql_safe_updates", 0,
254
 
                                         set_option_bit,
255
 
                                         OPTION_SAFE_UPDATES);
256
254
static sys_var_session_bit      sys_buffer_results(&vars, "sql_buffer_result", 0,
257
255
                                           set_option_bit,
258
256
                                           OPTION_BUFFER_RESULT);
1713
1711
  for (var= first; var; var= var->getNext())
1714
1712
  {
1715
1713
 
 
1714
    string lower_name(var->getName());
 
1715
    transform(lower_name.begin(), lower_name.end(),
 
1716
              lower_name.begin(), ::tolower);
 
1717
 
1716
1718
    /* this fails if there is a conflicting variable name. */
1717
 
    if (system_variable_hash.add(var))
 
1719
    if (system_variable_map.find(lower_name) != system_variable_map.end())
1718
1720
    {
 
1721
      errmsg_printf(ERRMSG_LVL_ERROR, _("Variable named %s already exists!\n"),
 
1722
                    var->getName().c_str());
1719
1723
      return 1;
1720
1724
    } 
 
1725
 
 
1726
    pair<SystemVariableMap::iterator, bool> ret= 
 
1727
      system_variable_map.insert(make_pair(lower_name, var));
 
1728
    if (ret.second == false)
 
1729
    {
 
1730
      errmsg_printf(ERRMSG_LVL_ERROR, _("Could not add Variable: %s\n"),
 
1731
                    var->getName().c_str());
 
1732
      return 1;
 
1733
    }
 
1734
 
1721
1735
    if (long_options)
1722
1736
      var->setOptionLimits(find_option(long_options, var->getName().c_str()));
1723
1737
  }
1740
1754
 
1741
1755
int mysql_del_sys_var_chain(sys_var *first)
1742
1756
{
1743
 
  int result= 0;
1744
1757
 
1745
1758
  /* A write lock should be held on LOCK_system_variables_hash */
1746
1759
  for (sys_var *var= first; var; var= var->getNext())
1747
1760
  {
1748
 
    system_variable_hash.remove(var);
 
1761
    string lower_name(var->getName());
 
1762
    transform(lower_name.begin(), lower_name.end(),
 
1763
              lower_name.begin(), ::tolower);
 
1764
    system_variable_map.erase(lower_name);
1749
1765
  }
1750
 
  return result;
 
1766
  return 0;
1751
1767
}
1752
1768
 
1753
1769
 
1768
1784
SHOW_VAR* enumerate_sys_vars(Session *session, bool)
1769
1785
{
1770
1786
  int fixed_count= fixed_show_vars.elements;
1771
 
  int size= sizeof(SHOW_VAR) * (system_variable_hash.size() + fixed_count + 1);
 
1787
  int size= sizeof(SHOW_VAR) * (system_variable_map.size() + fixed_count + 1);
1772
1788
  SHOW_VAR *result= (SHOW_VAR*) session->alloc(size);
1773
1789
 
1774
1790
  if (result)
1776
1792
    SHOW_VAR *show= result + fixed_count;
1777
1793
    memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(SHOW_VAR));
1778
1794
 
1779
 
    NameMap<sys_var *>::const_iterator iter;
1780
 
    for(iter= system_variable_hash.begin();
1781
 
        iter != system_variable_hash.end();
1782
 
        iter++)
 
1795
    SystemVariableMap::const_iterator iter= system_variable_map.begin();
 
1796
    while (iter != system_variable_map.end())
1783
1797
    {
1784
 
      sys_var *var= *iter;
 
1798
      sys_var *var= (*iter).second;
1785
1799
      show->name= var->getName().c_str();
1786
1800
      show->value= (char*) var;
1787
1801
      show->type= SHOW_SYS;
1788
1802
      show++;
 
1803
      ++iter;
1789
1804
    }
1790
1805
 
1791
1806
    /* make last element empty */
1874
1889
 
1875
1890
sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error)
1876
1891
{
 
1892
  string lower_name(str);
 
1893
  transform(lower_name.begin(), lower_name.end(),
 
1894
            lower_name.begin(), ::tolower);
 
1895
 
 
1896
  sys_var *result= NULL;
 
1897
 
 
1898
  SystemVariableMap::iterator iter= system_variable_map.find(lower_name);
 
1899
  if (iter != system_variable_map.end())
 
1900
  {
 
1901
    result= (*iter).second;
 
1902
  } 
 
1903
 
1877
1904
  /*
1878
1905
    This function is only called from the sql_plugin.cc.
1879
1906
    A lock on LOCK_system_variable_hash should be held
1880
1907
  */
1881
 
  sys_var *result= system_variable_hash.find(str);
1882
1908
  if (result == NULL)
1883
1909
  {
1884
1910
    if (no_error)