~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/table.cc

  • Committer: Brian Aker
  • Date: 2011-01-12 06:45:23 UTC
  • mto: (2073.1.4 catalogs)
  • mto: This revision was merged to the branch mainline in revision 2080.
  • Revision ID: brian@tangent.org-20110112064523-rqhptaqbph22qmj1
RemoveĀ customĀ error.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
 
21
#include "config.h"
22
22
 
23
23
#include <assert.h>
24
24
#include <boost/lexical_cast.hpp>
25
 
#include <drizzled/identifier.h>
26
 
#include <drizzled/internal/my_sys.h>
27
 
 
28
 
#include <drizzled/error.h>
29
 
#include <drizzled/errmsg_print.h>
30
 
#include <drizzled/gettext.h>
31
 
 
32
 
#include <drizzled/table.h>
33
 
 
34
 
#include <drizzled/util/string.h>
35
 
#include <drizzled/util/tablename_to_filename.h>
 
25
#include "drizzled/identifier.h"
 
26
#include "drizzled/session.h"
 
27
#include "drizzled/internal/my_sys.h"
 
28
 
 
29
#include "drizzled/table.h"
 
30
 
 
31
#include "drizzled/util/string.h"
 
32
#include "drizzled/util/tablename_to_filename.h"
36
33
 
