~thomir-deactivatedaccount/drizzle/drizzle-fix-bug653747

« back to all changes in this revision

Viewing changes to server/sql_insert.cc

Merged in Jay's tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
    }
99
99
 
100
100
    thd->dup_field= 0;
101
 
    select_lex->no_wrap_view_item= TRUE;
 
101
    select_lex->no_wrap_view_item= true;
102
102
 
103
103
    /* Save the state of the current name resolution context. */
104
104
    ctx_state.save_state(context, table_list);
113
113
 
114
114
    /* Restore the current context. */
115
115
    ctx_state.restore_state(context, table_list);
116
 
    thd->lex->select_lex.no_wrap_view_item= FALSE;
 
116
    thd->lex->select_lex.no_wrap_view_item= false;
117
117
 
118
118
    if (res)
119
119
      return -1;
236
236
                  bool ignore)
237
237
{
238
238
  int error;
239
 
  bool transactional_table, joins_freed= FALSE;
 
239
  bool transactional_table, joins_freed= false;
240
240
  bool changed;
241
241
  bool was_insert_delayed= (table_list->lock_type ==  TL_WRITE_DELAYED);
242
242
  uint value_count;
270
270
  {
271
271
    my_error(ER_DELAYED_INSERT_TABLE_LOCKED, MYF(0),
272
272
             table_list->table_name);
273
 
    return(TRUE);
 
273
    return(true);
274
274
  }
275
275
 
276
276
  {
277
277
    if (open_and_lock_tables(thd, table_list))
278
 
      return(TRUE);
 
278
      return(true);
279
279
  }
280
280
  lock_type= table_list->lock_type;
281
281
 
286
286
 
287
287
  if (mysql_prepare_insert(thd, table_list, table, fields, values,
288
288
                           update_fields, update_values, duplic, &unused_conds,
289
 
                           FALSE,
 
289
                           false,
290
290
                           (fields.elements || !value_count ||
291
291
                            (0) != 0), !ignore))
292
292
    goto abort;
429
429
  }
430
430
 
431
431
  free_underlaid_joins(thd, &thd->lex->select_lex);
432
 
  joins_freed= TRUE;
 
432
  joins_freed= true;
433
433
 
434
434
  /*
435
435
    Now all rows are inserted.  Time to update logs and sends response to
492
492
        assert(thd->killed != THD::KILL_BAD_DATA || error > 0);
493
493
        if (thd->binlog_query(THD::ROW_QUERY_TYPE,
494
494
                              thd->query, thd->query_length,
495
 
                              transactional_table, FALSE,
 
495
                              transactional_table, false,
496
496
                              (error>0) ? thd->killed : THD::NOT_KILLED) &&
497
497
            transactional_table)
498
498
        {
500
500
        }
501
501
      }
502
502
      if (thd->transaction.stmt.modified_non_trans_table)
503
 
        thd->transaction.all.modified_non_trans_table= TRUE;
 
503
        thd->transaction.all.modified_non_trans_table= true;
504
504
    }
505
505
    assert(transactional_table || !changed || 
506
506
                thd->transaction.stmt.modified_non_trans_table);
525
525
     table->next_number_field->val_int() : 0));
526
526
  table->next_number_field=0;
527
527
  thd->count_cuted_fields= CHECK_FIELD_IGNORE;
528
 
  table->auto_increment_field_not_null= FALSE;
 
528
  table->auto_increment_field_not_null= false;
529
529
  if (duplic == DUP_REPLACE)
530
530
    table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
531
531
 
555
555
  }
556
556
  thd->abort_on_warning= 0;
557
557
  MYSQL_INSERT_END();
558
 
  return(FALSE);
 
558
  return(false);
559
559
 
560
560
abort:
561
561
  if (table != NULL)
564
564
    free_underlaid_joins(thd, &thd->lex->select_lex);
565
565
  thd->abort_on_warning= 0;
566
566
  MYSQL_INSERT_END();
567
 
  return(TRUE);
 
567
  return(true);
568
568
}
569
569
 
570
570
 
580
580
     select_insert      Check is making for SELECT ... INSERT
581
581
 
582
582
   RETURN
583
 
     FALSE ok
584
 
     TRUE  ERROR
 
583
     false ok
 
584
     true  ERROR
585
585
*/
586
586
 
587
587
static bool mysql_prepare_insert_check_table(THD *thd, TABLE_LIST *table_list,
602
602
                                    table_list,
603
603
                                    &thd->lex->select_lex.leaf_tables,
604
604
                                    select_insert))
605
 
    return(TRUE);
 
605
    return(true);
606
606
 
607
 
  return(FALSE);
 
