~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include <drizzled/alter_info.h>
38
38
#include <drizzled/sql_parse.h>
39
39
#include <drizzled/sql_lex.h>
 
40
#include <drizzled/statistics_variables.h>
 
41
#include <drizzled/session/transactions.h>
 
42
#include <drizzled/open_tables_state.h>
 
43
#include <drizzled/table/cache.h>
 
44
#include <drizzled/create_field.h>
40
45
 
41
 
namespace drizzled
42
 
{
 
46
namespace drizzled {
43
47
 
44
48
extern plugin::StorageEngine *heap_engine;
45
49
extern plugin::StorageEngine *myisam_engine;
251
255
  List_item *values;
252
256
  Name_resolution_context *context;
253
257
  Name_resolution_context_state ctx_state;
254
 
  thr_lock_type lock_type;
255
258
  Item *unused_conds= 0;
256
259
 
257
260
 
268
271
    return true;
269
272
  }
270
273
 
271
 
  lock_type= table_list->lock_type;
272
 
 
273
274
  session->set_proc_info("init");
274
275
  session->used_tables=0;
275
276
  values= its++;
549
550
     than INSERT.
550
551
  */
551
552
 
552
 
  if (setup_tables_and_check_access(session, &session->lex().select_lex.context,
553
 
                                    &session->lex().select_lex.top_join_list,
554
 
                                    table_list,
555
 
                                    &session->lex().select_lex.leaf_tables,
556
 
                                    select_insert))
557
 
    return(true);
558
 
 
559
 
  return(false);
 
553
  return setup_tables_and_check_access(session, &session->lex().select_lex.context,
 
554
    &session->lex().select_lex.top_join_list, table_list, &session->lex().select_lex.leaf_tables, select_insert);
560
555
}
561
556
 
562
557
 
632
627
  if (duplic == DUP_UPDATE)
633
628
  {
634
629
    /* it should be allocated before Item::fix_fields() */
635
 
    if (table_list->set_insert_values(session->mem_root))
636
 
      return(true);
 
630
    table_list->set_insert_values();
637
631
  }
638
632
 
639
633
  if (prepare_insert_check_table(session, table_list, fields, select_insert))
640
 
    return(true);
 
634
    return true;
641
635
 
642
636
 
643
637
  /* Prepare the fields in the statement. */
685
679
  }
686
680
 
687
681
  if (res)
688
 
    return(res);
 
682
    return res;
689
683
 
690
684
  if (not table)
691
685
    table= table_list->table;
692
686
 
693
 
  if (not select_insert)
 
687
  if (not select_insert && unique_table(table_list, table_list->next_global, true))
694
688
  {
695
 
    TableList *duplicate;
696
 
    if ((duplicate= unique_table(table_list, table_list->next_global, true)))
697
 
    {
698
 
      my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->alias);
699
 
 
700
 
      return true;
701
 
    }
 
689
    my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->alias);
 
690
    return true;
702
691
  }
703
692
 
704
693
  if (duplic == DUP_UPDATE || duplic == DUP_REPLACE)
961
950
gok_or_after_err:
962
951
  if (!table->cursor->has_transactions())
963
952
    session->transaction.stmt.markModifiedNonTransData();
964
 
  return(0);
 
953
  return 0;
965
954
 
966
955
err:
967
956
  info->last_errno= error;
988
977
 
989
978
  for (Field **field=entry->getFields() ; *field ; field++)
