~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/uncompressed_length/uncompressed_length.cc

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2006 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
 
 
16
 
#include <drizzled/common_includes.h>
17
 
#include <drizzled/item_func.h>
18
 
 
19
 
class Item_func_uncompressed_length : public Item_int_func
20
 
{
21
 
  String value;
22
 
public:
23
 
  Item_func_uncompressed_length():Item_int_func(){}
24
 
  const char *func_name() const{return "uncompressed_length";}
25
 
  void fix_length_and_dec() { max_length=10; }
26
 
  int64_t val_int();
27
 
};
28
 
 
29
 
int64_t Item_func_uncompressed_length::val_int()
30
 
{
31
 
  assert(fixed == 1);
32
 
  String *res= args[0]->val_str(&value);
33
 
  if (!res)
34
 
  {
35
 
    null_value=1;
36
 
    return 0; /* purecov: inspected */
37
 
  }
38
 
  null_value=0;
39
 
  if (res->is_empty()) return 0;
40
 
 
41
 
  /*
42
 
    res->ptr() using is safe because we have tested that string is not empty,
43
 
    res->c_ptr() is not used because:
44
 
      - we do not need \0 terminated string to get first 4 bytes
45
 
      - c_ptr() tests simbol after string end (uninitialiozed memory) which
46
 
        confuse valgrind
47
 
  */
48
 
  return uint4korr(res->ptr()) & 0x3FFFFFFF;
49
 
}
50
 
 
51
 
Item_func* create_uncompressed_lengthudf_item(MEM_ROOT* m)
52
 
{
53
 
  return  new (m) Item_func_uncompressed_length();
54
 
}
55
 
 
56
 
static struct udf_func uncompressed_lengthudf = {
57
 
  { C_STRING_WITH_LEN("uncompressed_length") },
58
 
  create_uncompressed_lengthudf_item
59
 
};
60
 
 
61
 
static int uncompressed_lengthudf_plugin_init(void *p)
62
 
{
63
 
  udf_func **f = (udf_func**) p;
64
 
 
65
 
  *f= &uncompressed_lengthudf;
66
 
 
67
 
  return 0;
68
 
}
69
 
 
70
 
static int uncompressed_lengthudf_plugin_deinit(void *p)
71
 
{
72
 
  udf_func *udff = (udf_func *) p;
73
 
  (void)udff;
74
 
  return 0;
75
 
}
76
 
 
77
 
mysql_declare_plugin(uncompressed_length)
78
 
{
79
 
  DRIZZLE_UDF_PLUGIN,
80
 
  "uncompressed_length",
81
 
  "1.0",
82
 
  "Stewart Smith",
83
 
  "UDF for compress()",
84
 
  PLUGIN_LICENSE_GPL,
85
 
  uncompressed_lengthudf_plugin_init, /* Plugin Init */
86
 
  uncompressed_lengthudf_plugin_deinit, /* Plugin Deinit */
87
 
  NULL,   /* status variables */
88
 
  NULL,   /* system variables */
89
 
  NULL    /* config options */
90
 
}
91
 
mysql_declare_plugin_end;