~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/hex_string.cc

  • Committer: Brian Aker
  • Date: 2009-10-07 16:55:53 UTC
  • mfrom: (1161.2.1 bug444827)
  • Revision ID: brian@gaz-20091007165553-9tnp7liw1k9g6gvc
Merge Padraig

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
22
22
#include <drizzled/error.h>
23
 
#include <drizzled/field.h>
 
23
#include <drizzled/item/string.h>
24
24
#include <drizzled/item/hex_string.h>
25
 
#include <drizzled/item/string.h>
26
 
#include <drizzled/type/decimal.h>
27
25
 
28
26
#include <algorithm>
29
27
 
30
28
using namespace std;
31
29
 
32
 
namespace drizzled
33
 
{
34
 
 
35
 
static char _dig_vec_lower[] =
36
 
  "0123456789abcdefghijklmnopqrstuvwxyz";
37
 
 
38
30
inline uint32_t char_val(char X)
39
31
{
40
32
  return (uint32_t) (X >= '0' && X <= '9' ? X-'0' :
45
37
Item_hex_string::Item_hex_string(const char *str, uint32_t str_length)
46
38
{
47
39
  max_length=(str_length+1)/2;
48
 
  char *ptr=(char*) memory::sql_alloc(max_length+1);
 
40
  char *ptr=(char*) sql_alloc(max_length+1);
49
41
  if (!ptr)
50
42
    return;
51
43
  str_value.set(ptr,max_length,&my_charset_bin);
68
60
  // following assert is redundant, because fixed=1 assigned in constructor
69
61
  assert(fixed == 1);
70
62
  char *end= (char*) str_value.ptr()+str_value.length(),
71
 
       *ptr= end - min(str_value.length(), sizeof(int64_t));
 
63
       *ptr= end - min(str_value.length(),(uint32_t)sizeof(int64_t));
72
64
 
73
65
  uint64_t value=0;
74
66
  for (; ptr != end ; ptr++)
77
69
}
78
70
 
79
71
 
80
 
type::Decimal *Item_hex_string::val_decimal(type::Decimal *decimal_value)
 
72
my_decimal *Item_hex_string::val_decimal(my_decimal *decimal_value)
81
73
{
82
74
  // following assert is redundant, because fixed=1 assigned in constructor
83
75
  assert(fixed == 1);
84
76
  uint64_t value= (uint64_t)val_int();
85
 
  int2_class_decimal(E_DEC_FATAL_ERROR, value, true, decimal_value);
 
77
  int2my_decimal(E_DEC_FATAL_ERROR, value, true, decimal_value);
86
78
  return (decimal_value);
87
79
}
88
80
 
118
110
void Item_hex_string::print(String *str, enum_query_type)
119
111
{
120
112
  char *end= (char*) str_value.ptr() + str_value.length(),
121
 
       *ptr= end - min(str_value.length(), sizeof(int64_t));
 
113
       *ptr= end - min(str_value.length(), (uint32_t)sizeof(int64_t));
122
114
  str->append("0x");
123
115
  for (; ptr != end ; ptr++)
124
116
  {
152
144
}
153
145
 
154
146
 
155
 
} /* namespace drizzled */