~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_update.cc

Merge with trunk.

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