~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/double.cc

  • Committer: Monty Taylor
  • Date: 2009-10-06 19:14:39 UTC
  • mfrom: (1130.2.18 plugin-base-class)
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20091006191439-fd1vvlp22654l3k3
Merged latest plugin-base-class.

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"
 
27
 
 
28
#include <algorithm>
34
29
 
35
30
using namespace std;
36
31
 
37
 
namespace drizzled
38
 
{
39
32
 
40
33
/****************************************************************************
41
34
  double precision floating point numbers
48
41
  double nr= my_strntod(cs,(char*) from, len, &end, &error);
49
42
 
50
43
  ASSERT_COLUMN_MARKED_FOR_WRITE;
51
 
  if (error || (!len || (((uint32_t) (end-from) != len) && getTable()->in_use->count_cuted_fields)))
 
44
  if (error || (!len || (((uint32_t) (end-from) != len) && table->in_use->count_cuted_fields)))
52
45
  {
53
46
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
54
47
                (error ? ER_WARN_DATA_OUT_OF_RANGE : ER_WARN_DATA_TRUNCATED), 1);
66
59
  ASSERT_COLUMN_MARKED_FOR_WRITE;
67
60
 
68
61
#ifdef WORDS_BIGENDIAN
69
 
  if (getTable()->getShare()->db_low_byte_first)
 
62
  if (table->s->db_low_byte_first)
70
63
  {
71
64
    float8store(ptr,nr);
72
65
  }
90
83
  ASSERT_COLUMN_MARKED_FOR_READ;
91
84
 
92
85
#ifdef WORDS_BIGENDIAN
93
 
  if (getTable()->getShare()->db_low_byte_first)
 
86
  if (table->s->db_low_byte_first)
94
87
  {
95
88
    float8get(j,ptr);
96
89
  }
108
101
  ASSERT_COLUMN_MARKED_FOR_READ;
109
102
 
110
103
#ifdef WORDS_BIGENDIAN
111
 
  if (getTable()->getShare()->db_low_byte_first)
 
104
  if (table->s->db_low_byte_first)
112
105
  {
113
106
    float8get(j,ptr);
114
107
  }
133
126
    char buf[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
134
127
    String tmp(buf, sizeof(buf), &my_charset_utf8_general_ci), *str;
135
128
    str= val_str(&tmp, &tmp);
136
 
    Session *session= getTable() ? getTable()->in_use : current_session;
137
 
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
129
    push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
138
130
                        ER_TRUNCATED_WRONG_VALUE,
139
131
                        ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
140
132
                        str->c_ptr());
151
143
  ASSERT_COLUMN_MARKED_FOR_READ;
152
144
 
153
145
#ifdef WORDS_BIGENDIAN
154
 
  if (getTable()->getShare()->db_low_byte_first)
 
146
  if (table->s->db_low_byte_first)
155
147
  {
156
148
    float8get(nr,ptr);
157
149
  }
165
157
  size_t len;
166
158
 
167
159
  if (dec >= NOT_FIXED_DEC)
168
 
    len= internal::my_gcvt(nr, internal::MY_GCVT_ARG_DOUBLE, to_length - 1, to, NULL);
 
160
    len= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, to_length - 1, to, NULL);
169
161
  else
170
 
    len= internal::my_fcvt(nr, dec, to, NULL);
 
162
    len= my_fcvt(nr, dec, to, NULL);
171
163
 
172
164
  val_buffer->length((uint32_t) len);
173
165
 
178
170
{
179
171
  double a,b;
180
172
#ifdef WORDS_BIGENDIAN
181
 
  if (getTable()->getShare()->db_low_byte_first)
 
173
  if (table->s->db_low_byte_first)
182
174
  {
183
175
    float8get(a,a_ptr);
184
176
    float8get(b,b_ptr);
199
191
{
200
192
  double nr;
201
193
#ifdef WORDS_BIGENDIAN
202
 
  if (getTable()->getShare()->db_low_byte_first)
 
194
  if (table->s->db_low_byte_first)
203
195
  {
204
196
    float8get(nr,ptr);
205
197
  }
210
202
}
211
203
 
212
204
 
 
205
/**
 
206
   Save the field metadata for double fields.
 
207
 
 
208
   Saves the pack length in the first byte of the field metadata array
 
209
   at index of *metadata_ptr.
 
210
 
 
211
   @param   metadata_ptr   First byte of field metadata
 
212
 
 
213
   @returns number of bytes written to metadata_ptr
 
214
*/
 
215
int Field_double::do_save_field_metadata(unsigned char *metadata_ptr)
 
216
{
 
217
  *metadata_ptr= pack_length();
 
218
  return 1;
 
219
}
 
220
 
 
221
 
213
222
void Field_double::sql_type(String &res) const
214
223
{
215
224
  const CHARSET_INFO * const cs=res.charset();
224
233
  }
225
234
}
226
235
 
227
 
} /* namespace drizzled */