~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Henrik Ingo
  • Date: 2011-09-23 06:14:37 UTC
  • mfrom: (2425 drizzle)
  • mto: This revision was merged to the branch mainline in revision 2439.
  • Revision ID: henrik.ingo@avoinelama.fi-20110923061437-ct1wedkb9s47uy2t
Merge newest trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
#include <drizzled/diagnostics_area.h>
46
46
#include <drizzled/open_tables_state.h>
47
47
#include <drizzled/table/cache.h>
 
48
#include <drizzled/create_field.h>
48
49
 
49
50
#include <algorithm>
50
51
#include <sstream>
55
56
 
56
57
namespace drizzled {
57
58
 
58
 
bool is_primary_key(KeyInfo *key_info)
59
 
{
60
 
  static const char * primary_key_name="PRIMARY";
61
 
  return (strcmp(key_info->name, primary_key_name)==0);
62
 
}
63
 
 
64
 
const char* is_primary_key_name(const char* key_name)
65
 
{
66
 
  static const char * primary_key_name="PRIMARY";
67
 
  if (strcmp(key_name, primary_key_name)==0)
68
 
    return key_name;
69
 
  else
70
 
    return NULL;
 
59
bool is_primary_key(const char* name)
 
60
{
 
61
  return strcmp(name, "PRIMARY") == 0;
71
62
}
72
63
 
73
64
static bool check_if_keyname_exists(const char *name,KeyInfo *start, KeyInfo *end);
74
 
static char *make_unique_key_name(const char *field_name,KeyInfo *start,KeyInfo *end);
75
 
 
 
65
static const char *make_unique_key_name(const char *field_name,KeyInfo *start,KeyInfo *end);
76
66
static bool prepare_blob_field(Session *session, CreateField *sql_field);
77
67
 
78
68
void set_table_default_charset(HA_CREATE_INFO *create_info, const char *db)
82
72
    let's fetch the database default character set and
83
73
    apply it to the table.
84
74
  */
85
 
  identifier::Schema identifier(db);
86
 
  if (create_info->default_table_charset == NULL)
87
 
    create_info->default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
 
75
  if (not create_info->default_table_charset)
 
76
    create_info->default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier::Schema(db));
88
77
}
89
78
 
90
79
/*
281
270
      /* Sort NOT NULL keys before other keys */
282
271
      return (a_flags & (HA_NULL_PART_KEY)) ? 1 : -1;
283
272
    }
284
 
    if (is_primary_key(a))
 
273
    if (is_primary_key(a->name))
285
274
      return -1;
286
 
    if (is_primary_key(b))
 
275
    if (is_primary_key(b->name))
287
276
      return 1;
288
277
    /* Sort keys don't containing partial segments before others */
289
278
    if ((a_flags ^ b_flags) & HA_KEY_HAS_PART_KEY_SEG)
502
491
  case DRIZZLE_TYPE_NULL:
503
492
  case DRIZZLE_TYPE_TIME:
504
493
  case DRIZZLE_TYPE_UUID:
 
494
  case DRIZZLE_TYPE_IPV6:
505
495
  case DRIZZLE_TYPE_VARCHAR:
506
496
    break;
507
497
  }
633
623
          if (String::needs_conversion(tmp->length(), tmp->charset(), cs))
634
624
          {
635
625
            conv.copy(tmp->ptr(), tmp->length(), cs);
636
 
            interval->type_names[i]= session->mem.strmake(conv);
 
626
            interval->type_names[i]= session->mem.strdup(conv);
637
627
            interval->type_lengths[i]= conv.length();
638
628
          }
639
629
 
878
868
      key_parts+=key->columns.size();
879
869
    else
880
870
      (*key_count)--;
881
 
    if (key->name.str && !tmp_table && (key->type != Key::PRIMARY) &&
882
 
        is_primary_key_name(key->name.str))
 
871
    if (key->name.str && !tmp_table && (key->type != Key::PRIMARY) && is_primary_key(key->name.str))
883
872
    {
884
873
      my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name.str);
885
874
      return true;
1553
1542
}
1554
1543
 
1555
1544
 
1556
 
static char *
 
1545
static const char*
1557
1546
make_unique_key_name(const char *field_name,KeyInfo *start,KeyInfo *end)
1558
1547
{
1559
1548
  char buff[MAX_FIELD_NAME],*buff_end;
1560
1549
 
1561
 
  if (!check_if_keyname_exists(field_name,start,end) &&
1562
 
      !is_primary_key_name(field_name))
1563
 
    return (char*) field_name;                  // Use fieldname
 
1550
  if (not check_if_keyname_exists(field_name,start,end) && not is_primary_key(field_name))
 
1551
    return field_name;                  // Use fieldname
1564
1552
 
1565
1553
  buff_end= strncpy(buff, field_name, sizeof(buff)-4);
1566
1554
  buff_end+= strlen(buff);
1961
1949
  }
1962
1950
 
1963
1951
  new_table_message.CopyFrom(*source_table_message);
1964
 
 
1965
 
  if (destination_identifier.isTmp())
1966
 
  {
1967
 
    new_table_message.set_type(message::Table::TEMPORARY);
1968
 
  }
1969
 
  else
1970
 
  {
1971
 
    new_table_message.set_type(message::Table::STANDARD);
1972
 
  }
 
1952
  new_table_message.set_type(destination_identifier.isTmp() ? message::Table::TEMPORARY : message::Table::STANDARD);
1973
1953
 
1974
1954
  if (is_engine_set)
1975
1955
  {
2003
1983
    As mysql_truncate don't work on a new table at this stage of
2004
1984
    creation, instead create the table directly (for both normal and temporary tables).
2005
1985
  */
2006
 
  bool success= plugin::StorageEngine::createTable(session,
2007
 
                                                   destination_identifier,
2008
 
                                                   new_table_message);
 
1986
  bool success= plugin::StorageEngine::createTable(session, destination_identifier, new_table_message);
2009
1987
 
2010
1988
  if (success && not destination_identifier.isTmp())
2011
1989
  {
2136
2114
 
2137
2115
bool analyze_table(Session* session, TableList* tables)
2138
2116
{
2139
 
  thr_lock_type lock_type = TL_READ_NO_INSERT;
2140
 
 
2141
 
  return(admin_table(session, tables, "analyze", lock_type, true, &Cursor::ha_analyze));
 
2117
  return admin_table(session, tables, "analyze", TL_READ_NO_INSERT, true, &Cursor::ha_analyze);
2142
2118
}
2143
2119
 
2144
2120
 
2145
2121
bool check_table(Session* session, TableList* tables)
2146
2122
{
2147
 
  thr_lock_type lock_type = TL_READ_NO_INSERT;
2148
 
  return admin_table(session, tables, "check", lock_type, false, &Cursor::ha_check);
 
2123
  return admin_table(session, tables, "check", TL_READ_NO_INSERT, false, &Cursor::ha_check);
2149
2124
}
2150
2125
 
2151
2126
} /* namespace drizzled */