990
979
  {
991
 
    if (((*field)->isWriteSet()) == false)
 
980
    if (not (*field)->isWriteSet())
992
981
    {
993
982
      /*
994
983
       * If the field doesn't have any default value
1055
1044
                           lex->update_list, lex->value_list,
1056
1045
                           lex->duplicates,
1057
1046
                           &select_lex->where, true, false, false))
1058
 
    return(true);
 
1047
    return true;
1059
1048
 
1060
1049
  /*
1061
1050
    exclude first table from leaf tables list, because it belong to
1065
1054
  lex->leaf_tables_insert= select_lex->leaf_tables;
1066
1055
  /* skip all leaf tables belonged to view where we are insert */
1067
1056
  select_lex->leaf_tables= select_lex->leaf_tables->next_leaf;
1068
 
  return(false);
 
1057
  return false;
1069
1058
}
1070
1059
 
1071
1060
 
1171
1160
 
1172
1161
  session->lex().current_select= lex_current_select_save;
1173
1162
  if (res)
1174
 
    return(1);
 
1163
    return 1;
1175
1164
  /*
1176
1165
    if it is INSERT into join view then check_insert_fields already found
1177
1166
    real table for insert
1219
1208
  table->mark_columns_needed_for_insert();
1220
1209
 
1221
1210
 
1222
 
  return(res);
 
1211
  return res;
1223
1212
}
1224
1213
 
1225
1214
 
1244
1233
  if (session->lex().current_select->options & OPTION_BUFFER_RESULT)
1245
1234
    table->cursor->ha_start_bulk_insert((ha_rows) 0);
1246
1235
 
1247
 
  return(0);
 
1236
  return 0;
1248
1237
}
1249
1238
 
1250
1239
 
1353
1342
 
1354
1343
  if ((changed= (info.copied || info.deleted || info.updated)))
1355
1344
  {
1356
 
    /*
1357
 
      We must invalidate the table in the query cache before binlog writing
1358
 
      and autocommitOrRollback.
1359
 
    */
1360
1345
    if (session->transaction.stmt.hasModifiedNonTransData())
1361
1346
      session->transaction.all.markModifiedNonTransData();
1362
1347
  }
1407
1392
 
1408
1393
    table->cursor->ha_end_bulk_insert();
1409
1394
 
1410
 
    /*
1411
 
      If at least one row has been inserted/modified and will stay in
1412
 
      the table (the table doesn't have transactions) we must write to
1413
 
      the binlog (and the error code will make the slave stop).
1414
 
 
1415
 
      For many errors (example: we got a duplicate key error while
1416
 
      inserting into a MyISAM table), no row will be added to the table,
1417
 
      so passing the error to the slave will not help since there will
1418
 
      be an error code mismatch (the inserts will succeed on the slave
1419
 
      with no error).
1420
 
 
1421
 
      If table creation failed, the number of rows modified will also be
1422
 
      zero, so no check for that is made.
1423
 
    */
1424
1395
    changed= (info.copied || info.deleted || info.updated);
1425
1396
    transactional_table= table->cursor->has_transactions();
1426
1397
    assert(transactional_table || !changed ||
1490
1461
                                      List<Item> *items,
1491
1462
                                      bool is_if_not_exists,
1492
1463
                                      DrizzleLock **lock,
1493
 
                                      identifier::Table::const_reference identifier)
 
1464
                                      const identifier::Table& identifier)
1494
1465
{
1495
1466
  TableShare share(message::Table::INTERNAL);
1496
1467
  uint32_t select_field_count= items->size();
1596
1567
      if (not identifier.isTmp())
1597
1568
      {
1598
1569
        /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
1599
 
        boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex());
 
1570
        boost::mutex::scoped_lock scopedLock(table::Cache::mutex());
1600
1571
 
1601
1572
        if (create_table->table)
1602
1573
        {
1627
1598
            it preparable for open. But let us do close_temporary_table() here
1628
1599
            just in case.
1629
1600
          */
1630
 
          session->drop_temporary_table(identifier);
 
1601
          session->open_tables.drop_temporary_table(identifier);
1631
1602
        }
1632
1603
      }
1633
1604
    }
1686
1657
    if (identifier.isTmp())
1687
1658
      m_plock= &m_lock;
1688
1659
    else
1689
 
      m_plock= &session->extra_lock;
 
1660
      m_plock= &session->open_tables.extra_lock;
1690
1661
 
1691
1662
    *m_plock= extra_lock;
1692
1663
  }
1724
1695
  table->cursor->ha_start_bulk_insert((ha_rows) 0);
1725
1696
  session->setAbortOnWarning(not info.ignore);
1726
1697
  if (check_that_all_fields_are_given_values(session, table, table_list))
1727
 
    return(1);
 
1698
    return 1;
1728
1699
 
1729
1700
  table->mark_columns_needed_for_insert();
1730
1701
  table->cursor->extra(HA_EXTRA_WRITE_CACHE);
1731
 
  return(0);
 
1702
  return 0;
1732
1703
}
1733
1704
 
1734
1705
void select_create::store_values(List<Item> &values)
1768
1739
    */
1769
1740
    if (!table->getShare()->getType())
1770
1741
    {
1771
 
      TransactionServices &transaction_services= TransactionServices::singleton();
1772
 
      transaction_services.autocommitOrRollback(*session, 0);
 
1742
      TransactionServices::autocommitOrRollback(*session, 0);
1773
1743
      (void) session->endActiveTransaction();
1774
1744
    }
1775
1745