Merge lp:~capttofu/drizzle/memcached-udf-current into lp:~drizzle-trunk/drizzle/development

Proposed by CaptTofu
Status: Superseded
Proposed branch: lp:~capttofu/drizzle/memcached-udf-current
Merge into: lp:~drizzle-trunk/drizzle/development
Diff against target: 6333 lines
66 files modified
plugin/memcached_udf/docs/Makefile.am (+37/-0)
plugin/memcached_udf/docs/memc_append.pod (+53/-0)
plugin/memcached_udf/docs/memc_behavior_get.pod (+50/-0)
plugin/memcached_udf/docs/memc_behavior_set.pod (+59/-0)
plugin/memcached_udf/docs/memc_get.pod (+56/-0)
plugin/memcached_udf/docs/memc_libmemcached_version.pod (+44/-0)
plugin/memcached_udf/docs/memc_prepend.pod (+53/-0)
plugin/memcached_udf/docs/memc_servers_set.pod (+46/-0)
plugin/memcached_udf/docs/memc_set.pod (+79/-0)
plugin/memcached_udf/docs/memc_udf_version.pod (+43/-0)
plugin/memcached_udf/memc_add.cc (+78/-0)
plugin/memcached_udf/memc_add.h (+77/-0)
plugin/memcached_udf/memc_add_by_key.cc (+82/-0)
plugin/memcached_udf/memc_add_by_key.h (+78/-0)
plugin/memcached_udf/memc_append.cc (+75/-0)
plugin/memcached_udf/memc_append.h (+80/-0)
plugin/memcached_udf/memc_append_by_key.cc (+80/-0)
plugin/memcached_udf/memc_append_by_key.h (+77/-0)
plugin/memcached_udf/memc_behavior_get.cc (+151/-0)
plugin/memcached_udf/memc_behavior_get.h (+257/-0)
plugin/memcached_udf/memc_behavior_set.cc (+170/-0)
plugin/memcached_udf/memc_behavior_set.h (+174/-0)
plugin/memcached_udf/memc_cas.cc (+80/-0)
plugin/memcached_udf/memc_cas.h (+69/-0)
plugin/memcached_udf/memc_cas_by_key.cc (+84/-0)
plugin/memcached_udf/memc_cas_by_key.h (+69/-0)
plugin/memcached_udf/memc_decrement.cc (+91/-0)
plugin/memcached_udf/memc_decrement.h (+66/-0)
plugin/memcached_udf/memc_delete.cc (+65/-0)
plugin/memcached_udf/memc_delete.h (+70/-0)
plugin/memcached_udf/memc_delete_by_key.cc (+70/-0)
plugin/memcached_udf/memc_delete_by_key.h (+73/-0)
plugin/memcached_udf/memc_get.cc (+80/-0)
plugin/memcached_udf/memc_get.h (+65/-0)
plugin/memcached_udf/memc_get_by_key.cc (+77/-0)
plugin/memcached_udf/memc_get_by_key.h (+66/-0)
plugin/memcached_udf/memc_increment.cc (+92/-0)
plugin/memcached_udf/memc_increment.h (+65/-0)
plugin/memcached_udf/memc_misc.cc (+70/-0)
plugin/memcached_udf/memc_misc.h (+90/-0)
plugin/memcached_udf/memc_prepend.cc (+74/-0)
plugin/memcached_udf/memc_prepend.h (+71/-0)
plugin/memcached_udf/memc_prepend_by_key.cc (+80/-0)
plugin/memcached_udf/memc_prepend_by_key.h (+73/-0)
plugin/memcached_udf/memc_replace.cc (+78/-0)
plugin/memcached_udf/memc_replace.h (+71/-0)
plugin/memcached_udf/memc_replace_by_key.cc (+82/-0)
plugin/memcached_udf/memc_replace_by_key.h (+72/-0)
plugin/memcached_udf/memc_servers_set.cc (+73/-0)
plugin/memcached_udf/memc_servers_set.h (+77/-0)
plugin/memcached_udf/memc_set.cc (+79/-0)
plugin/memcached_udf/memc_set.h (+65/-0)
plugin/memcached_udf/memc_set_by_key.cc (+81/-0)
plugin/memcached_udf/memc_set_by_key.h (+70/-0)
plugin/memcached_udf/memc_stats.cc (+130/-0)
plugin/memcached_udf/memc_stats.h (+74/-0)
plugin/memcached_udf/memcached_udf.cc (+387/-0)
plugin/memcached_udf/memcached_udf.h (+52/-0)
plugin/memcached_udf/plugin.ac (+9/-0)
plugin/memcached_udf/plugin.ini (+34/-0)
plugin/memcached_udf/test/memc_test.expected (+190/-0)
plugin/memcached_udf/test/memc_test.sql (+168/-0)
plugin/sleep/sleep.cc (+1/-1)
tests/suite/memcached_udf/r/memc.result (+417/-0)
tests/suite/memcached_udf/start_mc.sh (+48/-0)
tests/suite/memcached_udf/t/memc.test (+194/-0)
To merge this branch: bzr merge lp:~capttofu/drizzle/memcached-udf-current
Reviewer Review Type Date Requested Status
Stewart Smith (community) Approve
Padraig O'Sullivan (community) Needs Fixing
CaptTofu Pending
Drizzle Developers Pending
Review via email: mp+12500@code.launchpad.net

This proposal supersedes a proposal from 2009-08-14.

To post a comment you must log in.
Revision history for this message
CaptTofu (capttofu) wrote : Posted in a previous version of this proposal

I propose a merge please - this merge will give all basic memcached UDFs for get/set operations as well as client behavior. This work includes Padraig's and my latest.

Revision history for this message
Jay Pipes (jaypipes) wrote : Posted in a previous version of this proposal

  Review: Resubmit

Hi! As discussed on IRC, we'll need a test suite for this plugin...just
marking this on the review.

Revision history for this message
CaptTofu (capttofu) wrote : Posted in a previous version of this proposal

> Review: Resubmit
>
> Hi! As discussed on IRC, we'll need a test suite for this plugin...just
> marking this on the review.

Hi!

I added tests, more UDFs, and tests pass!

So, may this branch please be merged?

Regards,

Patrick

Revision history for this message
Monty Taylor (mordred) wrote : Posted in a previous version of this proposal

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

CaptTofu wrote:
>> Review: Resubmit
>>
>> Hi! As discussed on IRC, we'll need a test suite for this plugin...just
>> marking this on the review.
>
> Hi!
>
> I added tests, more UDFs, and tests pass!
>
> So, may this branch please be merged?

Yes... except I'm going to make you wait just a little while longer...
as soon as my most recent changes to plugin stuff hit trunk (should be
today), I want to get you to merge up, and then you can add a new
magical line to your plugin.ini ... testsuite=whatever ... which will
cause the standard make test to run your plugin's test suite as long as
we built the plugin.

woot.

Then I'll merge you. Promise.

Monty
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpwmpQACgkQ2Jv7/VK1RgHJBQCeJrvsW25ONOkVTKiKJ7MnFp1+
czwAn3oBxlpo6TYMGhH/FrT87xWiV9G2
=ugE6
-----END PGP SIGNATURE-----

Revision history for this message
Stewart Smith (stewart) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Monty Taylor (mordred) wrote : Posted in a previous version of this proposal

Hullo.

"%llu" should not be used. That needs be changed to "%"PRIu64 to match your uint64_t variable.

The test suite did not work for me. I started a memcached, no dice. So I started using port 19191 like the script in tests/suite/memcached_udf indicated. Still no luck. (BTW, /etc/sysconfig is redhat specific)

The tests in gearman start and stop memcached as needed ... but I think at some point we should figure that out systemically.

review: Needs Fixing
Revision history for this message
Padraig O'Sullivan (posulliv) wrote : Posted in a previous version of this proposal

So for the test suite, I checked it out and the issue is that the result file seems to not have been updated after some UDF's return types were changed? When I run the test suite, I see there are a few diff's (this is just a sampling, there are more diff's):

 memc_delete('mysql:doc1')
-0
+1
 select memc_get('mysql:doc1');
 memc_get('mysql:doc1')
 NULL
 select memc_set('spot:test', ' Spot ');
 memc_set('spot:test', ' Spot ')
-0
+1
 select memc_get('spot:test');
 memc_get('spot:test')
-NULL
+ Spot
 select memc_prepend('spot:test', 'See');
 memc_prepend('spot:test', 'See')
-0
+1
 select memc_get('spot:test');
 memc_get('spot:test')
-NULL
+See Spot

It looks like the result file was recorded on a test run when all these UDF's failed! To record the result file, do the following:

$ ./dtr --record --suite=memcached_udf memc

Since I wrote the test suite, I should comment on some issues I see with the test suite:

 * it requires memcached to be in your path before running
 * it always starts memcached on the same port so if memcached is already running on this port, bad things will happen
 * the test cases are hard-coded to use a memcached instance on this port

I guess the major question I have here is how to have a test case with the ability to take an input parameter that can affect the result output (in this case, the port number to start memcached on)? I'm assuming its not possible right now unless we pass the parameter as an environment variable but I don't know how to access an environment variable from a test case?

Also, Monty's comment on not using %llu also needs to be implemented. Not sure how this branch compiled cleanly with that in there? I had to modify that to compile the branch and run the test suite.

-Padraig

review: Needs Fixing
Revision history for this message
CaptTofu (capttofu) wrote : Posted in a previous version of this proposal

Hi Padraig,

My bad - I was so focused on checking the results for the behavior issue
I didn't double check this! It appears the memcached server didn't start
in this instance when I recorded it.

I've pushed a new version into
lp:~capttofu/drizzle/memcached-udf-current. I also fixed the same issue
that I fixed for behavior types for hash and distribution types. I still
have some issues with some of the behavior settings though that I need
to ask Trond or Brian about (or someone else) as to why when I set some
of the behavior settings, they end up being set to zero. It might be
that the setting I'm trying to assign it is out of bounds and the value
then defaults to zero.

Thanks much!

Other things I need to look at (by tomorrow or tuesday will have done so
this branch can be marged) are the changes that Monty Taylor told me
about that are currently in command_log, pertaining to the loading of
the plugin.

--Patrick

Padraig O'Sullivan wrote:
> Review: Needs Fixing
> So for the test suite, I checked it out and the issue is that the result file seems to not have been updated after some UDF's return types were changed? When I run the test suite, I see there are a few diff's (this is just a sampling, there are more diff's):
>
> memc_delete('mysql:doc1')
> -0
> +1
> select memc_get('mysql:doc1');
> memc_get('mysql:doc1')
> NULL
> select memc_set('spot:test', ' Spot ');
> memc_set('spot:test', ' Spot ')
> -0
> +1
> select memc_get('spot:test');
> memc_get('spot:test')
> -NULL
> + Spot
> select memc_prepend('spot:test', 'See');
> memc_prepend('spot:test', 'See')
> -0
> +1
> select memc_get('spot:test');
> memc_get('spot:test')
> -NULL
> +See Spot
>
> It looks like the result file was recorded on a test run when all these UDF's failed! To record the result file, do the following:
>
> $ ./dtr --record --suite=memcached_udf memc
>
> Since I wrote the test suite, I should comment on some issues I see with the test suite:
>
> * it requires memcached to be in your path before running
> * it always starts memcached on the same port so if memcached is already running on this port, bad things will happen
> * the test cases are hard-coded to use a memcached instance on this port
>
> I guess the major question I have here is how to have a test case with the ability to take an input parameter that can affect the result output (in this case, the port number to start memcached on)? I'm assuming its not possible right now unless we pass the parameter as an environment variable but I don't know how to access an environment variable from a test case?
>
> Also, Monty's comment on not using %llu also needs to be implemented. Not sure how this branch compiled cleanly with that in there? I had to modify that to compile the branch and run the test suite.
>
> -Padraig
>

Revision history for this message
Stewart Smith (stewart) wrote : Posted in a previous version of this proposal
Download full text (21.2 KiB)

review: needs-fixing

On Fri, Aug 14, 2009 at 09:20:24PM -0000, Padraig O'Sullivan wrote:
> === added directory 'plugin/memcached_udf'
> === added directory 'plugin/memcached_udf/docs'
> === added file 'plugin/memcached_udf/docs/Makefile.am'
> --- plugin/memcached_udf/docs/Makefile.am 1970-01-01 00:00:00 +0000
> +++ plugin/memcached_udf/docs/Makefile.am 2009-07-13 19:59:16 +0000
> @@ -0,0 +1,37 @@
> +INCLUDES = include
> +
> +EXTRA_DIST = memc_get.pod\

File shouldn't include ^M at end of line.

> === added file 'plugin/memcached_udf/docs/memc_append.pod'
> --- plugin/memcached_udf/docs/memc_append.pod 1970-01-01 00:00:00 +0000
> +++ plugin/memcached_udf/docs/memc_append.pod 2009-07-13 19:59:16 +0000
> @@ -0,0 +1,53 @@
<snip>
> +=head1 INSTALL
> +
> +CREATE FUNCTION memc_append RETURNS INT SONAME "libmemcached_functions_mysql.so";
> +CREATE FUNCTION memc_append_by_key RETURNS INT SONAME "libmemcached_functions_mysql.so";
> +

n/a for drizzle

> === added file 'plugin/memcached_udf/docs/memc_behavior_get.pod'
> --- plugin/memcached_udf/docs/memc_behavior_get.pod 1970-01-01 00:00:00 +0000
> +++ plugin/memcached_udf/docs/memc_behavior_get.pod 2009-07-13 19:59:16 +0000
> @@ -0,0 +1,50 @@
<snip>
> +=head1 INSTALL
> +
> +CREATE FUNCTION memc_behavior_get RETURNS STRING SONAME "libmemcached_functions_mysql.so";

Also n/a for drizzle

> === added file 'plugin/memcached_udf/docs/memc_behavior_set.pod'
> --- plugin/memcached_udf/docs/memc_behavior_set.pod 1970-01-01 00:00:00 +0000
> +++ plugin/memcached_udf/docs/memc_behavior_set.pod 2009-07-13 19:59:16 +0000
> @@ -0,0 +1,59 @@
> +=head1 INSTALL
> +
> +CREATE FUNCTION memc_behavior_set RETURNS INT SONAME "libmemcached_functions_mysql.so";

n/a for drizzle

> === added file 'plugin/memcached_udf/docs/memc_get.pod'
> --- plugin/memcached_udf/docs/memc_get.pod 1970-01-01 00:00:00 +0000
> +++ plugin/memcached_udf/docs/memc_get.pod 2009-07-13 19:59:16 +0000
> @@ -0,0 +1,56 @@
> +=head1 INSTALL
> +
> +CREATE FUNCTION memc_get RETURNS STRING SONAME "libmemcached_functions_mysql.so";
> +CREATE FUNCTION memc_get_by_key RETURNS STRING SONAME
"libmemcached_functions_mysql.so";

also n/a for drizzle

> === added file 'plugin/memcached_udf/docs/memc_libmemcached_version.pod'
> --- plugin/memcached_udf/docs/memc_libmemcached_version.pod 1970-01-01 00:00:00 +0000
> +++ plugin/memcached_udf/docs/memc_libmemcached_version.pod 2009-07-13 19:59:16 +0000
> @@ -0,0 +1,44 @@
> +=head1 INSTALL
> +
> +CREATE FUNCTION memc_libmemcached_version RETURNS STRING SONAME "libmemcached_functions_mysql.so";

also here.

> === added file 'plugin/memcached_udf/docs/memc_prepend.pod'
> --- plugin/memcached_udf/docs/memc_prepend.pod 1970-01-01 00:00:00 +0000
> +++ plugin/memcached_udf/docs/memc_prepend.pod 2009-07-13 19:59:16 +0000
> @@ -0,0 +1,53 @@
> +=head1 INSTALL
> +
> +CREATE FUNCTION memc_prepend RETURNS INT SONAME "libmemcached_functions_mysql.so";
> +CREATE FUNCTION memc_prepend_by_key RETURNS INT SONAME "libmemcached_functions_mysql.so";

and here.

> === added file 'plugin/memcached_udf/docs/memc_servers_set.pod'
> --- plugin/memcached_udf/docs/memc_servers_set.pod 1970-01-01 00:00:00 +0000
> +++ plugin/memcached_udf/docs/memc_...

Revision history for this message
Monty Taylor (mordred) wrote : Posted in a previous version of this proposal
Download full text (17.3 KiB)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stewart Smith wrote:
> review: needs-fixing

>> +#include <drizzled/server_includes.h>
>> +#include <drizzled/sql_udf.h>
>
> I'm not sure if we strictly need the sql_udf.h include as it is a bit of
> a mix of things. Not that concerned about it, but perhaps is something
> to look into.

In fact, I'm totally changing what headers you need here at the moment,
so don't lose too much sleep over this.

>> +String *MemcachedAdd::val_str(String *str)
>> +{
>> + memcached_return rc;
>> + time_t expiration= 0;
>> + String *key;
>> + String *value;
>> +
>> + if ((arg_count != 2 && arg_count != 3) ||
>> + ! (key= args[0]->val_str(str)) ||
>> + ! (value= args[1]->val_str(str)) ||
>> + ! memc)
>> + {
>> + return &failure_buff;
>> + }
>> +
>> + if (arg_count == 3)
>> + {
>> + String *tmp_exp= args[2]->val_str(str);;
>> +
>> + expiration= (time_t)atoi(tmp_exp->c_ptr());
>> + }
>
> This logic for argument count checking should be in
> check_argument_count().
>
>> +
>> + rc= memcached_add(memc, key->c_ptr(), key->length(),
>> + value->c_ptr(), value->length(),
>> + expiration, (uint16_t) 0);
>> +
>> + if (rc != MEMCACHED_SUCCESS)
>> + {
>> + return &failure_buff;
>> + }
>> +
>> + return &success_buff;
>> +}
>> +
>
> We should probably also push a warning if there is failure.
>
>> === added file 'plugin/memcached_udf/memc_add.h'
>> --- plugin/memcached_udf/memc_add.h 1970-01-01 00:00:00 +0000
>> +++ plugin/memcached_udf/memc_add.h 2009-07-19 08:26:01 +0000
>> @@ -0,0 +1,56 @@
>> +/* implements memc_add */
>
> I don't think the comment adds anything :)

++

>> +class MemcachedAdd: public Item_str_func
>> +{
>> +public:
>> + MemcachedAdd()
>> + :
>> + Item_str_func(),
>> + failure_buff("0", &my_charset_bin),
>> + success_buff("1", &my_charset_bin)
>> + {}
>
> Returning a 0 or 1 string instead of integer is a little strange.
> Probably best to either return an integer or maybe even key/value to
> make query writing a bit easier.
>
>> === added file 'plugin/memcached_udf/memc_add_by_key.cc'
>> --- plugin/memcached_udf/memc_add_by_key.cc 1970-01-01 00:00:00 +0000
>> +++ plugin/memcached_udf/memc_add_by_key.cc 2009-07-18 11:13:08 +0000
>> @@ -0,0 +1,71 @@
>> +String *MemcachedAddByKey::val_str(String *str)
>> +{
>> + memcached_return rc;
>> + time_t expiration= 0;
>> + String *master_key;
>> + String *key;
>> + String *value;
>> +
>> + if ((arg_count != 3 && arg_count != 4) ||
>> + ! (master_key= args[0]->val_str(str)) ||
>> + ! (key= args[1]->val_str(str)) ||
>> + ! (value= args[2]->val_str(str)) ||
>> + ! memc)
>> + {
>> + return &failure_buff;
>> + }
>> +
>> + if (arg_count == 4)
>> + {
>> + String *tmp_exp= args[3]->val_str(str);;
>> +
>> + expiration= (time_t)atoi(tmp_exp->c_ptr());
>> + }
>
> same as above with arg count
>
>> + rc= memcached_add_by_key(memc,
>> + master_key->c_ptr(), master_key->length(),
>> + key->c_ptr(), key->length(),
>> + value->c_ptr(), value->length(),
>> + ...

Revision history for this message
Stewart Smith (stewart) : Posted in a previous version of this proposal
review: Needs Fixing
Revision history for this message
CaptTofu (capttofu) wrote : Posted in a previous version of this proposal

Hi Stewart - I made every change except the behavior map you mentioned. I'm not sure what you mean and need some of your time to do this. I was wondering if it'd be possible to get what I have merged and then work on other changes including what you mentioned about improving the way the behavior map works?

review: Needs Resubmitting
Revision history for this message
Padraig O'Sullivan (posulliv) wrote :

Hi Patrick!

I thought I would give you a few comments that I had from briefly looking at your patch.

1) In a number of header files, you have the 'using namespace' declaration. This can cause namespace pollution which can end up causing a world of pain. This is actually mentioned in the coding standards (http://drizzle.org/wiki/Coding_Standards#Namespaces) - 'using namespace should never be used in header files'.

2) I believe that what Stewart was reffering in an earlier review was that the behavior maps in various classes (such as MemcachedBehaviorGet) are the same and could maybe be replaced by one global class that contains one copy of this map. Do you think this would be possible? Maybe you could have a singleton which contains the map of behavior types that you can then reference.

3) This is not a huge issue but the include guards should reflect the directory structure. For example, for the header file memc_add.h, the include guard should be DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_ADD_H. This is referenced in the coding standards at http://drizzle.org/wiki/Coding_Standards#Include_Guards

4) There is some code that is commented out:

1208 + /*if (mbehavior == -1)
1209 + {
1210 + setFailureString("UNKNOWN BEHAVIOR TYPE!");
1211 + return &failure_buff;
1212 + }
1213 +*/

There is no need to comment code out when using source control so you can just delete these lines if thet are not needed.

5) Some more informative comments might be useful? Maybe some in doxygen format? Not really an issue, more of a suggestion as I like to see copious amounts of comments for some reason. So that's just more of a personal preference on my part.

Besides that, it looks good to me. Nice work!

-Padraig

review: Needs Fixing
Revision history for this message
Stewart Smith (stewart) wrote : Posted in a previous version of this proposal

On Sun, Sep 27, 2009 at 03:30:47PM -0000, CaptTofu wrote:
> Review: Resubmit
> Hi Stewart - I made every change except the behavior map you
> mentioned. I'm not sure what you mean and need some of your time to do
> this. I was wondering if it'd be possible to get what I have merged and
> then work on other changes including what you mentioned about improving
> the way the behavior map works?

I'm okay with this.

--
Stewart Smith

Revision history for this message
Monty Taylor (mordred) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Padraig O'Sullivan wrote:
> Review: Needs Fixing Hi Patrick!
>
> I thought I would give you a few comments that I had from briefly
> looking at your patch.
>
> 1) In a number of header files, you have the 'using namespace'
> declaration. This can cause namespace pollution which can end up
> causing a world of pain. This is actually mentioned in the coding
> standards (http://drizzle.org/wiki/Coding_Standards#Namespaces) -
> 'using namespace should never be used in header files'.

Agree. This is very important.

> 2) I believe that what Stewart was reffering in an earlier review was
> that the behavior maps in various classes (such as
> MemcachedBehaviorGet) are the same and could maybe be replaced by one
> global class that contains one copy of this map. Do you think this
> would be possible? Maybe you could have a singleton which contains
> the map of behavior types that you can then reference.
>
> 3) This is not a huge issue but the include guards should reflect the
> directory structure. For example, for the header file memc_add.h, the
> include guard should be DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_ADD_H. This

Actually, drop the DRIZZLE - it's not in a drizzle subdir. So it should be:

#ifndef PLUGIN_MEMCACHED_UDF_MEMC_ADD_H

I've got a utility coming in a merge in a few days that will help check
that.

Monty
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkrAXJwACgkQ2Jv7/VK1RgGj1wCgxkrKomkM1aUVzMiKamUL/tgR
HLEAoKxRMWMM9A9kAOWPf8B7S0nzBZ7z
=nreF
-----END PGP SIGNATURE-----

Revision history for this message
Stewart Smith (stewart) :
review: Approve
1118. By Patrick Galbraith <email address hidden>

Changed License to BSD

1119. By Patrick Galbraith <email address hidden>