37
34
#include <algorithm>
38
35
#include <sstream>
45
42
namespace drizzled
46
43
{
47
44
 
48
 
class Table;
 
45
class SchemaIdentifier;
49
46
 
50
47
extern std::string drizzle_tmpdir;
51
48
extern pid_t current_pid;
52
49
 
53
 
namespace identifier {
54
 
class Schema;
55
 
 
56
50
static const char hexchars[]= "0123456789abcdef";
57
51
 
58
52
/*
67
61
  RETURN
68
62
    Table name length.
69
63
*/
70
 
uint32_t Table::filename_to_tablename(const char *from, char *to, uint32_t to_length)
 
64
uint32_t TableIdentifier::filename_to_tablename(const char *from, char *to, uint32_t to_length)
71
65
{
72
66
  uint32_t length= 0;
73
67
 
145
139
 
146
140
#endif
147
141
 
148
 
size_t Table::build_tmptable_filename(std::string &buffer)
 
142
size_t TableIdentifier::build_tmptable_filename(std::string &buffer)
149
143
{
150
144
  size_t tmpdir_length;
151
145
  ostringstream post_tmpdir_str;
163
157
  return buffer.length();
164
158
}
165
159
 
166
 
size_t Table::build_tmptable_filename(std::vector<char> &buffer)
 
160
size_t TableIdentifier::build_tmptable_filename(std::vector<char> &buffer)
167
161
{
168
162
  ostringstream post_tmpdir_str;
169
163
 
210
204
    path length on success, 0 on failure
211
205
*/
212
206
 
213
 
size_t Table::build_table_filename(std::string &in_path, const std::string &in_db, const std::string &in_table_name, bool is_tmp)
 
207
size_t TableIdentifier::build_table_filename(std::string &in_path, const std::string &in_db, const std::string &in_table_name, bool is_tmp)
214
208
{
215
209
  bool conversion_error= false;
216
210
 
217
211
  conversion_error= util::tablename_to_filename(in_db, in_path);
218
212
  if (conversion_error)
219
213
  {
220
 
    errmsg_printf(error::ERROR,
 
214
    errmsg_printf(ERRMSG_LVL_ERROR,
221
215
                  _("Schema name cannot be encoded and fit within filesystem "
222
216
                    "name length restrictions."));
223
217
    return 0;
234
228
    conversion_error= util::tablename_to_filename(in_table_name, in_path);
235
229
    if (conversion_error)
236
230
    {
237
 
      errmsg_printf(error::ERROR,
 
231
      errmsg_printf(ERRMSG_LVL_ERROR,
238
232
                    _("Table name cannot be encoded and fit within filesystem "
239
233
                      "name length restrictions."));
240
234
      return 0;
244
238
  return in_path.length();
245
239
}
246
240
 
247
 
Table::Table(const drizzled::Table &table) :
248
 
  identifier::Schema(table.getShare()->getSchemaName()),
 
241
TableIdentifier::TableIdentifier(const drizzled::Table &table) :
 
242
  SchemaIdentifier(table.getShare()->getSchemaName()),
249
243
  type(table.getShare()->getTableType()),
250
244
  table_name(table.getShare()->getTableName())
251
245
{
255
249
  init();
256
250
}
257
251
 
258
 
void Table::init()
 
252
void TableIdentifier::init()
259
253
{
260
254
  switch (type) {
261
255
  case message::Table::FUNCTION:
275
269
    break;
276
270
  }
277
271
 
278
 
  switch (type) {
279
 
  case message::Table::FUNCTION:
280
 
  case message::Table::STANDARD:
281
 
  case message::Table::INTERNAL:
282
 
    break;
283
 
  case message::Table::TEMPORARY:
284
 
    {
285
 
      size_t pos;
286
 
 
287
 
      pos= path.find("tmp/#sql");
288
 
      if (pos != std::string::npos) 
289
 
      {
290
 
        key_path= path.substr(pos);
291
 
      }
292
 
    }
293
 
    break;
294
 
  }
295
 
 
296
272
  util::insensitive_hash hasher;
297
273
  hash_value= hasher(path);
298
274
 
303
279
}
304
280
 
305
281
 
306
 
const std::string &Table::getPath() const
 
282
const std::string &TableIdentifier::getPath() const
307
283
{
308
284
  return path;
309
285
}
310
286
 
311
 
const std::string &Table::getKeyPath() const
312
 
{
313
 
  if (key_path.empty())
314
 
    return path;
315
 
 
316
 
  return key_path;
317
 
}
318
 
 
319
 
void Table::getSQLPath(std::string &sql_path) const  // @todo this is just used for errors, we should find a way to optimize it
 
287
void TableIdentifier::getSQLPath(std::string &sql_path) const  // @todo this is just used for errors, we should find a way to optimize it
320
288
{
321
289
  switch (type) {
322
290
  case message::Table::FUNCTION:
337
305
  }
338
306
}
339
307
 
340
 
bool Table::isValid() const
 
308
bool TableIdentifier::isValid() const
341
309
{
342
 
  if (not identifier::Schema::isValid())
 
310
  if (not SchemaIdentifier::isValid())
343
311
    return false;
344
312
 
345
313
  bool error= false;
397
365
}
398
366
 
399
367
 
400
 
void Table::copyToTableMessage(message::Table &message) const
 
368
void TableIdentifier::copyToTableMessage(message::Table &message) const
401
369
{
402
370
  message.set_name(table_name);
403
371
  message.set_schema(getSchemaName());
404
372
}
405
373
 
406
 
void Table::Key::set(size_t resize_arg, const std::string &a, const std::string &b)
 
374
void TableIdentifier::Key::set(size_t resize_arg, const std::string &a, const std::string &b)
407
375
{
408
376
  key_buffer.resize(resize_arg);
409
377
 
414
382
  hash_value= hasher(key_buffer);
415
383
}
416
384
 
417
 
std::size_t hash_value(Table const& b)
418
 
{
419
 
  return b.getHashValue();
420
 
}
421
 
 
422
 
std::size_t hash_value(Table::Key const& b)
423
 
{
424
 
  return b.getHashValue();
425
 
}
426
 
 
427
 
 
428
 
std::ostream& operator<<(std::ostream& output, Table::const_reference identifier)
429
 
{
430
 
  output << "Table:(";
431
 
  output <<  identifier.getSchemaName();
432
 
  output << ", ";
433
 
  output << identifier.getTableName();
434
 
  output << ", ";
435
 
  output << message::type(identifier.getType());
436
 
  output << ", ";
437
 
  output << identifier.getPath();
438
 
  output << ", ";
439
 
  output << identifier.getHashValue();
440
 
  output << ")";
441
 
 
442
 
  return output;  // for multiple << operators.
443
 
}
444
 
 
445
 
} /* namespace identifier */
 
385
std::size_t hash_value(TableIdentifier const& b)
 
386
{
 
387
  return b.getHashValue();
 
388
}
 
389
 
 
390
std::size_t hash_value(TableIdentifier::Key const& b)
 
391
{
 
392
  return b.getHashValue();
 
393
}
 
394
 
446
395
} /* namespace drizzled */