~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cursor.cc

  • Committer: Brian Aker
  • Date: 2009-11-18 06:11:12 UTC
  • mfrom: (1220.1.10 staging)
  • Revision ID: brian@gaz-20091118061112-tyf4qrfr5v7i946b
Monty + Brian Merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
  return inited == INDEX ? ha_index_end() : inited == RND ? ha_rnd_end() : 0;
113
113
}
114
114
 
115
 
Cursor::Table_flags Cursor::ha_table_flags() const
 
115
plugin::StorageEngine::Table_flags Cursor::ha_table_flags() const
116
116
{
117
 
  return cached_table_flags;
 
117
  return engine->table_flags();
118
118
}
119
119
 
120
120
void Cursor::ha_start_bulk_insert(ha_rows rows)
218
218
    }
219
219
    else
220
220
      dup_ref=ref+ALIGN_SIZE(ref_length);
221
 
    cached_table_flags= table_flags();
222
221
  }
223
222
  return error;
224
223
}
651
650
  }
652
651
}
653
652
 
654
 
 
655
 
void Cursor::print_keydup_error(uint32_t key_nr, const char *msg)
656
 
{
657
 
  /* Write the duplicated key in the error message */
658
 
  char key[MAX_KEY_LENGTH];
659
 
  String str(key,sizeof(key),system_charset_info);
660
 
 
661
 
  if (key_nr == MAX_KEY)
662
 
  {
663
 
    /* Key is unknown */
664
 
    str.copy("", 0, system_charset_info);
665
 
    my_printf_error(ER_DUP_ENTRY, msg, MYF(0), str.c_ptr(), "*UNKNOWN*");
666
 
  }
667
 
  else
668
 
  {
669
 
    /* Table is opened and defined at this point */
670
 
    key_unpack(&str,table,(uint32_t) key_nr);
671
 
    uint32_t max_length=DRIZZLE_ERRMSG_SIZE-(uint32_t) strlen(msg);
672
 
    if (str.length() >= max_length)
673
 
    {
674
 
      str.length(max_length-4);
675
 
      str.append(STRING_WITH_LEN("..."));
676
 
    }
677
 
    my_printf_error(ER_DUP_ENTRY, msg,
678
 
                    MYF(0), str.c_ptr(), table->key_info[key_nr].name);
679
 
  }
680
 
}
681
 
 
682
 
 
683
 
/**
684
 
  Print error that we got from Cursor function.
685
 
 
686
 
  @note
687
 
    In case of delete table it's only safe to use the following parts of
688
 
    the 'table' structure:
689
 
    - table->s->path
690
 
    - table->alias
691
 
*/
692
 
void Cursor::print_error(int error, myf errflag)
693
 
