~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Brian Aker
  • Date: 2009-08-04 03:12:11 UTC
  • mto: (1108.2.1 merge)
  • mto: This revision was merged to the branch mainline in revision 1109.
  • Revision ID: brian@gaz-20090804031211-kgc4ve14cesax4s4
Additional multi-update

Show diffs side-by-side

added added

removed removed

Lines of Context:
2495
2495
  return(false);
2496
2496
}
2497
2497
 
2498
 
/**
2499
 
  Multi delete query pre-check.
2500
 
 
2501
 
  @param session                        Thread handler
2502
 
  @param tables         Global/local table list
2503
 
 
2504
 
  @retval
2505
 
    false OK
2506
 
  @retval
2507
 
    true  error
2508
 
*/
2509
 
 
2510
 
bool multi_delete_precheck(Session *session, TableList *)
2511
 
{
2512
 
  Select_Lex *select_lex= &session->lex->select_lex;
2513
 
  TableList **save_query_tables_own_last= session->lex->query_tables_own_last;
2514
 
 
2515
 
  session->lex->query_tables_own_last= 0;
2516
 
  session->lex->query_tables_own_last= save_query_tables_own_last;
2517
 
 
2518
 
  if ((session->options & OPTION_SAFE_UPDATES) && !select_lex->where)
2519
 
  {
2520
 
    my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,
2521
 
               ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0));
2522
 
    return(true);
2523
 
  }
2524
 
  return(false);
2525
 
}
2526
 
 
2527
 
 
2528
 
/*
2529
 
  Given a table in the source list, find a correspondent table in the
2530
 
  table references list.
2531
 
 
2532
 
  @param lex Pointer to LEX representing multi-delete.
2533
 
  @param src Source table to match.
2534
 
  @param ref Table references list.
2535
 
 
2536
 
  @remark The source table list (tables listed before the FROM clause
2537
 
  or tables listed in the FROM clause before the USING clause) may
2538
 
  contain table names or aliases that must match unambiguously one,
2539
 
  and only one, table in the target table list (table references list,
2540
 
  after FROM/USING clause).
2541
 
 
2542
 
  @return Matching table, NULL otherwise.
2543
 
*/
2544
 
 
2545
 
static TableList *multi_delete_table_match(LEX *, TableList *tbl,
2546
 
                                           TableList *tables)
2547
 
{
2548
 
  TableList *match= NULL;
2549
 
 
2550
 
  for (TableList *elem= tables; elem; elem= elem->next_local)
2551
 
  {
2552
 
    int cmp;
2553
 
 
2554
 
    if (tbl->is_fqtn && elem->is_alias)
2555
 
      continue; /* no match */
2556
 
    if (tbl->is_fqtn && elem->is_fqtn)
2557
 
      cmp= my_strcasecmp(table_alias_charset, tbl->table_name, elem->table_name) ||
2558
 
           strcmp(tbl->db, elem->db);
2559
 
    else if (elem->is_alias)
2560
 
      cmp= my_strcasecmp(table_alias_charset, tbl->alias, elem->alias);
2561
 
    else
2562
 
      cmp= my_strcasecmp(table_alias_charset, tbl->table_name, elem->table_name) ||
2563
 
           strcmp(tbl->db, elem->db);
2564
 
 
2565
 
    if (cmp)
2566
 
      continue;
2567
 
 
2568
 
    if (match)
2569
 
    {
2570
 
      my_error(ER_NONUNIQ_TABLE, MYF(0), elem->alias);
2571
 
      return NULL;
2572
 
    }
2573
 
 
2574
 
    match= elem;
2575
 
  }
2576
 
 
2577
 
  if (!match)
2578
 
    my_error(ER_UNKNOWN_TABLE, MYF(0), tbl->table_name, "MULTI DELETE");
2579
 
 
2580
 
  return(match);
2581
 
}
2582
 
 
2583
 
 
2584
 
/**
2585
 
  Link tables in auxilary table list of multi-delete with corresponding
2586
 
  elements in main table list, and set proper locks for them.
2587
 
 
2588
 
  @param lex   pointer to LEX representing multi-delete
2589
 
 
2590
 
  @retval
2591
 
    false   success
2592
 
  @retval
2593
 
    true    error
2594
 
*/
2595
 
 
2596
 
bool multi_delete_set_locks_and_link_aux_tables(LEX *lex)
2597
 
{
2598
 
  TableList *tables= (TableList*)lex->select_lex.table_list.first;
2599
 
  TableList *target_tbl;
2600
 
 
2601
 
  lex->table_count= 0;
2602
 
 
2603
 
  for (target_tbl= (TableList *)lex->auxiliary_table_list.first;
2604
 
       target_tbl; target_tbl= target_tbl->next_local)
2605
 
  {
2606
 
    lex->table_count++;
2607
 
    /* All tables in aux_tables must be found in FROM PART */
2608
 
    TableList *walk= multi_delete_table_match(lex, target_tbl, tables);
2609
 
    if (!walk)
2610
 
      return(true);
2611
 
    if (!walk->derived)
2612
 
    {
2613
 
      target_tbl->table_name= walk->table_name;
2614
 
      target_tbl->table_name_length= walk->table_name_length;
2615
 
    }
2616
 
    walk->updating= target_tbl->updating;
2617
 
    walk->lock_type= target_tbl->lock_type;
2618
 
    target_tbl->correspondent_table= walk;      // Remember corresponding table
2619
 
  }
2620
 
  return(false);
2621
 
}
2622
 
 
2623
2498
 
2624
2499
/**
2625
2500
  simple INSERT query pre-check.