~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/double.cc

  • Committer: Stewart Smith
  • Date: 2009-06-17 06:44:38 UTC
  • mto: This revision was merged to the branch mainline in revision 1094.
  • Revision ID: stewart@flamingspork.com-20090617064438-062owpgtdzgr4lvx
type_float.test for MyISAM as temp only

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
24
#include <drizzled/error.h>
31
25
#include <drizzled/table.h>
32
26
#include <drizzled/session.h>
33
 
#include "drizzled/internal/m_string.h"
34
 
 
35
 
using namespace std;
36
 
 
37
 
namespace drizzled
38
 
{
 
27
#include <drizzled/protocol.h>
 
28
 
39
29
 
40
30
/****************************************************************************
41
31
  double precision floating point numbers
46
36
  int error;
47
37
  char *end;
48
38
  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)))
 
39
  if (error || (!len || (((uint32_t) (end-from) != len) && table->in_use->count_cuted_fields)))
52
40
  {
53
41
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
54
42
                (error ? ER_WARN_DATA_OUT_OF_RANGE : ER_WARN_DATA_TRUNCATED), 1);
63
51
{
64
52
  int error= truncate(&nr, DBL_MAX);
65
53
 
66
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
67
 
 
68
54
#ifdef WORDS_BIGENDIAN
69
 
  if (getTable()->getShare()->db_low_byte_first)
 
55
  if (table->s->db_low_byte_first)
70
56
  {
71
57
    float8store(ptr,nr);
72
58
  }
86
72
double Field_double::val_real(void)
87
73
{
88
74
  double j;
89
 
 
90
 
  ASSERT_COLUMN_MARKED_FOR_READ;
91
 
 
92
75
#ifdef WORDS_BIGENDIAN
93
 
  if (getTable()->getShare()->db_low_byte_first)
 
76
  if (table->s->db_low_byte_first)
94
77
  {
95
78
    float8get(j,ptr);
96
79
  }
104
87
{
105
88
  double j;
106
89
  int64_t res;
107
 
 
108
 
  ASSERT_COLUMN_MARKED_FOR_READ;
109
 
 
110
90
#ifdef WORDS_BIGENDIAN
111
 
  if (getTable()->getShare()->db_low_byte_first)
 
91
  if (table->s->db_low_byte_first)
112
92
  {
113
93
    float8get(j,ptr);
114
94
  }
146
126
                              String *)
147
127
{
148
128
  double nr;
149
 
 
150
 
  ASSERT_COLUMN_MARKED_FOR_READ;
151
 
 
152
129
#ifdef WORDS_BIGENDIAN
153
 
  if (getTable()->getShare()->db_low_byte_first)
 
130
  if (table->s->db_low_byte_first)
154
131
  {
155
132
    float8get(nr,ptr);
156
133
  }
158
135
#endif
159
136
    doubleget(nr,ptr);
160
137
 
161
 
  uint32_t to_length= max(field_length, (uint32_t)DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
 
138
  uint32_t to_length=cmax(field_length, (uint32_t)DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
162
139
  val_buffer->alloc(to_length);
163
140
  char *to=(char*) val_buffer->ptr();
164
141
  size_t len;
165
142
 
166
143
  if (dec >= NOT_FIXED_DEC)
167
 
    len= internal::my_gcvt(nr, internal::MY_GCVT_ARG_DOUBLE, to_length - 1, to, NULL);
 
144
    len= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, to_length - 1, to, NULL);
168
145
  else
169
 
    len= internal::my_fcvt(nr, dec, to, NULL);
 
146
    len= my_fcvt(nr, dec, to, NULL);
170
147
 
171
148
  val_buffer->length((uint32_t) len);
172
149
 
177
154
{
178
155
  double a,b;
179
156
#ifdef WORDS_BIGENDIAN
180
 
  if (getTable()->getShare()->db_low_byte_first)
 
157
  if (table->s->db_low_byte_first)
181
158
  {
182
159
    float8get(a,a_ptr);
183
160
    float8get(b,b_ptr);
198
175
{
199
176
  double nr;
200
177
#ifdef WORDS_BIGENDIAN
201
 
  if (getTable()->getShare()->db_low_byte_first)
 
178
  if (table->s->db_low_byte_first)
202
179
  {
203
180
    float8get(nr,ptr);
204
181
  }
209
186
}
210
187
 
211
188
 
 
189
/**
 
190
   Save the field metadata for double fields.
 
191
 
 
192
   Saves the pack length in the first byte of the field metadata array
 
193
   at index of *metadata_ptr.
 
194
 
 
195
   @param   metadata_ptr   First byte of field metadata
 
196
 
 
197
   @returns number of bytes written to metadata_ptr
 
198
*/
 
199
int Field_double::do_save_field_metadata(unsigned char *metadata_ptr)
 
200
{
 
201
  *metadata_ptr= pack_length();
 
202
  return 1;
 
203
}
 
204
 
 
205
 
212
206
void Field_double::sql_type(String &res) const
213
207
{
214
208
  const CHARSET_INFO * const cs=res.charset();
223
217
  }
224
218
}
225
219
 
226
 
} /* namespace drizzled */