~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/crc32/crc32udf.cc

Merge Devananda's CRC32 cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
using namespace std;
28
28
 
29
 
class Item_func_crc32 :public Item_int_func
 
29
class Crc32Function :public Item_int_func
30
30
{
31
31
  String value;
32
32
public:
33
 
  Item_func_crc32() :Item_int_func() { unsigned_flag= 1; }
34
 
  const char *func_name() const { return "crc32"; }
35
 
  void fix_length_and_dec() { max_length=10; }
36
33
  int64_t val_int();
37
 
  bool check_argument_count(int n) { return (n==1); }
 
34
  
 
35
  Crc32Function() :Item_int_func() 
 
36
  { 
 
37
    unsigned_flag= true; 
 
38
  }
 
39
  
 
40
  const char *func_name() const 
 
41
  { 
 
42
    return "crc32"; 
 
43
  }
 
44
  
 
45
  void fix_length_and_dec() 
 
46
  { 
 
47
    max_length= 10; 
 
48
  }
 
49
  
 
50
  bool check_argument_count(int n) 
 
51
  { 
 
52
    return (n == 1); 
 
53
  }
38
54
};
39
55
 
40
 
int64_t Item_func_crc32::val_int()
 
56
int64_t Crc32Function::val_int()
41
57
{
42
 
  assert(fixed == 1);
 
58
  assert(fixed == true);
43
59
  String *res=args[0]->val_str(&value);
44
 
  if (!res)
 
60
  
 
61
  if (res == NULL)
45
62
  {
46
 
    null_value=1;
47
 
    return 0; /* purecov: inspected */
 
63
    null_value= true;
 
64
    return 0;
48
65
  }
49
 
  null_value=0;
 
66
 
 
67
  null_value= false;
50
68
  return (int64_t) crc32(0L, (unsigned char*)res->ptr(), res->length());
51
69
}
52
70
 
53
 
Create_function<Item_func_crc32> crc32udf(string("crc32"));
 
71
Create_function<Crc32Function> crc32udf(string("crc32"));
54
72
 
55
 
static int crc32udf_plugin_init(PluginRegistry &registry)
 
73
static int initialize(PluginRegistry &registry)
56
74
{
57
75
  registry.add(&crc32udf);
 
76
  return 0;
 
77
}
58
78
 
 
79
static int finalize(PluginRegistry &registry)  
 
80
{
 
81
  registry.remove(&crc32udf);
59
82
  return 0;
60
83
}
61
84
 
66
89
  "Stewart Smith",
67
90
  "UDF for computing CRC32",
68
91
  PLUGIN_LICENSE_GPL,
69
 
  crc32udf_plugin_init, /* Plugin Init */
70
 
  NULL,   /* Plugin Deinit */
 
92
  initialize, /* Plugin Init */
 
93
  finalize,   /* Plugin Deinit */
71
94
  NULL,   /* status variables */
72
95
  NULL,   /* system variables */
73
96
  NULL    /* config options */