~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/ident.cc

  • Committer: Stewart Smith
  • Date: 2008-11-21 16:06:07 UTC
  • mto: This revision was merged to the branch mainline in revision 593.
  • Revision ID: stewart@flamingspork.com-20081121160607-n6gdlt013spuo54r
remove mysql_frm_type
and fix engines to return correct value from delete_table when table doesn't exist.
(it should be ENOENT).

Also fix up some tests that manipulated frm files by hand. These tests are no longer valid and will need to be rewritten in the not too distant future.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#include "config.h"
21
 
#include <drizzled/show.h>
22
 
#include <drizzled/table.h>
23
 
#include <drizzled/current_session.h>
24
 
#include <drizzled/item/ident.h>
25
 
 
26
 
#include <cstdio>
27
 
 
28
 
using namespace std;
29
 
 
30
 
namespace drizzled
31
 
{
32
 
 
33
 
const uint32_t NO_CACHED_FIELD_INDEX= UINT32_MAX;
34
 
 
35
 
Item_ident::Item_ident(Name_resolution_context *context_arg,
36
 
                       const char *db_name_arg,const char *table_name_arg,
37
 
                       const char *field_name_arg)
38
 
  :orig_db_name(db_name_arg), orig_table_name(table_name_arg),
39
 
   orig_field_name(field_name_arg), context(context_arg),
40
 
   db_name(db_name_arg), table_name(table_name_arg),
41
 
   field_name(field_name_arg),
42
 
   alias_name_used(false), cached_field_index(NO_CACHED_FIELD_INDEX),
43
 
   cached_table(0), depended_from(0)
44
 
{
45
 
  name = (char*) field_name_arg;
46
 
}
47
 
 
48
 
/**
49
 
  Constructor used by Item_field & Item_*_ref (see Item comment)
50
 
*/
51
 
 
52
 
Item_ident::Item_ident(Session *session, Item_ident *item)
53
 
  :Item(session, item),
54
 
   orig_db_name(item->orig_db_name),
55
 
   orig_table_name(item->orig_table_name),
56
 
   orig_field_name(item->orig_field_name),
57
 
   context(item->context),
58
 
   db_name(item->db_name),
59
 
   table_name(item->table_name),
60
 
   field_name(item->field_name),
61
 
   alias_name_used(item->alias_name_used),
62
 
   cached_field_index(item->cached_field_index),
63
 
   cached_table(item->cached_table),
64
 
   depended_from(item->depended_from)
65
 
{}
66
 
 
67
 
void Item_ident::cleanup()
68
 
{
69
 
  Item::cleanup();
70
 
  db_name= orig_db_name;
71
 
  table_name= orig_table_name;
72
 
  field_name= orig_field_name;
73
 
  depended_from= 0;
74
 
  return;
75
 
}
76
 
 
77
 
bool Item_ident::remove_dependence_processor(unsigned char * arg)
78
 
{
79
 
  if (depended_from == (Select_Lex *) arg)
80
 
    depended_from= 0;
81
 
  return(0);
82
 
}
83
 
 
84
 
const char *Item_ident::full_name() const
85
 
{
86
 
  char *tmp;
87
 
        size_t tmp_len;
88
 
  if (!table_name || !field_name)
89
 
    return field_name ? field_name : name ? name : "tmp_field";
90
 
  if (db_name && db_name[0])
91
 
  {
92
 
    tmp_len= strlen(db_name)+strlen(table_name)+strlen(field_name)+3;
93
 
    tmp= (char*) memory::sql_alloc(tmp_len);
94
 
    snprintf(tmp, tmp_len, "%s.%s.%s",db_name,table_name,field_name);
95
 
  }
96
 
  else
97
 
  {
98
 
    if (table_name[0])
99
 
    {
100
 
      tmp_len=strlen(table_name)+strlen(field_name)+2;
101
 
      tmp= (char*) memory::sql_alloc(tmp_len);
102
 
      snprintf(tmp, tmp_len, "%s.%s", table_name, field_name);
103
 
    }
104
 
    else
105
 
      tmp= (char*) field_name;
106
 
  }
107
 
  return tmp;
108
 
}
109
 
 
110
 
 
111
 
void Item_ident::print(String *str,
112
 
                       enum_query_type)
113
 
{
114
 
  string d_name, t_name;
115
 
 
116
 
  if (table_name && table_name[0])
117
 
  {
118
 
    t_name.assign(table_name);
119
 
    std::transform(t_name.begin(), t_name.end(),
120
 
                   t_name.begin(), ::tolower);
121
 
  }
122
 
 
123
 
  if (db_name && db_name[0])
124
 
  {
125
 
    d_name.assign(db_name);
126
 
    // Keeping the std:: prefix here, since Item_ident has a transform
127
 
    // method
128
 
      std::transform(d_name.begin(), d_name.end(),
129
 
                     d_name.begin(), ::tolower);
130
 
  }
131
 
 
132
 
  if (!table_name || !field_name || !field_name[0])
133
 
  {
134
 
    const char *nm= (field_name && field_name[0]) ?
135
 
                      field_name : name ? name : "tmp_field";
136
 
    str->append_identifier(nm, (uint32_t) strlen(nm));
137
 
 
138
 
    return;
139
 
  }
140
 
  if (db_name && db_name[0] && !alias_name_used)
141
 
  {
142
 
    {
143
 
      str->append_identifier(d_name.c_str(), d_name.length());
144
 
      str->append('.');
145
 
    }
146
 
    str->append_identifier(t_name.c_str(), t_name.length());
147
 
    str->append('.');
148
 
    str->append_identifier(field_name, (uint32_t)strlen(field_name));
149
 
  }
150
 
  else
151
 
  {
152
 
    if (table_name[0])
153
 
    {
154
 
      str->append_identifier(t_name.c_str(), t_name.length());
155
 
      str->append('.');
156
 
      str->append_identifier(field_name, (uint32_t) strlen(field_name));
157
 
    }
158
 
    else
159
 
      str->append_identifier(field_name, (uint32_t) strlen(field_name));
160
 
  }
161
 
}
162
 
 
163
 
double Item_ident_for_show::val_real()
164
 
{
165
 
  return field->val_real();
166
 
}
167
 
 
168
 
 
169
 
int64_t Item_ident_for_show::val_int()
170
 
{
171
 
  return field->val_int();
172
 
}
173
 
 
174
 
 
175
 
String *Item_ident_for_show::val_str(String *str)
176
 
{
177
 
  return field->val_str(str);
178
 
}
179
 
 
180
 
 
181
 
my_decimal *Item_ident_for_show::val_decimal(my_decimal *dec)
182
 
{
183
 
  return field->val_decimal(dec);
184
 
}
185
 
 
186
 
void Item_ident_for_show::make_field(SendField *tmp_field)
187
 
{
188
 
  tmp_field->table_name= tmp_field->org_table_name= table_name;
189
 
  tmp_field->db_name= db_name;
190
 
  tmp_field->col_name= tmp_field->org_col_name= field->field_name;
191
 
  tmp_field->charsetnr= field->charset()->number;
192
 
  tmp_field->length=field->field_length;
193
 
  tmp_field->type=field->type();
194
 
  tmp_field->flags= field->getTable()->maybe_null ?
195
 
    (field->flags & ~NOT_NULL_FLAG) : field->flags;
196
 
  tmp_field->decimals= field->decimals();
197
 
}
198
 
 
199
 
} /* namespace drizzled */