{
694
 
  int textno= ER_GET_ERRNO;
695
 
  switch (error) {
696
 
  case EACCES:
697
 
    textno=ER_OPEN_AS_READONLY;
698
 
    break;
699
 
  case EAGAIN:
700
 
    textno=ER_FILE_USED;
701
 
    break;
702
 
  case ENOENT:
703
 
    textno=ER_FILE_NOT_FOUND;
704
 
    break;
705
 
  case HA_ERR_KEY_NOT_FOUND:
706
 
  case HA_ERR_NO_ACTIVE_RECORD:
707
 
  case HA_ERR_END_OF_FILE:
708
 
    textno=ER_KEY_NOT_FOUND;
709
 
    break;
710
 
  case HA_ERR_WRONG_MRG_TABLE_DEF:
711
 
    textno=ER_WRONG_MRG_TABLE;
712
 
    break;
713
 
  case HA_ERR_FOUND_DUPP_KEY:
714
 
  {
715
 
    uint32_t key_nr=get_dup_key(error);
716
 
    if ((int) key_nr >= 0)
717
 
    {
718
 
      print_keydup_error(key_nr, ER(ER_DUP_ENTRY_WITH_KEY_NAME));
719
 
      return;
720
 
    }
721
 
    textno=ER_DUP_KEY;
722
 
    break;
723
 
  }
724
 
  case HA_ERR_FOREIGN_DUPLICATE_KEY:
725
 
  {
726
 
    uint32_t key_nr= get_dup_key(error);
727
 
    if ((int) key_nr >= 0)
728
 
    {
729
 
      uint32_t max_length;
730
 
      /* Write the key in the error message */
731
 
      char key[MAX_KEY_LENGTH];
732
 
      String str(key,sizeof(key),system_charset_info);
733
 
      /* Table is opened and defined at this point */
734
 
      key_unpack(&str,table,(uint32_t) key_nr);
735
 
      max_length= (DRIZZLE_ERRMSG_SIZE-
736
 
                   (uint32_t) strlen(ER(ER_FOREIGN_DUPLICATE_KEY)));
737
 
      if (str.length() >= max_length)
738
 
      {
739
 
        str.length(max_length-4);
740
 
        str.append(STRING_WITH_LEN("..."));
741
 
      }
742
 
      my_error(ER_FOREIGN_DUPLICATE_KEY, MYF(0), table_share->table_name.str,
743
 
        str.c_ptr(), key_nr+1);
744
 
      return;
745
 
    }
746
 
    textno= ER_DUP_KEY;
747
 
    break;
748
 
  }
749
 
  case HA_ERR_FOUND_DUPP_UNIQUE:
750
 
    textno=ER_DUP_UNIQUE;
751
 
    break;
752
 
  case HA_ERR_RECORD_CHANGED:
753
 
    textno=ER_CHECKREAD;
754
 
    break;
755
 
  case HA_ERR_CRASHED:
756
 
    textno=ER_NOT_KEYFILE;
757
 
    break;
758
 
  case HA_ERR_WRONG_IN_RECORD:
759
 
    textno= ER_CRASHED_ON_USAGE;
760
 
    break;
761
 
  case HA_ERR_CRASHED_ON_USAGE:
762
 
    textno=ER_CRASHED_ON_USAGE;
763
 
    break;
764
 
  case HA_ERR_NOT_A_TABLE:
765
 
    textno= error;
766
 
    break;
767
 
  case HA_ERR_CRASHED_ON_REPAIR:
768
 
    textno=ER_CRASHED_ON_REPAIR;
769
 
    break;
770
 
  case HA_ERR_OUT_OF_MEM:
771
 
    textno=ER_OUT_OF_RESOURCES;
772
 
    break;
773
 
  case HA_ERR_WRONG_COMMAND:
774
 
    textno=ER_ILLEGAL_HA;
775
 
    break;
776
 
  case HA_ERR_OLD_FILE:
777
 
    textno=ER_OLD_KEYFILE;
778
 
    break;
779
 
  case HA_ERR_UNSUPPORTED:
780
 
    textno=ER_UNSUPPORTED_EXTENSION;
781
 
    break;
782
 
  case HA_ERR_RECORD_FILE_FULL:
783
 
  case HA_ERR_INDEX_FILE_FULL:
784
 
    textno=ER_RECORD_FILE_FULL;
785
 
    break;
786
 
  case HA_ERR_LOCK_WAIT_TIMEOUT:
787
 
    textno=ER_LOCK_WAIT_TIMEOUT;
788
 
    break;
789
 
  case HA_ERR_LOCK_TABLE_FULL:
790
 
    textno=ER_LOCK_TABLE_FULL;
791
 
    break;
792
 
  case HA_ERR_LOCK_DEADLOCK:
793
 
    textno=ER_LOCK_DEADLOCK;
794
 
    break;
795
 
  case HA_ERR_READ_ONLY_TRANSACTION:
796
 
    textno=ER_READ_ONLY_TRANSACTION;
797
 
    break;
798
 
  case HA_ERR_CANNOT_ADD_FOREIGN:
799
 
    textno=ER_CANNOT_ADD_FOREIGN;
800
 
    break;
801
 
  case HA_ERR_ROW_IS_REFERENCED:
802
 
  {
803
 
    String str;
804
 
    get_error_message(error, &str);
805
 
    my_error(ER_ROW_IS_REFERENCED_2, MYF(0), str.c_ptr_safe());
806
 
    return;
807
 
  }
808
 
  case HA_ERR_NO_REFERENCED_ROW:
809
 
  {
810
 
    String str;
811
 
    get_error_message(error, &str);
812
 
    my_error(ER_NO_REFERENCED_ROW_2, MYF(0), str.c_ptr_safe());
813
 
    return;
814
 
  }
815
 
  case HA_ERR_TABLE_DEF_CHANGED:
816
 
    textno=ER_TABLE_DEF_CHANGED;
817
 
    break;
818
 
  case HA_ERR_NO_SUCH_TABLE:
819
 
    my_error(ER_NO_SUCH_TABLE, MYF(0), table_share->db.str,
820
 
             table_share->table_name.str);
821
 
    return;
822
 
  case HA_ERR_RBR_LOGGING_FAILED:
823
 
    textno= ER_BINLOG_ROW_LOGGING_FAILED;
824
 
    break;
825
 
  case HA_ERR_DROP_INDEX_FK:
826
 
  {
827
 
    const char *ptr= "???";
828
 
    uint32_t key_nr= get_dup_key(error);
829
 
    if ((int) key_nr >= 0)
830
 
      ptr= table->key_info[key_nr].name;
831
 
    my_error(ER_DROP_INDEX_FK, MYF(0), ptr);
832
 
    return;
833
 
  }
834
 
  case HA_ERR_TABLE_NEEDS_UPGRADE:
835
 
    textno=ER_TABLE_NEEDS_UPGRADE;
836
 
    break;
837
 
  case HA_ERR_TABLE_READONLY:
838
 
    textno= ER_OPEN_AS_READONLY;
839
 
    break;
840
 
  case HA_ERR_AUTOINC_READ_FAILED:
841
 
    textno= ER_AUTOINC_READ_FAILED;
842
 
    break;
843
 
  case HA_ERR_AUTOINC_ERANGE:
844
 
    textno= ER_WARN_DATA_OUT_OF_RANGE;
845
 
    break;
846
 
  case HA_ERR_LOCK_OR_ACTIVE_TRANSACTION:
847
 
    my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
848
 
               ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
849
 
    return;
850
 
  default:
851
 
    {
852
 
      /* 
853
 
        The error was "unknown" to this function.
854
 
        Ask Cursor if it has got a message for this error 
855
 
      */
856
 
      bool temporary= false;
857
 
      String str;
858
 
      temporary= get_error_message(error, &str);
859
 
      if (!str.is_empty())
860
 
      {
861
 
        const char* engine_name= engine->getName().c_str();
862
 
        if (temporary)
863
 
          my_error(ER_GET_TEMPORARY_ERRMSG, MYF(0), error, str.ptr(),
864
 
                   engine_name);
865
 
        else
866
 
          my_error(ER_GET_ERRMSG, MYF(0), error, str.ptr(), engine_name);
867
 
      }
868
 
      else
869
 
      {
870
 
              my_error(ER_GET_ERRNO,errflag,error);
871
 
      }
872
 
      return;
873
 
    }
874
 
  }
875
 
  my_error(textno, errflag, table_share->table_name.str, error);
876
 
}
877
 
 
878
 
 
879
 
