~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Lee Bieber
  • Date: 2011-02-19 18:28:30 UTC
  • mfrom: (1994.4.78 drizzle)
  • mto: This revision was merged to the branch mainline in revision 2185.
  • Revision ID: kalebral@gmail.com-20110219182830-kb8m3ali4yjmcg0s
Merge Marisa - adds logo references to the include file

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* drop and alter of tables */
17
17
 
18
 
#include "config.h"
 
18
#include <config.h>
19
19
#include <plugin/myisam/myisam.h>
20
20
#include <drizzled/show.h>
21
21
#include <drizzled/error.h>
26
26
#include <drizzled/sql_lex.h>
27
27
#include <drizzled/session.h>
28
28
#include <drizzled/sql_base.h>
29
 
#include "drizzled/strfunc.h"
30
 
#include <drizzled/db.h>
 
29
#include <drizzled/strfunc.h>
31
30
#include <drizzled/lock.h>
32
31
#include <drizzled/unireg.h>
33
32
#include <drizzled/item/int.h>
34
33
#include <drizzled/item/empty_string.h>
35
34
#include <drizzled/transaction_services.h>
36
 
#include "drizzled/transaction_services.h"
 
35
#include <drizzled/transaction_services.h>
37
36
#include <drizzled/table_proto.h>
38
37
#include <drizzled/plugin/client.h>
39
38
#include <drizzled/identifier.h>
40
 
#include "drizzled/internal/m_string.h"
41
 
#include "drizzled/global_charset_info.h"
42
 
#include "drizzled/charset.h"
43
 
 
44
 
#include "drizzled/definition/cache.h"
45
 
 
46
 
 
47
 
#include "drizzled/statement/alter_table.h"
48
 
#include "drizzled/sql_table.h"
49
 
#include "drizzled/pthread_globals.h"
50
 
#include "drizzled/plugin/storage_engine.h"
 
39
#include <drizzled/internal/m_string.h>
 
40
#include <drizzled/global_charset_info.h>
 
41
#include <drizzled/charset.h>
 
42
 
 
43
#include <drizzled/definition/cache.h>
 
44
 
 
45
#include <drizzled/statement/alter_table.h>
 
46
#include <drizzled/sql_table.h>
 
47
#include <drizzled/pthread_globals.h>
 
48
#include <drizzled/typelib.h>
 
49
#include <drizzled/plugin/storage_engine.h>
51
50
 
52
51
#include <algorithm>
53
52
#include <sstream>
143
142
                   bool drop_temporary)
144
143
{
145
144
  TableList *table;
146
 
  String wrong_tables;
 
145
  util::string::vector wrong_tables;
147
146
  int error= 0;
148
147
  bool foreign_key_error= false;
149
148
 
199
198
      }
200
199
      identifier::Table identifier(table->getSchemaName(), table->getTableName(), table->getInternalTmpTable() ? message::Table::INTERNAL : message::Table::STANDARD);
201
200
 
 
201
      message::table::shared_ptr message= plugin::StorageEngine::getTableMessage(*session, identifier, true);
 
202
 
202
203
      if (drop_temporary || not plugin::StorageEngine::doesTableExist(*session, identifier))
203
204
      {
204
205
        // Table was not found on disk and table can't be created from engine
205
206
        if (if_exists)
 
207
        {
206
208
          push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
207
209
                              ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR),
208
210
                              table->getTableName());
 
211
        }
209
212
        else
