~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_update.cc

  • Committer: Monty Taylor
  • Date: 2008-07-05 11:38:34 UTC
  • mfrom: (60 drizzle)
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: monty@inaugust.com-20080705113834-23bn0884hk8pqfu9
MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
  if (memcmp(table->null_flags,
33
33
             table->null_flags+table->s->rec_buff_length,
34
34
             table->s->null_bytes))
35
 
    return TRUE;                                // Diff in NULL value
 
35
    return true;                                // Diff in NULL value
36
36
  /* Compare updated fields */
37
37
  for (Field **ptr= table->field ; *ptr ; ptr++)
38
38
  {
39
39
    if (bitmap_is_set(table->write_set, (*ptr)->field_index) &&
40
40
        (*ptr)->cmp_binary_offset(table->s->rec_buff_length))
41
 
      return TRUE;
 
41
      return true;
42
42
  }
43
 
  return FALSE;
 
43
  return false;
44
44
}
45
45
 
46
46
 
53
53
    items           Items for check
54
54
 
55
55
  RETURN
56
 
    TRUE  Items can't be used in UPDATE
57
 
    FALSE Items are OK
 
56
    true  Items can't be used in UPDATE
 
57
    false Items are OK
58
58
*/
59
59
 
60
60
static bool check_fields(THD *thd, List<Item> &items)
69
69
    {
70
70
      /* item has name, because it comes from VIEW SELECT list */
71
71
      my_error(ER_NONUPDATEABLE_COLUMN, MYF(0), item->name);
72
 
      return TRUE;
 
72
      return true;
73
73
    }
74
74
    /*
75
75
      we make temporary copy of Item_field, to avoid influence of changing
77
77
    */
78
78
    thd->change_item_tree(it.ref(), new Item_field(thd, field));
79
79
  }
80
 
  return FALSE;
 
80
  return false;
81
81
}
82
82
 
83
83
 
118
118
    DBUG_VOID_RETURN;
119
119
 
120
120
  /* Create unique_map with all fields used by that index. */
121
 
  bitmap_init(&unique_map, unique_map_buf, table->s->fields, FALSE);
 
121
  bitmap_init(&unique_map, unique_map_buf, table->s->fields, false);
122
122
  table->mark_columns_used_by_index_no_reset(keynr, &unique_map);
123
123
 
124
124
  /* Subtract read_set and write_set. */
186
186
  bool          can_compare_record;
187
187
  int           error, loc_error;
188
188
  uint          used_index= MAX_KEY, dup_key_found;
189
 
  bool          need_sort= TRUE;
 
189
  bool          need_sort= true;
190
190
  uint          table_count= 0;
191
191
  ha_rows       updated, found;
192
192
  key_map       old_covering_keys;
299
299
  if (!select && limit != HA_POS_ERROR)
300
300
  {
301
301
    if ((used_index= get_index_for_order(table, order, limit)) != MAX_KEY)
302
 
      need_sort= FALSE;
 
302
      need_sort= false;
303
303
  }
304
304
  /* If running in safe sql mode, don't allow updates without keys */
305
305
  if (table->quick_keys.is_clear_all())
676
676
  table->file->try_semi_consistent_read(0);
677
677
 
678
678
  if (!transactional_table && updated > 0)
679
 
    thd->transaction.stmt.modified_non_trans_table= TRUE;
 
679
    thd->transaction.stmt.modified_non_trans_table= true;
680
680
 
681
681
  end_read_record(&info);
682
682
  delete select;
700
700
        thd->clear_error();
701
701
      if (thd->binlog_query(THD::ROW_QUERY_TYPE,
702
702
                            thd->query, thd->query_length,
703
 
                            transactional_table, FALSE, killed_status) &&
 
703
                            transactional_table, false, killed_status) &&
704
704
          transactional_table)
705
705
      {
706
706
        error=1;                                // Rollback update
707
707
      }
708
708
    }
709
709
    if (thd->transaction.stmt.modified_non_trans_table)
710
 
      thd->transaction.all.modified_non_trans_table= TRUE;
 
710
      thd->transaction.all.modified_non_trans_table= true;
711
711
  }
712
712
  DBUG_ASSERT(transactional_table || !updated || thd->transaction.stmt.modified_non_trans_table);
713
713
  free_underlaid_joins(thd, select_lex);
758
758
    order               - ORDER BY clause list
759
759
 
760
760
  RETURN VALUE
761
 
    FALSE OK
762
 
    TRUE  error
 
761
    false OK
 
762
    true  error
763
763
*/
764
764
bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
765
765
                         Item **conds, uint order_num, ORDER *order)
794
794
      select_lex->setup_ref_array(thd, order_num) ||
795
795
      setup_order(thd, select_lex->ref_pointer_array,
796
796
                  table_list, all_fields, all_fields, order))