Changes per review by Padraig O'Sullivan

1120. By Patrick Galbraith <email address hidden>

* Merge with latest trunk
* Changes per Posulliv

Unmerged revisions

1120. By Patrick Galbraith <email address hidden>

* Merge with latest trunk
* Changes per Posulliv

1119. By Patrick Galbraith <email address hidden>

Changes per review by Padraig O'Sullivan

1118. By Patrick Galbraith <email address hidden>

Changed License to BSD

1117. By Patrick Galbraith <email address hidden>

A couple more review fixes

1116. By Patrick Galbraith <email address hidden>

modified all set-type memcached UDFs to return 0 for failure.

1115. By Patrick Galbraith <email address hidden>

* Changed true/false functions to return actual int values vs. strings
* Code cleanup

1114. By Patrick Galbraith <email address hidden>

Memcached UDFs working with plugin slot re-org. Also merged with latest.

Ok, Monty, so, you won't change anything for a little while? :) Joking. Sort of.

1113. By Patrick Galbraith <email address hidden>

Merged in Padraig's changes - thanks Padraig!

* He removed the Redhat-specific code in the memcached startup script
* Removed tests that need looking into further and could be system-specific, causing failures
* Added the test suite to plugin.ini

1112. By Patrick Galbraith <email address hidden>

* Fixed distribution type check to use iterator to check if a distribution is truly defined
* Fixed hash type check to use iterator check
* Re-recorded the test results

1111. By Patrick Galbraith <email address hidden>

