~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/uncompress/uncompressudf.cc

  • Committer: Lee
  • Date: 2009-01-07 22:45:50 UTC
  • mfrom: (772 drizzle)
  • mto: This revision was merged to the branch mainline in revision 777.
  • Revision ID: lbieber@lbieber-desktop-20090107224550-tzjtc8klmv84ppyg
finish enabling tests, remove timezone2, timezone3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#include "config.h"
 
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/server_includes.h>
21
17
#include <drizzled/session.h>
22
18
#include <drizzled/error.h>
23
19
#include <drizzled/function/str/strfunc.h>
24
 
#include "plugin/compression/uncompress.h"
25
20
 
26
21
#include <zlib.h>
27
 
#include <string>
28
22
 
29
 
using namespace std;
30
 
using namespace drizzled;
 
23
class Item_func_uncompress: public Item_str_func
 
24
{
 
25
  String buffer;
 
26
public:
 
27
  Item_func_uncompress(): Item_str_func(){}
 
28
  void fix_length_and_dec(){ maybe_null= 1; max_length= MAX_BLOB_WIDTH; }
 
29
  const char *func_name() const{return "uncompress";}
 
30
  String *val_str(String *) ;
 
31
};
31
32
 
32
33
String *Item_func_uncompress::val_str(String *str)
33
34
{
35
36
  String *res= args[0]->val_str(str);
36
37
  ulong new_size;
37
38
  int err;
38
 
  drizzled::error_t code;
 
39
  uint32_t code;
39
40
 
40
41
  if (!res)
41
42
    goto err;
73
74
  }
74
75
 
75
76
  code= ((err == Z_BUF_ERROR) ? ER_ZLIB_Z_BUF_ERROR :
76
 
         ((err == Z_MEM_ERROR) ? ER_ZLIB_Z_MEM_ERROR : ER_ZLIB_Z_DATA_ERROR));
 
77
         ((err == Z_MEM_ERROR) ? ER_ZLIB_Z_MEM_ERROR : ER_ZLIB_Z_DATA_ERROR));
77
78
  push_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, code, ER(code));
78
79
 
79
80
err:
81
82
  return 0;
82
83
}
83
84
 
 
85
 
 
86
Item_func* create_uncompressudf_item(MEM_ROOT* m)
 
87
{
 
88
  return  new (m) Item_func_uncompress();
 
89
}
 
90
 
 
91
static struct udf_func uncompressudf = {
 
92
  { C_STRING_WITH_LEN("uncompress") },
 
93
  create_uncompressudf_item
 
94
};
 
95
 
 
96
static int uncompressudf_plugin_init(void *p)
 
97
{
 
98
  udf_func **f = (udf_func**) p;
 
99
 
 
100
  *f= &uncompressudf;
 
101
 
 
102
  return 0;
 
103
}
 
104
 
 
105
static int uncompressudf_plugin_deinit(void *p)
 
106
{
 
107
  udf_func *udff = (udf_func *) p;
 
108
  (void)udff;
 
109
  return 0;
 
110
}
 
111
 
 
112
mysql_declare_plugin(uncompress)
 
113
{
 
114
  DRIZZLE_UDF_PLUGIN,
 
115
  "uncompress",
 
116
  "1.0",
 
117
  "Stewart Smith",
 
118
  "UDF for compress()",
 
119
  PLUGIN_LICENSE_GPL,
 
120
  uncompressudf_plugin_init, /* Plugin Init */
 
121
  uncompressudf_plugin_deinit, /* Plugin Deinit */
 
122
  NULL,   /* status variables */
 
123
  NULL,   /* system variables */
 
124
  NULL    /* config options */
 
125
}
 
126
mysql_declare_plugin_end;