210
213
        {
211
214
          error= 1;
218
221
        /* Generate transaction event ONLY when we successfully drop */ 
219
222
        if (plugin::StorageEngine::dropTable(*session, identifier, local_error))
220
223
        {
221
 
          TransactionServices &transaction_services= TransactionServices::singleton();
222
 
          transaction_services.dropTable(*session, identifier, if_exists);
 
224
          if (message) // If we have no definition, we don't know if the table should have been replicated
 
225
          {
 
226
            TransactionServices &transaction_services= TransactionServices::singleton();
 
227
            transaction_services.dropTable(*session, identifier, *message, if_exists);
 
228
          }
223
229
        }
224
230
        else
225
231
        {
240
246
 
241
247
      if (error)
242
248
      {
243
 
        if (wrong_tables.length())
244
 
          wrong_tables.append(',');
245
 
        wrong_tables.append(String(table->getTableName(), system_charset_info));
 
249
        wrong_tables.push_back(table->getTableName());
246
250
      }
247
251
    }
248
252
 
250
254
 
251
255
  } while (0);
252
256
 
253
 
  if (wrong_tables.length())
 
257
  if (wrong_tables.size())
254
258
  {
255
259
    if (not foreign_key_error)
256
260
    {
 
261
      std::string table_error;
 
262
 
 
263
      for (util::string::vector::iterator iter= wrong_tables.begin();
 
264
           iter != wrong_tables.end();
 
265
           iter++)
 
266
      {
 
267
        table_error+= *iter;
 
268
        table_error+= ',';
 
269
      }
 
270
      table_error.resize(table_error.size() -1);
 
271
 
257
272
      my_printf_error(ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), MYF(0),
258
 
                      wrong_tables.c_ptr());
 
273
                      table_error.c_str());
259
274
    }
260
275
    else
261
276
    {
542
557
  int           timestamps= 0, timestamps_with_niladic= 0;
543
558
  int           dup_no;
544
559
  int           select_field_pos,auto_increment=0;
545
 
  List_iterator<CreateField> it(alter_info->create_list);
546
 
  List_iterator<CreateField> it2(alter_info->create_list);
 
560
  List<CreateField>::iterator it(alter_info->create_list);
 
561
  List<CreateField>::iterator it2(alter_info->create_list);
547
562
  uint32_t total_uneven_bit_length= 0;
548
563
 
549
564
  plugin::StorageEngine *engine= plugin::StorageEngine::findByName(create_proto.engine().name());
637
652
        interval= sql_field->interval= typelib(session->mem_root,
638
653
                                               sql_field->interval_list);
639
654
 
640
 
        List_iterator<String> int_it(sql_field->interval_list);
 
655
        List<String>::iterator int_it(sql_field->interval_list);
641
656
        String conv, *tmp;
642
657
        char comma_buf[4];
643
658
        int comma_length= cs->cset->wc_mb(cs, ',', (unsigned char*) comma_buf,
663
678
          interval->type_lengths[i]= lengthsp;
664
679
          ((unsigned char *)interval->type_names[i])[lengthsp]= '\0';
665
680
        }
666
 
        sql_field->interval_list.empty(); // Don't need interval_list anymore
 
681
        sql_field->interval_list.clear(); // Don't need interval_list anymore
667
682
      }
668
683
 
669
684
      /* DRIZZLE_TYPE_ENUM */
686
701
          else /* not NULL */
687
702
          {
688
703
            def->length(cs->cset->lengthsp(cs, def->ptr(), def->length()));
689
 
            if (find_type2(interval, def->ptr(), def->length(), cs) == 0) /* not found */
 
704
            if (interval->find_type2(def->ptr(), def->length(), cs) == 0) /* not found */
690
705
            {
691
706
              my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
692
707
              return(true);
767
782
      (*db_options)|= HA_OPTION_PACK_RECORD;
768
783
    }
769
784
 
770
 
    it2.rewind();
 
785
    it2= alter_info->create_list;
771
786
  }
772
787
 
773
788
  /* record_offset will be increased with 'length-of-null-bits' later */
774
789
  record_offset= 0;
775
790
  null_fields+= total_uneven_bit_length;
776
791
 
777
 
  it.rewind();
 
792
  it= alter_info->create_list;
778
793
  while ((sql_field=it++))
