~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/double.cc

Merged in code for extra warnings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
 
22
 
#include "config.h"
23
 
 
24
 
#include <float.h>
25
 
#include <math.h>
26
 
 
27
 
#include <algorithm>
28
 
 
 
22
#include <drizzled/server_includes.h>
29
23
#include <drizzled/field/double.h>
30
 
#include <drizzled/error.h>
31
 
#include <drizzled/table.h>
32
 
#include <drizzled/session.h>
33
 
#include "drizzled/internal/m_string.h"
34
 
 
35
 
using namespace std;
36
 
 
37
 
namespace drizzled
38
 
{
 
24
#include <drizzled/drizzled_error_messages.h>
39
25
 
40
26
/****************************************************************************
41
27
  double precision floating point numbers
46
32
  int error;
47
33
  char *end;
48
34
  double nr= my_strntod(cs,(char*) from, len, &end, &error);
49
 
 
50
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
51
 
  if (error || (!len || (((uint32_t) (end-from) != len) && getTable()->in_use->count_cuted_fields)))
 
35
  if (error || (!len || (((uint) (end-from) != len) && table->in_use->count_cuted_fields)))
52
36
  {
53
37
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
54
38
                (error ? ER_WARN_DATA_OUT_OF_RANGE : ER_WARN_DATA_TRUNCATED), 1);
63
47
{
64
48
  int error= truncate(&nr, DBL_MAX);
65
49
 
66
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
67
 
 
68
50
#ifdef WORDS_BIGENDIAN
69
 
  if (getTable()->getShare()->db_low_byte_first)
 
51
  if (table->s->db_low_byte_first)
70
52
  {
71
53
    float8store(ptr,nr);
72
54
  }
86
68
double Field_double::val_real(void)
87
69
{
88
70
  double j;
89
 
 
90
 
  ASSERT_COLUMN_MARKED_FOR_READ;
91
 
 
92
71
#ifdef WORDS_BIGENDIAN
93
 
  if (getTable()->getShare()->db_low_byte_first)
 
72
  if (table->s->db_low_byte_first)
94
73
  {
95
74
    float8get(j,ptr);
96
75
  }
104
83
{
105
84
  double j;
106
85
  int64_t res;
107
 
 
108
 
  ASSERT_COLUMN_MARKED_FOR_READ;
109
 
 
110
86
#ifdef WORDS_BIGENDIAN
111
 
  if (getTable()->getShare()->db_low_byte_first)
 
87
  if (table->s->db_low_byte_first)
112
88
  {
113
89
    float8get(j,ptr);
114
90
  }
132
108
  {
133
109
    char buf[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
134
110
    String tmp(buf, sizeof(buf), &my_charset_utf8_general_ci), *str;
135
 
    str= val_str(&tmp, &tmp);
136
 
    push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
111
    str= val_str(&tmp, 0);
 
112
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
137
113
                        ER_TRUNCATED_WRONG_VALUE,
138
114
                        ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
139
115
                        str->c_ptr());
143
119
 
144
120
 
145
121
String *Field_double::val_str(String *val_buffer,
146
 
                              String *)
 
122
                              String *val_ptr __attribute__((unused)))
147
123
{
148
124
  double nr;
149
 
 
150
 
  ASSERT_COLUMN_MARKED_FOR_READ;
151
 
 
152
125
#ifdef WORDS_BIGENDIAN
153
 
  if (getTable()->getShare()->db_low_byte_first)
 
126
  if (table->s->db_low_byte_first)
154
127
  {
155
128
    float8get(nr,ptr);
156
129
  }
158
131
#endif
159
132
    doubleget(nr,ptr);
160
133
 
161
 
  uint32_t to_length= max(field_length, (uint32_t)DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
 
134
  uint32_t to_length=cmax(field_length, (uint32_t)DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
162
135
  val_buffer->alloc(to_length);
163
136
  char *to=(char*) val_buffer->ptr();
164
137
  size_t len;
165
138
 
166
139
  if (dec >= NOT_FIXED_DEC)
167
 
    len= internal::my_gcvt(nr, internal::MY_GCVT_ARG_DOUBLE, to_length - 1, to, NULL);
 
140
    len= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, to_length - 1, to, NULL);
168
141
  else
169
 
    len= internal::my_fcvt(nr, dec, to, NULL);
 
142
    len= my_fcvt(nr, dec, to, NULL);
170
143
 
171
 
  val_buffer->length((uint32_t) len);
 
144
  val_buffer->length((uint) len);
172
145
 
173
146
  return val_buffer;
174
147
}
175
148
 
 
149
bool Field_double::send_binary(Protocol *protocol)
 
150
{
 
151
  return protocol->store((double) Field_double::val_real(), dec, (String*) 0);
 
152
}
 
153
 
 
154
 
176
155
int Field_double::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
177
156
{
178
157
  double a,b;
179
158
#ifdef WORDS_BIGENDIAN
180
 
  if (getTable()->getShare()->db_low_byte_first)
 
159
  if (table->s->db_low_byte_first)
181
160
  {
182
161
    float8get(a,a_ptr);
183
162
    float8get(b,b_ptr);
192
171
}
193
172
 
194
173
 
 
174
#define DBL_EXP_DIG (sizeof(double)*8-DBL_MANT_DIG)
 
175
 
195
176
/* The following should work for IEEE */
196
177
 
197
 
void Field_double::sort_string(unsigned char *to,uint32_t )
 
178
void Field_double::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
198
179
{
199
180
  double nr;
200
181
#ifdef WORDS_BIGENDIAN
201
 
  if (getTable()->getShare()->db_low_byte_first)
 
182
  if (table->s->db_low_byte_first)
202
183
  {
203
184
    float8get(nr,ptr);
204
185
  }
209
190
}
210
191
 
211
192
 
 
193
/**
 
194
   Save the field metadata for double fields.
 
195
 
 
196
   Saves the pack length in the first byte of the field metadata array
 
197
   at index of *metadata_ptr.
 
198
 
 
199
   @param   metadata_ptr   First byte of field metadata
 
200
 
 
201
   @returns number of bytes written to metadata_ptr
 
202
*/
 
203
int Field_double::do_save_field_metadata(unsigned char *metadata_ptr)
 
204
{
 
205
  *metadata_ptr= pack_length();
 
206
  return 1;
 
207
}
 
208
 
 
209
 
212
210
void Field_double::sql_type(String &res) const
213
211
{
214
212
  const CHARSET_INFO * const cs=res.charset();
223
221
  }
224
222
}
225
223
 
226
 
} /* namespace drizzled */