607
  return(false);
608
608
}
609
609
 
610
610
 
618
618
    table               Table to insert into (can be NULL if table should
619
619
                        be taken from table_list->table)    
620
620
    where               Where clause (for insert ... select)
621
 
    select_insert       TRUE if INSERT ... SELECT statement
622
 
    check_fields        TRUE if need to check that all INSERT fields are 
 
621
    select_insert       true if INSERT ... SELECT statement
 
622
    check_fields        true if need to check that all INSERT fields are 
623
623
                        given values.
624
624
    abort_on_warning    whether to report if some INSERT field is not 
625
 
                        assigned as an error (TRUE) or as a warning (FALSE).
 
625
                        assigned as an error (true) or as a warning (false).
626
626
 
627
627
  TODO (in far future)
628
628
    In cases of:
635
635
    before releasing the table object.
636
636
  
637
637
  RETURN VALUE
638
 
    FALSE OK
639
 
    TRUE  error
 
638
    false OK
 
639
    true  error
640
640
*/
641
641
 
642
642
bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
681
681
  {
682
682
    /* it should be allocated before Item::fix_fields() */
683
683
    if (table_list->set_insert_values(thd->mem_root))
684
 
      return(TRUE);
 
684
      return(true);
685
685
  }
686
686
 
687
687
  if (mysql_prepare_insert_check_table(thd, table_list, fields, select_insert))
688
 
    return(TRUE);
 
688
    return(true);
689
689
 
690
690
 
691
691
  /* Prepare the fields in the statement. */
721
721
 
722
722
    if (!res && duplic == DUP_UPDATE)
723
723
    {
724
 
      select_lex->no_wrap_view_item= TRUE;
 
724
      select_lex->no_wrap_view_item= true;
725
725
      res= check_update_fields(thd, context->table_list, update_fields, &map);
726
 
      select_lex->no_wrap_view_item= FALSE;
 
726
      select_lex->no_wrap_view_item= false;
727
727
    }
728
728
 
729
729
    /* Restore the current context. */
746
746
    if ((duplicate= unique_table(thd, table_list, table_list->next_global, 1)))
747
747
    {
748
748
      update_non_unique_table_error(table_list, "INSERT", duplicate);
749
 
      return(TRUE);
 
749
      return(true);
750
750
    }
751
751
    select_lex->fix_prepare_information(thd, &fake_conds, &fake_conds);
752
752
    select_lex->first_execution= 0;
753
753
  }
754
754
  if (duplic == DUP_UPDATE || duplic == DUP_REPLACE)
755
755
    table->prepare_for_position();
756
 
  return(FALSE);
 
756
  return(false);
757
757
}
758
758
 
759
759
 
786
786
    then both on update triggers will work instead. Similarly both on
787
787
    delete triggers will be invoked if we will delete conflicting records.
788
788
 
789
 
    Sets thd->transaction.stmt.modified_non_trans_table to TRUE if table which is updated didn't have
 
789
    Sets thd->transaction.stmt.modified_non_trans_table to true if table which is updated didn't have
790
790
    transactions.
791
791
 
792
792
  RETURN VALUE
987
987
            goto err;
988
988
          info->deleted++;
989
989
          if (!table->file->has_transactions())
990
 
            thd->transaction.stmt.modified_non_trans_table= TRUE;
 
990
            thd->transaction.stmt.modified_non_trans_table= true;
991
991
          /* Let us attempt do write_row() once more */
992
992
        }
993
993
      }
1018
1018
  if (key)
1019
1019
    my_safe_afree(key,table->s->max_unique_length,MAX_KEY_LENGTH);
1020
1020
  if (!table->file->has_transactions())
1021
 
    thd->transaction.stmt.modified_non_trans_table= TRUE;
 
1021
    thd->transaction.stmt.modified_non_trans_table= true;
1022
1022
  return(0);
1023
1023
 
1024
1024
err:
1053
1053
        ((*field)->flags & NO_DEFAULT_VALUE_FLAG) &&
1054
1054
        ((*field)->real_type() != MYSQL_TYPE_ENUM))
1055
1055
    {
1056
 
      bool view= FALSE;
 
1056
      bool view= false;
1057
1057
      if (table_list)
1058
1058
      {
1059
1059
        table_list= table_list->top_table();
1084
1084
    thd         thread handler
1085
1085
 
1086
1086
  RETURN
1087
 
    FALSE OK
1088
 
    TRUE  Error
 
1087
    false OK
 
1088
    true  Error
1089
1089
*/
1090
1090
 
1091
1091
bool mysql_insert_select_prepare(THD *thd)
1117
1117
                           lex->query_tables->table, lex->field_list, 0,
1118
1118
                           lex->update_list, lex->value_list,
1119
1119
                           lex->duplicates,
1120
 
                           &select_lex->where, TRUE, FALSE, FALSE))
