Drizzled Public API Documentation

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) 2010 Mark Atwood
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include <config.h>
00021 
00022 #include <drizzled/gettext.h>
00023 #include <drizzled/session.h>
00024 
00025 #include "function.h"
00026 #include "wrap.h"
00027 
00028 namespace drizzle_plugin
00029 {
00030 
00031 udf::Syslog::Syslog()
00032   : Item_str_func()
00033 { }
00034 
00035 drizzled::String *udf::Syslog::val_str(drizzled::String *s)
00036 {
00037 
00038   if (args[0]->null_value || args[1]->null_value || args[2]->null_value)
00039   {
00040     null_value= 1;
00041     return 0;
00042   }
00043 
00044   int syslog_facility= WrapSyslog::getFacilityByName(args[0]->val_str(s)->c_ptr());
00045   int syslog_priority= WrapSyslog::getPriorityByName(args[1]->val_str(s)->c_ptr());
00046 
00047   if ((syslog_facility == -1) || (syslog_priority == -1))
00048   {
00049     null_value= 1;
00050     return 0;
00051   }
00052 
00053   char *syslog_string= args[2]->val_str(s)->c_ptr();
00054   if ((syslog_string == 0) || (syslog_string[0] == 0))
00055   {
00056     null_value= 1;
00057     return 0;
00058   }
00059 
00060   WrapSyslog::singleton().log(syslog_facility, syslog_priority, "%s", syslog_string);
00061 
00062   null_value= 0;
00063   return args[2]->val_str(s);
00064 }
00065 
00066 void udf::Syslog::fix_length_and_dec()
00067 {
00068   max_length= args[0]->max_length;
00069 }
00070 
00071 bool udf::Syslog::check_argument_count(int n)
00072 {
00073   return (n == 3);
00074 }
00075 
00076 } /* namespace drizzle_plugin */