* fixed issue of behavior hash result checking
* updated test

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'plugin/memcached_udf'
2=== added directory 'plugin/memcached_udf/docs'
3=== added file 'plugin/memcached_udf/docs/Makefile.am'
4--- plugin/memcached_udf/docs/Makefile.am 1970-01-01 00:00:00 +0000
5+++ plugin/memcached_udf/docs/Makefile.am 2009-10-05 20:45:24 +0000
6@@ -0,0 +1,37 @@
7+INCLUDES = include
8+
9+EXTRA_DIST = memc_get.pod\
10+ memc_set.pod\
11+ memc_append.pod\
12+ memc_prepend.pod\
13+ memc_servers_set.pod\
14+ memc_behavior_set.pod\
15+ memc_behavior_get.pod\
16+ memc_libmemcached_version.pod\
17+
18+man_MANS = memc_get.3\
19+ memc_set.3\
20+ memc_append.3\
21+ memc_prepend.3\
22+ memc_servers_set.3\
23+ memc_behavior_set.3\
24+ memc_behavior_get.3\
25+ memc_version.3\
26+
27+memc_get.3: memc_get.pod
28+ pod2man -r "" -s 3 memc_get.pod > memc_get.3
29+memc_set.3: memc_set.pod
30+ pod2man -r "" -s 3 memc_set.pod > memc_set.3
31+memc_append.3: memc_append.pod
32+ pod2man -r "" -s 3 memc_append.pod > memc_append.3
33+memc_prepend.3: memc_prepend.pod
34+ pod2man -r "" -s 3 memc_prepend.pod > memc_prepend.3
35+memc_servers_set.3: memc_servers_set.pod
36+ pod2man -r "" -s 3 memc_servers_set.pod > memc_servers_set.3
37+memc_behavior_set.3: memc_behavior_set.pod
38+ pod2man -r "" -s 3 memc_servers_behavior_set.pod > memc_servers_behavior_set.3
39+memc_behavior_get.3: memc_behavior_get.pod
40+ pod2man -r "" -s 3 memc_servers_behavior_set.pod > memc_servers_behavior_set.3
41+
42+clean:
43+ rm -f *.3
44
45=== added file 'plugin/memcached_udf/docs/memc_append.pod'
46--- plugin/memcached_udf/docs/memc_append.pod 1970-01-01 00:00:00 +0000
47+++ plugin/memcached_udf/docs/memc_append.pod 2009-10-05 20:45:24 +0000
48@@ -0,0 +1,53 @@
49+=head1 NAME
50+
51+memc_append
52+
53+=head1 UDF
54+
55+Libmemcached User Defined Function for MySQL
56+
57+=head1 SYNOPSIS
58+
59+=head1 DESCRIPTION
60+
61+memc_append() is a UDF used to prepend content to the end of an
62+existing individual value from the memcached server from within
63+MySQL. The first argument you must pass in a key value. The second
64+aregument must be a data value which you wish to append to the end
65+of your existing value stored in memcached.
66+
67+memc_append_by_key() is a UDF that does the same thing as
68+memc_append() with and additional (1st arg) master key.
69+
70+=head1 RETURN
71+
72+
73+=head1 USAGE
74+
75+memc_append('keyfoo', ' this will be appended to the end of object');
76+memc_append('master keyA', 'keyfoo', ' this will be appended to the end of object');
77+
78+NULL
79+
80+=head1 HOME
81+
82+To find out more information please check:
83+L<http://hg.tangent.org/memcached_functions_mysql>
84+L<http://tangent.org/552/libmemcached.html>
85+
86+=head1 INSTALL
87+
88+CREATE FUNCTION memc_append RETURNS INT SONAME "libmemcached_functions_mysql.so";
89+CREATE FUNCTION memc_append_by_key RETURNS INT SONAME "libmemcached_functions_mysql.so";
90+
91+=head1 AUTHOR
92+
93+Patrick Galbraith, E<lt>patg@patg.netE<gt>
94+Brian Aker, E<lt>brian@tangent.orgE<gt>
95+
96+=head1 SEE ALSO
97+
98+memc_prepend()
99+
100+=cut
101+
102
103=== added file 'plugin/memcached_udf/docs/memc_behavior_get.pod'
104--- plugin/memcached_udf/docs/memc_behavior_get.pod 1970-01-01 00:00:00 +0000
105+++ plugin/memcached_udf/docs/memc_behavior_get.pod 2009-10-05 20:45:24 +0000
106@@ -0,0 +1,50 @@
107+=head1 NAME
108+
109+memc_behavior_set
110+
111+=head1 UDF
112+
113+Libmemcached User Defined Function for MySQL
114+
115+=head1 SYNOPSIS
116+
117+=head1 DESCRIPTION
118+
119+memc_behavior_get() is a UDF used to retrieve the behavior of a connection
120+to a memcached server from within MySQL. An alias to this function is memc_servers_behavior_get();
121+
122+=head1 RETURN
123+
124+NULL
125+
126+=head1 USAGE
127+
128+select memc_behavior_get('MEMCACHED_BEHAVIOR_SUPPORT_CAS');
129+
130+or with SET:
131+
132+set @setval = memc_behavior_get('MEMCACHED_BEHAVIOR_SUPPORT_CAS');
133+select @setval;
134+
135+
136+=head1 HOME
137+
138+To find out more information please check:
139+L<http://hg.tangent.org/memcached_functions_mysql>
140+L<http://tangent.org/552/libmemcached.html>
141+
142+=head1 INSTALL
143+
144+CREATE FUNCTION memc_behavior_get RETURNS STRING SONAME "libmemcached_functions_mysql.so";
145+
146+=head1 AUTHOR
147+
148+Patrick Galbraith, E<lt>patg@patg.netE<gt>
149+Brian Aker, E<lt>brian@tangent.orgE<gt>
150+
151+=head1 SEE ALSO
152+
153+memc_set(), memc_behavior_get(), memc_behavior_set(), memc_behavior_set(), memc_list_behaviors()
154+
155+=cut
156+
157
158=== added file 'plugin/memcached_udf/docs/memc_behavior_set.pod'
159--- plugin/memcached_udf/docs/memc_behavior_set.pod 1970-01-01 00:00:00 +0000
160+++ plugin/memcached_udf/docs/memc_behavior_set.pod 2009-10-05 20:45:24 +0000
161@@ -0,0 +1,59 @@
162+=head1 NAME
163+
164+memc_behavior_set
165+
166+=head1 UDF
167+
168+Libmemcached User Defined Function for MySQL
169+
170+=head1 SYNOPSIS
171+
172+=head1 DESCRIPTION
173+
174+memc_behavior_set() is a UDF used to set the behavior of a connection
175+to a memcached server from within MySQL. You must pass in a behavior string
176+(please use memc_list_behaviors() UDF to obtain possible values) and setting
177+value - quoted (important).
178+
179+=head1 RETURN
180+
181+NULL
182+
183+=head1 USAGE
184+
185+Should return 'SUCCESS'
186+
187+boolean:
188+
189+set @setval = memc_behavior_set('MEMCACHED_BEHAVIOR_SUPPORT_CAS', 1);
190+select @setval;
191+
192+canonical:
193+
194+select memc_behavior_set('MEMCACHED_BEHAVIOR_HASH','MEMCACHED_HASH_MD5' );
195+
196+numeric:
197+
198+select memc_behavior_set('MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE', 60000);
199+
200+=head1 HOME
201+
202+To find out more information please check:
203+L<http://hg.tangent.org/memcached_functions_mysql>
204+L<http://tangent.org/552/libmemcached.html>
205+
206+=head1 INSTALL
207+
208+CREATE FUNCTION memc_behavior_set RETURNS INT SONAME "libmemcached_functions_mysql.so";
209+
210+=head1 AUTHOR
211+
212+Patrick Galbraith, E<lt>patg@patg.netE<gt>
213+Brian Aker, E<lt>brian@tangent.orgE<gt>
214+
215+=head1 SEE ALSO
216+
217+memc_servers_set(), memc_list_behaviors()
218+
219+=cut
220+
221
222=== added file 'plugin/memcached_udf/docs/memc_get.pod'
223--- plugin/memcached_udf/docs/memc_get.pod 1970-01-01 00:00:00 +0000
224+++ plugin/memcached_udf/docs/memc_get.pod 2009-10-05 20:45:24 +0000
225@@ -0,0 +1,56 @@
226+=head1 NAME
227+
228+memc_get, memc_mget
229+
230+=head1 UDF
231+
232+Libmemcached User Defined Function for MySQL
233+
234+=head1 SYNOPSIS
235+
236+=head1 DESCRIPTION
237+
238+memc_get() is a UDF used to fetch an individual value from the memcached
239+server from within MySQL. You must pass in a key to fetch the object.
240+
241+memc_get_by_key() is a UDF used to fetch an individual value from the memcached
242+server from within MySQL. You must pass in a master key, as well as a key to fetch
243+the object.
244+
245+memcached_mget() <this function is not yet complete>
246+is used to select multiple keys at once. For multiple key
247+operations it is always faster to use this function. This function always
248+works asynchronously. memcached_fetch() is then used to retrieve any keys
249+found. No error is given on keys that are not found.
250+
251+=head1 RETURN
252+
253+Data stored in Memcached keyed by supplied hash value
254+
255+=head1 USAGE
256+
257+memc_get('keyfoo') <-- fetches object stored as 'keyfoo'
258+memc_get_by_key('masterA', 'keyfoo') <-- fetches object stored as 'keyfoo'
259+
260+=head1 HOME
261+
262+To find out more information please check:
263+L<http://hg.tangent.org/memcached_functions_mysql>
264+L<http://tangent.org/552/libmemcached.html>
265+
266+=head1 INSTALL
267+
268+CREATE FUNCTION memc_get RETURNS STRING SONAME "libmemcached_functions_mysql.so";
269+CREATE FUNCTION memc_get_by_key RETURNS STRING SONAME "libmemcached_functions_mysql.so";
270+
271+=head1 AUTHOR
272+
273+Patrick Galbraith, E<lt>patg@patg.netE<gt>
274+Brian Aker, E<lt>brian@tangent.orgE<gt>
275+
276+=head1 SEE ALSO
277+
278+memc_set(), memc_set_by_key(), memc_delete()...
279+
280+=cut
281+
282
283=== added file 'plugin/memcached_udf/docs/memc_libmemcached_version.pod'
284--- plugin/memcached_udf/docs/memc_libmemcached_version.pod 1970-01-01 00:00:00 +0000
285+++ plugin/memcached_udf/docs/memc_libmemcached_version.pod 2009-10-05 20:45:24 +0000
286@@ -0,0 +1,44 @@
287+=head1 NAME
288+
289+memc_libmemcached_version
290+
291+=head1 UDF
292+
293+Libmemcached User Defined Function for MySQL
294+
295+=head1 SYNOPSIS
296+
297+=head1 DESCRIPTION
298+
299+memc_libmemcached_version() is a UDF used to obtain the version string of the
300+libmemcached library the Memcached Functions for MySQL were compiled/linked
301+against
302+
303+=head1 RETURN
304+
305+NULL
306+
307+=head1 USAGE
308+
309+memc_libmemcached_version()
310+
311+=head1 HOME
312+
313+To find out more information please check:
314+L<http://hg.tangent.org/memcached_functions_mysql>
315+L<http://tangent.org/552/libmemcached.html>
316+
317+=head1 INSTALL
318+
319+CREATE FUNCTION memc_libmemcached_version RETURNS STRING SONAME "libmemcached_functions_mysql.so";
320+
321+=head1 AUTHOR
322+
323+Patrick Galbraith, E<lt>patg@patg.netE<gt>
324+
325+=head1 SEE ALSO
326+
327+memc_udf_version()
328+
329+=cut
330+
331
332=== added file 'plugin/memcached_udf/docs/memc_prepend.pod'
333--- plugin/memcached_udf/docs/memc_prepend.pod 1970-01-01 00:00:00 +0000
334+++ plugin/memcached_udf/docs/memc_prepend.pod 2009-10-05 20:45:24 +0000
335@@ -0,0 +1,53 @@
336+=head1 NAME
337+
338+memc_prepend
339+
340+=head1 UDF
341+
342+Libmemcached User Defined Function for MySQL
343+
344+=head1 SYNOPSIS
345+
346+=head1 DESCRIPTION
347+
348+memc_prepend() is a UDF used to prepend content to the beginning
349+of an existing individual value from the memcached server from within
350+MySQL. The first argument you must pass in a key value. The second
351+aregument must be a data value which you wish to prepend to the end
352+of your existing value stored in memcached.
353+
354+memc_prepend_by_key() functions the same as memc_prepend() with the addition
355+requirement of a master key supplied (1st arg)
356+
357+=head1 RETURN
358+
359+NULL
360+
361+=head1 USAGE
362+
363+memc_prepend('keyfoo', 'this will be prepended to beginning of object')
364+memc_prepend_by_key('masterA', 'keyfoo', 'this will be prepended to beginning of object')
365+
366+
367+=head1 HOME
368+
369+To find out more information please check:
370+L<http://hg.tangent.org/memcached_functions_mysql>
371+L<http://tangent.org/552/libmemcached.html>
372+
373+=head1 INSTALL
374+
375+CREATE FUNCTION memc_prepend RETURNS INT SONAME "libmemcached_functions_mysql.so";
376+CREATE FUNCTION memc_prepend_by_key RETURNS INT SONAME "libmemcached_functions_mysql.so";
377+
378+=head1 AUTHOR
379+
380+Patrick Galbraith, E<lt>patg@patg.netE<gt>
381+Brian Aker, E<lt>brian@tangent.orgE<gt>
382+
383+=head1 SEE ALSO
384+
385+memc_append()
386+
387+=cut
388+
389
390=== added file 'plugin/memcached_udf/docs/memc_servers_set.pod'
391--- plugin/memcached_udf/docs/memc_servers_set.pod 1970-01-01 00:00:00 +0000
392+++ plugin/memcached_udf/docs/memc_servers_set.pod 2009-10-05 20:45:24 +0000
393@@ -0,0 +1,46 @@
394+=head1 NAME
395+
396+memc_servers_set
397+
398+=head1 UDF
399+
400+Libmemcached User Defined Function for MySQL
401+
402+=head1 SYNOPSIS
403+
404+=head1 DESCRIPTION
405+
406+memc_servers_set() is a UDF used to set which memcached server you
407+wish your memcached UDFs to interact with / connect to. The only
408+argument is a string of comma-separated memcached servers,
409+hostname/ip:port (if port).
410+
411+=head1 RETURN
412+
413+NULL
414+
415+=head1 USAGE
416+
417+memc_servers_set('localhost:11211')
418+
419+=head1 HOME
420+
421+To find out more information please check:
422+L<http://hg.tangent.org/memcached_functions_mysql>
423+L<http://tangent.org/552/libmemcached.html>
424+
425+=head1 INSTALL
426+
427+CREATE FUNCTION memc_servers_set RETURNS INT SONAME "libmemcached_functions_mysql.so";
428+
429+=head1 AUTHOR
430+
431+Patrick Galbraith, E<lt>patg@patg.netE<gt>
432+Brian Aker, E<lt>brian@tangent.orgE<gt>
433+
434+=head1 SEE ALSO
435+
436+memc_servers_set(), memc_behavior_set()
437+
438+=cut
439+
440
441=== added file 'plugin/memcached_udf/docs/memc_set.pod'
442--- plugin/memcached_udf/docs/memc_set.pod 1970-01-01 00:00:00 +0000
443+++ plugin/memcached_udf/docs/memc_set.pod 2009-10-05 20:45:24 +0000
444@@ -0,0 +1,79 @@
445+=head1 NAME
446+
447+memc_set
448+
449+=head1 UDF
450+
451+Libmemcached User Defined Function for MySQL
452+
453+=head1 SYNOPSIS
454+
455+=head1 DESCRIPTION
456+
457+memc_set('<key>', '<value>') is a UDF used to set an individual value from the memcached
458+server from within MySQL. You must pass in a key and data value. The key
459+you use to set the value with will be the key you use to subsequently
460+retrieve that data with (memc_get('<key>'))
461+
462+memc_add() adds an object to the server. If the object is found on the
463+server an error occurs, otherwise the value is stored.
464+
465+memc_prepend() places a segment of data before the last piece of data
466+stored. Currently expiration and key are not used in the server.
467+
468+memc_append() places a segment of data at the end of the last piece of
469+data stored. Currently expiration and key are not used in the server.
470+
471+memc_cas() overwrites data in the server as long as the "cas" value is
472+still the same in the server. At the point that this note was written
473+cas is still buggy in memached.
474+
475+memc_set_by_key(), memc_add_by_key(), mem_replace_by_key(), memc_prepend_by_key(),
476+memc_append_by_key_by_key(), memc_cas_by_key() methods all behave in a
477+similar method as the non key methods. The difference is that they use
478+their master_key parameter to map objects to particular servers.
479+
480+If you are looking for performance, memc_set() with non-blocking IO is
481+the fastest way to store data on the server.
482+
483+=head1 RETURN
484+
485+NULL
486+
487+=head1 USAGE
488+
489+memc_set('keyfoo', 'somevalue hahah');
490+memc_set_by_key('master key', 'keyfoo', 'somevalue hahah');
491+memc_add('keyfoo', 'somevalue hahah');
492+memc_add_by_key('master key', 'keyfoo', 'somevalue hahah');
493+memc_replace('keyfoo', 'replaced value');
494+memc_replace_by_key('master key', 'keyfoo', 'replaced value');
495+
496+=head1 HOME
497+
498+To find out more information please check:
499+L<http://hg.tangent.org/memcached_functions_mysql>
500+L<http://tangent.org/552/libmemcached.html>
501+
502+=head1 INSTALL
503+
504+CREATE FUNCTION memc_set RETURNS INT SONAME "libmemcached_functions_mysql.so";
505+CREATE FUNCTION memc_set_by_key RETURNS INT SONAME "libmemcached_functions_mysql.so";
506+CREATE FUNCTION memc_cas RETURNS INT SONAME "libmemcached_functions_mysql.so";
507+CREATE FUNCTION memc_cas_by_key RETURNS INT SONAME "libmemcached_functions_mysql.so";
508+CREATE FUNCTION memc_add RETURNS INT SONAME "libmemcached_functions_mysql.so";
509+CREATE FUNCTION memc_add_by_key RETURNS INT SONAME "libmemcached_functions_mysql.so";
510+CREATE FUNCTION memc_replace RETURNS INT SONAME "libmemcached_functions_mysql.so";
511+CREATE FUNCTION memc_replace_by_key RETURNS INT SONAME "libmemcached_functions_mysql.so";
512+
513+=head1 AUTHOR
514+
515+Patrick Galbraith, E<lt>patg@patg.netE<gt>
516+Brian Aker, E<lt>brian@tangent.orgE<gt>
517+
518+=head1 SEE ALSO
519+
520+memc_set(), memc_delete()...
521+
522+=cut
523+
524
525=== added file 'plugin/memcached_udf/docs/memc_udf_version.pod'
526--- plugin/memcached_udf/docs/memc_udf_version.pod 1970-01-01 00:00:00 +0000
527+++ plugin/memcached_udf/docs/memc_udf_version.pod 2009-10-05 20:45:24 +0000
528@@ -0,0 +1,43 @@
529+=head1 NAME
530+
531+memc_udf_version
532+
533+=head1 UDF
534+
535+Libmemcached User Defined Function for MySQL
536+
537+=head1 SYNOPSIS
538+
539+=head1 DESCRIPTION
540+
541+memc_udf_version() is a UDF used to obtain the version string of
542+the Memcached Functions for MySQL
543+
544+=head1 RETURN
545+
546+NULL
547+
548+=head1 USAGE
549+
550+memc_udf_version()
551+
552+=head1 HOME
553+
554+To find out more information please check:
555+L<http://hg.tangent.org/memcached_functions_mysql>
556+L<http://tangent.org/552/libmemcached.html>
557+
558+=head1 INSTALL
559+
560+CREATE FUNCTION memc_udf_version RETURNS STRING SONAME "libmemcached_functions_mysql.so";
561+
562+=head1 AUTHOR
563+
564+Patrick Galbraith, E<lt>patg@patg.netE<gt>
565+
566+=head1 SEE ALSO
567+
568+memc_libmemcached_version()
569+
570+=cut
571+
572
573=== added file 'plugin/memcached_udf/memc_add.cc'
574--- plugin/memcached_udf/memc_add.cc 1970-01-01 00:00:00 +0000
575+++ plugin/memcached_udf/memc_add.cc 2009-10-05 20:45:23 +0000
576@@ -0,0 +1,78 @@
577+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
578+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
579+ *
580+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
581+ * All rights reserved.
582+ *
583+ * Redistribution and use in source and binary forms, with or without
584+ * modification, are permitted provided that the following conditions are met:
585+ *
586+ * * Redistributions of source code must retain the above copyright notice,
587+ * this list of conditions and the following disclaimer.
588+ * * Redistributions in binary form must reproduce the above copyright notice,
589+ * this list of conditions and the following disclaimer in the documentation
590+ * and/or other materials provided with the distribution.
591+ * * Neither the name of Patrick Galbraith nor the names of its contributors
592+ * may be used to endorse or promote products derived from this software
593+ * without specific prior written permission.
594+ *
595+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
596+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
597+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
598+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
599+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
600+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
601+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
602+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
603+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
604+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
605+ * THE POSSIBILITY OF SUCH DAMAGE.
606+ *
607+ */
608+
609+#include <drizzled/server_includes.h>
610+#include <drizzled/function/str/strfunc.h>
611+
612+#include "memcached_udf.h"
613+#include "memc_add.h"
614+
615+#include <libmemcached/memcached.h>
616+
617+#include <string>
618+
619+using namespace std;
620+
621+int64_t MemcachedAdd::val_int()
622+{
623+ memcached_return rc;
624+ time_t expiration= 0;
625+ String *key;
626+ String *res;
627+ null_value= false;
628+
629+ if ((arg_count != 2 && arg_count != 3) ||
630+ ! (key= args[0]->val_str(&value)) ||
631+ ! (res= args[1]->val_str(&value)) ||
632+ ! memc)
633+ {
634+ return 0;
635+ }
636+
637+ if (arg_count == 3)
638+ {
639+ String *tmp_exp= args[2]->val_str(&value);;
640+
641+ expiration= (time_t)atoi(tmp_exp->c_ptr());
642+ }
643+
644+ rc= memcached_add(memc, key->c_ptr(), key->length(),
645+ res->c_ptr(), res->length(),
646+ expiration, (uint16_t) 0);
647+
648+ if (rc != MEMCACHED_SUCCESS)
649+ {
650+ return 0;
651+ }
652+
653+ return 1;
654+}
655
656=== added file 'plugin/memcached_udf/memc_add.h'
657--- plugin/memcached_udf/memc_add.h 1970-01-01 00:00:00 +0000
658+++ plugin/memcached_udf/memc_add.h 2009-10-05 20:45:23 +0000
659@@ -0,0 +1,77 @@
660+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
661+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
662+ *
663+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
664+ * All rights reserved.
665+ *
666+ * Redistribution and use in source and binary forms, with or without
667+ * modification, are permitted provided that the following conditions are met:
668+ *
669+ * * Redistributions of source code must retain the above copyright notice,
670+ * this list of conditions and the following disclaimer.
671+ * * Redistributions in binary form must reproduce the above copyright notice,
672+ * this list of conditions and the following disclaimer in the documentation
673+ * and/or other materials provided with the distribution.
674+ * * Neither the name of Patrick Galbraith nor the names of its contributors
675+ * may be used to endorse or promote products derived from this software
676+ * without specific prior written permission.
677+ *
678+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
679+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
680+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
681+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
682+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
683+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
684+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
685+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
686+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
687+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
688+ * THE POSSIBILITY OF SUCH DAMAGE.
689+ *
690+ */
691+
692+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_ADD_H
693+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_ADD_H
694+
695+#include <drizzled/server_includes.h>
696+#include <drizzled/function/str/strfunc.h>
697+#include <drizzled/item/func.h>
698+#include <string>
699+
700+/**
701+ * @file
702+ * memc_add UDF
703+*/
704+class MemcachedAdd: public Item_int_func
705+{
706+ String value;
707+ String failure_buff;
708+public:
709+ MemcachedAdd()
710+ :
711+ Item_int_func(),
712+ failure_buff("0", &my_charset_bin)
713+ {}
714+
715+ const char *func_name() const
716+ {
717+ return "memc_add";
718+ }
719+
720+ int64_t val_int();
721+
722+ void fix_length_and_dec()
723+ {
724+ max_length= 32;
725+ }
726+/*
727+ * memc_add takes 2 or 3 arguments
728+*/
729+ bool check_argument_count(int n)
730+ {
731+ return ((n == 2 || n == 3));
732+ }
733+
734+};
735+
736+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_ADD_H */
737
738=== added file 'plugin/memcached_udf/memc_add_by_key.cc'
739--- plugin/memcached_udf/memc_add_by_key.cc 1970-01-01 00:00:00 +0000
740+++ plugin/memcached_udf/memc_add_by_key.cc 2009-10-05 20:45:23 +0000
741@@ -0,0 +1,82 @@
742+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
743+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
744+ *
745+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
746+ * All rights reserved.
747+ *
748+ * Redistribution and use in source and binary forms, with or without
749+ * modification, are permitted provided that the following conditions are met:
750+ *
751+ * * Redistributions of source code must retain the above copyright notice,
752+ * this list of conditions and the following disclaimer.
753+ * * Redistributions in binary form must reproduce the above copyright notice,
754+ * this list of conditions and the following disclaimer in the documentation
755+ * and/or other materials provided with the distribution.
756+ * * Neither the name of Patrick Galbraith nor the names of its contributors
757+ * may be used to endorse or promote products derived from this software
758+ * without specific prior written permission.
759+ *
760+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
761+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
762+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
763+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
764+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
765+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
766+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
767+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
768+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
769+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
770+ * THE POSSIBILITY OF SUCH DAMAGE.
771+ *
772+ */
773+
774+#include <drizzled/server_includes.h>
775+#include <drizzled/function/str/strfunc.h>
776+
777+#include "memcached_udf.h"
778+#include "memc_add_by_key.h"
779+
780+#include <libmemcached/memcached.h>
781+
782+#include <string>
783+
784+using namespace std;
785+
786+int64_t MemcachedAddByKey::val_int()
787+{
788+ memcached_return rc;
789+ time_t expiration= 0;
790+ String *master_key;
791+ String *key;
792+ String *res;
793+ null_value= false;
794+
795+ if ((arg_count != 3 && arg_count != 4) ||
796+ ! (master_key= args[0]->val_str(&value)) ||
797+ ! (key= args[1]->val_str(&value)) ||
798+ ! (res= args[2]->val_str(&value)) ||
799+ ! memc)
800+ {
801+ return 0;
802+ }
803+
804+ if (arg_count == 4)
805+ {
806+ String *tmp_exp= args[3]->val_str(&value);;
807+
808+ expiration= (time_t)atoi(tmp_exp->c_ptr());
809+ }
810+
811+ rc= memcached_add_by_key(memc,
812+ master_key->c_ptr(), master_key->length(),
813+ key->c_ptr(), key->length(),
814+ res->c_ptr(), res->length(),
815+ expiration, (uint16_t) 0);
816+
817+ if (rc != MEMCACHED_SUCCESS)
818+ {
819+ return 0;
820+ }
821+
822+ return 1;
823+}
824
825=== added file 'plugin/memcached_udf/memc_add_by_key.h'
826--- plugin/memcached_udf/memc_add_by_key.h 1970-01-01 00:00:00 +0000
827+++ plugin/memcached_udf/memc_add_by_key.h 2009-10-05 20:45:23 +0000
828@@ -0,0 +1,78 @@
829+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
830+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
831+ *
832+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
833+ * All rights reserved.
834+ *
835+ * Redistribution and use in source and binary forms, with or without
836+ * modification, are permitted provided that the following conditions are met:
837+ *
838+ * * Redistributions of source code must retain the above copyright notice,
839+ * this list of conditions and the following disclaimer.
840+ * * Redistributions in binary form must reproduce the above copyright notice,
841+ * this list of conditions and the following disclaimer in the documentation
842+ * and/or other materials provided with the distribution.
843+ * * Neither the name of Patrick Galbraith nor the names of its contributors
844+ * may be used to endorse or promote products derived from this software
845+ * without specific prior written permission.
846+ *
847+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
848+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
849+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
850+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
851+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
852+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
853+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
854+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
855+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
856+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
857+ * THE POSSIBILITY OF SUCH DAMAGE.
858+ *
859+ */
860+
861+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_ADD_BY_KEY_H
862+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_ADD_BY_KEY_H
863+
864+#include <drizzled/server_includes.h>
865+#include <drizzled/function/str/strfunc.h>
866+#include <drizzled/item/func.h>
867+#include <string>
868+
869+
870+/**
871+ * @file
872+ * The memc_add_by_key UDF
873+*/
874+class MemcachedAddByKey : public Item_int_func
875+{
876+ String value;
877+ String failure_buff;
878+public:
879+ MemcachedAddByKey()
880+ :
881+ Item_int_func(),
882+ failure_buff("0", &my_charset_bin)
883+ {}
884+
885+ const char *func_name() const
886+ {
887+ return "memc_add_by_key";
888+ }
889+
890+ int64_t val_int();
891+
892+ void fix_length_and_dec()
893+ {
894+ max_length= 32;
895+ }
896+/*
897+ * This UDF takes 3 or 4 arguments
898+*/
899+
900+ bool check_argument_count(int n)
901+ {
902+ return ((n == 3 || n == 4));
903+ }
904+};
905+
906+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_SET_BY_KEY_H */
907
908=== added file 'plugin/memcached_udf/memc_append.cc'
909--- plugin/memcached_udf/memc_append.cc 1970-01-01 00:00:00 +0000
910+++ plugin/memcached_udf/memc_append.cc 2009-10-05 20:45:23 +0000
911@@ -0,0 +1,75 @@
912+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
913+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
914+ *
915+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
916+ * All rights reserved.
917+ *
918+ * Redistribution and use in source and binary forms, with or without
919+ * modification, are permitted provided that the following conditions are met:
920+ *
921+ * * Redistributions of source code must retain the above copyright notice,
922+ * this list of conditions and the following disclaimer.
923+ * * Redistributions in binary form must reproduce the above copyright notice,
924+ * this list of conditions and the following disclaimer in the documentation
925+ * and/or other materials provided with the distribution.
926+ * * Neither the name of Patrick Galbraith nor the names of its contributors
927+ * may be used to endorse or promote products derived from this software
928+ * without specific prior written permission.
929+ *
930+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
931+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
932+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
933+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
934+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
935+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
936+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
937+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
938+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
939+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
940+ * THE POSSIBILITY OF SUCH DAMAGE.
941+ */
942+
943+#include <drizzled/server_includes.h>
944+#include <drizzled/function/str/strfunc.h>
945+
946+#include "memcached_udf.h"
947+#include "memc_append.h"
948+
949+#include <libmemcached/memcached.h>
950+
951+#include <string>
952+
953+using namespace std;
954+
955+int64_t MemcachedAppend::val_int()
956+{
957+ memcached_return rc;
958+ time_t expiration= 0;
959+ String *key;
960+ String *res;
961+ null_value= false;
962+
963+ if ((arg_count != 2 && arg_count != 3) ||
964+ !(key= args[0]->val_str(&value)) ||
965+ !(res= args[1]->val_str(&value)) ||
966+ !memc)
967+ {
968+ return 0;
969+ }
970+ if (arg_count == 3)
971+ {
972+ String *tmp_exp= args[2]->val_str(&value);
973+ expiration= (time_t)atoi(tmp_exp->c_ptr());
974+ }
975+
976+ rc= memcached_append(memc, key->c_ptr(), key->length(),
977+ res->c_ptr(), res->length(),
978+ expiration, (uint16_t) 0);
979+
980+ if (rc != MEMCACHED_SUCCESS)
981+ {
982+ return 0;
983+ }
984+
985+ return 1;
986+}
987
988=== added file 'plugin/memcached_udf/memc_append.h'
989--- plugin/memcached_udf/memc_append.h 1970-01-01 00:00:00 +0000
990+++ plugin/memcached_udf/memc_append.h 2009-10-05 20:45:23 +0000
991@@ -0,0 +1,80 @@
992+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
993+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
994+ *
995+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
996+ * All rights reserved.
997+ *
998+ * Redistribution and use in source and binary forms, with or without
999+ * modification, are permitted provided that the following conditions are met:
1000+ *
1001+ * * Redistributions of source code must retain the above copyright notice,
1002+ * this list of conditions and the following disclaimer.
1003+ * * Redistributions in binary form must reproduce the above copyright notice,
1004+ * this list of conditions and the following disclaimer in the documentation
1005+ * and/or other materials provided with the distribution.
1006+ * * Neither the name of Patrick Galbraith nor the names of its contributors
1007+ * may be used to endorse or promote products derived from this software
1008+ * without specific prior written permission.
1009+ *
1010+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1011+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1012+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1013+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1014+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1015+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1016+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1017+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1018+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1019+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
1020+ * THE POSSIBILITY OF SUCH DAMAGE.
1021+ *
1022+ */
1023+
1024+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_APPEND_H
1025+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_APPEND_H
1026+
1027+#include <drizzled/server_includes.h>
1028+#include <drizzled/function/str/strfunc.h>
1029+#include <drizzled/item/func.h>
1030+#include <string>
1031+
1032+
1033+using namespace std;
1034+
1035+/**
1036+ * @file
1037+ * The memc_append UDF
1038+ */
1039+class MemcachedAppend : public Item_int_func
1040+{
1041+ String value;
1042+ String failure_buff;
1043+public:
1044+ MemcachedAppend()
1045+ :
1046+ Item_int_func(),
1047+ failure_buff("failure ...", &my_charset_bin)
1048+ {}
1049+
1050+ const char *func_name() const
1051+ {
1052+ return "memc_append";
1053+ }
1054+
1055+ int64_t val_int();
1056+
1057+ void fix_length_and_dec()
1058+ {
1059+ max_length= 32;
1060+ }
1061+/*
1062+ * This UDF takes 2 or 3 arguments
1063+ */
1064+ bool check_argument_count(int n)
1065+ {
1066+ return ((n == 2 || n == 3));
1067+ }
1068+
1069+};
1070+
1071+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_APPEND_H */
1072
1073=== added file 'plugin/memcached_udf/memc_append_by_key.cc'
1074--- plugin/memcached_udf/memc_append_by_key.cc 1970-01-01 00:00:00 +0000
1075+++ plugin/memcached_udf/memc_append_by_key.cc 2009-10-05 20:45:23 +0000
1076@@ -0,0 +1,80 @@
1077+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1078+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1079+ *
1080+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
1081+ * All rights reserved.
1082+ *
1083+ * Redistribution and use in source and binary forms, with or without
1084+ * modification, are permitted provided that the following conditions are met:
1085+ *
1086+ * * Redistributions of source code must retain the above copyright notice,
1087+ * this list of conditions and the following disclaimer.
1088+ * * Redistributions in binary form must reproduce the above copyright notice,
1089+ * this list of conditions and the following disclaimer in the documentation
1090+ * and/or other materials provided with the distribution.
1091+ * * Neither the name of Patrick Galbraith nor the names of its contributors
1092+ * may be used to endorse or promote products derived from this software
1093+ * without specific prior written permission.
1094+ *
1095+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1096+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1097+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1098+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1099+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1100+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1101+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1102+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1103+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1104+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
1105+ * THE POSSIBILITY OF SUCH DAMAGE.
1106+ *
1107+ */
1108+
1109+#include <drizzled/server_includes.h>
1110+#include <drizzled/function/str/strfunc.h>
1111+
1112+#include "memcached_udf.h"
1113+#include "memc_append_by_key.h"
1114+
1115+#include <libmemcached/memcached.h>
1116+
1117+#include <string>
1118+
1119+using namespace std;
1120+
1121+int64_t MemcachedAppendByKey::val_int()
1122+{
1123+ memcached_return rc;
1124+ time_t expiration= 0;
1125+ String *master_key;
1126+ String *key;
1127+ String *res;
1128+ null_value= false;
1129+
1130+ if ((arg_count != 3 && arg_count != 4) ||
1131+ ! (master_key= args[0]->val_str(&value)) ||
1132+ ! (key= args[1]->val_str(&value)) ||
1133+ ! (res= args[2]->val_str(&value)) ||
1134+ ! memc)
1135+ {
1136+ return 0;
1137+ }
1138+ if (arg_count == 4)
1139+ {
1140+ String *tmp_exp= args[3]->val_str(&value);;
1141+ expiration= (time_t)atoi(tmp_exp->c_ptr());
1142+ }
1143+
1144+ rc= memcached_append_by_key(memc,
1145+ master_key->c_ptr(),
1146+ master_key->length(),
1147+ key->c_ptr(), key->length(),
1148+ res->c_ptr(), res->length(),
1149+ expiration, (uint16_t) 0);
1150+ if (rc != MEMCACHED_SUCCESS)
1151+ {
1152+ return 0;
1153+ }
1154+
1155+ return 1;
1156+}
1157
1158=== added file 'plugin/memcached_udf/memc_append_by_key.h'
1159--- plugin/memcached_udf/memc_append_by_key.h 1970-01-01 00:00:00 +0000
1160+++ plugin/memcached_udf/memc_append_by_key.h 2009-10-05 20:45:23 +0000
1161@@ -0,0 +1,77 @@
1162+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1163+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1164+ *
1165+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
1166+ * All rights reserved.
1167+ *
1168+ * Redistribution and use in source and binary forms, with or without
1169+ * modification, are permitted provided that the following conditions are met:
1170+ *
1171+ * * Redistributions of source code must retain the above copyright notice,
1172+ * this list of conditions and the following disclaimer.
1173+ * * Redistributions in binary form must reproduce the above copyright notice,
1174+ * this list of conditions and the following disclaimer in the documentation
1175+ * and/or other materials provided with the distribution.
1176+ * * Neither the name of Patrick Galbraith nor the names of its contributors
1177+ * may be used to endorse or promote products derived from this software
1178+ * without specific prior written permission.
1179+ *
1180+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1181+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1182+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1183+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1184+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1185+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1186+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1187+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1188+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1189+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
1190+ * THE POSSIBILITY OF SUCH DAMAGE.
1191+ *
1192+ */
1193+
1194+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_APPEND_BY_KEY_H
1195+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_APPEND_BY_KEY_H
1196+
1197+#include <drizzled/server_includes.h>
1198+#include <drizzled/function/str/strfunc.h>
1199+#include <drizzled/item/func.h>
1200+#include <string>
1201+
1202+using namespace std;
1203+
1204+/**
1205+ * @file
1206+ The memc_append_by_key UDF
1207+*/
1208+class MemcachedAppendByKey : public Item_int_func
1209+{
1210+ String failure_buff;
1211+ String value;
1212+public:
1213+ MemcachedAppendByKey()
1214+ :
1215+ Item_int_func(),
1216+ failure_buff("failure ...", &my_charset_bin)
1217+ {}
1218+
1219+ const char *func_name() const
1220+ {
1221+ return "memc_append_by_key";
1222+ }
1223+
1224+ int64_t val_int();
1225+
1226+ void fix_length_and_dec()
1227+ {
1228+ max_length= 32;
1229+ }
1230+ bool check_argument_count(int n)
1231+ {
1232+ return ((n == 3 || n == 4));
1233+ }
1234+
1235+
1236+};
1237+
1238+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_APPEND_BY_KEY_H */
1239
1240=== added file 'plugin/memcached_udf/memc_behavior_get.cc'
1241--- plugin/memcached_udf/memc_behavior_get.cc 1970-01-01 00:00:00 +0000
1242+++ plugin/memcached_udf/memc_behavior_get.cc 2009-10-05 20:45:23 +0000
1243@@ -0,0 +1,151 @@
1244+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1245+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1246+ *
1247+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
1248+ * All rights reserved.
1249+ *
1250+ * Redistribution and use in source and binary forms, with or without
1251+ * modification, are permitted provided that the following conditions are met:
1252+ *
1253+ * * Redistributions of source code must retain the above copyright notice,
1254+ * this list of conditions and the following disclaimer.
1255+ * * Redistributions in binary form must reproduce the above copyright notice,
1256+ * this list of conditions and the following disclaimer in the documentation
1257+ * and/or other materials provided with the distribution.
1258+ * * Neither the name of Patrick Galbraith nor the names of its contributors
1259+ * may be used to endorse or promote products derived from this software
1260+ * without specific prior written permission.
1261+ *
1262+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1263+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1264+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1265+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1266+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1267+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1268+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1269+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1270+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1271+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
1272+ * THE POSSIBILITY OF SUCH DAMAGE.
1273+ */
1274+
1275+#include <drizzled/server_includes.h>
1276+#include <drizzled/item/func.h>
1277+#include <drizzled/function/str/strfunc.h>
1278+
1279+#include "memcached_udf.h"
1280+#include "memc_behavior_get.h"
1281+
1282+#include <libmemcached/memcached.h>
1283+
1284+#include <string>
1285+#include <algorithm>
1286+
1287+using namespace std;
1288+
1289+void MemcachedBehaviorGet::setFailureString(const char *error)
1290+{
1291+ size_t size= strlen(error);
1292+ failure_buff.realloc(size);
1293+ failure_buff.length(size);
1294+ memcpy(failure_buff.ptr(), error, size);
1295+}
1296+
1297+String *MemcachedBehaviorGet::val_str(String *str)
1298+{
1299+ memcached_behavior mbehavior;
1300+ uint64_t isetting;
1301+ map<const string, memcached_behavior>::iterator it;
1302+ String *tmp_behavior;
1303+
1304+ if (arg_count != 1 ||
1305+ ! (tmp_behavior= args[0]->val_str(str)) ||
1306+ ! memc)
1307+ {
1308+ setFailureString("USAGE: memc_behavior_get('<behavior type>')");
1309+ return &failure_buff;
1310+ }
1311+
1312+ string behavior(tmp_behavior->c_ptr());
1313+
1314+ /*
1315+ * We don't want the user to have to type in all input in upper
1316+ * case so we transform the input strings to upper case here.
1317+ */
1318+ std::transform(behavior.begin(), behavior.end(),
1319+ behavior.begin(), ::toupper);
1320+
1321+ it = behavior_map.find(behavior);
1322+ if (it == behavior_map.end())
1323+ {
1324+ setFailureString("UNKNOWN BEHAVIOR TYPE!");
1325+ return &failure_buff;
1326+ }
1327+
1328+ mbehavior= behavior_map[behavior];
1329+
1330+ isetting= memcached_behavior_get(memc, mbehavior);
1331+
1332+ switch (mbehavior)
1333+ {
1334+ case MEMCACHED_BEHAVIOR_SUPPORT_CAS:
1335+ case MEMCACHED_BEHAVIOR_NO_BLOCK:
1336+ case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS:
1337+ case MEMCACHED_BEHAVIOR_USER_DATA:
1338+ case MEMCACHED_BEHAVIOR_SORT_HOSTS:
1339+ case MEMCACHED_BEHAVIOR_VERIFY_KEY:
1340+ case MEMCACHED_BEHAVIOR_TCP_NODELAY:
1341+ case MEMCACHED_BEHAVIOR_KETAMA:
1342+ case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS:
1343+ if (isetting == 1)
1344+ return_buff.append("1");
1345+ else if (isetting == 0)
1346+ return_buff.append("0");
1347+ else
1348+ {
1349+ setFailureString("INVALID VALUE FOR BEHAVIOR - MUST be 1 OR 0!");
1350+ return &failure_buff;
1351+ }
1352+ break;
1353+ case MEMCACHED_BEHAVIOR_DISTRIBUTION:
1354+ {
1355+ string setting(dist_settings_reverse_map[isetting]);
1356+ return_buff.append(setting.c_str());
1357+ }
1358+ break;
1359+ case MEMCACHED_BEHAVIOR_HASH:
1360+ {
1361+ string setting(hash_settings_reverse_map[isetting]);
1362+ return_buff.append(setting.c_str());
1363+ }
1364+ break;
1365+ case MEMCACHED_BEHAVIOR_KETAMA_HASH:
1366+ {
1367+ string setting(ketama_hash_settings_reverse_map[isetting]);
1368+ return_buff.append(setting.c_str());
1369+ }
1370+ break;
1371+ case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE:
1372+ case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE:
1373+ case MEMCACHED_BEHAVIOR_POLL_TIMEOUT:
1374+ case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT:
1375+ case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT:
1376+ case MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK:
1377+ case MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK:
1378+ {
1379+ size_t setting_len= 0;
1380+ char tmp_buff[16];
1381+
1382+ snprintf(tmp_buff, 16, "%"PRIu64, isetting);
1383+ setting_len= strlen(tmp_buff);
1384+ return_buff.realloc(setting_len);
1385+ return_buff.length(setting_len);
1386+ memcpy(return_buff.ptr(),tmp_buff, setting_len);
1387+ }
1388+ break;
1389+ default:
1390+ break;
1391+ }
1392+
1393+ return &return_buff;
1394+}
1395
1396=== added file 'plugin/memcached_udf/memc_behavior_get.h'
1397--- plugin/memcached_udf/memc_behavior_get.h 1970-01-01 00:00:00 +0000
1398+++ plugin/memcached_udf/memc_behavior_get.h 2009-10-05 20:45:23 +0000
1399@@ -0,0 +1,257 @@
1400+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1401+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1402+ *
1403+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
1404+ * All rights reserved.
1405+ *
1406+ * Redistribution and use in source and binary forms, with or without
1407+ * modification, are permitted provided that the following conditions are met:
1408+ *
1409+ * * Redistributions of source code must retain the above copyright notice,
1410+ * this list of conditions and the following disclaimer.
1411+ * * Redistributions in binary form must reproduce the above copyright notice,
1412+ * this list of conditions and the following disclaimer in the documentation
1413+ * and/or other materials provided with the distribution.
1414+ * * Neither the name of Patrick Galbraith nor the names of its contributors
1415+ * may be used to endorse or promote products derived from this software
1416+ * without specific prior written permission.
1417+ *
1418+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1419+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1420+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1421+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1422+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1423+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1424+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1425+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1426+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1427+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
1428+ * THE POSSIBILITY OF SUCH DAMAGE.
1429+ */
1430+
1431+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_BEHAVIOR_GET_H
1432+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_BEHAVIOR_GET_H
1433+
1434+#include <drizzled/server_includes.h>
1435+#include <drizzled/item/func.h>
1436+
1437+#include <libmemcached/memcached.h>
1438+
1439+#include <map>
1440+#include <string>
1441+
1442+/**
1443+ * @file
1444+ * The memc_behavior_get UDF
1445+ */
1446+class MemcachedBehaviorGet : public Item_str_func
1447+{
1448+public:
1449+ MemcachedBehaviorGet()
1450+ :
1451+ Item_str_func(),
1452+ failure_buff("FAILURE", &my_charset_bin),
1453+ return_buff("", &my_charset_bin),
1454+ behavior_map(),
1455+ behavior_reverse_map(),
1456+ dist_settings_reverse_map(),
1457+ hash_settings_reverse_map(),
1458+ ketama_hash_settings_reverse_map()
1459+ {
1460+ /*
1461+ * std::map for mapping string behaviors to int behavior values
1462+ * This is used to take user input behaviors from the UDF and
1463+ * be able to set the correct int behavior
1464+ */
1465+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1466+ ("MEMCACHED_BEHAVIOR_SUPPORT_CAS", MEMCACHED_BEHAVIOR_SUPPORT_CAS));
1467+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1468+ ("MEMCACHED_BEHAVIOR_NO_BLOCK", MEMCACHED_BEHAVIOR_NO_BLOCK));
1469+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1470+ ("MEMCACHED_BEHAVIOR_TCP_NODELAY", MEMCACHED_BEHAVIOR_TCP_NODELAY));
1471+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1472+ ("MEMCACHED_BEHAVIOR_HASH", MEMCACHED_BEHAVIOR_HASH));
1473+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1474+ ("MEMCACHED_BEHAVIOR_CACHE_LOOKUPS", MEMCACHED_BEHAVIOR_CACHE_LOOKUPS));
1475+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1476+ ("MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE", MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE));
1477+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1478+ ("MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE", MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE));
1479+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1480+ ("MEMCACHED_BEHAVIOR_BUFFER_REQUESTS", MEMCACHED_BEHAVIOR_BUFFER_REQUESTS));
1481+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1482+ ("MEMCACHED_BEHAVIOR_KETAMA", MEMCACHED_BEHAVIOR_KETAMA));
1483+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1484+ ("MEMCACHED_BEHAVIOR_POLL_TIMEOUT", MEMCACHED_BEHAVIOR_POLL_TIMEOUT));
1485+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1486+ ("MEMCACHED_BEHAVIOR_RETRY_TIMEOUT", MEMCACHED_BEHAVIOR_RETRY_TIMEOUT));
1487+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1488+ ("MEMCACHED_BEHAVIOR_DISTRIBUTION", MEMCACHED_BEHAVIOR_DISTRIBUTION));
1489+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1490+ ("MEMCACHED_BEHAVIOR_USER_DATA", MEMCACHED_BEHAVIOR_USER_DATA));
1491+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1492+ ("MEMCACHED_BEHAVIOR_SORT_HOSTS", MEMCACHED_BEHAVIOR_SORT_HOSTS));
1493+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1494+ ("MEMCACHED_BEHAVIOR_VERIFY_KEY", MEMCACHED_BEHAVIOR_VERIFY_KEY));
1495+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1496+ ("MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT", MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT));
1497+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1498+ ("MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED", MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED));
1499+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1500+ ("MEMCACHED_BEHAVIOR_KETAMA_HASH", MEMCACHED_BEHAVIOR_KETAMA_HASH));
1501+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1502+ ("MEMCACHED_BEHAVIOR_BINARY_PROTOCOL", MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
1503+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1504+ ("MEMCACHED_BEHAVIOR_SND_TIMEOUT", MEMCACHED_BEHAVIOR_SND_TIMEOUT));
1505+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1506+ ("MEMCACHED_BEHAVIOR_RCV_TIMEOUT", MEMCACHED_BEHAVIOR_RCV_TIMEOUT));
1507+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1508+ ("MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT", MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT));
1509+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1510+ ("MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK", MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK));
1511+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1512+ ("MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK", MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK));
1513+
1514+ /*
1515+ * std::map for mapping int behavior values to behavior strings
1516+ * This is used to take int behaviors from the the clien and be
1517+ * able to print the string value of the behavior in memc_behavior_get
1518+ * UDF
1519+ */
1520+ behavior_reverse_map.insert(std::pair<memcached_behavior, const std::string>
1521+ (MEMCACHED_BEHAVIOR_SUPPORT_CAS, "MEMCACHED_BEHAVIOR_SUPPORT_CAS"));
1522+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1523+ (MEMCACHED_BEHAVIOR_NO_BLOCK, "MEMCACHED_BEHAVIOR_NO_BLOCK"));
1524+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1525+ (MEMCACHED_BEHAVIOR_TCP_NODELAY, "MEMCACHED_BEHAVIOR_TCP_NODELAY"));
1526+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1527+ (MEMCACHED_BEHAVIOR_HASH, "MEMCACHED_BEHAVIOR_HASH"));
1528+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1529+ (MEMCACHED_BEHAVIOR_CACHE_LOOKUPS, "MEMCACHED_BEHAVIOR_CACHE_LOOKUPS"));
1530+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1531+ (MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, "MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE"));
1532+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1533+ (MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, "MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE"));
1534+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1535+ (MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, "MEMCACHED_BEHAVIOR_BUFFER_REQUESTS"));
1536+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1537+ (MEMCACHED_BEHAVIOR_KETAMA, "MEMCACHED_BEHAVIOR_KETAMA"));
1538+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1539+ (MEMCACHED_BEHAVIOR_POLL_TIMEOUT, "MEMCACHED_BEHAVIOR_POLL_TIMEOUT"));
1540+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1541+ (MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, "MEMCACHED_BEHAVIOR_RETRY_TIMEOUT"));
1542+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1543+ (MEMCACHED_BEHAVIOR_DISTRIBUTION, "MEMCACHED_BEHAVIOR_DISTRIBUTION"));
1544+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1545+ (MEMCACHED_BEHAVIOR_USER_DATA, "MEMCACHED_BEHAVIOR_USER_DATA"));
1546+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1547+ (MEMCACHED_BEHAVIOR_SORT_HOSTS, "MEMCACHED_BEHAVIOR_SORT_HOSTS"));
1548+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1549+ (MEMCACHED_BEHAVIOR_VERIFY_KEY, "MEMCACHED_BEHAVIOR_VERIFY_KEY"));
1550+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1551+ (MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, "MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT"));
1552+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1553+ (MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, "MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED"));
1554+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1555+ (MEMCACHED_BEHAVIOR_KETAMA_HASH, "MEMCACHED_BEHAVIOR_KETAMA_HASH"));
1556+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1557+ (MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, "MEMCACHED_BEHAVIOR_BINARY_PROTOCOL"));
1558+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1559+ (MEMCACHED_BEHAVIOR_SND_TIMEOUT, "MEMCACHED_BEHAVIOR_SND_TIMEOUT"));
1560+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1561+ (MEMCACHED_BEHAVIOR_RCV_TIMEOUT, "MEMCACHED_BEHAVIOR_RCV_TIMEOUT"));
1562+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1563+ (MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, "MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT"));
1564+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1565+ (MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK, "MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK"));
1566+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
1567+ (MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK, "MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK"));
1568+
1569+ /*
1570+ * std::map for mapping distribution string values to int distribution values
1571+ * For being able to map int distribution values to string distribution values
1572+ * Used by memc_behavior_get() for distribution types
1573+ */
1574+ dist_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1575+ (MEMCACHED_DISTRIBUTION_MODULA, "MEMCACHED_DISTRIBUTION_MODULA"));
1576+ dist_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1577+ (MEMCACHED_DISTRIBUTION_CONSISTENT, "MEMCACHED_DISTRIBUTION_CONSISTENT"));
1578+ dist_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1579+ (MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA, "MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA"));
1580+
1581+ /*
1582+ * std::map for mapping distribution string values to int distribution values
1583+ * For being able to map int distribution values to string distribution values
1584+ * Used by memc_behavior_get() for hash types
1585+ */
1586+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1587+ (MEMCACHED_HASH_DEFAULT, "MEMCACHED_HASH_DEFAULT"));
1588+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1589+ (MEMCACHED_HASH_MD5, "MEMCACHED_HASH_MD5"));
1590+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1591+ (MEMCACHED_HASH_CRC, "MEMCACHED_HASH_CRC"));
1592+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1593+ (MEMCACHED_HASH_FNV1_64, "MEMCACHED_HASH_FNV1_64"));
1594+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1595+ (MEMCACHED_HASH_FNV1A_64, "MEMCACHED_HASH_FNV1A_64"));
1596+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1597+ (MEMCACHED_HASH_FNV1_32, "MEMCACHED_HASH_FNV1_32"));
1598+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1599+ (MEMCACHED_HASH_FNV1A_32, "MEMCACHED_HASH_FNV1A_32"));
1600+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1601+ (MEMCACHED_HASH_JENKINS, "MEMCACHED_HASH_JENKINS"));
1602+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1603+ (MEMCACHED_HASH_HSIEH, "MEMCACHED_HASH_HSIEH"));
1604+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1605+ (MEMCACHED_HASH_MURMUR, "MEMCACHED_HASH_MURMUR"));
1606+
1607+ /*
1608+ * std::map for mapping distribution string values to int distribution values
1609+ * For being able to map int distribution values to string distribution values
1610+ * Used by memc_behavior_get() for ketama hash types
1611+ */
1612+ ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1613+ (MEMCACHED_HASH_DEFAULT, "MEMCACHED_HASH_DEFAULT"));
1614+ ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1615+ (MEMCACHED_HASH_MD5, "MEMCACHED_HASH_MD5"));
1616+ ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1617+ (MEMCACHED_HASH_CRC, "MEMCACHED_HASH_CRC"));
1618+ ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1619+ (MEMCACHED_HASH_FNV1_64, "MEMCACHED_HASH_FNV1_64"));
1620+ ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1621+ (MEMCACHED_HASH_FNV1A_64, "MEMCACHED_HASH_FNV1A_64"));
1622+ ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1623+ (MEMCACHED_HASH_FNV1_32, "MEMCACHED_HASH_FNV1_32"));
1624+ ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
1625+ (MEMCACHED_HASH_FNV1A_32, "MEMCACHED_HASH_FNV1A_32"));
1626+ }
1627+
1628+ const char *func_name() const
1629+ {
1630+ return "memc_behavior_set";
1631+ }
1632+
1633+ String *val_str(String *);
1634+
1635+ void fix_length_and_dec()
1636+ {
1637+ max_length= 32;
1638+ }
1639+
1640+private:
1641+ void setFailureString(const char *error);
1642+
1643+ String failure_buff;
1644+ String return_buff;
1645+
1646+ /*
1647+ * std::map for behavioral get/set UDFs
1648+ */
1649+ std::map<const std::string, memcached_behavior> behavior_map;
1650+ std::map<memcached_behavior, const std::string> behavior_reverse_map;
1651+ std::map<uint64_t, const std::string> dist_settings_reverse_map;
1652+ std::map<uint64_t, const std::string> hash_settings_reverse_map;
1653+ std::map<uint64_t, const std::string> ketama_hash_settings_reverse_map;
1654+};
1655+
1656+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_BEHAVIOR_GET_H */
1657
1658=== added file 'plugin/memcached_udf/memc_behavior_set.cc'
1659--- plugin/memcached_udf/memc_behavior_set.cc 1970-01-01 00:00:00 +0000
1660+++ plugin/memcached_udf/memc_behavior_set.cc 2009-10-05 20:45:23 +0000
1661@@ -0,0 +1,170 @@
1662+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1663+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1664+ *
1665+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
1666+ * All rights reserved.
1667+ *
1668+ * Redistribution and use in source and binary forms, with or without
1669+ * modification, are permitted provided that the following conditions are met:
1670+ *
1671+ * * Redistributions of source code must retain the above copyright notice,
1672+ * this list of conditions and the following disclaimer.
1673+ * * Redistributions in binary form must reproduce the above copyright notice,
1674+ * this list of conditions and the following disclaimer in the documentation
1675+ * and/or other materials provided with the distribution.
1676+ * * Neither the name of Patrick Galbraith nor the names of its contributors
1677+ * may be used to endorse or promote products derived from this software
1678+ * without specific prior written permission.
1679+ *
1680+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1681+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1682+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1683+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1684+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1685+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1686+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1687+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1688+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1689+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
1690+ * THE POSSIBILITY OF SUCH DAMAGE.
1691+ */
1692+
1693+#include <drizzled/server_includes.h>
1694+#include <drizzled/item/func.h>
1695+#include <drizzled/function/str/strfunc.h>
1696+
1697+#include "memcached_udf.h"
1698+#include "memc_behavior_set.h"
1699+
1700+#include <libmemcached/memcached.h>
1701+
1702+#include <string>
1703+#include <algorithm>
1704+
1705+using namespace std;
1706+
1707+void MemcachedBehaviorSet::setFailureString(const char *error)
1708+{
1709+ size_t size= strlen(error);
1710+ failure_buff.realloc(size);
1711+ failure_buff.length(size);
1712+ memcpy(failure_buff.ptr(), error, size);
1713+}
1714+
1715+String *MemcachedBehaviorSet::val_str(String *str)
1716+{
1717+ memcached_return rc;
1718+ memcached_behavior mbehavior;
1719+ uint64_t isetting= 0;
1720+ map<const string, memcached_behavior>::iterator it_behav;
1721+ map<const string, uint64_t>::iterator it_hash;
1722+ map<const string, uint64_t>::iterator it_dist;
1723+ String *tmp_behavior;
1724+ String *tmp_setting;
1725+
1726+ if (arg_count != 2 ||
1727+ ! (tmp_behavior= args[0]->val_str(str)) ||
1728+ ! (tmp_setting= args[1]->val_str(str)) ||
1729+ ! memc)
1730+ {
1731+ setFailureString("USAGE: memc_behavior_set('<behavior type>','<value>')");
1732+ return &failure_buff;
1733+ }
1734+
1735+ string behavior(tmp_behavior->c_ptr());
1736+ string setting(tmp_setting->c_ptr());
1737+
1738+ /*
1739+ * We don't want the user to have to type in all input in upper
1740+ * case so we transform the input strings to upper case here.
1741+ */
1742+ std::transform(behavior.begin(), behavior.end(),
1743+ behavior.begin(), ::toupper);
1744+ std::transform(setting.begin(), setting.end(),
1745+ setting.begin(), ::toupper);
1746+
1747+ it_behav= behavior_map.find(behavior);
1748+ if (it_behav == behavior_map.end())
1749+ {
1750+ setFailureString("UNKNOWN BEHAVIOR TYPE!");
1751+ return &failure_buff;
1752+ }
1753+ mbehavior= behavior_map[behavior];
1754+
1755+ switch (mbehavior)
1756+ {
1757+ case MEMCACHED_BEHAVIOR_SUPPORT_CAS:
1758+ case MEMCACHED_BEHAVIOR_NO_BLOCK:
1759+ case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS:
1760+ case MEMCACHED_BEHAVIOR_USER_DATA:
1761+ case MEMCACHED_BEHAVIOR_SORT_HOSTS:
1762+ case MEMCACHED_BEHAVIOR_VERIFY_KEY:
1763+ case MEMCACHED_BEHAVIOR_TCP_NODELAY:
1764+ case MEMCACHED_BEHAVIOR_KETAMA:
1765+ case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS:
1766+ if (setting.compare("1") == 0)
1767+ {
1768+ isetting= 1;
1769+ }
1770+ else if (setting.compare("0") == 0)
1771+ {
1772+ isetting= 0;
1773+ }
1774+ else
1775+ {
1776+ setFailureString("INVALID VALUE FOR BEHAVIOR - MUST be 1 OR 0!");
1777+ return &failure_buff;
1778+ }
1779+ break;
1780+ case MEMCACHED_BEHAVIOR_DISTRIBUTION:
1781+ it_dist= dist_settings_map.find(setting);
1782+ if (it_dist == dist_settings_map.end())
1783+ {
1784+ setFailureString("INVALID VALUE FOR DISTRIBUTION!");
1785+ return &failure_buff;
1786+ }
1787+ isetting= dist_settings_map[setting];
1788+ break;
1789+ case MEMCACHED_BEHAVIOR_HASH:
1790+ it_hash= hash_settings_map.find(setting);
1791+ if (it_hash == hash_settings_map.end())
1792+ {
1793+ setFailureString("INVALID VALUE FOR MEMCACHED HASH ALGORITHM!");
1794+ return &failure_buff;
1795+ }
1796+ isetting= hash_settings_map[setting];
1797+ break;
1798+ case MEMCACHED_BEHAVIOR_KETAMA_HASH:
1799+ isetting= ketama_hash_settings_map[setting];
1800+ if (! isetting)
1801+ {
1802+ setFailureString("INVALID VALUE FOR KETAMA HASH ALGORITHM!");
1803+ return &failure_buff;
1804+ }
1805+ break;
1806+ case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE:
1807+ case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE:
1808+ case MEMCACHED_BEHAVIOR_POLL_TIMEOUT:
1809+ case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT:
1810+ case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT:
1811+ case MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK:
1812+ case MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK:
1813+ /*
1814+ What type of check the values passed to these behaviors?
1815+ Range?
1816+ */
1817+ break;
1818+ default:
1819+ break;
1820+ }
1821+
1822+ rc= memcached_behavior_set(memc, mbehavior, isetting);
1823+
1824+ if (rc != MEMCACHED_SUCCESS)
1825+ {
1826+ return &failure_buff;
1827+ }
1828+
1829+ return &success_buff;
1830+}
1831+
1832
1833=== added file 'plugin/memcached_udf/memc_behavior_set.h'
1834--- plugin/memcached_udf/memc_behavior_set.h 1970-01-01 00:00:00 +0000
1835+++ plugin/memcached_udf/memc_behavior_set.h 2009-10-05 20:45:23 +0000
1836@@ -0,0 +1,174 @@
1837+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1838+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1839+ *
1840+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
1841+ * All rights reserved.
1842+ *
1843+ * Redistribution and use in source and binary forms, with or without
1844+ * modification, are permitted provided that the following conditions are met:
1845+ *
1846+ * * Redistributions of source code must retain the above copyright notice,
1847+ * this list of conditions and the following disclaimer.
1848+ * * Redistributions in binary form must reproduce the above copyright notice,
1849+ * this list of conditions and the following disclaimer in the documentation
1850+ * and/or other materials provided with the distribution.
1851+ * * Neither the name of Patrick Galbraith nor the names of its contributors
1852+ * may be used to endorse or promote products derived from this software
1853+ * without specific prior written permission.
1854+ *
1855+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1856+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1857+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1858+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1859+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1860+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1861+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1862+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1863+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1864+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
1865+ * THE POSSIBILITY OF SUCH DAMAGE.
1866+ */
1867+
1868+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_BEHAVIOR_SET_H
1869+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_BEHAVIOR_SET_H
1870+
1871+#include <drizzled/server_includes.h>
1872+#include <drizzled/item/func.h>
1873+
1874+#include <libmemcached/memcached.h>
1875+
1876+#include <map>
1877+#include <string>
1878+
1879+/* implements memc_behavior_set */
1880+class MemcachedBehaviorSet : public Item_str_func
1881+{
1882+public:
1883+ MemcachedBehaviorSet()
1884+ :
1885+ Item_str_func(),
1886+ failure_buff("0", &my_charset_bin),
1887+ success_buff("1", &my_charset_bin),
1888+ behavior_map(),
1889+ dist_settings_map(),
1890+ hash_settings_map(),
1891+ ketama_hash_settings_map()
1892+ {
1893+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1894+ ("MEMCACHED_BEHAVIOR_SUPPORT_CAS", MEMCACHED_BEHAVIOR_SUPPORT_CAS));
1895+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1896+ ("MEMCACHED_BEHAVIOR_NO_BLOCK", MEMCACHED_BEHAVIOR_NO_BLOCK));
1897+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1898+ ("MEMCACHED_BEHAVIOR_TCP_NODELAY", MEMCACHED_BEHAVIOR_TCP_NODELAY));
1899+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1900+ ("MEMCACHED_BEHAVIOR_HASH", MEMCACHED_BEHAVIOR_HASH));
1901+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1902+ ("MEMCACHED_BEHAVIOR_CACHE_LOOKUPS", MEMCACHED_BEHAVIOR_CACHE_LOOKUPS));
1903+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1904+ ("MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE", MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE));
1905+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1906+ ("MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE", MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE));
1907+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1908+ ("MEMCACHED_BEHAVIOR_BUFFER_REQUESTS", MEMCACHED_BEHAVIOR_BUFFER_REQUESTS));
1909+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1910+ ("MEMCACHED_BEHAVIOR_KETAMA", MEMCACHED_BEHAVIOR_KETAMA));
1911+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1912+ ("MEMCACHED_BEHAVIOR_POLL_TIMEOUT", MEMCACHED_BEHAVIOR_POLL_TIMEOUT));
1913+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1914+ ("MEMCACHED_BEHAVIOR_RETRY_TIMEOUT", MEMCACHED_BEHAVIOR_RETRY_TIMEOUT));
1915+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1916+ ("MEMCACHED_BEHAVIOR_DISTRIBUTION", MEMCACHED_BEHAVIOR_DISTRIBUTION));
1917+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1918+ ("MEMCACHED_BEHAVIOR_USER_DATA", MEMCACHED_BEHAVIOR_USER_DATA));
1919+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1920+ ("MEMCACHED_BEHAVIOR_SORT_HOSTS", MEMCACHED_BEHAVIOR_SORT_HOSTS));
1921+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1922+ ("MEMCACHED_BEHAVIOR_VERIFY_KEY", MEMCACHED_BEHAVIOR_VERIFY_KEY));
1923+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1924+ ("MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT", MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT));
1925+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1926+ ("MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED", MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED));
1927+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1928+ ("MEMCACHED_BEHAVIOR_KETAMA_HASH", MEMCACHED_BEHAVIOR_KETAMA_HASH));
1929+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1930+ ("MEMCACHED_BEHAVIOR_BINARY_PROTOCOL", MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
1931+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1932+ ("MEMCACHED_BEHAVIOR_SND_TIMEOUT", MEMCACHED_BEHAVIOR_SND_TIMEOUT));
1933+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1934+ ("MEMCACHED_BEHAVIOR_RCV_TIMEOUT", MEMCACHED_BEHAVIOR_RCV_TIMEOUT));
1935+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1936+ ("MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT", MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT));
1937+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1938+ ("MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK", MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK));
1939+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
1940+ ("MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK", MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK));
1941+
1942+ dist_settings_map.insert(std::pair<const std::string, uint64_t>
1943+ ("MEMCACHED_DISTRIBUTION_MODULA", MEMCACHED_DISTRIBUTION_MODULA));
1944+ dist_settings_map.insert(std::pair<const std::string, uint64_t>
1945+ ("MEMCACHED_DISTRIBUTION_CONSISTENT", MEMCACHED_DISTRIBUTION_CONSISTENT));
1946+ dist_settings_map.insert(std::pair<const std::string, uint64_t>
1947+ ("MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA", MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA));
1948+
1949+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
1950+ ("MEMCACHED_HASH_DEFAULT", MEMCACHED_HASH_DEFAULT));
1951+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
1952+ ("MEMCACHED_HASH_MD5", MEMCACHED_HASH_MD5));
1953+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
1954+ ("MEMCACHED_HASH_CRC", MEMCACHED_HASH_CRC));
1955+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
1956+ ("MEMCACHED_HASH_FNV1_64", MEMCACHED_HASH_FNV1_64));
1957+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
1958+ ("MEMCACHED_HASH_FNV1A_64", MEMCACHED_HASH_FNV1A_64));
1959+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
1960+ ("MEMCACHED_HASH_FNV1_32", MEMCACHED_HASH_FNV1_32));
1961+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
1962+ ("MEMCACHED_HASH_FNV1A_32", MEMCACHED_HASH_FNV1A_32));
1963+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
1964+ ("MEMCACHED_HASH_JENKINS", MEMCACHED_HASH_JENKINS));
1965+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
1966+ ("MEMCACHED_HASH_HSIEH", MEMCACHED_HASH_HSIEH));
1967+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
1968+ ("MEMCACHED_HASH_MURMUR", MEMCACHED_HASH_MURMUR));
1969+
1970+ ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
1971+ ("MEMCACHED_HASH_DEFAULT", MEMCACHED_HASH_DEFAULT));
1972+ ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
1973+ ("MEMCACHED_HASH_MD5", MEMCACHED_HASH_MD5));
1974+ ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
1975+ ("MEMCACHED_HASH_CRC", MEMCACHED_HASH_CRC));
1976+ ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
1977+ ("MEMCACHED_HASH_FNV1_64", MEMCACHED_HASH_FNV1_64));
1978+ ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
1979+ ("MEMCACHED_HASH_FNV1A_64", MEMCACHED_HASH_FNV1A_64));
1980+ ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
1981+ ("MEMCACHED_HASH_FNV1_32", MEMCACHED_HASH_FNV1_32));
1982+ ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
1983+ ("MEMCACHED_HASH_FNV1A_32", MEMCACHED_HASH_FNV1A_32));
1984+ }
1985+
1986+ const char *func_name() const
1987+ {
1988+ return "memc_behavior_set";
1989+ }
1990+
1991+ String *val_str(String *);
1992+
1993+ void fix_length_and_dec()
1994+ {
1995+ max_length= 32;
1996+ }
1997+
1998+private:
1999+ void setFailureString(const char *error);
2000+
2001+ String failure_buff;
2002+ String success_buff;
2003+
2004+ std::map<const std::string, memcached_behavior> behavior_map;
2005+ std::map<const std::string, uint64_t> dist_settings_map;
2006+ std::map<const std::string, uint64_t> hash_settings_map;
2007+ std::map<const std::string, uint64_t> ketama_hash_settings_map;
2008+};
2009+
2010+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_BEHAVIOR_SET_H */
2011
2012=== added file 'plugin/memcached_udf/memc_cas.cc'
2013--- plugin/memcached_udf/memc_cas.cc 1970-01-01 00:00:00 +0000
2014+++ plugin/memcached_udf/memc_cas.cc 2009-10-05 20:45:23 +0000
2015@@ -0,0 +1,80 @@
2016+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2017+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2018+ *
2019+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
2020+ * All rights reserved.
2021+ *
2022+ * Redistribution and use in source and binary forms, with or without
2023+ * modification, are permitted provided that the following conditions are met:
2024+ *
2025+ * * Redistributions of source code must retain the above copyright notice,
2026+ * this list of conditions and the following disclaimer.
2027+ * * Redistributions in binary form must reproduce the above copyright notice,
2028+ * this list of conditions and the following disclaimer in the documentation
2029+ * and/or other materials provided with the distribution.
2030+ * * Neither the name of Patrick Galbraith nor the names of its contributors
2031+ * may be used to endorse or promote products derived from this software
2032+ * without specific prior written permission.
2033+ *
2034+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2035+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2036+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2037+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2038+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2039+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2040+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2041+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2042+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2043+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2044+ * THE POSSIBILITY OF SUCH DAMAGE.
2045+ */
2046+
2047+#include <drizzled/server_includes.h>
2048+#include <drizzled/function/str/strfunc.h>
2049+
2050+#include "memcached_udf.h"
2051+#include "memc_cas.h"
2052+
2053+#include <libmemcached/memcached.h>
2054+
2055+#include <string>
2056+
2057+using namespace std;
2058+
2059+int64_t MemcachedCas::val_int()
2060+{
2061+ memcached_return rc;
2062+ time_t expiration= 0;
2063+ String *key;
2064+ String *res;
2065+ String *cas;
2066+ null_value= false;
2067+
2068+ if ((arg_count != 3 && arg_count != 4) ||
2069+ ! (key= args[0]->val_str(&value)) ||
2070+ ! (res= args[1]->val_str(&value)) ||
2071+ ! (cas= args[2]->val_str(&value)) ||
2072+ ! memc)
2073+ {
2074+ return 0;
2075+ }
2076+
2077+ if (arg_count == 4)
2078+ {
2079+ String *tmp_exp= args[3]->val_str(&value);;
2080+
2081+ expiration= (time_t)atoi(tmp_exp->c_ptr());
2082+ }
2083+
2084+ rc= memcached_cas(memc, key->c_ptr(), key->length(),
2085+ res->c_ptr(), res->length(),
2086+ expiration, (uint16_t) 0,
2087+ (uint64_t) strtol(cas->c_ptr(), (char **)NULL, 10));
2088+
2089+ if (rc != MEMCACHED_SUCCESS)
2090+ {
2091+ return 0;
2092+ }
2093+
2094+ return 1;
2095+}
2096
2097=== added file 'plugin/memcached_udf/memc_cas.h'
2098--- plugin/memcached_udf/memc_cas.h 1970-01-01 00:00:00 +0000
2099+++ plugin/memcached_udf/memc_cas.h 2009-10-05 20:45:23 +0000
2100@@ -0,0 +1,69 @@
2101+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2102+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2103+ *
2104+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
2105+ * All rights reserved.
2106+ *
2107+ * Redistribution and use in source and binary forms, with or without
2108+ * modification, are permitted provided that the following conditions are met:
2109+ *
2110+ * * Redistributions of source code must retain the above copyright notice,
2111+ * this list of conditions and the following disclaimer.
2112+ * * Redistributions in binary form must reproduce the above copyright notice,
2113+ * this list of conditions and the following disclaimer in the documentation
2114+ * and/or other materials provided with the distribution.
2115+ * * Neither the name of Patrick Galbraith nor the names of its contributors
2116+ * may be used to endorse or promote products derived from this software
2117+ * without specific prior written permission.
2118+ *
2119+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2120+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2121+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2122+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2123+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2124+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2125+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2126+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2127+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2128+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2129+ * THE POSSIBILITY OF SUCH DAMAGE.
2130+ */
2131+
2132+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_CAS_H
2133+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_CAS_H
2134+
2135+#include <drizzled/server_includes.h>
2136+#include <drizzled/function/str/strfunc.h>
2137+#include <drizzled/item/func.h>
2138+#include <string>
2139+
2140+/* implements memc_cas */
2141+class MemcachedCas : public Item_int_func
2142+{
2143+ String value;
2144+ String failure_buff;
2145+public:
2146+ MemcachedCas()
2147+ :
2148+ Item_int_func(),
2149+ failure_buff("error ... ", &my_charset_bin)
2150+ {}
2151+
2152+ const char *func_name() const
2153+ {
2154+ return "memc_cas";
2155+ }
2156+
2157+ int64_t val_int();
2158+
2159+ void fix_length_and_dec()
2160+ {
2161+ max_length= 32;
2162+ }
2163+ bool check_argument_count(int n)
2164+ {
2165+ return ((n == 3 || n == 4));
2166+ }
2167+};
2168+
2169+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_CAS_H */
2170
2171=== added file 'plugin/memcached_udf/memc_cas_by_key.cc'
2172--- plugin/memcached_udf/memc_cas_by_key.cc 1970-01-01 00:00:00 +0000
2173+++ plugin/memcached_udf/memc_cas_by_key.cc 2009-10-05 20:45:23 +0000
2174@@ -0,0 +1,84 @@
2175+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2176+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2177+ *
2178+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
2179+ * All rights reserved.
2180+ *
2181+ * Redistribution and use in source and binary forms, with or without
2182+ * modification, are permitted provided that the following conditions are met:
2183+ *
2184+ * * Redistributions of source code must retain the above copyright notice,
2185+ * this list of conditions and the following disclaimer.
2186+ * * Redistributions in binary form must reproduce the above copyright notice,
2187+ * this list of conditions and the following disclaimer in the documentation
2188+ * and/or other materials provided with the distribution.
2189+ * * Neither the name of Patrick Galbraith nor the names of its contributors
2190+ * may be used to endorse or promote products derived from this software
2191+ * without specific prior written permission.
2192+ *
2193+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2194+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2195+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2196+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2197+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2198+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2199+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2200+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2201+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2202+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2203+ * THE POSSIBILITY OF SUCH DAMAGE.
2204+ */
2205+
2206+#include <drizzled/server_includes.h>
2207+#include <drizzled/function/str/strfunc.h>
2208+
2209+#include "memcached_udf.h"
2210+#include "memc_cas_by_key.h"
2211+
2212+#include <libmemcached/memcached.h>
2213+
2214+#include <string>
2215+
2216+using namespace std;
2217+
2218+int64_t MemcachedCasByKey::val_int()
2219+{
2220+ memcached_return rc;
2221+ time_t expiration= 0;
2222+ String *master_key;
2223+ String *key;
2224+ String *res;
2225+ String *cas;
2226+ null_value= false;
2227+
2228+ if ((arg_count != 4 && arg_count != 5) ||
2229+ ! (master_key= args[0]->val_str(&value)) ||
2230+ ! (key= args[1]->val_str(&value)) ||
2231+ ! (res= args[2]->val_str(&value)) ||
2232+ ! (cas= args[3]->val_str(&value)) ||
2233+ ! memc)
2234+ {
2235+ return 0;
2236+ }
2237+
2238+ if (arg_count == 5)
2239+ {
2240+ String *tmp_exp= args[4]->val_str(&value);
2241+ expiration= (time_t)atoi(tmp_exp->c_ptr());
2242+ }
2243+
2244+ rc= memcached_cas_by_key(memc,
2245+ master_key->c_ptr(),
2246+ master_key->length(),
2247+ key->c_ptr(), key->length(),
2248+ res->c_ptr(), res->length(),
2249+ expiration, (uint16_t) 0,
2250+ (uint64_t) strtol(cas->c_ptr(), (char **)NULL, 10));
2251+
2252+ if (rc != MEMCACHED_SUCCESS)
2253+ {
2254+ return 0;
2255+ }
2256+
2257+ return 1;
2258+}
2259
2260=== added file 'plugin/memcached_udf/memc_cas_by_key.h'
2261--- plugin/memcached_udf/memc_cas_by_key.h 1970-01-01 00:00:00 +0000
2262+++ plugin/memcached_udf/memc_cas_by_key.h 2009-10-05 20:45:23 +0000
2263@@ -0,0 +1,69 @@
2264+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2265+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2266+ *
2267+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
2268+ * All rights reserved.
2269+ *
2270+ * Redistribution and use in source and binary forms, with or without
2271+ * modification, are permitted provided that the following conditions are met:
2272+ *
2273+ * * Redistributions of source code must retain the above copyright notice,
2274+ * this list of conditions and the following disclaimer.
2275+ * * Redistributions in binary form must reproduce the above copyright notice,
2276+ * this list of conditions and the following disclaimer in the documentation
2277+ * and/or other materials provided with the distribution.
2278+ * * Neither the name of Patrick Galbraith nor the names of its contributors
2279+ * may be used to endorse or promote products derived from this software
2280+ * without specific prior written permission.
2281+ *
2282+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2283+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2284+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2285+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2286+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2287+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2288+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2289+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2290+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2291+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2292+ * THE POSSIBILITY OF SUCH DAMAGE.
2293+ */
2294+
2295+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_CAS_BY_KEY_H
2296+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_CAS_BY_KEY_H
2297+
2298+#include <drizzled/server_includes.h>
2299+#include <drizzled/function/str/strfunc.h>
2300+#include <drizzled/item/func.h>
2301+#include <string>
2302+
2303+/* implements memc_cas */
2304+class MemcachedCasByKey : public Item_int_func
2305+{
2306+ String failure_buff;
2307+ String value;
2308+public:
2309+ MemcachedCasByKey()
2310+ :
2311+ Item_int_func(),
2312+ failure_buff("failure", &my_charset_bin)
2313+ {}
2314+
2315+ const char *func_name() const
2316+ {
2317+ return "memc_cas_by_key";
2318+ }
2319+
2320+ int64_t val_int();
2321+
2322+ void fix_length_and_dec()
2323+ {
2324+ max_length= 32;
2325+ }
2326+ bool check_argument_count(int n)
2327+ {
2328+ return ((n == 4 || n == 5));
2329+ }
2330+};
2331+
2332+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_CAS_BY_KEY_H */
2333
2334=== added file 'plugin/memcached_udf/memc_decrement.cc'
2335--- plugin/memcached_udf/memc_decrement.cc 1970-01-01 00:00:00 +0000
2336+++ plugin/memcached_udf/memc_decrement.cc 2009-10-05 20:45:24 +0000
2337@@ -0,0 +1,91 @@
2338+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2339+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2340+ *
2341+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
2342+ * All rights reserved.
2343+ *
2344+ * Redistribution and use in source and binary forms, with or without
2345+ * modification, are permitted provided that the following conditions are met:
2346+ *
2347+ * * Redistributions of source code must retain the above copyright notice,
2348+ * this list of conditions and the following disclaimer.
2349+ * * Redistributions in binary form must reproduce the above copyright notice,
2350+ * this list of conditions and the following disclaimer in the documentation
2351+ * and/or other materials provided with the distribution.
2352+ * * Neither the name of Patrick Galbraith nor the names of its contributors
2353+ * may be used to endorse or promote products derived from this software
2354+ * without specific prior written permission.
2355+ *
2356+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2357+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2358+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2359+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2360+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2361+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2362+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2363+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2364+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2365+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2366+ * THE POSSIBILITY OF SUCH DAMAGE.
2367+ */
2368+
2369+#include <drizzled/server_includes.h>
2370+#include <drizzled/function/str/strfunc.h>
2371+
2372+#include "memcached_udf.h"
2373+#include "memc_decrement.h"
2374+
2375+#include <libmemcached/memcached.h>
2376+
2377+#include <string>
2378+
2379+using namespace std;
2380+
2381+String *MemcachedDecrement::val_str(String *str)
2382+{
2383+ memcached_return rc;
2384+ int64_t offset;
2385+ uint64_t value;
2386+ size_t val_len;
2387+ char tmp_buff[32]= "";
2388+ String *key;
2389+ String *dec_str;
2390+ null_value= false;
2391+
2392+ if ((arg_count != 1 && arg_count != 2) ||
2393+ ! (key= args[0]->val_str(str)) ||
2394+ ! memc)
2395+ {
2396+ return &failure_buff;
2397+ }
2398+
2399+ if (arg_count == 2) {
2400+ dec_str= args[1]->val_str(str);
2401+ offset= atoi(dec_str->c_ptr());
2402+ }
2403+ else
2404+ {
2405+ offset= 1;
2406+ }
2407+
2408+ rc= memcached_decrement(memc,
2409+ key->c_ptr(),
2410+ key->length(),
2411+ offset,
2412+ &value);
2413+
2414+ snprintf(tmp_buff, 32, "%"PRIu64, value);
2415+ val_len= strlen(tmp_buff);
2416+
2417+ if (rc != MEMCACHED_SUCCESS)
2418+ {
2419+ return &failure_buff;
2420+ }
2421+
2422+ buffer.realloc(val_len);
2423+ buffer.length(val_len);
2424+ memcpy(buffer.ptr(), tmp_buff, val_len);
2425+
2426+ return &buffer;
2427+}
2428+
2429
2430=== added file 'plugin/memcached_udf/memc_decrement.h'
2431--- plugin/memcached_udf/memc_decrement.h 1970-01-01 00:00:00 +0000
2432+++ plugin/memcached_udf/memc_decrement.h 2009-10-05 20:45:24 +0000
2433@@ -0,0 +1,66 @@
2434+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2435+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2436+ *
2437+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
2438+ * All rights reserved.
2439+ *
2440+ * Redistribution and use in source and binary forms, with or without
2441+ * modification, are permitted provided that the following conditions are met:
2442+ *
2443+ * * Redistributions of source code must retain the above copyright notice,
2444+ * this list of conditions and the following disclaimer.
2445+ * * Redistributions in binary form must reproduce the above copyright notice,
2446+ * this list of conditions and the following disclaimer in the documentation
2447+ * and/or other materials provided with the distribution.
2448+ * * Neither the name of Patrick Galbraith nor the names of its contributors
2449+ * may be used to endorse or promote products derived from this software
2450+ * without specific prior written permission.
2451+ *
2452+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2453+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2454+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2455+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2456+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2457+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2458+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2459+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2460+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2461+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2462+ * THE POSSIBILITY OF SUCH DAMAGE.
2463+ *
2464+ */
2465+
2466+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_DECREMENT_H
2467+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_DECREMENT_H
2468+
2469+#include <drizzled/server_includes.h>
2470+#include <drizzled/function/str/strfunc.h>
2471+
2472+/* implements memc_decrement */
2473+class MemcachedDecrement : public Item_str_func
2474+{
2475+public:
2476+ MemcachedDecrement()
2477+ :
2478+ Item_str_func(),
2479+ failure_buff("FAILURE", &my_charset_bin)
2480+ {}
2481+
2482+ const char *func_name() const
2483+ {
2484+ return "memc_decrement";
2485+ }
2486+
2487+ String *val_str(String *);
2488+
2489+ void fix_length_and_dec()
2490+ {
2491+ max_length= 32;
2492+ }
2493+
2494+private:
2495+ String failure_buff;
2496+ String buffer;
2497+};
2498+
2499+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_DECREMENT_H */
2500
2501=== added file 'plugin/memcached_udf/memc_delete.cc'
2502--- plugin/memcached_udf/memc_delete.cc 1970-01-01 00:00:00 +0000
2503+++ plugin/memcached_udf/memc_delete.cc 2009-10-05 20:45:24 +0000
2504@@ -0,0 +1,65 @@
2505+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2506+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2507+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
2508+ * All rights reserved.
2509+ *
2510+ * Redistribution and use in source and binary forms, with or without
2511+ * modification, are permitted provided that the following conditions are met:
2512+ *
2513+ * * Redistributions of source code must retain the above copyright notice,
2514+ * this list of conditions and the following disclaimer.
2515+ * * Redistributions in binary form must reproduce the above copyright notice,
2516+ * this list of conditions and the following disclaimer in the documentation
2517+ * and/or other materials provided with the distribution.
2518+ * * Neither the name of Patrick Galbraith nor the names of its contributors
2519+ * may be used to endorse or promote products derived from this software
2520+ * without specific prior written permission.
2521+ *
2522+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2523+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2524+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2525+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2526+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2527+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2528+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2529+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2530+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2531+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2532+ * THE POSSIBILITY OF SUCH DAMAGE.
2533+ */
2534+
2535+#include <drizzled/server_includes.h>
2536+#include <drizzled/function/str/strfunc.h>
2537+
2538+#include "memcached_udf.h"
2539+#include "memc_delete.h"
2540+
2541+#include <libmemcached/memcached.h>
2542+
2543+#include <string>
2544+
2545+using namespace std;
2546+
2547+
2548+int64_t MemcachedDelete::val_int()
2549+{
2550+ memcached_return rc;
2551+ String *key;
2552+ null_value= false;
2553+
2554+ if (arg_count != 1 ||
2555+ ! (key= args[0]->val_str(&value)) ||
2556+ ! memc)
2557+ {
2558+ return 0;
2559+ }
2560+
2561+ rc= memcached_delete(memc, key->c_ptr(), key->length(), 0);
2562+
2563+ if (rc != MEMCACHED_SUCCESS)
2564+ {
2565+ return 0;
2566+ }
2567+
2568+ return 1;
2569+}
2570
2571=== added file 'plugin/memcached_udf/memc_delete.h'
2572--- plugin/memcached_udf/memc_delete.h 1970-01-01 00:00:00 +0000
2573+++ plugin/memcached_udf/memc_delete.h 2009-10-05 20:45:24 +0000
2574@@ -0,0 +1,70 @@
2575+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2576+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2577+ *
2578+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
2579+ * All rights reserved.
2580+ *
2581+ * Redistribution and use in source and binary forms, with or without
2582+ * modification, are permitted provided that the following conditions are met:
2583+ *
2584+ * * Redistributions of source code must retain the above copyright notice,
2585+ * this list of conditions and the following disclaimer.
2586+ * * Redistributions in binary form must reproduce the above copyright notice,
2587+ * this list of conditions and the following disclaimer in the documentation
2588+ * and/or other materials provided with the distribution.
2589+ * * Neither the name of Patrick Galbraith nor the names of its contributors
2590+ * may be used to endorse or promote products derived from this software
2591+ * without specific prior written permission.
2592+ *
2593+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2594+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2595+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2596+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2597+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2598+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2599+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2600+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2601+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2602+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2603+ * THE POSSIBILITY OF SUCH DAMAGE.
2604+ */
2605+
2606+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_DELETE_H
2607+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_DELETE_H
2608+
2609+#include <drizzled/server_includes.h>
2610+#include <drizzled/function/str/strfunc.h>
2611+#include <drizzled/item/func.h>
2612+#include <string>
2613+
2614+/* implements memc_delete */
2615+class MemcachedDelete : public Item_int_func
2616+{
2617+ String failure_buff;
2618+ String value;
2619+public:
2620+ MemcachedDelete()
2621+ :
2622+ Item_int_func(),
2623+ failure_buff("0", &my_charset_bin)
2624+ {}
2625+
2626+ const char *func_name() const
2627+ {
2628+ return "memc_delete";
2629+ }
2630+
2631+ int64_t val_int();
2632+
2633+ void fix_length_and_dec()
2634+ {
2635+ max_length= 32;
2636+ }
2637+ bool check_argument_count(int n)
2638+ {
2639+ return (n == 1);
2640+ }
2641+
2642+};
2643+
2644+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_DELETE_H */
2645
2646=== added file 'plugin/memcached_udf/memc_delete_by_key.cc'
2647--- plugin/memcached_udf/memc_delete_by_key.cc 1970-01-01 00:00:00 +0000
2648+++ plugin/memcached_udf/memc_delete_by_key.cc 2009-10-05 20:45:24 +0000
2649@@ -0,0 +1,70 @@
2650+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2651+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2652+ *
2653+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
2654+ * All rights reserved.
2655+ *
2656+ * Redistribution and use in source and binary forms, with or without
2657+ * modification, are permitted provided that the following conditions are met:
2658+ *
2659+ * * Redistributions of source code must retain the above copyright notice,
2660+ * this list of conditions and the following disclaimer.
2661+ * * Redistributions in binary form must reproduce the above copyright notice,
2662+ * this list of conditions and the following disclaimer in the documentation
2663+ * and/or other materials provided with the distribution.
2664+ * * Neither the name of Patrick Galbraith nor the names of its contributors
2665+ * may be used to endorse or promote products derived from this software
2666+ * without specific prior written permission.
2667+ *
2668+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2669+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2670+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2671+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2672+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2673+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2674+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2675+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2676+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2677+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2678+ * THE POSSIBILITY OF SUCH DAMAGE.
2679+ */
2680+
2681+#include <drizzled/server_includes.h>
2682+#include <drizzled/function/str/strfunc.h>
2683+
2684+#include "memcached_udf.h"
2685+#include "memc_delete_by_key.h"
2686+
2687+#include <libmemcached/memcached.h>
2688+
2689+#include <string>
2690+
2691+using namespace std;
2692+
2693+int64_t MemcachedDeleteByKey::val_int()
2694+{
2695+ memcached_return rc;
2696+ String *master_key;
2697+ String *key;
2698+ null_value= false;
2699+
2700+ if (arg_count != 2 ||
2701+ ! (master_key= args[0]->val_str(&value)) ||
2702+ ! (key= args[0]->val_str(&value)) ||
2703+ ! memc)
2704+ {
2705+ return 0;
2706+ }
2707+
2708+ rc= memcached_delete_by_key(memc,
2709+ master_key->c_ptr(),
2710+ master_key->length(),
2711+ key->c_ptr(), key->length(), 0);
2712+
2713+ if (rc != MEMCACHED_SUCCESS)
2714+ {
2715+ return 0;
2716+ }
2717+
2718+ return 1;
2719+}
2720
2721=== added file 'plugin/memcached_udf/memc_delete_by_key.h'
2722--- plugin/memcached_udf/memc_delete_by_key.h 1970-01-01 00:00:00 +0000
2723+++ plugin/memcached_udf/memc_delete_by_key.h 2009-10-05 20:45:24 +0000
2724@@ -0,0 +1,73 @@
2725+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2726+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2727+ *
2728+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
2729+ * All rights reserved.
2730+ *
2731+ * Redistribution and use in source and binary forms, with or without
2732+ * modification, are permitted provided that the following conditions are met:
2733+ *
2734+ * * Redistributions of source code must retain the above copyright notice,
2735+ * this list of conditions and the following disclaimer.
2736+ * * Redistributions in binary form must reproduce the above copyright notice,
2737+ * this list of conditions and the following disclaimer in the documentation
2738+ * and/or other materials provided with the distribution.
2739+ * * Neither the name of Patrick Galbraith nor the names of its contributors
2740+ * may be used to endorse or promote products derived from this software
2741+ * without specific prior written permission.
2742+ *
2743+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2744+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2745+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2746+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2747+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2748+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2749+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2750+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2751+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2752+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2753+ * THE POSSIBILITY OF SUCH DAMAGE.
2754+ */
2755+
2756+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_DELETE_BY_KEY_H
2757+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_DELETE_BY_KEY_H
2758+
2759+#include <drizzled/server_includes.h>
2760+#include <drizzled/function/str/strfunc.h>
2761+#include <drizzled/item/func.h>
2762+#include <string>
2763+
2764+using namespace std;
2765+using namespace drizzled;
2766+
2767+/* implements memc_delete */
2768+class MemcachedDeleteByKey : public Item_int_func
2769+{
2770+ String failure_buff;
2771+ String value;
2772+public:
2773+ MemcachedDeleteByKey()
2774+ :
2775+ Item_int_func(),
2776+ failure_buff("0", &my_charset_bin)
2777+ {}
2778+
2779+ const char *func_name() const
2780+ {
2781+ return "memc_delete_by_key";
2782+ }
2783+
2784+ int64_t val_int();
2785+
2786+ void fix_length_and_dec()
2787+ {
2788+ max_length= 32;
2789+ }
2790+ bool check_argument_count(int n)
2791+ {
2792+ return (n == 2);
2793+ }
2794+
2795+};
2796+
2797+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_DELETE_BY_KEY_H */
2798
2799=== added file 'plugin/memcached_udf/memc_get.cc'
2800--- plugin/memcached_udf/memc_get.cc 1970-01-01 00:00:00 +0000
2801+++ plugin/memcached_udf/memc_get.cc 2009-10-05 20:45:24 +0000
2802@@ -0,0 +1,80 @@
2803+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2804+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2805+ *
2806+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
2807+ * All rights reserved.
2808+ *
2809+ * Redistribution and use in source and binary forms, with or without
2810+ * modification, are permitted provided that the following conditions are met:
2811+ *
2812+ * * Redistributions of source code must retain the above copyright notice,
2813+ * this list of conditions and the following disclaimer.
2814+ * * Redistributions in binary form must reproduce the above copyright notice,
2815+ * this list of conditions and the following disclaimer in the documentation
2816+ * and/or other materials provided with the distribution.
2817+ * * Neither the name of Patrick Galbraith nor the names of its contributors
2818+ * may be used to endorse or promote products derived from this software
2819+ * without specific prior written permission.
2820+ *
2821+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2822+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2823+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2824+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2825+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2826+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2827+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2828+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2829+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2830+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2831+ * THE POSSIBILITY OF SUCH DAMAGE.
2832+ */
2833+/**
2834+ * @file
2835+ * memc_get UDF implementation
2836+ */
2837+
2838+#include <drizzled/server_includes.h>
2839+#include <drizzled/function/str/strfunc.h>
2840+
2841+#include "memcached_udf.h"
2842+#include "memc_get.h"
2843+
2844+#include <libmemcached/memcached.h>
2845+
2846+#include <string>
2847+
2848+using namespace std;
2849+
2850+/**
2851+ * value function for memc_get UDF
2852+ *
2853+ * @return string value from memcached
2854+ */
2855+String *MemcachedGet::val_str(String *str)
2856+{
2857+ memcached_return rc;
2858+ String *key;
2859+ uint32_t flags;
2860+ size_t val_len;
2861+
2862+ if (arg_count != 1 ||
2863+ ! (key= args[0]->val_str(str)) ||
2864+ ! memc)
2865+ {
2866+ return &failure_buff;
2867+ }
2868+
2869+ char *value= memcached_get(memc, key->c_ptr(), key->length(), &val_len, &flags, &rc);
2870+ if (rc != MEMCACHED_SUCCESS)
2871+ {
2872+ null_value= true;
2873+ return NULL;
2874+ }
2875+
2876+ buffer.realloc(val_len);
2877+ buffer.length(val_len);
2878+ memcpy(buffer.ptr(), value, val_len);
2879+
2880+ return &buffer;
2881+}
2882+
2883
2884=== added file 'plugin/memcached_udf/memc_get.h'
2885--- plugin/memcached_udf/memc_get.h 1970-01-01 00:00:00 +0000
2886+++ plugin/memcached_udf/memc_get.h 2009-10-05 20:45:24 +0000
2887@@ -0,0 +1,65 @@
2888+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2889+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2890+ *
2891+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
2892+ * All rights reserved.
2893+ *
2894+ * Redistribution and use in source and binary forms, with or without
2895+ * modification, are permitted provided that the following conditions are met:
2896+ *
2897+ * * Redistributions of source code must retain the above copyright notice,
2898+ * this list of conditions and the following disclaimer.
2899+ * * Redistributions in binary form must reproduce the above copyright notice,
2900+ * this list of conditions and the following disclaimer in the documentation
2901+ * and/or other materials provided with the distribution.
2902+ * * Neither the name of Patrick Galbraith nor the names of its contributors
2903+ * may be used to endorse or promote products derived from this software
2904+ * without specific prior written permission.
2905+ *
2906+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2907+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2908+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2909+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2910+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2911+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2912+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2913+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2914+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2915+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2916+ * THE POSSIBILITY OF SUCH DAMAGE.
2917+ */
2918+
2919+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_GET_H
2920+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_GET_H
2921+
2922+#include <drizzled/server_includes.h>
2923+#include <drizzled/function/str/strfunc.h>
2924+
2925+/* implements memc_get */
2926+class MemcachedGet : public Item_str_func
2927+{
2928+public:
2929+ MemcachedGet()
2930+ :
2931+ Item_str_func(),
2932+ failure_buff("FAILURE", &my_charset_bin)
2933+ {}
2934+
2935+ const char *func_name() const
2936+ {
2937+ return "memc_get";
2938+ }
2939+
2940+ String *val_str(String *);
2941+
2942+ void fix_length_and_dec()
2943+ {
2944+ max_length= 32;
2945+ }
2946+
2947+private:
2948+ String failure_buff;
2949+ String buffer;
2950+};
2951+
2952+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_GET_H */
2953
2954=== added file 'plugin/memcached_udf/memc_get_by_key.cc'
2955--- plugin/memcached_udf/memc_get_by_key.cc 1970-01-01 00:00:00 +0000
2956+++ plugin/memcached_udf/memc_get_by_key.cc 2009-10-05 20:45:24 +0000
2957@@ -0,0 +1,77 @@
2958+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2959+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2960+ *
2961+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
2962+ * All rights reserved.
2963+ *
2964+ * Redistribution and use in source and binary forms, with or without
2965+ * modification, are permitted provided that the following conditions are met:
2966+ *
2967+ * * Redistributions of source code must retain the above copyright notice,
2968+ * this list of conditions and the following disclaimer.
2969+ * * Redistributions in binary form must reproduce the above copyright notice,
2970+ * this list of conditions and the following disclaimer in the documentation
2971+ * and/or other materials provided with the distribution.
2972+ * * Neither the name of Patrick Galbraith nor the names of its contributors
2973+ * may be used to endorse or promote products derived from this software
2974+ * without specific prior written permission.
2975+ *
2976+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2977+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2978+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2979+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2980+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2981+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2982+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2983+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2984+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2985+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2986+ * THE POSSIBILITY OF SUCH DAMAGE.
2987+ */
2988+
2989+#include <drizzled/server_includes.h>
2990+#include <drizzled/function/str/strfunc.h>
2991+
2992+#include "memcached_udf.h"
2993+#include "memc_get_by_key.h"
2994+
2995+#include <libmemcached/memcached.h>
2996+
2997+#include <string>
2998+
2999+using namespace std;
3000+
3001+String *MemcachedGetByKey::val_str(String *str)
3002+{
3003+ memcached_return rc;
3004+ String *master_key;
3005+ String *key;
3006+ uint32_t flags;
3007+ size_t val_len;
3008+
3009+ if (arg_count != 2 ||
3010+ ! (master_key= args[0]->val_str(str)) ||
3011+ ! (key= args[1]->val_str(str)) ||
3012+ ! memc)
3013+ {
3014+ return &failure_buff;
3015+ }
3016+
3017+ char *value= memcached_get_by_key(memc,
3018+ master_key->c_ptr(),
3019+ master_key->length(),
3020+ key->c_ptr(), key->length(),
3021+ &val_len, &flags, &rc);
3022+ if (rc != MEMCACHED_SUCCESS)
3023+ {
3024+ null_value= true;
3025+ return NULL;
3026+ }
3027+
3028+ buffer.realloc(val_len);
3029+ buffer.length(val_len);
3030+ memcpy(buffer.ptr(), value, val_len);
3031+
3032+ return &buffer;
3033+}
3034+
3035
3036=== added file 'plugin/memcached_udf/memc_get_by_key.h'
3037--- plugin/memcached_udf/memc_get_by_key.h 1970-01-01 00:00:00 +0000
3038+++ plugin/memcached_udf/memc_get_by_key.h 2009-10-05 20:45:24 +0000
3039@@ -0,0 +1,66 @@
3040+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3041+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3042+ *
3043+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
3044+ * All rights reserved.
3045+ *
3046+ * Redistribution and use in source and binary forms, with or without
3047+ * modification, are permitted provided that the following conditions are met:
3048+ *
3049+ * * Redistributions of source code must retain the above copyright notice,
3050+ * this list of conditions and the following disclaimer.
3051+ * * Redistributions in binary form must reproduce the above copyright notice,
3052+ * this list of conditions and the following disclaimer in the documentation
3053+ * and/or other materials provided with the distribution.
3054+ * * Neither the name of Patrick Galbraith nor the names of its contributors
3055+ * may be used to endorse or promote products derived from this software
3056+ * without specific prior written permission.
3057+ *
3058+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3059+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3060+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3061+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3062+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3063+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3064+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3065+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3066+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3067+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3068+ * THE POSSIBILITY OF SUCH DAMAGE.
3069+ *
3070+ */
3071+
3072+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_GET_BY_KEY_H
3073+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_GET_BY_KEY_H
3074+
3075+#include <drizzled/server_includes.h>
3076+#include <drizzled/function/str/strfunc.h>
3077+
3078+/* implements memc_get_by_key */
3079+class MemcachedGetByKey : public Item_str_func
3080+{
3081+public:
3082+ MemcachedGetByKey()
3083+ :
3084+ Item_str_func(),
3085+ failure_buff("FAILURE", &my_charset_bin)
3086+ {}
3087+
3088+ const char *func_name() const
3089+ {
3090+ return "memc_get_by_key";
3091+ }
3092+
3093+ String *val_str(String *);
3094+
3095+ void fix_length_and_dec()
3096+ {
3097+ max_length= 32;
3098+ }
3099+
3100+private:
3101+ String failure_buff;
3102+ String buffer;
3103+};
3104+
3105+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_GET_BY_KEY_H */
3106
3107=== added file 'plugin/memcached_udf/memc_increment.cc'
3108--- plugin/memcached_udf/memc_increment.cc 1970-01-01 00:00:00 +0000
3109+++ plugin/memcached_udf/memc_increment.cc 2009-10-05 20:45:24 +0000
3110@@ -0,0 +1,92 @@
3111+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3112+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3113+ *
3114+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
3115+ * All rights reserved.
3116+ *
3117+ * Redistribution and use in source and binary forms, with or without
3118+ * modification, are permitted provided that the following conditions are met:
3119+ *
3120+ * * Redistributions of source code must retain the above copyright notice,
3121+ * this list of conditions and the following disclaimer.
3122+ * * Redistributions in binary form must reproduce the above copyright notice,
3123+ * this list of conditions and the following disclaimer in the documentation
3124+ * and/or other materials provided with the distribution.
3125+ * * Neither the name of Patrick Galbraith nor the names of its contributors
3126+ * may be used to endorse or promote products derived from this software
3127+ * without specific prior written permission.
3128+ *
3129+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3130+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3131+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3132+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3133+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3134+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3135+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3136+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3137+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3138+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3139+ * THE POSSIBILITY OF SUCH DAMAGE.
3140+ *
3141+ */
3142+
3143+#include <drizzled/server_includes.h>
3144+#include <drizzled/function/str/strfunc.h>
3145+
3146+#include "memcached_udf.h"
3147+#include "memc_increment.h"
3148+
3149+#include <libmemcached/memcached.h>
3150+
3151+#include <string>
3152+
3153+using namespace std;
3154+
3155+String *MemcachedIncrement::val_str(String *str)
3156+{
3157+ memcached_return rc;
3158+ int64_t offset;
3159+ uint64_t value;
3160+ size_t val_len;
3161+ char tmp_buff[32]= "";
3162+ String *key;
3163+ String *inc_str;
3164+
3165+ if ((arg_count != 1 && arg_count != 2) ||
3166+ ! (key= args[0]->val_str(str)) ||
3167+ ! memc)
3168+ {
3169+ return &failure_buff;
3170+ }
3171+
3172+ if (arg_count == 2) {
3173+ inc_str= args[1]->val_str(str);
3174+ offset= atoi(inc_str->c_ptr());
3175+ }
3176+ else
3177+ {
3178+ offset= 1;
3179+ }
3180+
3181+
3182+ rc= memcached_increment(memc,
3183+ key->c_ptr(),
3184+ key->length(),
3185+ offset,
3186+ &value);
3187+
3188+ snprintf(tmp_buff, 32, "%"PRIu64, value);
3189+ val_len= strlen(tmp_buff);
3190+
3191+ if (rc != MEMCACHED_SUCCESS)
3192+ {
3193+ return &failure_buff;
3194+ }
3195+
3196+ buffer.realloc(val_len);
3197+ buffer.length(val_len);
3198+ memcpy(buffer.ptr(), tmp_buff, val_len);
3199+
3200+ return &buffer;
3201+}
3202+
3203
3204=== added file 'plugin/memcached_udf/memc_increment.h'
3205--- plugin/memcached_udf/memc_increment.h 1970-01-01 00:00:00 +0000
3206+++ plugin/memcached_udf/memc_increment.h 2009-10-05 20:45:24 +0000
3207@@ -0,0 +1,65 @@
3208+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3209+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3210+ *
3211+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
3212+ * All rights reserved.
3213+ *
3214+ * Redistribution and use in source and binary forms, with or without
3215+ * modification, are permitted provided that the following conditions are met:
3216+ *
3217+ * * Redistributions of source code must retain the above copyright notice,
3218+ * this list of conditions and the following disclaimer.
3219+ * * Redistributions in binary form must reproduce the above copyright notice,
3220+ * this list of conditions and the following disclaimer in the documentation
3221+ * and/or other materials provided with the distribution.
3222+ * * Neither the name of Patrick Galbraith nor the names of its contributors
3223+ * may be used to endorse or promote products derived from this software
3224+ * without specific prior written permission.
3225+ *
3226+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3227+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3228+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3229+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3230+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3231+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3232+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3233+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3234+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3235+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3236+ * THE POSSIBILITY OF SUCH DAMAGE.
3237+ */
3238+
3239+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_INCREMENT_H
3240+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_INCREMENT_H
3241+
3242+#include <drizzled/server_includes.h>
3243+#include <drizzled/function/str/strfunc.h>
3244+
3245+/* implements memc_increment */
3246+class MemcachedIncrement : public Item_str_func
3247+{
3248+public:
3249+ MemcachedIncrement()
3250+ :
3251+ Item_str_func(),
3252+ failure_buff("FAILURE", &my_charset_bin)
3253+ {}
3254+
3255+ const char *func_name() const
3256+ {
3257+ return "memc_increment";
3258+ }
3259+
3260+ String *val_str(String *);
3261+
3262+ void fix_length_and_dec()
3263+ {
3264+ max_length= 32;
3265+ }
3266+
3267+private:
3268+ String failure_buff;
3269+ String buffer;
3270+};
3271+
3272+#endif /* MEMC_INCREMENT_H */
3273
3274=== added file 'plugin/memcached_udf/memc_misc.cc'
3275--- plugin/memcached_udf/memc_misc.cc 1970-01-01 00:00:00 +0000
3276+++ plugin/memcached_udf/memc_misc.cc 2009-10-05 20:45:24 +0000
3277@@ -0,0 +1,70 @@
3278+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3279+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3280+ *
3281+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
3282+ * All rights reserved.
3283+ *
3284+ * Redistribution and use in source and binary forms, with or without
3285+ * modification, are permitted provided that the following conditions are met:
3286+ *
3287+ * * Redistributions of source code must retain the above copyright notice,
3288+ * this list of conditions and the following disclaimer.
3289+ * * Redistributions in binary form must reproduce the above copyright notice,
3290+ * this list of conditions and the following disclaimer in the documentation
3291+ * and/or other materials provided with the distribution.
3292+ * * Neither the name of Patrick Galbraith nor the names of its contributors
3293+ * may be used to endorse or promote products derived from this software
3294+ * without specific prior written permission.
3295+ *
3296+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3297+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3298+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3299+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3300+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3301+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3302+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3303+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3304+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3305+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3306+ * THE POSSIBILITY OF SUCH DAMAGE.
3307+ *
3308+ */
3309+
3310+#include <drizzled/server_includes.h>
3311+#include <drizzled/function/str/strfunc.h>
3312+
3313+#include "memcached_udf.h"
3314+#include "memc_misc.h"
3315+
3316+#include <libmemcached/memcached.h>
3317+
3318+#include <string>
3319+
3320+using namespace std;
3321+
3322+String *MemcachedVersion::val_str(String*)
3323+{
3324+ if (! memc)
3325+ {
3326+ return &failure_buff;
3327+ }
3328+
3329+ const char *version= memcached_lib_version();
3330+ size_t ver_len= strlen(version);
3331+
3332+ buffer.realloc(ver_len);
3333+ buffer.length(ver_len);
3334+ memcpy(buffer.ptr(), version, ver_len);
3335+
3336+ return &buffer;
3337+}
3338+
3339+int64_t MemcachedServerCount::val_int()
3340+{
3341+ if (! memc)
3342+ {
3343+ return 0;
3344+ }
3345+
3346+ return (memcached_server_count(memc));
3347+}
3348
3349=== added file 'plugin/memcached_udf/memc_misc.h'
3350--- plugin/memcached_udf/memc_misc.h 1970-01-01 00:00:00 +0000
3351+++ plugin/memcached_udf/memc_misc.h 2009-10-05 20:45:24 +0000
3352@@ -0,0 +1,90 @@
3353+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3354+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3355+ *
3356+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
3357+ * All rights reserved.
3358+ *
3359+ * Redistribution and use in source and binary forms, with or without
3360+ * modification, are permitted provided that the following conditions are met:
3361+ *
3362+ * * Redistributions of source code must retain the above copyright notice,
3363+ * this list of conditions and the following disclaimer.
3364+ * * Redistributions in binary form must reproduce the above copyright notice,
3365+ * this list of conditions and the following disclaimer in the documentation
3366+ * and/or other materials provided with the distribution.
3367+ * * Neither the name of Patrick Galbraith nor the names of its contributors
3368+ * may be used to endorse or promote products derived from this software
3369+ * without specific prior written permission.
3370+ *
3371+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3372+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3373+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3374+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3375+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3376+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3377+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3378+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3379+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3380+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3381+ * THE POSSIBILITY OF SUCH DAMAGE.
3382+ */
3383+
3384+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_MISC_H
3385+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_MISC_H
3386+
3387+#include <drizzled/server_includes.h>
3388+#include <drizzled/item/func.h>
3389+#include <drizzled/function/str/strfunc.h>
3390+
3391+/* implements memc_libmemcached_version */
3392+class MemcachedVersion : public Item_str_func
3393+{
3394+public:
3395+ MemcachedVersion()
3396+ :
3397+ Item_str_func(),
3398+ failure_buff("FAILURE", &my_charset_bin)
3399+ {}
3400+
3401+ const char *func_name() const
3402+ {
3403+ return "memc_libmemcached_version";
3404+ }
3405+
3406+ String *val_str(String *);
3407+
3408+ void fix_length_and_dec()
3409+ {
3410+ max_length= 32;
3411+ }
3412+
3413+private:
3414+ String buffer;
3415+ String failure_buff;
3416+};
3417+
3418+/* implements memc_server_count */
3419+class MemcachedServerCount : public Item_int_func
3420+{
3421+public:
3422+ MemcachedServerCount()
3423+ :
3424+ Item_int_func()
3425+ {
3426+ unsigned_flag= 1;
3427+ }
3428+
3429+ const char *func_name() const
3430+ {
3431+ return "memc_server_count";
3432+ }
3433+
3434+ void fix_length_and_dec()
3435+ {
3436+ max_length= 10;
3437+ }
3438+
3439+ int64_t val_int();
3440+};
3441+
3442+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_MISC_H */
3443
3444=== added file 'plugin/memcached_udf/memc_prepend.cc'
3445--- plugin/memcached_udf/memc_prepend.cc 1970-01-01 00:00:00 +0000
3446+++ plugin/memcached_udf/memc_prepend.cc 2009-10-05 20:45:24 +0000
3447@@ -0,0 +1,74 @@
3448+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3449+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3450+ *
3451+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
3452+ * All rights reserved.
3453+ *
3454+ * Redistribution and use in source and binary forms, with or without
3455+ * modification, are permitted provided that the following conditions are met:
3456+ *
3457+ * * Redistributions of source code must retain the above copyright notice,
3458+ * this list of conditions and the following disclaimer.
3459+ * * Redistributions in binary form must reproduce the above copyright notice,
3460+ * this list of conditions and the following disclaimer in the documentation
3461+ * and/or other materials provided with the distribution.
3462+ * * Neither the name of Patrick Galbraith nor the names of its contributors
3463+ * may be used to endorse or promote products derived from this software
3464+ * without specific prior written permission.
3465+ *
3466+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3467+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3468+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3469+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3470+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3471+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3472+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3473+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3474+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3475+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3476+ * THE POSSIBILITY OF SUCH DAMAGE.
3477+ *
3478+ */
3479+
3480+#include <drizzled/server_includes.h>
3481+#include <drizzled/function/str/strfunc.h>
3482+
3483+#include "memcached_udf.h"
3484+#include "memc_prepend.h"
3485+
3486+#include <libmemcached/memcached.h>
3487+
3488+#include <string>
3489+
3490+using namespace std;
3491+
3492+int64_t MemcachedPrepend::val_int()
3493+{
3494+ memcached_return rc;
3495+ time_t expiration= 0;
3496+ String *key;
3497+ String *res;
3498+ null_value= false;
3499+
3500+ if ((arg_count != 2 && arg_count != 3) ||
3501+ ! (key= args[0]->val_str(&value)) ||
3502+ ! (res= args[1]->val_str(&value)) ||
3503+ ! memc)
3504+ {
3505+ return 0;
3506+ }
3507+ if (arg_count == 3)
3508+ {
3509+ String *tmp_exp= args[2]->val_str(&value);
3510+ expiration= (time_t)atoi(tmp_exp->c_ptr());
3511+ }
3512+
3513+ rc= memcached_prepend(memc, key->c_ptr(), key->length(),
3514+ res->c_ptr(), res->length(),
3515+ expiration, (uint16_t) 0);
3516+ if (rc != MEMCACHED_SUCCESS)
3517+ {
3518+ return 0;
3519+ }
3520+ return 1;
3521+}
3522
3523=== added file 'plugin/memcached_udf/memc_prepend.h'
3524--- plugin/memcached_udf/memc_prepend.h 1970-01-01 00:00:00 +0000
3525+++ plugin/memcached_udf/memc_prepend.h 2009-10-05 20:45:24 +0000
3526@@ -0,0 +1,71 @@
3527+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3528+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3529+ *
3530+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
3531+ * All rights reserved.
3532+ *
3533+ * Redistribution and use in source and binary forms, with or without
3534+ * modification, are permitted provided that the following conditions are met:
3535+ *
3536+ * * Redistributions of source code must retain the above copyright notice,
3537+ * this list of conditions and the following disclaimer.
3538+ * * Redistributions in binary form must reproduce the above copyright notice,
3539+ * this list of conditions and the following disclaimer in the documentation
3540+ * and/or other materials provided with the distribution.
3541+ * * Neither the name of Patrick Galbraith nor the names of its contributors
3542+ * may be used to endorse or promote products derived from this software
3543+ * without specific prior written permission.
3544+ *
3545+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3546+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3547+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3548+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3549+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3550+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3551+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3552+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3553+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3554+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3555+ * THE POSSIBILITY OF SUCH DAMAGE.
3556+ *
3557+ */
3558+
3559+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_PREPEND_H
3560+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_PREPEND_H
3561+
3562+#include <drizzled/server_includes.h>
3563+#include <drizzled/function/str/strfunc.h>
3564+#include <drizzled/item/func.h>
3565+#include <string>
3566+
3567+/* implements memc_prepend */
3568+class MemcachedPrepend : public Item_int_func
3569+{
3570+ String failure_buff;
3571+ String value;
3572+public:
3573+ MemcachedPrepend()
3574+ :
3575+ Item_int_func(),
3576+ failure_buff("0", &my_charset_bin)
3577+ {}
3578+
3579+ const char *func_name() const
3580+ {
3581+ return "memc_prepend";
3582+ }
3583+
3584+ int64_t val_int();
3585+
3586+ void fix_length_and_dec()
3587+ {
3588+ max_length= 32;
3589+ }
3590+ bool check_argument_count(int n)
3591+ {
3592+ return ((n == 2 || n == 3));
3593+ }
3594+
3595+};
3596+
3597+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_PREPEND_H */
3598
3599=== added file 'plugin/memcached_udf/memc_prepend_by_key.cc'
3600--- plugin/memcached_udf/memc_prepend_by_key.cc 1970-01-01 00:00:00 +0000
3601+++ plugin/memcached_udf/memc_prepend_by_key.cc 2009-10-05 20:45:24 +0000
3602@@ -0,0 +1,80 @@
3603+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3604+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3605+ *
3606+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
3607+ * All rights reserved.
3608+ *
3609+ * Redistribution and use in source and binary forms, with or without
3610+ * modification, are permitted provided that the following conditions are met:
3611+ *
3612+ * * Redistributions of source code must retain the above copyright notice,
3613+ * this list of conditions and the following disclaimer.
3614+ * * Redistributions in binary form must reproduce the above copyright notice,
3615+ * this list of conditions and the following disclaimer in the documentation
3616+ * and/or other materials provided with the distribution.
3617+ * * Neither the name of Patrick Galbraith nor the names of its contributors
3618+ * may be used to endorse or promote products derived from this software
3619+ * without specific prior written permission.
3620+ *
3621+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3622+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3623+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3624+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3625+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3626+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3627+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3628+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3629+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3630+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3631+ * THE POSSIBILITY OF SUCH DAMAGE.
3632+ *
3633+ */
3634+
3635+#include <drizzled/server_includes.h>
3636+#include <drizzled/function/str/strfunc.h>
3637+
3638+#include "memcached_udf.h"
3639+#include "memc_prepend_by_key.h"
3640+
3641+#include <libmemcached/memcached.h>
3642+
3643+#include <string>
3644+
3645+using namespace std;
3646+
3647+int64_t MemcachedPrependByKey::val_int()
3648+{
3649+ memcached_return rc;
3650+ time_t expiration= 0;
3651+ String *master_key;
3652+ String *key;
3653+ String *res;
3654+ null_value= false;
3655+
3656+ if ((arg_count != 3 && arg_count != 4) ||
3657+ ! (master_key= args[0]->val_str(&value)) ||
3658+ ! (key= args[1]->val_str(&value)) ||
3659+ ! (res= args[2]->val_str(&value)) ||
3660+ ! memc)
3661+ {
3662+ return 0;
3663+ }
3664+ if (arg_count == 4)
3665+ {
3666+ String *tmp_exp= args[3]->val_str(&value);;
3667+ expiration= (time_t)atoi(tmp_exp->c_ptr());
3668+ }
3669+
3670+ rc= memcached_prepend_by_key(memc,
3671+ master_key->c_ptr(),
3672+ master_key->length(),
3673+ key->c_ptr(), key->length(),
3674+ res->c_ptr(), res->length(),
3675+ expiration, (uint16_t) 0);
3676+ if (rc != MEMCACHED_SUCCESS)
3677+ {
3678+ return 0;
3679+ }
3680+
3681+ return 1;
3682+}
3683
3684=== added file 'plugin/memcached_udf/memc_prepend_by_key.h'
3685--- plugin/memcached_udf/memc_prepend_by_key.h 1970-01-01 00:00:00 +0000
3686+++ plugin/memcached_udf/memc_prepend_by_key.h 2009-10-05 20:45:24 +0000
3687@@ -0,0 +1,73 @@
3688+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3689+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3690+ *
3691+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
3692+ * All rights reserved.
3693+ *
3694+ * Redistribution and use in source and binary forms, with or without
3695+ * modification, are permitted provided that the following conditions are met:
3696+ *
3697+ * * Redistributions of source code must retain the above copyright notice,
3698+ * this list of conditions and the following disclaimer.
3699+ * * Redistributions in binary form must reproduce the above copyright notice,
3700+ * this list of conditions and the following disclaimer in the documentation
3701+ * and/or other materials provided with the distribution.
3702+ * * Neither the name of Patrick Galbraith nor the names of its contributors
3703+ * may be used to endorse or promote products derived from this software
3704+ * without specific prior written permission.
3705+ *
3706+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3707+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3708+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3709+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3710+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3711+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3712+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3713+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3714+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3715+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3716+ * THE POSSIBILITY OF SUCH DAMAGE.
3717+ *
3718+
3719+ */
3720+
3721+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_PREPEND_BY_KEY_H
3722+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_PREPEND_BY_KEY_H
3723+
3724+#include <drizzled/server_includes.h>
3725+#include <drizzled/function/str/strfunc.h>
3726+#include <drizzled/item/func.h>
3727+#include <string>
3728+
3729+
3730+/* implements memc_prepend_by_key */
3731+class MemcachedPrependByKey : public Item_int_func
3732+{
3733+ String failure_buff;
3734+ String value;
3735+public:
3736+ MemcachedPrependByKey()
3737+ :
3738+ Item_int_func(),
3739+ failure_buff("failure ...", &my_charset_bin)
3740+ {}
3741+
3742+ const char *func_name() const
3743+ {
3744+ return "memc_prepend_by_key";
3745+ }
3746+
3747+ int64_t val_int();
3748+
3749+ void fix_length_and_dec()
3750+ {
3751+ max_length= 32;
3752+ }
3753+ bool check_argument_count(int n)
3754+ {
3755+ return ((n == 3 || n == 4));
3756+ }
3757+
3758+};
3759+
3760+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_PREPEND_BY_KEY_H */
3761
3762=== added file 'plugin/memcached_udf/memc_replace.cc'
3763--- plugin/memcached_udf/memc_replace.cc 1970-01-01 00:00:00 +0000
3764+++ plugin/memcached_udf/memc_replace.cc 2009-10-05 20:45:24 +0000
3765@@ -0,0 +1,78 @@
3766+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3767+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3768+ *
3769+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
3770+ * All rights reserved.
3771+ *
3772+ * Redistribution and use in source and binary forms, with or without
3773+ * modification, are permitted provided that the following conditions are met:
3774+ *
3775+ * * Redistributions of source code must retain the above copyright notice,
3776+ * this list of conditions and the following disclaimer.
3777+ * * Redistributions in binary form must reproduce the above copyright notice,
3778+ * this list of conditions and the following disclaimer in the documentation
3779+ * and/or other materials provided with the distribution.
3780+ * * Neither the name of Patrick Galbraith nor the names of its contributors
3781+ * may be used to endorse or promote products derived from this software
3782+ * without specific prior written permission.
3783+ *
3784+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3785+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3786+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3787+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3788+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3789+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3790+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3791+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3792+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3793+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3794+ * THE POSSIBILITY OF SUCH DAMAGE.
3795+ *
3796+ */
3797+
3798+#include <drizzled/server_includes.h>
3799+#include <drizzled/function/str/strfunc.h>
3800+
3801+#include "memcached_udf.h"
3802+#include "memc_replace.h"
3803+
3804+#include <libmemcached/memcached.h>
3805+
3806+#include <string>
3807+
3808+using namespace std;
3809+
3810+int64_t MemcachedReplace::val_int()
3811+{
3812+ memcached_return rc;
3813+ time_t expiration= 0;
3814+ String *key;
3815+ String *res;
3816+ null_value= false;
3817+
3818+ if ((arg_count != 2 && arg_count != 3) ||
3819+ ! (key= args[0]->val_str(&value)) ||
3820+ ! (res= args[1]->val_str(&value)) ||
3821+ ! memc)
3822+ {
3823+ return 0;
3824+ }
3825+
3826+ if (arg_count == 3)
3827+ {
3828+ String *tmp_exp= args[2]->val_str(&value);;
3829+
3830+ expiration= (time_t)atoi(tmp_exp->c_ptr());
3831+ }
3832+
3833+ rc= memcached_replace(memc, key->c_ptr(), key->length(),
3834+ res->c_ptr(), res->length(),
3835+ expiration, (uint16_t) 0);
3836+
3837+ if (rc != MEMCACHED_SUCCESS)
3838+ {
3839+ return 0;
3840+ }
3841+
3842+ return 1;
3843+}
3844
3845=== added file 'plugin/memcached_udf/memc_replace.h'
3846--- plugin/memcached_udf/memc_replace.h 1970-01-01 00:00:00 +0000
3847+++ plugin/memcached_udf/memc_replace.h 2009-10-05 20:45:24 +0000
3848@@ -0,0 +1,71 @@
3849+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3850+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3851+ *
3852+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
3853+ * All rights reserved.
3854+ *
3855+ * Redistribution and use in source and binary forms, with or without
3856+ * modification, are permitted provided that the following conditions are met:
3857+ *
3858+ * * Redistributions of source code must retain the above copyright notice,
3859+ * this list of conditions and the following disclaimer.
3860+ * * Redistributions in binary form must reproduce the above copyright notice,
3861+ * this list of conditions and the following disclaimer in the documentation
3862+ * and/or other materials provided with the distribution.
3863+ * * Neither the name of Patrick Galbraith nor the names of its contributors
3864+ * may be used to endorse or promote products derived from this software
3865+ * without specific prior written permission.
3866+ *
3867+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3868+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3869+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3870+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3871+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3872+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3873+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3874+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3875+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3876+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3877+ * THE POSSIBILITY OF SUCH DAMAGE.
3878+ *
3879+ */
3880+
3881+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_REPLACE_H
3882+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_REPLACE_H
3883+
3884+#include <drizzled/server_includes.h>
3885+#include <drizzled/function/str/strfunc.h>
3886+#include <drizzled/item/func.h>
3887+#include <string>
3888+
3889+/* implements memc_replace */
3890+class MemcachedReplace: public Item_int_func
3891+{
3892+ String failure_buff;
3893+ String value;
3894+public:
3895+ MemcachedReplace()
3896+ :
3897+ Item_int_func(),
3898+ failure_buff("0", &my_charset_bin)
3899+ {}
3900+
3901+ const char *func_name() const
3902+ {
3903+ return "memc_replace";
3904+ }
3905+
3906+ int64_t val_int();
3907+
3908+ void fix_length_and_dec()
3909+ {
3910+ max_length= 32;
3911+ }
3912+ bool check_argument_count(int n)
3913+ {
3914+ return ((n == 2 || n == 3));
3915+ }
3916+
3917+};
3918+
3919+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_REPLACE_H */
3920
3921=== added file 'plugin/memcached_udf/memc_replace_by_key.cc'
3922--- plugin/memcached_udf/memc_replace_by_key.cc 1970-01-01 00:00:00 +0000
3923+++ plugin/memcached_udf/memc_replace_by_key.cc 2009-10-05 20:45:24 +0000
3924@@ -0,0 +1,82 @@
3925+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3926+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3927+ *
3928+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
3929+ * All rights reserved.
3930+ *
3931+ * Redistribution and use in source and binary forms, with or without
3932+ * modification, are permitted provided that the following conditions are met:
3933+ *
3934+ * * Redistributions of source code must retain the above copyright notice,
3935+ * this list of conditions and the following disclaimer.
3936+ * * Redistributions in binary form must reproduce the above copyright notice,
3937+ * this list of conditions and the following disclaimer in the documentation
3938+ * and/or other materials provided with the distribution.
3939+ * * Neither the name of Patrick Galbraith nor the names of its contributors
3940+ * may be used to endorse or promote products derived from this software
3941+ * without specific prior written permission.
3942+ *
3943+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3944+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3945+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3946+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3947+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3948+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3949+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3950+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3951+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3952+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3953+ * THE POSSIBILITY OF SUCH DAMAGE.
3954+ *
3955+ */
3956+
3957+#include <drizzled/server_includes.h>
3958+#include <drizzled/function/str/strfunc.h>
3959+
3960+#include "memcached_udf.h"
3961+#include "memc_replace_by_key.h"
3962+
3963+#include <libmemcached/memcached.h>
3964+
3965+#include <string>
3966+
3967+using namespace std;
3968+
3969+int64_t MemcachedReplaceByKey::val_int()
3970+{
3971+ memcached_return rc;
3972+ time_t expiration= 0;
3973+ String *master_key;
3974+ String *key;
3975+ String *res;
3976+ null_value= false;
3977+
3978+ if ((arg_count != 3 && arg_count != 4) ||
3979+ ! (master_key= args[0]->val_str(&value)) ||
3980+ ! (key= args[1]->val_str(&value)) ||
3981+ ! (res= args[2]->val_str(&value)) ||
3982+ ! memc)
3983+ {
3984+ return 0;
3985+ }
3986+
3987+ if (arg_count == 4)
3988+ {
3989+ String *tmp_exp= args[3]->val_str(&value);;
3990+
3991+ expiration= (time_t)atoi(tmp_exp->c_ptr());
3992+ }
3993+
3994+ rc= memcached_replace_by_key(memc,
3995+ master_key->c_ptr(), master_key->length(),
3996+ key->c_ptr(), key->length(),
3997+ res->c_ptr(), res->length(),
3998+ expiration, (uint16_t) 0);
3999+
4000+ if (rc != MEMCACHED_SUCCESS)
4001+ {
4002+ return 0;
4003+ }
4004+
4005+ return 1;
4006+}
4007
4008=== added file 'plugin/memcached_udf/memc_replace_by_key.h'
4009--- plugin/memcached_udf/memc_replace_by_key.h 1970-01-01 00:00:00 +0000
4010+++ plugin/memcached_udf/memc_replace_by_key.h 2009-10-05 20:45:24 +0000
4011@@ -0,0 +1,72 @@
4012+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
4013+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4014+ *
4015+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
4016+ * All rights reserved.
4017+ *
4018+ * Redistribution and use in source and binary forms, with or without
4019+ * modification, are permitted provided that the following conditions are met:
4020+ *
4021+ * * Redistributions of source code must retain the above copyright notice,
4022+ * this list of conditions and the following disclaimer.
4023+ * * Redistributions in binary form must reproduce the above copyright notice,
4024+ * this list of conditions and the following disclaimer in the documentation
4025+ * and/or other materials provided with the distribution.
4026+ * * Neither the name of Patrick Galbraith nor the names of its contributors
4027+ * may be used to endorse or promote products derived from this software
4028+ * without specific prior written permission.
4029+ *
4030+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
4031+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4032+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4033+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
4034+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4035+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4036+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4037+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4038+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4039+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
4040+ * THE POSSIBILITY OF SUCH DAMAGE.
4041+ *
4042+ */
4043+
4044+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_REPLACE_BY_KEY_H
4045+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_REPLACE_BY_KEY_H
4046+
4047+#include <drizzled/server_includes.h>
4048+#include <drizzled/function/str/strfunc.h>
4049+#include <drizzled/item/func.h>
4050+#include <string>
4051+
4052+
4053+/* implements memc_replace_by_key */
4054+class MemcachedReplaceByKey : public Item_int_func
4055+{
4056+ String value;
4057+ String failure_buff;
4058+public:
4059+ MemcachedReplaceByKey()
4060+ :
4061+ Item_int_func(),
4062+ failure_buff("0", &my_charset_bin)
4063+ {}
4064+
4065+ const char *func_name() const
4066+ {
4067+ return "memc_replace_by_key";
4068+ }
4069+
4070+ int64_t val_int();
4071+
4072+ void fix_length_and_dec()
4073+ {
4074+ max_length= 32;
4075+ }
4076+ bool check_argument_count(int n)
4077+ {
4078+ return ((n == 3 || n == 4));
4079+ }
4080+
4081+};
4082+
4083+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_SET_BY_KEY_H */
4084
4085=== added file 'plugin/memcached_udf/memc_servers_set.cc'
4086--- plugin/memcached_udf/memc_servers_set.cc 1970-01-01 00:00:00 +0000
4087+++ plugin/memcached_udf/memc_servers_set.cc 2009-10-05 20:45:24 +0000
4088@@ -0,0 +1,73 @@
4089+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
4090+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4091+ *
4092+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
4093+ * All rights reserved.
4094+ *
4095+ * Redistribution and use in source and binary forms, with or without
4096+ * modification, are permitted provided that the following conditions are met:
4097+ *
4098+ * * Redistributions of source code must retain the above copyright notice,
4099+ * this list of conditions and the following disclaimer.
4100+ * * Redistributions in binary form must reproduce the above copyright notice,
4101+ * this list of conditions and the following disclaimer in the documentation
4102+ * and/or other materials provided with the distribution.
4103+ * * Neither the name of Patrick Galbraith nor the names of its contributors
4104+ * may be used to endorse or promote products derived from this software
4105+ * without specific prior written permission.
4106+ *
4107+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
4108+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4109+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4110+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
4111+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4112+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4113+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4114+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4115+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4116+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
4117+ * THE POSSIBILITY OF SUCH DAMAGE.
4118+ *
4119+ *
4120+ */
4121+
4122+#include <drizzled/server_includes.h>
4123+#include <drizzled/slot/function.h>
4124+
4125+#include "memcached_udf.h"
4126+#include "memc_servers_set.h"
4127+
4128+#include <libmemcached/memcached.h>
4129+
4130+#include <string>
4131+
4132+using namespace std;
4133+
4134+int64_t MemcachedServersSet::val_int()
4135+{
4136+ memcached_return rc;
4137+ memcached_server_st *servers;
4138+ String *server_names;
4139+ null_value= false;
4140+
4141+ if (arg_count != 1 ||
4142+ ! (server_names= args[0]->val_str(&value)) ||
4143+ ! memc)
4144+ {
4145+ return 0;
4146+ }
4147+
4148+ servers= memcached_servers_parse(server_names->c_ptr());
4149+ if (servers == NULL)
4150+ {
4151+ return 0;
4152+ }
4153+
4154+ rc= memcached_server_push(memc, servers);
4155+ if (rc != MEMCACHED_SUCCESS)
4156+ {
4157+ return 0;
4158+ }
4159+
4160+ return 1;
4161+}
4162
4163=== added file 'plugin/memcached_udf/memc_servers_set.h'
4164--- plugin/memcached_udf/memc_servers_set.h 1970-01-01 00:00:00 +0000
4165+++ plugin/memcached_udf/memc_servers_set.h 2009-10-05 20:45:24 +0000
4166@@ -0,0 +1,77 @@
4167+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
4168+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4169+ *
4170+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
4171+ * All rights reserved.
4172+ *
4173+ * Redistribution and use in source and binary forms, with or without
4174+ * modification, are permitted provided that the following conditions are met:
4175+ *
4176+ * * Redistributions of source code must retain the above copyright notice,
4177+ * this list of conditions and the following disclaimer.
4178+ * * Redistributions in binary form must reproduce the above copyright notice,
4179+ * this list of conditions and the following disclaimer in the documentation
4180+ * and/or other materials provided with the distribution.
4181+ * * Neither the name of Patrick Galbraith nor the names of its contributors
4182+ * may be used to endorse or promote products derived from this software
4183+ * without specific prior written permission.
4184+ *
4185+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
4186+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4187+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4188+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
4189+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4190+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4191+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4192+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4193+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4194+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
4195+ * THE POSSIBILITY OF SUCH DAMAGE.
4196+ *
4197+ *
4198+ */
4199+
4200+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_SERVERS_SET_H
4201+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_SERVERS_SET_H
4202+
4203+#include <string>
4204+#include <drizzled/function/str/strfunc.h>
4205+#include <drizzled/server_includes.h>
4206+#include <drizzled/item/func.h>
4207+
4208+/* implements memc_servers_set */
4209+class MemcachedServersSet : public Item_int_func
4210+{
4211+private:
4212+ String failure_buff;
4213+ String value;
4214+public:
4215+ MemcachedServersSet()
4216+ :
4217+ Item_int_func(),
4218+ failure_buff("FAILURE", &my_charset_bin)
4219+ {}
4220+
4221+ const char *func_name() const
4222+ {
4223+ return "memc_servers_set";
4224+ }
4225+
4226+ int64_t val_int();
4227+
4228+ void fix_length_and_dec()
4229+ {
4230+ max_length= 32;
4231+ args[0]->collation.set(
4232+ get_charset_by_csname(args[0]->collation.collation->csname,
4233+ MY_CS_BINSORT),
4234+ DERIVATION_COERCIBLE);
4235+ }
4236+ bool check_argument_count(int n)
4237+ {
4238+ return (n == 1);
4239+ }
4240+
4241+};
4242+
4243+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_SERVERS_SET_H */
4244
4245=== added file 'plugin/memcached_udf/memc_set.cc'
4246--- plugin/memcached_udf/memc_set.cc 1970-01-01 00:00:00 +0000
4247+++ plugin/memcached_udf/memc_set.cc 2009-10-05 20:45:24 +0000
4248@@ -0,0 +1,79 @@
4249+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
4250+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4251+ *
4252+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
4253+ * All rights reserved.
4254+ *
4255+ * Redistribution and use in source and binary forms, with or without
4256+ * modification, are permitted provided that the following conditions are met:
4257+ *
4258+ * * Redistributions of source code must retain the above copyright notice,
4259+ * this list of conditions and the following disclaimer.
4260+ * * Redistributions in binary form must reproduce the above copyright notice,
4261+ * this list of conditions and the following disclaimer in the documentation
4262+ * and/or other materials provided with the distribution.
4263+ * * Neither the name of Patrick Galbraith nor the names of its contributors
4264+ * may be used to endorse or promote products derived from this software
4265+ * without specific prior written permission.
4266+ *
4267+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
4268+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4269+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4270+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
4271+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4272+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4273+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4274+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4275+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4276+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
4277+ * THE POSSIBILITY OF SUCH DAMAGE.
4278+ *
4279+ *
4280+ */
4281+
4282+#include <drizzled/server_includes.h>
4283+#include <drizzled/function/str/strfunc.h>
4284+
4285+#include "memcached_udf.h"
4286+#include "memc_set.h"
4287+
4288+#include <libmemcached/memcached.h>
4289+
4290+#include <string>
4291+
4292+using namespace std;
4293+
4294+int64_t MemcachedSet::val_int()
4295+{
4296+ memcached_return rc;
4297+ time_t expiration= 0;
4298+ String *key;
4299+ String *res;
4300+ null_value= false;
4301+
4302+ if ((arg_count != 2 && arg_count != 3) ||
4303+ ! (key= args[0]->val_str(&value)) ||
4304+ ! (res= args[1]->val_str(&value)) ||
4305+ ! memc)
4306+ {
4307+ return 0;
4308+ }
4309+
4310+ if (arg_count == 3)
4311+ {
4312+ String *tmp_exp= args[2]->val_str(&value);;
4313+
4314+ expiration= (time_t)atoi(tmp_exp->c_ptr());
4315+ }
4316+
4317+ rc= memcached_set(memc, key->c_ptr(), key->length(),
4318+ res->c_ptr(), res->length(),
4319+ expiration, (uint16_t) 0);
4320+
4321+ if (rc != MEMCACHED_SUCCESS)
4322+ {
4323+ return 0;
4324+ }
4325+
4326+ return 1;
4327+}
4328
4329=== added file 'plugin/memcached_udf/memc_set.h'
4330--- plugin/memcached_udf/memc_set.h 1970-01-01 00:00:00 +0000
4331+++ plugin/memcached_udf/memc_set.h 2009-10-05 20:45:24 +0000
4332@@ -0,0 +1,65 @@
4333+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
4334+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4335+ *
4336+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
4337+ * All rights reserved.
4338+ *
4339+ * Redistribution and use in source and binary forms, with or without
4340+ * modification, are permitted provided that the following conditions are met:
4341+ *
4342+ * * Redistributions of source code must retain the above copyright notice,
4343+ * this list of conditions and the following disclaimer.
4344+ * * Redistributions in binary form must reproduce the above copyright notice,
4345+ * this list of conditions and the following disclaimer in the documentation
4346+ * and/or other materials provided with the distribution.
4347+ * * Neither the name of Patrick Galbraith nor the names of its contributors
4348+ * may be used to endorse or promote products derived from this software
4349+ * without specific prior written permission.
4350+ *
4351+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
4352+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4353+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4354+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
4355+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4356+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4357+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4358+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4359+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4360+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
4361+ * THE POSSIBILITY OF SUCH DAMAGE.
4362+ */
4363+
4364+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_SET_H
4365+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_SET_H
4366+
4367+#include <drizzled/server_includes.h>
4368+#include <drizzled/function/str/strfunc.h>
4369+#include <drizzled/item/func.h>
4370+#include <string>
4371+
4372+/* implements memc_set */
4373+class MemcachedSet :public Item_int_func
4374+{
4375+ String failure_buff;
4376+ String value;
4377+public:
4378+ int64_t val_int();
4379+ MemcachedSet() :Item_int_func() {}
4380+
4381+ const char *func_name() const
4382+ {
4383+ return "memc_set";
4384+ }
4385+
4386+ void fix_length_and_dec()
4387+ {
4388+ max_length= 32;
4389+ }
4390+ bool check_argument_count(int n)
4391+ {
4392+ return ((n == 2 || n == 3));
4393+ }
4394+
4395+};
4396+
4397+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_SET_H */
4398
4399=== added file 'plugin/memcached_udf/memc_set_by_key.cc'
4400--- plugin/memcached_udf/memc_set_by_key.cc 1970-01-01 00:00:00 +0000
4401+++ plugin/memcached_udf/memc_set_by_key.cc 2009-10-05 20:45:24 +0000
4402@@ -0,0 +1,81 @@
4403+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
4404+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4405+ *
4406+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
4407+ * All rights reserved.
4408+ *
4409+ * Redistribution and use in source and binary forms, with or without
4410+ * modification, are permitted provided that the following conditions are met:
4411+ *
4412+ * * Redistributions of source code must retain the above copyright notice,
4413+ * this list of conditions and the following disclaimer.
4414+ * * Redistributions in binary form must reproduce the above copyright notice,
4415+ * this list of conditions and the following disclaimer in the documentation
4416+ * and/or other materials provided with the distribution.
4417+ * * Neither the name of Patrick Galbraith nor the names of its contributors
4418+ * may be used to endorse or promote products derived from this software
4419+ * without specific prior written permission.
4420+ *
4421+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
4422+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4423+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4424+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
4425+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4426+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4427+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4428+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4429+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4430+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
4431+ * THE POSSIBILITY OF SUCH DAMAGE.
4432+ *
4433+ */
4434+
4435+#include <drizzled/server_includes.h>
4436+#include <drizzled/function/str/strfunc.h>
4437+
4438+#include "memcached_udf.h"
4439+#include "memc_set_by_key.h"
4440+
4441+#include <libmemcached/memcached.h>
4442+
4443+#include <string>
4444+
4445+using namespace std;
4446+
4447+int64_t MemcachedSetByKey::val_int()
4448+{
4449+ memcached_return rc;
4450+ time_t expiration= 0;
4451+ String *master_key;
4452+ String *key;
4453+ String *res;
4454+ null_value= false;
4455+
4456+ if ((arg_count != 3 && arg_count != 4) ||
4457+ ! (master_key= args[0]->val_str(&value)) ||
4458+ ! (key= args[1]->val_str(&value)) ||
4459+ ! (res= args[2]->val_str(&value)) ||
4460+ ! memc)
4461+ {
4462+ return 0;
4463+ }
4464+
4465+ if (arg_count == 4)
4466+ {
4467+ String *tmp_exp= args[3]->val_str(&value);;
4468+ expiration= (time_t)atoi(tmp_exp->c_ptr());
4469+ }
4470+
4471+ rc= memcached_set_by_key(memc,
4472+ master_key->c_ptr(), master_key->length(),
4473+ key->c_ptr(), key->length(),
4474+ res->c_ptr(), res->length(),
4475+ expiration, (uint16_t) 0);
4476+
4477+ if (rc != MEMCACHED_SUCCESS)
4478+ {
4479+ return 0;
4480+ }
4481+
4482+ return 1;
4483+}
4484
4485=== added file 'plugin/memcached_udf/memc_set_by_key.h'
4486--- plugin/memcached_udf/memc_set_by_key.h 1970-01-01 00:00:00 +0000
4487+++ plugin/memcached_udf/memc_set_by_key.h 2009-10-05 20:45:24 +0000
4488@@ -0,0 +1,70 @@
4489+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
4490+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4491+ *
4492+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
4493+ * All rights reserved.
4494+ *
4495+ * Redistribution and use in source and binary forms, with or without
4496+ * modification, are permitted provided that the following conditions are met:
4497+ *
4498+ * * Redistributions of source code must retain the above copyright notice,
4499+ * this list of conditions and the following disclaimer.
4500+ * * Redistributions in binary form must reproduce the above copyright notice,
4501+ * this list of conditions and the following disclaimer in the documentation
4502+ * and/or other materials provided with the distribution.
4503+ * * Neither the name of Patrick Galbraith nor the names of its contributors
4504+ * may be used to endorse or promote products derived from this software
4505+ * without specific prior written permission.
4506+ *
4507+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
4508+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4509+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4510+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
4511+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4512+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4513+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4514+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4515+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4516+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
4517+ * THE POSSIBILITY OF SUCH DAMAGE.
4518+ */
4519+
4520+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_SET_BY_KEY_H
4521+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_SET_BY_KEY_H
4522+
4523+#include <drizzled/server_includes.h>
4524+#include <drizzled/function/str/strfunc.h>
4525+#include <drizzled/item/func.h>
4526+#include <string>
4527+
4528+/* implements memc_set_by_key */
4529+class MemcachedSetByKey : public Item_int_func
4530+{
4531+ String value;
4532+ String failure_buff;
4533+public:
4534+ MemcachedSetByKey()
4535+ :
4536+ Item_int_func(),
4537+ failure_buff("error ...", &my_charset_bin)
4538+ {}
4539+
4540+ const char *func_name() const
4541+ {
4542+ return "memc_set_by_key";
4543+ }
4544+
4545+ int64_t val_int();
4546+
4547+ void fix_length_and_dec()
4548+ {
4549+ max_length= 32;
4550+ }
4551+ bool check_argument_count(int n)
4552+ {
4553+ return ((n == 3 || n == 4));
4554+ }
4555+
4556+};
4557+
4558+#endif /* DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_SET_BY_KEY_H */
4559
4560=== added file 'plugin/memcached_udf/memc_stats.cc'
4561--- plugin/memcached_udf/memc_stats.cc 1970-01-01 00:00:00 +0000
4562+++ plugin/memcached_udf/memc_stats.cc 2009-10-05 20:45:24 +0000
4563@@ -0,0 +1,130 @@
4564+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
4565+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4566+ *
4567+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
4568+ * All rights reserved.
4569+ *
4570+ * Redistribution and use in source and binary forms, with or without
4571+ * modification, are permitted provided that the following conditions are met:
4572+ *
4573+ * * Redistributions of source code must retain the above copyright notice,
4574+ * this list of conditions and the following disclaimer.
4575+ * * Redistributions in binary form must reproduce the above copyright notice,
4576+ * this list of conditions and the following disclaimer in the documentation
4577+ * and/or other materials provided with the distribution.
4578+ * * Neither the name of Patrick Galbraith nor the names of its contributors
4579+ * may be used to endorse or promote products derived from this software
4580+ * without specific prior written permission.
4581+ *
4582+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
4583+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4584+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4585+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
4586+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4587+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4588+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4589+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4590+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4591+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
4592+ * THE POSSIBILITY OF SUCH DAMAGE.
4593+ */
4594+
4595+#include <drizzled/server_includes.h>
4596+#include <drizzled/item/func.h>
4597+#include <drizzled/function/str/strfunc.h>
4598+
4599+#include "memcached_udf.h"
4600+#include "memc_stats.h"
4601+
4602+#include <libmemcached/memcached.h>
4603+
4604+#include <string>
4605+#include <algorithm>
4606+
4607+using namespace std;
4608+
4609+void MemcachedStats::setFailureString(const char *error)
4610+{
4611+ size_t size= strlen(error);
4612+ failure_buff.realloc(size);
4613+ failure_buff.length(size);
4614+ memcpy(failure_buff.ptr(), error, size);
4615+}
4616+
4617+String *MemcachedStats::val_str(String *str)
4618+{
4619+ memcached_return rc;
4620+ unsigned int count;
4621+ char buff[100];
4622+ memcached_stat_st *stat;
4623+ memcached_server_st *servers;
4624+ memcached_server_st *server_list;
4625+ String *server_names;
4626+
4627+
4628+ if (arg_count != 1 ||
4629+ ! (server_names= args[0]->val_str(str)) ||
4630+ ! memc)
4631+ {
4632+ setFailureString("USAGE: memc_stats('<server list>')");
4633+ return &failure_buff;
4634+ }
4635+
4636+ servers= memcached_servers_parse(server_names->c_ptr());
4637+ if (servers == NULL)
4638+ {
4639+ setFailureString(" ERROR: unable to parse servers string!");
4640+ return &failure_buff;
4641+ }
4642+ memcached_server_push(memc, servers);
4643+ memcached_server_list_free(servers);
4644+
4645+ stat= memcached_stat(memc, NULL, &rc);
4646+
4647+ if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_SOME_ERRORS)
4648+ {
4649+ snprintf(buff, 100, "Failure to communicate with servers (%s)\n",
4650+ memcached_strerror(memc, rc));
4651+
4652+ setFailureString(buff);
4653+ return &failure_buff;
4654+ }
4655+
4656+ server_list= memcached_server_list(memc);
4657+
4658+ results_buff.length(0);
4659+ snprintf(buff, 100, "Listing %u Server\n\n", memcached_server_count(memc));
4660+ results_buff.append(buff);
4661+
4662+ for (count= 0; count < memcached_server_count(memc); count++)
4663+ {
4664+ char **list;
4665+ char **ptr;
4666+
4667+ list= memcached_stat_get_keys(memc, &stat[count], &rc);
4668+
4669+ snprintf(buff, 100, "Server: %s (%u)\n",
4670+ memcached_server_name(memc, server_list[count]),
4671+ memcached_server_port(memc, server_list[count]));
4672+
4673+
4674+ results_buff.append(buff);
4675+
4676+ for (ptr= list; *ptr; ptr++)
4677+ {
4678+ char *value= memcached_stat_get_value(memc, &stat[count], *ptr, &rc);
4679+
4680+ snprintf(buff, 100, "\t %s: %s\n", *ptr, value);
4681+ free(value);
4682+ results_buff.append(buff);
4683+ }
4684+
4685+ free(list);
4686+ results_buff.append("\n");
4687+ }
4688+
4689+ free(stat);
4690+
4691+ return &results_buff;
4692+
4693+}
4694
4695=== added file 'plugin/memcached_udf/memc_stats.h'
4696--- plugin/memcached_udf/memc_stats.h 1970-01-01 00:00:00 +0000
4697+++ plugin/memcached_udf/memc_stats.h 2009-10-05 20:45:24 +0000
4698@@ -0,0 +1,74 @@
4699+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
4700+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4701+ *
4702+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
4703+ * All rights reserved.
4704+ *
4705+ * Redistribution and use in source and binary forms, with or without
4706+ * modification, are permitted provided that the following conditions are met:
4707+ *
4708+ * * Redistributions of source code must retain the above copyright notice,
4709+ * this list of conditions and the following disclaimer.
4710+ * * Redistributions in binary form must reproduce the above copyright notice,
4711+ * this list of conditions and the following disclaimer in the documentation
4712+ * and/or other materials provided with the distribution.
4713+ * * Neither the name of Patrick Galbraith nor the names of its contributors
4714+ * may be used to endorse or promote products derived from this software
4715+ * without specific prior written permission.
4716+ *
4717+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
4718+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4719+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4720+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
4721+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4722+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4723+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4724+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4725+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4726+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
4727+ * THE POSSIBILITY OF SUCH DAMAGE.
4728+ */
4729+
4730+#ifndef DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_STATS_H
4731+#define DRIZZLE_PLUGIN_MEMCACHED_UDF_MEMC_STATS_H
4732+
4733+#include <drizzled/server_includes.h>
4734+#include <drizzled/item/func.h>
4735+
4736+#include <libmemcached/memcached.h>
4737+
4738+#include <map>
4739+#include <string>
4740+
4741+/* implements memc_stats */
4742+class MemcachedStats: public Item_str_func
4743+{
4744+public:
4745+ MemcachedStats()
4746+ :
4747+ Item_str_func(),
4748+ failure_buff("FAILURE: ", &my_charset_bin),
4749+ results_buff("", &my_charset_bin)
4750+ {
4751+ }
4752+
4753+ const char *func_name() const
4754+ {
4755+ return "memc_stats";
4756+ }
4757+
4758+ String *val_str(String *);
4759+
4760+ void fix_length_and_dec()
4761+ {
4762+ max_length= 32;
4763+ }
4764+
4765+private:
4766+ void setFailureString(const char *error);
4767+
4768+ String failure_buff;
4769+ String results_buff;
4770+};
4771+
4772+#endif /* MEMC_STATS_H */
4773
4774=== added file 'plugin/memcached_udf/memcached_udf.cc'
4775--- plugin/memcached_udf/memcached_udf.cc 1970-01-01 00:00:00 +0000
4776+++ plugin/memcached_udf/memcached_udf.cc 2009-10-05 20:45:24 +0000
4777@@ -0,0 +1,387 @@
4778+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
4779+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4780+ *
4781+ * Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
4782+ * All rights reserved.
4783+ *
4784+ * Redistribution and use in source and binary forms, with or without
4785+ * modification, are permitted provided that the following conditions are met:
4786+ *
4787+ * * Redistributions of source code must retain the above copyright notice,
4788+ * this list of conditions and the following disclaimer.
4789+ * * Redistributions in binary form must reproduce the above copyright notice,
4790+ * this list of conditions and the following disclaimer in the documentation
4791+ * and/or other materials provided with the distribution.
4792+ * * Neither the name of Patrick Galbraith nor the names of its contributors
4793+ * may be used to endorse or promote products derived from this software
4794+ * without specific prior written permission.
4795+ *
4796+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
4797+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4798+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4799+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
4800+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4801+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4802+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4803+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4804+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4805+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
4806+ * THE POSSIBILITY OF SUCH DAMAGE.
4807+ */
4808+
4809+#include <drizzled/server_includes.h>
4810+#include <drizzled/slot/function.h>
4811+#include <drizzled/function/str/strfunc.h>
4812+
4813+#include "memcached_udf.h"
4814+#include "memc_servers_set.h"
4815+#include "memc_behavior_set.h"
4816+#include "memc_behavior_get.h"
4817+#include "memc_stats.h"
4818+#include "memc_get.h"
4819+#include "memc_get_by_key.h"
4820+#include "memc_set.h"
4821+#include "memc_set_by_key.h"
4822+#include "memc_add.h"
4823+#include "memc_add_by_key.h"
4824+#include "memc_replace.h"
4825+#include "memc_replace_by_key.h"
4826+#include "memc_delete.h"
4827+#include "memc_delete_by_key.h"
4828+#include "memc_append.h"
4829+#include "memc_append_by_key.h"
4830+#include "memc_prepend.h"
4831+#include "memc_prepend_by_key.h"
4832+#include "memc_cas.h"
4833+#include "memc_cas_by_key.h"
4834+#include "memc_increment.h"
4835+#include "memc_decrement.h"
4836+#include "memc_misc.h"
4837+
4838+#include <libmemcached/memcached.h>
4839+
4840+#include <string>
4841+
4842+using namespace std;
4843+using namespace drizzled;
4844+
4845+/*
4846+ * A global memcached data structure needed by
4847+ * the various libmemcached API functions.
4848+ */
4849+memcached_st *memc= NULL;
4850+
4851+/*
4852+ * The memcached UDF's.
4853+ */
4854+plugin::Create_function<MemcachedServersSet> *memc_servers_set= NULL;
4855+plugin::Create_function<MemcachedBehaviorSet> *memc_behavior_set= NULL;
4856+plugin::Create_function<MemcachedBehaviorGet> *memc_behavior_get= NULL;
4857+plugin::Create_function<MemcachedStats> *memc_stats= NULL;
4858+plugin::Create_function<MemcachedGet> *memc_get= NULL;
4859+plugin::Create_function<MemcachedGetByKey> *memc_get_by_key= NULL;
4860+plugin::Create_function<MemcachedSet> *memc_set= NULL;
4861+plugin::Create_function<MemcachedSetByKey> *memc_set_by_key= NULL;
4862+plugin::Create_function<MemcachedAdd> *memc_add= NULL;
4863+plugin::Create_function<MemcachedAddByKey> *memc_add_by_key= NULL;
4864+plugin::Create_function<MemcachedReplace> *memc_replace= NULL;
4865+plugin::Create_function<MemcachedReplaceByKey> *memc_replace_by_key= NULL;
4866+plugin::Create_function<MemcachedIncrement> *memc_increment= NULL;
4867+plugin::Create_function<MemcachedDecrement> *memc_decrement= NULL;
4868+plugin::Create_function<MemcachedDelete> *memc_delete= NULL;
4869+plugin::Create_function<MemcachedDeleteByKey> *memc_delete_by_key= NULL;
4870+plugin::Create_function<MemcachedAppend> *memc_append= NULL;
4871+plugin::Create_function<MemcachedAppendByKey> *memc_append_by_key= NULL;
4872+plugin::Create_function<MemcachedPrepend> *memc_prepend= NULL;
4873+plugin::Create_function<MemcachedPrependByKey> *memc_prepend_by_key= NULL;
4874+plugin::Create_function<MemcachedCas> *memc_cas= NULL;
4875+plugin::Create_function<MemcachedCasByKey> *memc_cas_by_key= NULL;
4876+plugin::Create_function<MemcachedServerCount> *memc_serv_count= NULL;
4877+plugin::Create_function<MemcachedVersion> *memc_version= NULL;
4878+
4879+bool initMemcUDF()
4880+{
4881+ memc_servers_set= new plugin::Create_function<MemcachedServersSet>("memc_servers_set");
4882+ if (memc_servers_set == NULL)
4883+ {
4884+ return true;
4885+ }
4886+
4887+ memc_behavior_set= new plugin::Create_function<MemcachedBehaviorSet>("memc_behavior_set");
4888+ if (memc_behavior_set == NULL)
4889+ {
4890+ return true;
4891+ }
4892+
4893+ memc_behavior_get= new plugin::Create_function<MemcachedBehaviorGet>("memc_behavior_get");
4894+ if (memc_behavior_get == NULL)
4895+ {
4896+ return true;
4897+ }
4898+
4899+ memc_stats= new plugin::Create_function<MemcachedStats>("memc_stats");
4900+ if (memc_stats == NULL)
4901+ {
4902+ return true;
4903+ }
4904+
4905+ memc_get= new plugin::Create_function<MemcachedGet>("memc_get");
4906+ if (memc_get == NULL)
4907+ {
4908+ return true;
4909+ }
4910+
4911+ memc_get_by_key= new plugin::Create_function<MemcachedGetByKey>("memc_get_by_key");
4912+ if (memc_get_by_key == NULL)
4913+ {
4914+ return true;
4915+ }
4916+
4917+ memc_set= new plugin::Create_function<MemcachedSet>("memc_set");
4918+ if (memc_set == NULL)
4919+ {
4920+ return true;
4921+ }
4922+ memc_set_by_key= new plugin::Create_function<MemcachedSetByKey>("memc_set_by_key");
4923+ if (memc_set_by_key == NULL)
4924+ {
4925+ return true;
4926+ }
4927+
4928+ memc_add= new plugin::Create_function<MemcachedAdd>("memc_add");
4929+ if (memc_add== NULL)
4930+ {
4931+ return true;
4932+ }
4933+
4934+ memc_add_by_key= new plugin::Create_function<MemcachedAddByKey>("memc_add_by_key");
4935+ if (memc_add_by_key == NULL)
4936+ {
4937+ return true;
4938+ }
4939+
4940+ memc_replace= new plugin::Create_function<MemcachedReplace>("memc_replace");
4941+ if (memc_replace== NULL)
4942+ {
4943+ return true;
4944+ }
4945+
4946+ memc_replace_by_key= new plugin::Create_function<MemcachedReplaceByKey>("memc_replace_by_key");
4947+ if (memc_replace_by_key == NULL)
4948+ {
4949+ return true;
4950+ }
4951+
4952+ memc_delete= new plugin::Create_function<MemcachedDelete>("memc_delete");
4953+ if (memc_delete == NULL)
4954+ {
4955+ return true;
4956+ }
4957+
4958+ memc_delete_by_key= new plugin::Create_function<MemcachedDeleteByKey>("memc_delete_by_key");
4959+ if (memc_delete_by_key == NULL)
4960+ {
4961+ return true;
4962+ }
4963+
4964+ memc_append= new plugin::Create_function<MemcachedAppend>("memc_append");
4965+ if (memc_append == NULL)
4966+ {
4967+ return true;
4968+ }
4969+
4970+ memc_append_by_key= new plugin::Create_function<MemcachedAppendByKey>("memc_append_by_key");
4971+ if (memc_append_by_key == NULL)
4972+ {
4973+ return true;
4974+ }
4975+
4976+ memc_prepend= new plugin::Create_function<MemcachedPrepend>("memc_prepend");
4977+ if (memc_prepend == NULL)
4978+ {
4979+ return true;
4980+ }
4981+
4982+ memc_prepend_by_key= new plugin::Create_function<MemcachedPrependByKey>("memc_prepend_by_key");
4983+ if (memc_prepend_by_key == NULL)
4984+ {
4985+ return true;
4986+ }
4987+
4988+ memc_cas= new plugin::Create_function<MemcachedCas>("memc_cas");
4989+ if (memc_cas == NULL)
4990+ {
4991+ return true;
4992+ }
4993+
4994+ memc_cas_by_key= new plugin::Create_function<MemcachedCasByKey>("memc_cas_by_key");
4995+ if (memc_cas_by_key == NULL)
4996+ {
4997+ return true;
4998+ }
4999+
5000+ memc_serv_count= new plugin::Create_function<MemcachedServerCount>("memc_server_count");
The diff has been truncated for viewing.