~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_update.cc

  • Committer: Andrew Hutchings
  • Date: 2010-12-15 18:59:55 UTC
  • mto: This revision was merged to the branch mainline in revision 2006.
  • Revision ID: andrew@linuxjedi.co.uk-20101215185955-q12lkja8hdnpjqg7
Make the test look for drizzleadmin failure instead of success as this test is not possible to fix for success on our FreeBSD 8.0 box

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
/*
18
18
  Single table and multi table updates of tables.
 
19
  Multi-table updates were introduced by Sinisa & Monty
19
20
*/
20
 
 
21
21
#include "config.h"
22
 
 
23
22
#include "drizzled/sql_select.h"
24
23
#include "drizzled/error.h"
25
24
#include "drizzled/probes.h"
26
25
#include "drizzled/sql_base.h"
27
 
#include "drizzled/field/epoch.h"
 
26
#include "drizzled/field/timestamp.h"
28
27
#include "drizzled/sql_parse.h"
29
28
#include "drizzled/optimizer/range.h"
30
29
#include "drizzled/records.h"
32
31
#include "drizzled/internal/iocache.h"
33
32
#include "drizzled/transaction_services.h"
34
33
#include "drizzled/filesort.h"
35
 
#include "drizzled/plugin/storage_engine.h"
36
34
 
37
35
#include <boost/dynamic_bitset.hpp>
38
36
#include <list>
100
98
  /* Copy the newly read columns into the new record. */
101
99
  for (field_p= table->getFields(); (field= *field_p); field_p++)
102
100
  {
103
 
    if (unique_map.test(field->position()))
 
101
    if (unique_map.test(field->field_index))
104
102
    {
105
103
      field->copy_from_tmp(table->getShare()->rec_buff_length);
106
104
    }
114
112
  Process usual UPDATE
115
113
 
116
114
  SYNOPSIS
117
 
    update_query()
 
115
    mysql_update()
118
116
    session                     thread handler
119
117
    fields              fields for update
120
118
    values              values of fields for update
129
127
    1  - error
130
128
*/
131
129
 
132
 
int update_query(Session *session, TableList *table_list,
 
130
int mysql_update(Session *session, TableList *table_list,
133
131
                 List<Item> &fields, List<Item> &values, COND *conds,
134
132
                 uint32_t order_num, Order *order,
135
133
                 ha_rows limit, enum enum_duplicates,
138
136
  bool          using_limit= limit != HA_POS_ERROR;
139
137
  bool          used_key_is_modified;
140
138
  bool          transactional_table;
141
 
  int           error= 0;
 
139
  int           error;
142
140
  uint          used_index= MAX_KEY, dup_key_found;
143
141
  bool          need_sort= true;
144
142
  ha_rows       updated, found;
165
163
  table->covering_keys= table->getShare()->keys_in_use;
166
164
  table->quick_keys.reset();
167
165
 
168
 
  if (prepare_update(session, table_list, &conds, order_num, order))
 
166
  if (mysql_prepare_update(session, table_list, &conds, order_num, order))
169
167
  {
170
168
    DRIZZLE_UPDATE_DONE(1, 0, 0);
171
169
    return 1;
191
189
      if (table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_UPDATE ||
192
190
          table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH)
193
191
      {
194
 
        table->setWriteSet(table->timestamp_field->position());
 
192
        table->setWriteSet(table->timestamp_field->field_index);
195
193
      }
196
194
    }
197
195
  }
208
206
    fix_inner_refs(session, all_fields, select_lex, select_lex->ref_pointer_array))
209
207
  {
210
208
    DRIZZLE_UPDATE_DONE(1, 0, 0);
211
 
    return 1;
 
209
    return -1;
212
210
  }
213
211
 
214
212
  if (conds)
248
246
     */
249
247
    session->main_da.reset_diagnostics_area();
250
248
    free_underlaid_joins(session, select_lex);
251
 
    if (error || session->is_error())
 
249
    if (error)
252
250
    {
253
251
      DRIZZLE_UPDATE_DONE(1, 0, 0);
254
252
      return 1;
365
363
 
366
364
      if (used_index == MAX_KEY || (select && select->quick))
367
365
      {
368
 
        if ((error= info.init_read_record(session, table, select, 0, true)))
369
 
          goto err;
 
366
        info.init_read_record(session, table, select, 0, true);
370
367
      }
371
368
      else
372
369
      {
373
 
        if ((error= info.init_read_record_idx(session, table, 1, used_index)))
374
 
          goto err;
 
370
        info.init_read_record_idx(session, table, 1, used_index);
375
371
      }
376
372
 
377
373
      session->set_proc_info("Searching rows for update");
417
413
      }
418
414
      else
419
415
      {
420
 
        select= new optimizer::SqlSelect();
 
416
        select= new optimizer::SqlSelect;
421
417
        select->head=table;
422
418
      }
423
419
      if (tempfile.reinit_io_cache(internal::READ_CACHE,0L,0,0))
437
433
  if (select && select->quick && select->quick->reset())
438
434
    goto err;
439
435
  table->cursor->try_semi_consistent_read(1);
440
 
  if ((error= info.init_read_record(session, table, select, 0, true)))
441
 
  {
442
 
    goto err;
443
 
  }
 
436
  info.init_read_record(session, table, select, 0, true);
444
437
 
445
438
  updated= found= 0;
446
439
  /*
456
449
  session->set_proc_info("Updating");
457
450
 
458
451
  transactional_table= table->cursor->has_transactions();
459
 
  session->setAbortOnWarning(test(!ignore));
 
452
  session->abort_on_warning= test(!ignore);
460
453
 
461
454
  /*
462
455
    Assure that we can use position()
578
571
     * lp bug# 439719
579
572
     */
580
573
    session->main_da.reset_diagnostics_area();
581
 
    session->my_ok((ulong) session->rowCount(), found, id, buff);
582
 
    session->status_var.updated_row_count+= session->rowCount();
 
574
    session->my_ok((ulong) session->row_count_func, found, id, buff);
 
575
    session->status_var.updated_row_count+= session->row_count_func;
583
576
  }
584
577
  session->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;              /* calc cuted fields */
585
 
  session->setAbortOnWarning(false);
 
578
  session->abort_on_warning= 0;
586
579
  DRIZZLE_UPDATE_DONE((error >= 0 || session->is_error()), found, updated);
587
580
  return ((error >= 0 || session->is_error()) ? 1 : 0);
588
581
 
589
582
err:
590
 
  if (error != 0)
591
 
    table->print_error(error,MYF(0));
592
 
 
593
583
  delete select;
594
584
  free_underlaid_joins(session, select_lex);
595
585
  if (table->key_read)
597
587
    table->key_read=0;
598
588
    table->cursor->extra(HA_EXTRA_NO_KEYREAD);
599
589
  }
600
 
  session->setAbortOnWarning(false);
 
590
  session->abort_on_warning= 0;
601
591
 
602
592
  DRIZZLE_UPDATE_DONE(1, 0, 0);
603
593
  return 1;
607
597
  Prepare items in UPDATE statement
608
598
 
609
599
  SYNOPSIS
610
 
    prepare_update()
 
600
    mysql_prepare_update()
611
601
    session                     - thread handler
612
602
    table_list          - global/local table list
613
603
    conds               - conditions
618
608
    false OK
619
609
    true  error
620
610
*/
621
 
bool prepare_update(Session *session, TableList *table_list,
 
611
bool mysql_prepare_update(Session *session, TableList *table_list,
622
612
                         Item **conds, uint32_t order_num, Order *order)
623
613
{
624
614
  List<Item> all_fields;