779
794
  {
780
795
    assert(sql_field->charset != 0);
814
829
 
815
830
  /* Create keys */
816
831
 
817
 
  List_iterator<Key> key_iterator(alter_info->key_list);
818
 
  List_iterator<Key> key_iterator2(alter_info->key_list);
 
832
  List<Key>::iterator key_iterator(alter_info->key_list);
 
833
  List<Key>::iterator key_iterator2(alter_info->key_list);
819
834
  uint32_t key_parts=0, fk_key_count=0;
820
835
  bool primary_key=0,unique_key=0;
821
836
  Key *key, *key2;
865
880
    }
866
881
    if (check_identifier_name(&key->name, ER_TOO_LONG_IDENT))
867
882
      return(true);
868
 
    key_iterator2.rewind ();
 
883
    key_iterator2= alter_info->key_list;
869
884
    if (key->type != Key::FOREIGN_KEY)
870
885
    {
871
886
      while ((key2 = key_iterator2++) != key)
918
933
  if (!*key_info_buffer || ! key_part_info)
919
934
    return(true);                               // Out of memory
920
935
 
921
 
  key_iterator.rewind();
 
936
  key_iterator= alter_info->key_list;
922
937
  key_number=0;
923
938
  for (; (key=key_iterator++) ; key_number++)
924
939
  {
977
992
 
978
993
    message::Table::Field *protofield= NULL;
979
994
 
980
 
    List_iterator<Key_part_spec> cols(key->columns), cols2(key->columns);
 
995
    List<Key_part_spec>::iterator cols(key->columns);
 
996
    List<Key_part_spec>::iterator cols2(key->columns);
981
997
    for (uint32_t column_nr=0 ; (column=cols++) ; column_nr++)
982
998
    {
983
999
      uint32_t length;
984
1000
      Key_part_spec *dup_column;
985
1001
      int proto_field_nr= 0;
986
1002
 
987
 
      it.rewind();
 
1003
      it= alter_info->create_list;
988
1004
      field=0;
989
1005
      while ((sql_field=it++) && ++proto_field_nr &&
990
1006
             my_strcasecmp(system_charset_info,
1011
1027
          return(true);
1012
1028
        }
1013
1029
      }
1014
 
      cols2.rewind();
 
1030
      cols2= key->columns;
1015
1031
 
1016
1032
      if (create_proto.field_size() > 0)
1017
1033
        protofield= create_proto.mutable_field(proto_field_nr - 1);
1224
1240
                     (qsort_cmp) sort_keys);
1225
1241
 
1226
1242
  /* Check fields. */
1227
 
  it.rewind();
 
1243
  it= alter_info->create_list;
1228
1244
  while ((sql_field=it++))
1229
1245
  {
1230
1246
    Field::utype type= (Field::utype) MTYP_TYPENR(sql_field->unireg_check);
1231
1247
 
1232
1248
    if (session->variables.sql_mode & MODE_NO_ZERO_DATE &&
1233
1249
        !sql_field->def &&
1234
 
        sql_field->sql_type == DRIZZLE_TYPE_TIMESTAMP &&
 
1250
        (sql_field->sql_type == DRIZZLE_TYPE_TIMESTAMP  or sql_field->sql_type == DRIZZLE_TYPE_MICROTIME) &&
1235
1251
        (sql_field->flags & NOT_NULL_FLAG) &&
1236
1252
        (type == Field::NONE || type == Field::TIMESTAMP_UN_FIELD))
1237
1253
    {
2002
2018
  // a "new" message and it will not have all of the information that the
2003
2019
  // source table message would have.
2004
2020
  message::Table new_table_message;
2005
 
  drizzled::error_t error;
2006
2021
 
2007
 
  message::table::shared_ptr source_table_message= plugin::StorageEngine::getTableMessage(session, source_identifier, error);
 
2022
  message::table::shared_ptr source_table_message= plugin::StorageEngine::getTableMessage(session, source_identifier);
2008
2023
 
2009
2024
  if (not source_table_message)
2010
2025
  {