~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
 
22
 
#include <config.h>
 
22
#include "config.h"
23
23
#include <drizzled/field/blob.h>
24
24
#include <drizzled/table.h>
25
25
#include <drizzled/session.h>
26
 
#include <plugin/myisam/myisam.h>
27
 
#include <drizzled/system_variables.h>
 
26
#include "plugin/myisam/myisam.h"
28
27
 
29
28
#include <string>
30
29
#include <algorithm>
31
30
 
32
31
using namespace std;
33
32
 
34
 
namespace drizzled {
 
33
namespace drizzled
 
34
{
35
35
 
36
36
static uint32_t blob_pack_length_to_max_length(uint32_t arg)
37
37
{
51
51
                       unsigned char null_bit_arg,
52
52
                                   const char *field_name_arg,
53
53
                       TableShare *share,
54
 
                       const charset_info_st * const cs)
 
54
                       const CHARSET_INFO * const cs)
55
55
  :Field_str(ptr_arg,
56
56
             blob_pack_length_to_max_length(sizeof(uint32_t)),
57
57
             null_ptr_arg,
90
90
 
91
91
 
92
92
uint32_t Field_blob::get_length(const unsigned char *pos,
93
 
                                bool low_byte_first) const
 
93
                                bool low_byte_first)
94
94
{
95
95
#ifndef WORDS_BIGENDIAN
96
96
  (void)low_byte_first;
113
113
}
114
114
 
115
115
 
116
 
uint32_t Field_blob::get_length(uint32_t row_offset) const
 
116
uint32_t Field_blob::get_length(uint32_t row_offset)
117
117
{
118
118
  return get_length(ptr+row_offset,
119
119
                    getTable()->getShare()->db_low_byte_first);
120
120
}
121
121
 
122
122
 
123
 
uint32_t Field_blob::get_length(const unsigned char *ptr_arg) const
 
123
uint32_t Field_blob::get_length(const unsigned char *ptr_arg)
124
124
{
125
125
  return get_length(ptr_arg, getTable()->getShare()->db_low_byte_first);
126
126
}
141
141
}
142
142
 
143
143
 
144
 
int Field_blob::store(const char *from,uint32_t length, const charset_info_st * const cs)
 
144
int Field_blob::store(const char *from,uint32_t length, const CHARSET_INFO * const cs)
145
145
{
146
146
  uint32_t copy_length, new_length;
147
147
  const char *well_formed_error_pos;
167
167
      memmove(ptr+sizeof(uint32_t), &from, sizeof(char*));
168
168
      return 0;
169
169
    }
170
 
    tmpstr.copy(from, length, cs);
 
170
    if (tmpstr.copy(from, length, cs))
 
171
      goto oom_error;
171
172
    from= tmpstr.ptr();
172
173
  }
173
174
 
174
175
  new_length= min(max_data_length(), field_charset->mbmaxlen * length);
175
 
  value.alloc(new_length);
 
176
  if (value.alloc(new_length))
 
177
    goto oom_error;
176
178
 
177
179
  /*
178
180
    "length" is OK as "nchars" argument to well_formed_copy_nchars as this
196
198
    return 2;
197
199
 
198
200
  return report_if_important_data(from_end_pos, from + length);
 
201
 
 
202
oom_error:
 
203
  /* Fatal OOM error */
 
204
  memset(ptr, 0, Field_blob::pack_length());
 
205
  return -1;
199
206
}
200
207
 
 
208
 
201
209
int Field_blob::store(double nr)
202
210
{
203
 
  const charset_info_st * const cs=charset();
 
211
  const CHARSET_INFO * const cs=charset();
204
212
  ASSERT_COLUMN_MARKED_FOR_WRITE;
205
213
  value.set_real(nr, NOT_FIXED_DEC, cs);
206
214
  return Field_blob::store(value.ptr(),(uint32_t) value.length(), cs);
207
215
}
208
216
 
 
217
 
209
218
int Field_blob::store(int64_t nr, bool unsigned_val)
210
219
{
211
 
  const charset_info_st * const cs=charset();
 
220
  const CHARSET_INFO * const cs=charset();
212
221
  ASSERT_COLUMN_MARKED_FOR_WRITE;
213
222
  value.set_int(nr, unsigned_val, cs);
214
223
  return Field_blob::store(value.ptr(), (uint32_t) value.length(), cs);
215
224
}
216
225
 
217
226
 
218
 
double Field_blob::val_real(void) const
 
227
double Field_blob::val_real(void)
219
228
{
220
229
  int not_used;
221
230
  char *end_not_used, *blob;
222
231
  uint32_t length;
223
 
  const charset_info_st *cs;
 
232
  const CHARSET_INFO *cs;
224
233
 
225
234
  ASSERT_COLUMN_MARKED_FOR_READ;
226
235
 
233
242
}
234
243
 
235
244
 
236
 
int64_t Field_blob::val_int(void) const
 
245
int64_t Field_blob::val_int(void)
237
246
{
238
247
  int not_used;
239
248
  char *blob;
243
252
  memcpy(&blob,ptr+sizeof(uint32_t),sizeof(char*));
244
253
  if (!blob)
245
254
    return 0;
246
 
  uint32_t length= get_length(ptr);
 
255
  uint32_t length=get_length(ptr);
247
256
  return my_strntoll(charset(),blob,length,10,NULL,&not_used);
248
257
}
249
258
 
250
 
String *Field_blob::val_str(String *, String *val_ptr) const
 
259
String *Field_blob::val_str(String *,
 
260
                            String *val_ptr)
251
261
{
252
262
  char *blob;
253
263
 
262
272
}
263
273
 
264
274
 
265
 
type::Decimal *Field_blob::val_decimal(type::Decimal *decimal_value) const
 
275
type::Decimal *Field_blob::val_decimal(type::Decimal *decimal_value)
266
276
{
267
277
  const char *blob;
268
278
  size_t length;
398
408
  unsigned char *blob1;
399
409
  uint32_t blob_length=get_length(ptr);
400
410
  memcpy(&blob1,ptr+sizeof(uint32_t),sizeof(char*));
401
 
  const charset_info_st * const cs= charset();
 
411
  const CHARSET_INFO * const cs= charset();
402
412
  uint32_t local_char_length= max_key_length / cs->mbmaxlen;
403
413
  local_char_length= my_charpos(cs, blob1, blob1+blob_length,
404
414
                                local_char_length);