Drizzled Public API Documentation

coercibility_function.cc

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *  Copyright (C) 2010 Andrew Hutchings
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; version 2 of the License.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <drizzled/plugin/function.h>
00024 #include <drizzled/function/math/int.h>
00025 
00026 using namespace drizzled;
00027 
00028 class CoercibilityFunction :public Item_int_func
00029 {
00030 public:
00031   CoercibilityFunction() :Item_int_func() 
00032   {
00033     unsigned_flag= true;
00034   }
00035 
00036   int64_t val_int();
00037 
00038   const char *func_name() const
00039   {
00040     return "coercibility";
00041   }
00042 
00043   void fix_length_and_dec()
00044   {
00045     max_length=10; maybe_null= 0;
00046   }
00047 
00048   table_map not_null_tables() const
00049   {
00050     return 0;
00051   }
00052 
00053   bool check_argument_count(int n)
00054   {
00055     return (n == 1);
00056   }
00057 };
00058 
00059 int64_t CoercibilityFunction::val_int()
00060 {
00061   assert(fixed == 1);
00062   null_value= 0;
00063   return (int64_t) args[0]->collation.derivation;
00064 }
00065 
00066 plugin::Create_function<CoercibilityFunction> *coercibility_function= NULL;
00067 
00068 static int initialize(drizzled::module::Context &context)
00069 {
00070   coercibility_function= new plugin::Create_function<CoercibilityFunction>("coercibility");
00071   context.add(coercibility_function);
00072   return 0;
00073 }
00074 
00075 DRIZZLE_DECLARE_PLUGIN
00076 {
00077   DRIZZLE_VERSION_ID,
00078   "coercibility_function",
00079   "1.0",
00080   "Andrew Hutchings",
00081   "COERCIBILITY()",
00082   PLUGIN_LICENSE_GPL,
00083   initialize,
00084   NULL,
00085   NULL
00086 }
00087 DRIZZLE_DECLARE_PLUGIN_END;