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 * 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 #include <drizzled/plugin/function.h> 00022 #include <drizzled/function/math/int.h> 00023 #include <plugin/compression/uncompressed_length.h> 00024 00025 #include <string> 00026 00027 using namespace std; 00028 using namespace drizzled; 00029 00030 00031 int64_t Item_func_uncompressed_length::val_int() 00032 { 00033 assert(fixed == 1); 00034 String *res= args[0]->val_str(&value); 00035 if (!res) 00036 { 00037 null_value=1; 00038 return 0; 00039 } 00040 null_value=0; 00041 if (res->is_empty()) return 0; 00042 00043 /* 00044 res->ptr() using is safe because we have tested that string is not empty, 00045 res->c_ptr() is not used because: 00046 - we do not need \0 terminated string to get first 4 bytes 00047 - c_ptr() tests simbol after string end (uninitialiozed memory) which 00048 confuse valgrind 00049 */ 00050 return uint4korr(res->ptr()) & 0x3FFFFFFF; 00051 } 00052