797
 
    DBUG_RETURN(TRUE);
 
797
    DBUG_RETURN(true);
798
798
 
799
799
  /* Check that we are not using table that we are updating in a sub select */
800
800
  {
803
803
    {
804
804
      update_non_unique_table_error(table_list, "UPDATE", duplicate);
805
805
      my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name);
806
 
      DBUG_RETURN(TRUE);
 
806
      DBUG_RETURN(true);
807
807
    }
808
808
  }
809
809
  select_lex->fix_prepare_information(thd, conds, &fake_conds);
810
 
  DBUG_RETURN(FALSE);
 
810
  DBUG_RETURN(false);
811
811
}
812
812
 
813
813
 
840
840
    thd         thread handler
841
841
 
842
842
  RETURN
843
 
    FALSE OK
844
 
    TRUE  Error
 
843
    false OK
 
844
    true  Error
845
845
*/
846
846
 
847
847
int mysql_multi_update_prepare(THD *thd)
860
860
  uint  table_count= lex->table_count;
861
861
  const bool using_lock_tables= thd->locked_tables != 0;
862
862
  bool original_multiupdate= (thd->lex->sql_command == SQLCOM_UPDATE_MULTI);
863
 
  bool need_reopen= FALSE;
 
863
  bool need_reopen= false;
864
864
  DBUG_ENTER("mysql_multi_update_prepare");
865
865
 
866
866
  /* following need for prepared statements, to run next time multi-update */
872
872
  if (((original_multiupdate || need_reopen) &&
873
873
       open_tables(thd, &table_list, &table_count, 0)) ||
874
874
      mysql_handle_derived(lex, &mysql_derived_prepare))
875
 
    DBUG_RETURN(TRUE);
 
875
    DBUG_RETURN(true);
876
876
  /*
877
877
    setup_tables() need for VIEWs. JOIN::prepare() will call setup_tables()
878
878
    second time, but this call will do nothing (there are check for second
883
883
                                    &lex->select_lex.top_join_list,
884
884
                                    table_list,
885
885
                                    &lex->select_lex.leaf_tables, false))
886
 
    DBUG_RETURN(TRUE);
 
886
    DBUG_RETURN(true);
887
887
 
888
888
  if (setup_fields_with_no_wrap(thd, 0, *fields, MARK_COLUMNS_WRITE, 0, 0))
889
 
    DBUG_RETURN(TRUE);
 
889
    DBUG_RETURN(true);
890
890
 
891
891
  if (update_view && check_fields(thd, *fields))
892
892
  {
893
 
    DBUG_RETURN(TRUE);
 
893
    DBUG_RETURN(true);
894
894
  }
895
895
 
896
896
  tables_for_update= get_table_map(fields);
938
938
  if (lock_tables(thd, table_list, table_count, &need_reopen))
939
939
  {
940
940
    if (!need_reopen)
941
 
      DBUG_RETURN(TRUE);
 
941
      DBUG_RETURN(true);
942
942
 
943
943
    /*
944
944
      We have to reopen tables since some of them were altered or dropped
963
963
    Check that we are not using table that we are updating, but we should
964
964
    skip all tables of UPDATE SELECT itself
965
965
  */
966
 
  lex->select_lex.exclude_from_table_unique_test= TRUE;
 
966
  lex->select_lex.exclude_from_table_unique_test= true;
967
967
  /* We only need SELECT privilege for columns in the values list */
968
968
  for (tl= leaves; tl; tl= tl->next_leaf)
969
969
  {
974
974
      if ((duplicate= unique_table(thd, tl, table_list, 0)))
975
975
      {
976
976
        update_non_unique_table_error(table_list, "UPDATE", duplicate);
977
 
        DBUG_RETURN(TRUE);
 
977
        DBUG_RETURN(true);
978
978
      }
979
979
    }
980
980
  }
981
981
  /*
982
 
    Set exclude_from_table_unique_test value back to FALSE. It is needed for
 
982
    Set exclude_from_table_unique_test value back to false. It is needed for
983
983
    further check in multi_update::prepare whether to use record cache.
984
984
  */
985
 
  lex->select_lex.exclude_from_table_unique_test= FALSE;
 
985
  lex->select_lex.exclude_from_table_unique_test= false;
986
986
 
987
987
  if (thd->fill_derived_tables() &&
988
988
      mysql_handle_derived(lex, &mysql_derived_filling))
989
 
    DBUG_RETURN(TRUE);
 
989
    DBUG_RETURN(true);
990
990
 
991
 
  DBUG_RETURN (FALSE);
 
991
  DBUG_RETURN (false);
992
992
}
993
993
 
994
994
 
1013
1013
                                 thd->lex->select_lex.leaf_tables,
1014
1014
                                 fields, values,
1015
1015
                                 handle_duplicates, ignore)))
