~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/double.cc

  • Committer: Mark Atwood
  • Date: 2009-03-04 01:02:00 UTC
  • mto: (968.2.20 mordred)
  • mto: This revision was merged to the branch mainline in revision 971.
  • Revision ID: me@mark.atwood.name-20090304010200-t1n4xxdoil2yae9a
add gearman logging plugin

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