~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/compress/compressudf.cc

  • Committer: Brian Aker
  • Date: 2009-03-27 22:55:28 UTC
  • mto: This revision was merged to the branch mainline in revision 968.
  • Revision ID: brian@tangent.org-20090327225528-8y76cfx8a4oemqv9
Remove ref_count

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
 
#include <drizzled/common_includes.h>
17
 
#include <drizzled/item_func.h>
18
 
#include <drizzled/item_strfunc.h>
19
 
#include <drizzled/drizzled_error_messages.h>
 
16
#include <drizzled/server_includes.h>
 
17
#include <drizzled/sql_udf.h>
 
18
#include <drizzled/item/func.h>
 
19
#include <drizzled/function/str/strfunc.h>
 
20
#include <drizzled/error.h>
 
21
#include <drizzled/sql_error.h>
 
22
#include <drizzled/current_session.h>
20
23
#include <zlib.h>
 
24
#include <string>
 
25
 
 
26
using namespace std;
21
27
 
22
28
class Item_func_compress: public Item_str_func
23
29
{
58
64
  new_size= res->length() + res->length() / 5 + 12;
59
65
 
60
66
  // Check new_size overflow: new_size <= res->length()
61
 
  if (((uint32_t) (new_size+5) <= res->length()) || 
 
67
  if (((uint32_t) (new_size+5) <= res->length()) ||
62
68
      buffer.realloc((uint32_t) new_size + 4 + 1))
63
69
  {
64
70
    null_value= 1;
69
75
 
70
76
  // As far as we have checked res->is_empty() we can use ptr()
71
77
  if ((err= compress(body, &new_size,
72
 
                     (const Bytef*)res->ptr(), res->length())) != Z_OK)
 
78
                     (const Bytef*)res->ptr(), res->length())) != Z_OK)
73
79
  {
74
80
    code= err==Z_MEM_ERROR ? ER_ZLIB_Z_MEM_ERROR : ER_ZLIB_Z_BUF_ERROR;
75
 
    push_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR, code, ER(code));
 
81
    push_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
82
                 code, ER(code));
76
83
    null_value= 1;
77
84
    return 0;
78
85
  }
93
100
}
94
101
 
95
102
 
96
 
Item_func* create_compressudf_item(MEM_ROOT* m)
97
 
{
98
 
  return  new (m) Item_func_compress();
99
 
}
100
 
 
101
 
static struct udf_func compressudf = {
102
 
  { C_STRING_WITH_LEN("compress") },
103
 
  create_compressudf_item
104
 
};
 
103
Create_function<Item_func_compress> compressudf(string("compress"));
105
104
 
106
105
static int compressudf_plugin_init(void *p)
107
106
{
108
 
  udf_func **f = (udf_func**) p;
 
107
  Function_builder **f = (Function_builder**) p;
109
108
 
110
109
  *f= &compressudf;
111
110
 
114
113
 
115
114
static int compressudf_plugin_deinit(void *p)
116
115
{
117
 
  udf_func *udff = (udf_func *) p;
 
116
  Function_builder *udff = (Function_builder *) p;
118
117
  (void)udff;
119
118
  return 0;
120
119
}
121
120
 
122
 
mysql_declare_plugin(compress)
 
121
drizzle_declare_plugin(compress)
123
122
{
124
123
  DRIZZLE_UDF_PLUGIN,
125
124
  "compress",
133
132
  NULL,   /* system variables */
134
133
  NULL    /* config options */
135
134
}
136
 
mysql_declare_plugin_end;
 
135
drizzle_declare_plugin_end;