~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.cc

  • Committer: Brian Aker
  • Date: 2009-04-17 01:45:33 UTC
  • Revision ID: brian@gaz-20090417014533-exdrtriab9zecqs2
Refactor get_variable to session

Show diffs side-by-side

added added

removed removed

Lines of Context:
2079
2079
  max_used_connections= 1; /* We set it to one, because we know we exist */
2080
2080
  pthread_mutex_unlock(&LOCK_status);
2081
2081
}
 
2082
 
 
2083
#define extra_size sizeof(double)
 
2084
 
 
2085
user_var_entry *Session::getVariable(LEX_STRING &name, bool create_if_not_exists)
 
2086
{
 
2087
  user_var_entry *entry= NULL;
 
2088
 
 
2089
  assert(name.length == strlen (name.str));
 
2090
  entry= (user_var_entry*) hash_search(&user_vars, (unsigned char*) name.str, name.length);
 
2091
 
 
2092
  if ((entry == NULL) && create_if_not_exists)
 
2093
  {
 
2094
    uint32_t size=ALIGN_SIZE(sizeof(user_var_entry))+name.length+1+extra_size;
 
2095
    if (!hash_inited(&user_vars))
 
2096
      return 0;
 
2097
    if (!(entry = (user_var_entry*) malloc(size)))
 
2098
      return 0;
 
2099
    entry->name.str=(char*) entry+ ALIGN_SIZE(sizeof(user_var_entry))+
 
2100
      extra_size;
 
2101
    entry->name.length=name.length;
 
2102
    entry->value=0;
 
2103
    entry->length=0;
 
2104
    entry->update_query_id=0;
 
2105
    entry->collation.set(NULL, DERIVATION_IMPLICIT, 0);
 
2106
    entry->unsigned_flag= 0;
 
2107
    /*
 
2108
      If we are here, we were called from a SET or a query which sets a
 
2109
      variable. Imagine it is this:
 
2110
      INSERT INTO t SELECT @a:=10, @a:=@a+1.
 
2111
      Then when we have a Item_func_get_user_var (because of the @a+1) so we
 
2112
      think we have to write the value of @a to the binlog. But before that,
 
2113
      we have a Item_func_set_user_var to create @a (@a:=10), in this we mark
 
2114
      the variable as "already logged" (line below) so that it won't be logged
 
2115
      by Item_func_get_user_var (because that's not necessary).
 
2116
    */
 
2117
    entry->used_query_id= query_id;
 
2118
    entry->type=STRING_RESULT;
 
2119
    memcpy(entry->name.str, name.str, name.length+1);
 
2120
    if (my_hash_insert(&user_vars, (unsigned char*) entry))
 
2121
    {
 
2122
      assert(1);
 
2123
      free((char*) entry);
 
2124
      return 0;
 
2125
    }
 
2126
 
 
2127
  }
 
2128
 
 
2129
  return entry;
 
2130
}