/**
880
 
  Return an error message specific to this Cursor.
881
 
 
882
 
  @param error  error code previously returned by Cursor
883
 
  @param buf    pointer to String where to add error message
884
 
 
885
 
  @return
886
 
    Returns true if this is a temporary error
887
 
*/
888
 
bool Cursor::get_error_message(int , String* )
889
 
{
890
 
  return false;
891
 
}
892
 
 
893
 
 
894
 
/* Code left, but Drizzle has no legacy yet (while MySQL did) */
895
 
int Cursor::check_old_types()
896
 
{
897
 
  return 0;
898
 
}
899
 
 
900
 
/**
901
 
  @return
902
 
    key if error because of duplicated keys
903
 
*/
904
 
uint32_t Cursor::get_dup_key(int error)
905
 
{
906
 
  table->cursor->errkey  = (uint32_t) -1;
907
 
  if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
908
 
      error == HA_ERR_FOUND_DUPP_UNIQUE ||
909
 
      error == HA_ERR_DROP_INDEX_FK)
910
 
    info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK);
911
 
  return(table->cursor->errkey);
912
 
}
913
 
 
914
653
void Cursor::drop_table(const char *)
915
654
{
916
655
  close();
1720
1459
 
1721
1460
  int error= external_lock(session, lock_type);
1722
1461
 
1723
 
  if (error == 0)
1724
 
    cached_table_flags= table_flags();
1725
1462
  return error;
1726
1463
}
1727
1464