~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

  • Committer: Brian Aker
  • Date: 2011-01-26 18:29:34 UTC
  • mto: (2122.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 2123.
  • Revision ID: brian@tangent.org-20110126182934-hsboi3ab5105on1g
fix test case along with the error message for TIME.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 * @file This file implements the Field class and API
24
24
 */
25
25
 
26
 
#include <config.h>
 
26
#include "config.h"
27
27
#include <cstdio>
28
28
#include <errno.h>
29
29
#include <float.h>
30
 
#include <drizzled/sql_select.h>
31
 
#include <drizzled/error.h>
32
 
#include <drizzled/field/str.h>
33
 
#include <drizzled/field/num.h>
34
 
#include <drizzled/field/blob.h>
35
 
#include <drizzled/field/boolean.h>
36
 
#include <drizzled/field/enum.h>
37
 
#include <drizzled/field/null.h>
38
 
#include <drizzled/field/date.h>
39
 
#include <drizzled/field/decimal.h>
40
 
#include <drizzled/field/real.h>
41
 
#include <drizzled/field/double.h>
42
 
#include <drizzled/field/int32.h>
43
 
#include <drizzled/field/int64.h>
44
 
#include <drizzled/field/num.h>
45
 
#include <drizzled/field/time.h>
46
 
#include <drizzled/field/epoch.h>
47
 
#include <drizzled/field/datetime.h>
48
 
#include <drizzled/field/microtime.h>
49
 
#include <drizzled/field/varstring.h>
50
 
#include <drizzled/field/uuid.h>
51
 
#include <drizzled/time_functions.h>
52
 
#include <drizzled/internal/m_string.h>
53
 
#include <drizzled/table.h>
54
 
#include <drizzled/util/test.h>
55
 
#include <drizzled/session.h>
56
 
#include <drizzled/current_session.h>
57
 
#include <drizzled/display.h>
58
 
#include <drizzled/typelib.h>
 
30
#include "drizzled/sql_select.h"
 
31
#include "drizzled/error.h"
 
32
#include "drizzled/field/str.h"
 
33
#include "drizzled/field/num.h"
 
34
#include "drizzled/field/blob.h"
 
35
#include "drizzled/field/boolean.h"
 
36
#include "drizzled/field/enum.h"
 
37
#include "drizzled/field/null.h"
 
38
#include "drizzled/field/date.h"
 
39
#include "drizzled/field/decimal.h"
 
40
#include "drizzled/field/real.h"
 
41
#include "drizzled/field/double.h"
 
42
#include "drizzled/field/int32.h"
 
43
#include "drizzled/field/int64.h"
 
44
#include "drizzled/field/num.h"
 
45
#include "drizzled/field/time.h"
 
46
#include "drizzled/field/epoch.h"
 
47
#include "drizzled/field/datetime.h"
 
48
#include "drizzled/field/microtime.h"
 
49
#include "drizzled/field/varstring.h"
 
50
#include "drizzled/field/uuid.h"
 
51
#include "drizzled/time_functions.h"
 
52
#include "drizzled/internal/m_string.h"
 
53
 
 
54
#include "drizzled/display.h"
59
55
 
60
56
namespace drizzled
61
57
{
746
742
  return 0;
747
743
}
748
744
 
749
 
bool Field::is_null(ptrdiff_t row_offset) const
 
745
bool Field::is_null(ptrdiff_t row_offset)
750
746
{
751
747
  return null_ptr ?
752
748
    (null_ptr[row_offset] & null_bit ? true : false) :
753
749
    table->null_row;
754
750
}
755
751
 
756
 
bool Field::is_real_null(ptrdiff_t row_offset) const
 
752
bool Field::is_real_null(ptrdiff_t row_offset)
757
753
{
758
754
  return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
759
755
}
760
756
 
761
 
bool Field::is_null_in_record(const unsigned char *record) const
 
757
bool Field::is_null_in_record(const unsigned char *record)
762
758
{
763
759
  if (! null_ptr)
764
760
    return false;
765
761
  return test(record[(uint32_t) (null_ptr -table->getInsertRecord())] & null_bit);
766
762
}
767
763
 
768
 
bool Field::is_null_in_record_with_offset(ptrdiff_t with_offset) const
 
764
bool Field::is_null_in_record_with_offset(ptrdiff_t with_offset)
769
765
{
770
766
  if (! null_ptr)
771
767
    return false;
784
780
    null_ptr[row_offset]&= (unsigned char) ~null_bit;
785
781
}
786
782
 
787
 
bool Field::maybe_null(void) const
 
783
bool Field::maybe_null(void)
788
784
{
789
785
  return null_ptr != 0 || table->maybe_null;
790
786
}
791
787
 
792
 
bool Field::real_maybe_null(void) const
 
788
bool Field::real_maybe_null(void)
793
789
{
794
790
  return null_ptr != 0;
795
791
}
831
827
             unsigned char *null_ptr_arg,
832
828
             unsigned char null_bit_arg,
833
829
             utype unireg_check_arg, 
834
 
             const char *field_name_arg) :
 
