~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/crc32/crc32udf.cc

  • Committer: Stewart Smith
  • Date: 2009-06-05 12:04:43 UTC
  • mto: This revision was merged to the branch mainline in revision 1053.
  • Revision ID: stewart@flamingspork.com-20090605120443-dn9ttgy0f1942cr8
Add code coverage for ALTER DATABASE

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
#include <drizzled/plugin/function.h>
 
20
#include <drizzled/server_includes.h>
 
21
#include <drizzled/sql_udf.h>
22
22
#include <drizzled/item/func.h>
23
 
#include <drizzled/algorithm/crc32.h>
 
23
#include <zlib.h>
24
24
 
25
25
#include <string>
26
26
 
27
27
using namespace std;
28
 
using namespace drizzled;
29
28
 
30
 
class Crc32Function :public Item_int_func
 
29
class Item_func_crc32 :public Item_int_func
31
30
{
 
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; }
33
36
  int64_t val_int();
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
 
  }
 
37
  bool check_argument_count(int n) { return (n==1); }
54
38
};
55
39
 
56
 
int64_t Crc32Function::val_int()
 
40
int64_t Item_func_crc32::val_int()
57
41
{
58
 
  assert(fixed == true);
59
 
  String value;
 
42
  assert(fixed == 1);
60
43
  String *res=args[0]->val_str(&value);
61
 
  
62
 
  if (res == NULL)
 
44
  if (!res)
63
45
  {
64
 
    null_value= true;
65
 
    return 0;
 
46
    null_value=1;
 
47
    return 0; /* purecov: inspected */
66
48
  }
67
 
 
68
 
  null_value= false;
69
 
  return static_cast<int64_t>(drizzled::algorithm::crc32(res->ptr(), res->length()));
 
49
  null_value=0;
 
50
  return (int64_t) crc32(0L, (unsigned char*)res->ptr(), res->length());
70
51
}
71
52
 
72
 
plugin::Create_function<Crc32Function> *crc32udf= NULL;
 
53
Create_function<Item_func_crc32> crc32udf(string("crc32"));
73
54
 
74
 
static int initialize(module::Context &context)
 
55
static int crc32udf_plugin_init(PluginRegistry &registry)
75
56
{
76
 
  crc32udf= new plugin::Create_function<Crc32Function>("crc32");
77
 
  context.add(crc32udf);
 
57
  registry.add(&crc32udf);
 
58
 
78
59
  return 0;
79
60
}
80
61
 
81
 
DRIZZLE_PLUGIN(initialize, NULL, NULL);
 
62
drizzle_declare_plugin(crc32)
 
63
{
 
64
  "crc32",
 
65
  "1.0",
 
66
  "Stewart Smith",
 
67
  "UDF for computing CRC32",
 
68
  PLUGIN_LICENSE_GPL,
 
69
  crc32udf_plugin_init, /* Plugin Init */
 
70
  NULL,   /* Plugin Deinit */
 
71
  NULL,   /* status variables */
 
72
  NULL,   /* system variables */
 
73
  NULL    /* config options */
 
74
}
 
75
drizzle_declare_plugin_end;