~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_delete.cc

  • Committer: Lee Bieber
  • Date: 2010-12-23 23:11:00 UTC
  • mfrom: (2024.1.1 clean)
  • Revision ID: kalebral@gmail.com-20101223231100-0rqirgz7ugkl10yp
Merge Brian - session list cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
  end of dispatch_command().
44
44
*/
45
45
 
46
 
bool delete_query(Session *session, TableList *table_list, COND *conds,
 
46
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
47
47
                  SQL_LIST *order, ha_rows limit, uint64_t,
48
48
                  bool reset_auto_increment)
49
49
{
71
71
  session->set_proc_info("init");
72
72
  table->map=1;
73
73
 
74
 
  if (prepare_delete(session, table_list, &conds))
 
74
  if (mysql_prepare_delete(session, table_list, &conds))
75
75
  {
76
76
    DRIZZLE_DELETE_DONE(1, 0);
77
77
    return true;
173
173
    delete select;
174
174
    free_underlaid_joins(session, select_lex);
175
175
    session->row_count_func= 0;
176
 
    if (session->is_error())
177
 
      return true;
178
176
    DRIZZLE_DELETE_DONE(0, 0);
179
177
    /**
180
178
     * Resetting the Diagnostic area to prevent
181
179
     * lp bug# 439719
182
180
     */
183
181
    session->main_da.reset_diagnostics_area();
184
 
    session->my_ok((ha_rows) session->rowCount());
 
182
    session->my_ok((ha_rows) session->row_count_func);
185
183
    /*
186
184
      We don't need to call reset_auto_increment in this case, because
187
185
      mysql_truncate always gives a NULL conds argument, hence we never
243
241
 
244
242
  if (usable_index==MAX_KEY)
245
243
  {
246
 
    if ((error= info.init_read_record(session,table,select,1,1)))
247
 
    {
248
 
      table->print_error(error, MYF(0));
249
 
      delete select;
250
 
      free_underlaid_joins(session, select_lex);
251
 
      return true;
252
 
    }
 
244
    info.init_read_record(session,table,select,1,1);
253
245
  }
254
246
  else
255
247
  {
256
 
    if ((error= info.init_read_record_idx(session, table, 1, usable_index)))
257
 
    {
258
 
      table->print_error(error, MYF(0));
259
 
      delete select;
260
 
      free_underlaid_joins(session, select_lex);
261
 
      return true;
262
 
    }
 
248
    info.init_read_record_idx(session, table, 1, usable_index);
263
249
  }
264
250
 
265
251
  session->set_proc_info("updating");
347
333
     * lp bug# 439719
348
334
     */
349
335
    session->main_da.reset_diagnostics_area();    
350
 
    session->my_ok((ha_rows) session->rowCount());
 
336
    session->my_ok((ha_rows) session->row_count_func);
351
337
  }
352
338
  session->status_var.deleted_row_count+= deleted;
353
339
 
359
345
  Prepare items in DELETE statement
360
346
 
361
347
  SYNOPSIS
362
 
    prepare_delete()
 
348
    mysql_prepare_delete()
363
349
    session                     - thread handler
364
350
    table_list          - global/local table list
365
351
    conds               - conditions
368
354
    false OK
369
355
    true  error
370
356
*/
371
 
int prepare_delete(Session *session, TableList *table_list, Item **conds)
 
357
int mysql_prepare_delete(Session *session, TableList *table_list, Item **conds)
372
358
{
373
359
  Select_Lex *select_lex= &session->lex->select_lex;
374
360
 
392
378
 
393
379
  if (select_lex->inner_refs_list.elements &&
394
380
    fix_inner_refs(session, all_fields, select_lex, select_lex->ref_pointer_array))
395
 
    return(true);
 
381
    return(-1);
396
382
 
397
383
  return(false);
398
384
}
407
393
  This will work even if the .ISM and .ISD tables are destroyed
408
394
*/
409
395
 
410
 
bool truncate(Session& session, TableList *table_list)
 
396
bool mysql_truncate(Session& session, TableList *table_list)
411
397
{
412
398
  bool error;
413
399
  TransactionServices &transaction_services= TransactionServices::singleton();
415
401
  uint64_t save_options= session.options;
416
402
  table_list->lock_type= TL_WRITE;
417
403
  session.options&= ~(OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT);
418
 
  init_select(session.lex);
419
 
  error= delete_query(&session, table_list, (COND*) 0, (SQL_LIST*) 0,
 
404
  mysql_init_select(session.lex);
 
405
  error= mysql_delete(&session, table_list, (COND*) 0, (SQL_LIST*) 0,
420
406
                      HA_POS_ERROR, 0L, true);
421
407
  /*
422
408
    Safety, in case the engine ignored ha_enable_transaction(false)
423
409
    above. Also clears session->transaction.*.
424
410
  */
425
 
  error= transaction_services.autocommitOrRollback(session, error);
 
411
  error= transaction_services.autocommitOrRollback(&session, error);
426
412
  session.options= save_options;
427
413
 
428
414
  return error;