~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/table.cc

  • Committer: Lee Bieber
  • Date: 2011-02-23 23:22:48 UTC
  • mfrom: (2183.2.20 list2)
  • mto: This revision was merged to the branch mainline in revision 2197.
  • Revision ID: kalebral@gmail.com-20110223232248-ev4y8pyt16b806o0
Merge Olaf - Use List::size()

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/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"
 
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>
33
36
 
34
37
#include <algorithm>
35
38
#include <sstream>
42
45
namespace drizzled
43
46
{
44
47
 
45
 
class SchemaIdentifier;
 
48
class Table;
46
49
 
47
50
extern std::string drizzle_tmpdir;
48
51
extern pid_t current_pid;
49
52
 
 
53
namespace identifier {
 
54
class Schema;
 
55
 
50
56
static const char hexchars[]= "0123456789abcdef";
51
57
 
52
58
/*
61
67
  RETURN
62
68
    Table name length.
63
69
*/
64
 
uint32_t TableIdentifier::filename_to_tablename(const char *from, char *to, uint32_t to_length)
 
70
uint32_t Table::filename_to_tablename(const char *from, char *to, uint32_t to_length)
65
71
{
66
72
  uint32_t length= 0;
67
73
 
139
145
 
140
146
#endif
141
147
 
142
 
size_t TableIdentifier::build_tmptable_filename(std::string &buffer)
 
148
size_t Table::build_tmptable_filename(std::string &buffer)
143
149
{
144
150
  size_t tmpdir_length;
145
151
  ostringstream post_tmpdir_str;
157
163
  return buffer.length();
158
164
}
159
165
 
160
 
size_t TableIdentifier::build_tmptable_filename(std::vector<char> &buffer)
 
166
size_t Table::build_tmptable_filename(std::vector<char> &buffer)
161
167
{
162
168
  ostringstream post_tmpdir_str;
163
169
 
204
210
    path length on success, 0 on failure
205
211
*/
206
212
 
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)
 
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)
208
214
{
209
215
  bool conversion_error= false;
210
216
 
211
217
  conversion_error= util::tablename_to_filename(in_db, in_path);
212
218
  if (conversion_error)
213
219
  {
214
 
    errmsg_printf(ERRMSG_LVL_ERROR,
 
220
    errmsg_printf(error::ERROR,
215
221
                  _("Schema name cannot be encoded and fit within filesystem "
216
222
                    "name length restrictions."));
217
223
    return 0;
228
234
    conversion_error= util::tablename_to_filename(in_table_name, in_path);
229
235
    if (conversion_error)
230
236
    {
231
 
      errmsg_printf(ERRMSG_LVL_ERROR,
 
237
      errmsg_printf(error::ERROR,
232
238
                    _("Table name cannot be encoded and fit within filesystem "
233
239
                      "name length restrictions."));
234
240
      return 0;
238
244
  return in_path.length();
239
245
}
240
246
 
241
 
TableIdentifier::TableIdentifier(const drizzled::Table &table) :
242
 
  SchemaIdentifier(table.getShare()->getSchemaName()),
 
247
Table::Table(const drizzled::Table &table) :
 
248
  identifier::Schema(table.getShare()->getSchemaName()),
243
249
  type(table.getShare()->getTableType()),
244
250
  table_name(table.getShare()->getTableName())
245
251
{
249
255
  init();
250
256
}
251
257
 
252
 
void TableIdentifier::init()
 
258
void Table::init()
253
259
{
254
260
  switch (type) {
255
261
  case message::Table::FUNCTION:
269
275
    break;
270
276
  }
271
277
 
 
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
 
272
296
  util::insensitive_hash hasher;
273
297
  hash_value= hasher(path);
274
298
 
279
303
}
280
304
 
281
305
 
282
 
const std::string &TableIdentifier::getPath() const
 
306
const std::string &Table::getPath() const
283
307
{
284
308
  return path;
285
309
}
286
310
 
287
 
void TableIdentifier::getSQLPath(std::string &sql_path) const  // @todo this is just used for errors, we should find a way to optimize it
 
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
288
320
{
289
321
  switch (type) {
290
322
  case message::Table::FUNCTION:
305
337
  }
306
338
}
307
339
 
308
 
bool TableIdentifier::isValid() const
 
340
bool Table::isValid() const
309
341
{
310
 
  if (not SchemaIdentifier::isValid())
 
342
  if (not identifier::Schema::isValid())
311
343
    return false;
312
344
 
313
345
  bool error= false;
365
397
}
366
398
 
367
399
 
368
 
void TableIdentifier::copyToTableMessage(message::Table &message) const
 
400
void Table::copyToTableMessage(message::Table &message) const
369
401
{
370
402
  message.set_name(table_name);
371
403
  message.set_schema(getSchemaName());
372
404
}
373
405
 
374
 
void TableIdentifier::Key::set(size_t resize_arg, const std::string &a, const std::string &b)
 
406
void Table::Key::set(size_t resize_arg, const std::string &a, const std::string &b)
375
407
{
376
408
  key_buffer.resize(resize_arg);
377
409
 
382
414
  hash_value= hasher(key_buffer);
383
415
}
384
416
 
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
 
 
 
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 */
395
446
} /* namespace drizzled */