1016
 
    DBUG_RETURN(TRUE);
 
1016
    DBUG_RETURN(true);
1017
1017
 
1018
1018
  thd->abort_on_warning= test(thd->variables.sql_mode &
1019
1019
                              (MODE_STRICT_TRANS_TABLES |
1039
1039
  }
1040
1040
  delete result;
1041
1041
  thd->abort_on_warning= 0;
1042
 
  DBUG_RETURN(FALSE);
 
1042
  DBUG_RETURN(false);
1043
1043
}
1044
1044
 
1045
1045
 
1204
1204
  case JT_SYSTEM:
1205
1205
  case JT_CONST:
1206
1206
  case JT_EQ_REF:
1207
 
    return TRUE;                                // At most one matching row
 
1207
    return true;                                // At most one matching row
1208
1208
  case JT_REF:
1209
1209
  case JT_REF_OR_NULL:
1210
1210
    return !is_key_used(table, join_tab->ref.key, table->write_set);
1216
1216
    if ((table->file->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) &&
1217
1217
        table->s->primary_key < MAX_KEY)
1218
1218
      return !is_key_used(table, table->s->primary_key, table->write_set);
1219
 
    return TRUE;
 
1219
    return true;
1220
1220
  default:
1221
1221
    break;                                      // Avoid compler warning
1222
1222
  }
1223
 
  return FALSE;
 
1223
  return false;
1224
1224
 
1225
1225
}
1226
1226
 
1447
1447
          else
1448
1448
          {
1449
1449
            trans_safe= 0;
1450
 
            thd->transaction.stmt.modified_non_trans_table= TRUE;
 
1450
            thd->transaction.stmt.modified_non_trans_table= true;
1451
1451
          }
1452
1452
        }
1453
1453
      }
1543
1543
      */
1544
1544
      thd->binlog_query(THD::ROW_QUERY_TYPE,
1545
1545
                        thd->query, thd->query_length,
1546
 
                        transactional_tables, FALSE);
 
1546
                        transactional_tables, false);
1547
1547
    }
1548
 
    thd->transaction.all.modified_non_trans_table= TRUE;
 
1548
    thd->transaction.all.modified_non_trans_table= true;
1549
1549
  }
1550
1550
  DBUG_ASSERT(trans_safe || !updated || thd->transaction.stmt.modified_non_trans_table);
1551
1551
}
1666
1666
      else
1667
1667
      {
1668
1668
        trans_safe= 0;                          // Can't do safe rollback
1669
 
        thd->transaction.stmt.modified_non_trans_table= TRUE;
 
1669
        thd->transaction.stmt.modified_non_trans_table= true;
1670
1670
      }
1671
1671
    }
1672
1672
    (void) table->file->ha_rnd_end();
1697
1697
    else
1698
1698
    {
1699
1699
      trans_safe= 0;
1700
 
      thd->transaction.stmt.modified_non_trans_table= TRUE;
 
1700
      thd->transaction.stmt.modified_non_trans_table= true;
1701
1701
    }
1702
1702
  }
1703
1703
  DBUG_RETURN(1);
1745
1745
        thd->clear_error();
1746
1746
      if (thd->binlog_query(THD::ROW_QUERY_TYPE,
1747
1747
                            thd->query, thd->query_length,
1748
 
                            transactional_tables, FALSE, killed_status) &&
 
1748
                            transactional_tables, false, killed_status) &&
1749
1749
          trans_safe)
1750
1750
      {
1751
1751
        local_error= 1;                         // Rollback update
1752
1752
      }
1753
1753
    }
1754
1754
    if (thd->transaction.stmt.modified_non_trans_table)
1755
 
      thd->transaction.all.modified_non_trans_table= TRUE;
 
1755
      thd->transaction.all.modified_non_trans_table= true;
1756
1756
  }
1757
1757
  if (local_error != 0)
1758
 
    error_handled= TRUE; // to force early leave from ::send_error()
 
1758
    error_handled= true; // to force early leave from ::send_error()
1759
1759
 
1760
1760
  if (local_error > 0) // if the above log write did not fail ...
1761
1761
  {
1762
1762
    /* Safety: If we haven't got an error before (can happen in do_updates) */
1763
1763
    my_message(ER_UNKNOWN_ERROR, "An error occured in multi-table update",
1764
1764
               MYF(0));
1765
 
    DBUG_RETURN(TRUE);
 
1765
    DBUG_RETURN(true);
1766
1766
  }
1767
1767
 
1768
1768
  id= thd->arg_of_last_insert_id_function ?
1772
1772
  thd->row_count_func=
1773
1773
    (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated;
1774
1774
  ::my_ok(thd, (ulong) thd->row_count_func, id, buff);
1775
 
  DBUG_RETURN(FALSE);
 
1775
  DBUG_RETURN(false);
1776
1776
}