1121
 
    return(TRUE);
 
1120
                           &select_lex->where, true, false, false))
 
1121
    return(true);
1122
1122
 
1123
1123
  /*
1124
1124
    exclude first table from leaf tables list, because it belong to
1135
1135
       first_select_leaf_table= first_select_leaf_table->next_leaf)
1136
1136
  {}
1137
1137
  select_lex->leaf_tables= first_select_leaf_table;
1138
 
  return(FALSE);
 
1138
  return(false);
1139
1139
}
1140
1140
 
1141
1141
 
1199
1199
    table_list->next_local= 0;
1200
1200
    context->resolve_in_table_list_only(table_list);
1201
1201
 
1202
 
    lex->select_lex.no_wrap_view_item= TRUE;
 
1202
    lex->select_lex.no_wrap_view_item= true;
1203
1203
    res= res || check_update_fields(thd, context->table_list,
1204
1204
                                    *info.update_fields, &map);
1205
 
    lex->select_lex.no_wrap_view_item= FALSE;
 
1205
    lex->select_lex.no_wrap_view_item= false;
1206
1206
    /*
1207
1207
      When we are not using GROUP BY and there are no ungrouped aggregate functions 
1208
1208
      we can refer to other tables in the ON DUPLICATE KEY part.
1338
1338
  if (table)
1339
1339
  {
1340
1340
    table->next_number_field=0;
1341
 
    table->auto_increment_field_not_null= FALSE;
 
1341
    table->auto_increment_field_not_null= false;
1342
1342
    table->file->ha_reset();
1343
1343
  }
1344
1344
  thd->count_cuted_fields= CHECK_FIELD_IGNORE;
1437
1437
      and ha_autocommit_or_rollback.
1438
1438
    */
1439
1439
    if (thd->transaction.stmt.modified_non_trans_table)
1440
 
      thd->transaction.all.modified_non_trans_table= TRUE;
 
1440
      thd->transaction.all.modified_non_trans_table= true;
1441
1441
  }
1442
1442
  assert(trans_table || !changed || 
1443
1443
              thd->transaction.stmt.modified_non_trans_table);
1454
1454
      thd->clear_error();
1455
1455
    thd->binlog_query(THD::ROW_QUERY_TYPE,
1456
1456
                      thd->query, thd->query_length,
1457
 
                      trans_table, FALSE, killed_status);
 
1457
                      trans_table, false, killed_status);
1458
1458
  }
1459
1459
  table->file->ha_release_auto_increment();
1460
1460
 
1518
1518
    {
1519
1519
        if (mysql_bin_log.is_open())
1520
1520
          thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query, thd->query_length,
1521
 
                            transactional_table, FALSE);
 
1521
                            transactional_table, false);
1522
1522
        if (!thd->current_stmt_binlog_row_based && !can_rollback_data())
1523
 
          thd->transaction.all.modified_non_trans_table= TRUE;
 
1523
          thd->transaction.all.modified_non_trans_table= true;
1524
1524
    }
1525
1525
    assert(transactional_table || !changed ||
1526
1526
                thd->transaction.stmt.modified_non_trans_table);
1684
1684
      if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE))
1685
1685
      {
1686
1686
        VOID(pthread_mutex_lock(&LOCK_open));
1687
 
        if (reopen_name_locked_table(thd, create_table, FALSE))
 
1687
        if (reopen_name_locked_table(thd, create_table, false))
1688
1688
        {
1689
1689
          quick_rm_table(create_info->db_type, create_table->db,
1690
1690
                         table_case_name(create_info, create_table->table_name),
1893
1893
 
1894
1894
  thd->binlog_query(THD::STMT_QUERY_TYPE,
1895
1895
                    query.ptr(), query.length(),
1896
 
                    /* is_trans */ TRUE,
1897
 
                    /* suppress_use */ FALSE);
 
1896
                    /* is_trans */ true,
 
1897
                    /* suppress_use */ false);
1898
1898
}
1899
1899
 
1900
1900
void select_create::store_values(List<Item> &values)
1978
1978
  */
1979
1979
  tmp_disable_binlog(thd);
1980
1980
  select_insert::abort();
1981
 
  thd->transaction.stmt.modified_non_trans_table= FALSE;
 
1981
  thd->transaction.stmt.modified_non_trans_table= false;
1982
1982
  reenable_binlog(thd);
1983
1983
 
1984
1984