~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

merged with latest trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
#include <algorithm>
50
50
#include <sstream>
51
51
 
 
52
#include <boost/unordered_set.hpp>
 
53
 
52
54
using namespace std;
53
55
 
54
56
namespace drizzled
395
397
    1             Error
396
398
*/
397
399
 
 
400
class typelib_set_member
 
401
{
 
402
public:
 
403
  string s;
 
404
  const CHARSET_INFO * const cs;
 
405
 
 
406
  typelib_set_member(const char* value, unsigned int length,
 
407
                     const CHARSET_INFO * const charset)
 
408
    : s(value, length),
 
409
      cs(charset)
 
410
  {}
 
411
};
 
412
 
 
413
static bool operator==(typelib_set_member const& a, typelib_set_member const& b)
 
414
{
 
415
  return (my_strnncoll(a.cs,
 
416
                       (const unsigned char*)a.s.c_str(), a.s.length(),
 
417
                       (const unsigned char*)b.s.c_str(), b.s.length())==0);
 
418
}
 
419
 
 
420
boost::hash<const typelib_set_member> typelib_set_member_hasher;
 
421
 
 
422
static std::size_t hash_value(const typelib_set_member& t)
 
423
{
 
424
  boost::hash<string> hasher;
 
425
  return hasher(t.s);
 
426
}
 
427
 
398
428
static bool check_duplicates_in_interval(const char *set_or_name,
399
429
                                         const char *name, TYPELIB *typelib,
400
430
                                         const CHARSET_INFO * const cs,
405
435
  unsigned int *cur_length= typelib->type_lengths;
406
436
  *dup_val_count= 0;
407
437
 
408
 
  for ( ; tmp.count > 1; cur_value++, cur_length++)
 
438
  boost::unordered_set<typelib_set_member, boost::hash<typelib_set_member> > interval_set;
 
439
 
 
440
  for ( ; tmp.count > 0; cur_value++, cur_length++)
409
441
  {
410
442
    tmp.type_names++;
411
443
    tmp.type_lengths++;
412
444
    tmp.count--;
413
 
    if (find_type2(&tmp, (const char*)*cur_value, *cur_length, cs))
 
445
    if (interval_set.find(typelib_set_member(*cur_value, *cur_length, cs)) != interval_set.end())
414
446
    {
415
447
      my_error(ER_DUPLICATED_VALUE_IN_TYPE, MYF(0),
416
448
               name,*cur_value,set_or_name);
417
449
      return 1;
418
450
    }
 
451
    else
 
452
      interval_set.insert(typelib_set_member(*cur_value, *cur_length, cs));
419
453
  }
420
454
  return 0;
421
455
}
488
522
 
489
523
  switch (sql_field->sql_type) {
490
524
  case DRIZZLE_TYPE_BLOB:
491
 
    sql_field->pack_flag= pack_length_to_packflag(sql_field->pack_length - portable_sizeof_char_ptr);
492
525
    sql_field->length= 8; // Unireg field length
493
526
    (*blob_columns)++;
494
527
    break;
495
528
  case DRIZZLE_TYPE_VARCHAR:
496
 
    sql_field->pack_flag=0;
497
529
    break;
498
530
  case DRIZZLE_TYPE_ENUM:
499
 
    sql_field->pack_flag=pack_length_to_packflag(sql_field->pack_length);
500
531
    if (check_duplicates_in_interval("ENUM",
501
532
                                     sql_field->field_name,
502
533
                                     sql_field->interval,
507
538
  case DRIZZLE_TYPE_DATE:  // Rest of string types
508
539
  case DRIZZLE_TYPE_DATETIME:
509
540
  case DRIZZLE_TYPE_NULL:
510
 
    sql_field->pack_flag=f_settype((uint32_t) sql_field->sql_type);
511
541
    break;
512
542
  case DRIZZLE_TYPE_DECIMAL:
513
 
    sql_field->pack_flag= 0;
514
543
    break;
515
544
  case DRIZZLE_TYPE_TIMESTAMP:
516
545
    /* We should replace old TIMESTAMP fields with their newer analogs */
522
551
        (*timestamps_with_niladic)++;
523
552
      }
524
553
      else
 
554
      {
525
555
        sql_field->unireg_check= Field::NONE;
 
556
      }
526
557
    }
527
558
    else if (sql_field->unireg_check != Field::NONE)
528
559
      (*timestamps_with_niladic)++;
530
561
    (*timestamps)++;
531
562
    /* fall-through */
532
563
  default:
533
 
    sql_field->pack_flag=(0 |
534
 
                          f_settype((uint32_t) sql_field->sql_type));
535
564
    break;
536
565
  }
 
566
 
537
567
  return 0;
538
568
}
539
569
 
1060
1090
 
1061
1091
      key_part_info->fieldnr= field;
1062
1092
      key_part_info->offset=  (uint16_t) sql_field->offset;
1063
 
      key_part_info->key_type=sql_field->pack_flag;
 
1093
      key_part_info->key_type= 0;
1064
1094
      length= sql_field->key_length;
1065
1095
 
1066
1096
      if (column->length)
1602
1632
 
1603
1633
  SYNOPSIS
1604
1634
    mysql_rename_table()
 
1635
      session
1605
1636
      base                      The plugin::StorageEngine handle.
1606
1637
      old_db                    The old database name.
1607
1638
      old_name                  The old table name.
1614
1645
*/
1615
1646
 
1616
1647
bool
1617
 
mysql_rename_table(plugin::StorageEngine *base,
 
1648
mysql_rename_table(Session &session,
 
1649
                   plugin::StorageEngine *base,
1618
1650
                   TableIdentifier &from,
1619
1651
                   TableIdentifier &to)
1620
1652
{
1621
 
  Session *session= current_session;
1622
1653
  int error= 0;
1623
1654
 
1624
1655
  assert(base);
1629
1660
    return true;
1630
1661
  }
1631
1662
 
1632
 
  error= base->renameTable(*session, from, to);
 
1663
  error= base->renameTable(session, from, to);
1633
1664
 
1634
1665
  if (error == HA_ERR_WRONG_COMMAND)
1635
1666
  {
1825
1856
    }
1826
1857
 
1827
1858
    /* Close all instances of the table to allow repair to rename files */
1828
 
    if (lock_type == TL_WRITE && table->table->getShare()->version)
 
1859
    if (lock_type == TL_WRITE && table->table->getShare()->getVersion())
1829
1860
    {
1830
1861
      pthread_mutex_lock(&LOCK_open); /* Lock type is TL_WRITE and we lock to repair the table */
1831
1862
      const char *old_message=session->enter_cond(&COND_refresh, &LOCK_open,
1923
1954
    if (table->table)
1924
1955
    {
1925
1956
      if (fatal_error)
1926
 
        table->table->getMutableShare()->version=0;               // Force close of table
 
1957
      {
 
1958
        table->table->getMutableShare()->resetVersion();               // Force close of table
 
1959
      }
1927
1960
      else if (open_for_modify)
1928
1961
      {
1929
1962
        if (table->table->getShare()->tmp_table)
 
1963
        {
1930
1964
          table->table->cursor->info(HA_STATUS_CONST);
 
1965
        }
1931
1966
        else
1932
1967
        {
1933
1968
          pthread_mutex_lock(&LOCK_open);