~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Jay Pipes
  • Date: 2009-02-04 15:44:25 UTC
  • mfrom: (829 drizzle)
  • mto: This revision was merged to the branch mainline in revision 830.
  • Revision ID: jpipes@serialcoder-20090204154425-th8xfk2ujz2y8xwg
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
#define DRIZZLE_LEX 1
17
17
#include <drizzled/server_includes.h>
18
 
#include <libdrizzle/libdrizzle.h>
 
18
#include <libdrizzleclient/libdrizzle.h>
19
19
#include <mysys/hash.h>
20
20
#include <drizzled/logging.h>
21
21
#include <drizzled/db.h>
962
962
{
963
963
  int res= false;
964
964
  bool need_start_waiting= false; // have protection against global read lock
965
 
  int  up_result= 0;
966
965
  LEX  *lex= session->lex;
967
966
  /* first SELECT_LEX (have special meaning for many of non-SELECTcommands) */
968
967
  SELECT_LEX *select_lex= &lex->select_lex;
1402
1401
  }
1403
1402
  case SQLCOM_UPDATE:
1404
1403
    assert(first_table == all_tables && first_table != 0);
1405
 
    if (update_precheck(session, all_tables))
 
1404
    if ((res= update_precheck(session, all_tables)))
1406
1405
      break;
1407
1406
    assert(select_lex->offset_limit == 0);
1408
1407
    unit->set_limit(select_lex);
1409
 
    res= (up_result= mysql_update(session, all_tables,
1410
 
                                  select_lex->item_list,
1411
 
                                  lex->value_list,
1412
 
                                  select_lex->where,
1413
 
                                  select_lex->order_list.elements,
1414
 
                                  (order_st *) select_lex->order_list.first,
1415
 
                                  unit->select_limit_cnt,
1416
 
                                  lex->duplicates, lex->ignore));
1417
 
    /* mysql_update return 2 if we need to switch to multi-update */
1418
 
    if (up_result != 2)
1419
 
      break;
1420
 
    /* Fall through */
 
1408
    res= mysql_update(session, all_tables,
 
1409
                      select_lex->item_list,
 
1410
                      lex->value_list,
 
1411
                      select_lex->where,
 
1412
                      select_lex->order_list.elements,
 
1413
                      (order_st *) select_lex->order_list.first,
 
1414
                      unit->select_limit_cnt,
 
1415
                      lex->duplicates, lex->ignore);
 
1416
    break;
1421
1417
  case SQLCOM_UPDATE_MULTI:
1422
1418
  {
1423
1419
    assert(first_table == all_tables && first_table != 0);
1424
 
    /* if we switched from normal update, rights are checked */
1425
 
    if (up_result != 2)
1426
 
    {
1427
 
      if ((res= multi_update_precheck(session, all_tables)))
1428
 
        break;
1429
 
    }
1430
 
    else
1431
 
      res= 0;
1432
 
 
1433
 
    res= mysql_multi_update_prepare(session);
1434
 
 
1435
 
    {
1436
 
      if (res)
1437
 
        break;
1438
 
 
1439
 
    }  /* unlikely */
 
1420
    if ((res= update_precheck(session, all_tables)))
 
1421
      break;
 
1422
 
 
1423
    if ((res= mysql_multi_update_prepare(session)))
 
1424
      break;
1440
1425
 
1441
1426
    res= mysql_multi_update(session, all_tables,
1442
1427
                            &select_lex->item_list,
3173
3158
    else
3174
3159
      result= close_cached_tables(session, tables, false, (options & REFRESH_FAST) ?
3175
3160
                                  false : true, false);
3176
 
    my_dbopt_cleanup();
3177
3161
  }
3178
3162
  if (session && (options & REFRESH_STATUS))
3179
3163
    refresh_status(session);
3327
3311
 
3328
3312
 
3329
3313
/**
3330
 
  Multi update query pre-check.
 
3314
  Update query pre-check.
3331
3315
 
3332
3316
  @param session                Thread handler
3333
3317
  @param tables Global/local table list (have to be the same)
3338
3322
    true  Error
3339
3323
*/
3340
3324
 
3341
 
bool multi_update_precheck(Session *session, TableList *)
 
3325
bool update_precheck(Session *session, TableList *)
3342
3326
{
3343
3327
  const char *msg= 0;
3344
3328
  LEX *lex= session->lex;
3345
3329
  SELECT_LEX *select_lex= &lex->select_lex;
3346
3330
 
3347
 
  if (select_lex->item_list.elements != lex->value_list.elements)
 
3331
  if (session->lex->select_lex.item_list.elements != session->lex->value_list.elements)
3348
3332
  {
3349
3333
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
3350
3334
    return(true);
3351
3335
  }
3352
3336
 
3353
 
  if (select_lex->order_list.elements)
3354
 
    msg= "ORDER BY";
3355
 
  else if (select_lex->select_limit)
3356
 
    msg= "LIMIT";
3357
 
  if (msg)
 
3337
  if (session->lex->select_lex.table_list.elements > 1)
3358
3338
  {
3359
 
    my_error(ER_WRONG_USAGE, MYF(0), "UPDATE", msg);
3360
 
    return(true);
 
3339
    if (select_lex->order_list.elements)
 
3340
      msg= "ORDER BY";
 
3341
    else if (select_lex->select_limit)
 
3342
      msg= "LIMIT";
 
3343
    if (msg)
 
3344
    {
 
3345
      my_error(ER_WRONG_USAGE, MYF(0), "UPDATE", msg);
 
3346
      return(true);
 
3347
    }
3361
3348
  }
3362
3349
  return(false);
3363
3350
}
3489
3476
 
3490
3477
 
3491
3478
/**
3492
 
  simple UPDATE query pre-check.
3493
 
 
3494
 
  @param session                Thread handler
3495
 
  @param tables Global table list
3496
 
 
3497
 
  @retval
3498
 
    false OK
3499
 
  @retval
3500
 
    true  Error
3501
 
*/
3502
 
 
3503
 
bool update_precheck(Session *session, TableList *)
3504
 
{
3505
 
  if (session->lex->select_lex.item_list.elements != session->lex->value_list.elements)
3506
 
  {
3507
 
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
3508
 
    return(true);
3509
 
  }
3510
 
  return(false);
3511
 
}
3512
 
 
3513
 
 
3514
 
/**
3515
3479
  simple INSERT query pre-check.
3516
3480
 
3517
3481
  @param session                Thread handler