830
             const char *field_name_arg)
 
831
  :
835
832
    ptr(ptr_arg),
836
833
    null_ptr(null_ptr_arg),
837
834
    table(NULL),
838
835
    orig_table(NULL),
839
836
    field_name(field_name_arg),
840
 
    comment(NULL_LEX_STRING),
841
837
    key_start(0),
842
838
    part_of_key(0),
843
839
    part_of_key_not_clustered(0),
844
840
    part_of_sortkey(0),
845
841
    unireg_check(unireg_check_arg),
846
842
    field_length(length_arg),
847
 
    flags(null_ptr ? 0: NOT_NULL_FLAG),
848
 
    field_index(0),
849
843
    null_bit(null_bit_arg),
850
844
    is_created_from_null_item(false)
851
845
{
 
846
  flags= null_ptr ? 0: NOT_NULL_FLAG;
 
847
  comment.str= (char*) "";
 
848
  comment.length= 0;
 
849
  field_index= 0;
852
850
}
853
851
 
854
 
void Field::hash(uint32_t *nr, uint32_t *nr2) const
 
852
void Field::hash(uint32_t *nr, uint32_t *nr2)
855
853
{
856
854
  if (is_null())
857
855
  {
943
941
  return(result);
944
942
}
945
943
 
946
 
type::Decimal *Field::val_decimal(type::Decimal *) const
 
944
type::Decimal *Field::val_decimal(type::Decimal *)
947
945
{
948
946
  /* This never have to be called */
949
947
  assert(0);
1001
999
  {
1002
1000
    copy->blob_field=(Field_blob*) this;
1003
1001
    copy->strip=0;
1004
 
    copy->length-= table->getShare()->sizeBlobPtr();
 
1002
    copy->length-= table->getShare()->blob_ptr_size;
1005
1003
    return copy->length;
1006
1004
  }
1007
1005
  else
1012
1010
  return copy->length+ store_length;
1013
1011
}
1014
1012
 
1015
 
bool Field::get_date(type::Time &ltime, uint32_t fuzzydate) const
 
1013
bool Field::get_date(type::Time &ltime,uint32_t fuzzydate)
1016
1014
{
1017
 
  char buff[type::Time::MAX_STRING_LENGTH];
 
1015
  char buff[40];
1018
1016
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1019
1017
 
1020
1018
  assert(getTable() and getTable()->getSession());
1021
1019
 
1022
 
  if (not (res= val_str_internal(&tmp)) or
 
1020
  if (not (res=val_str_internal(&tmp)) or
1023
1021
      str_to_datetime_with_warn(getTable()->getSession(),
1024
1022
                                res->ptr(), res->length(),
1025
1023
                                &ltime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
1030
1028
  return false;
1031
1029
}
1032
1030
 
1033
 
bool Field::get_time(type::Time &ltime) const
 
1031
bool Field::get_time(type::Time &ltime)
1034
1032
{
1035
 
  char buff[type::Time::MAX_STRING_LENGTH];
 
1033
  char buff[40];
1036
1034
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1037
1035
 
1038
 
  if (not (res= val_str_internal(&tmp)) or
1039
 
      str_to_time_with_warn(getTable()->getSession(), res->ptr(), res->length(), &ltime))
 
1036
  if (!(res=val_str_internal(&tmp)) || str_to_time_with_warn(res->ptr(), res->length(), &ltime))
1040
1037
  {
1041
1038
    return true;
1042
1039
  }
1228
1225
  if (session->abortOnWarning() or
1229
1226
      set_warning(level, code, cuted_increment))
1230
1227
  {
1231
 
    char str_nr[DECIMAL_LONGLONG_DIGITS];
 
1228
    char str_nr[22];
1232
1229
    char *str_end= internal::int64_t10_to_str(nr, str_nr, -10);
1233
1230
    make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
1234
1231
                                 ts_type, field_name);
1253
1250
  }
1254
1251
}
1255
1252
 
1256
 
bool Field::isReadSet() const 
 
1253
bool Field::isReadSet() 
1257
1254
1258
1255
  return table->isReadSet(field_index); 
1259
1256
}