1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include <drizzled/charset_info.h>
23
#include <drizzled/function/locate.h>
24
#include <drizzled/lex_string.h>
29
void Item_func_locate::fix_length_and_dec()
31
max_length= MY_INT32_NUM_DECIMAL_DIGITS;
32
agg_arg_charsets(cmp_collation, args, 2, MY_COLL_CMP_CONV, 1);
35
int64_t Item_func_locate::val_int()
38
String *a=args[0]->val_str(&value1);
39
String *b=args[1]->val_str(&value2);
46
/* must be int64_t to avoid truncation */
53
start0= start= args[2]->val_int() - 1;
55
if ((start < 0) || (start > static_cast<int64_t>(a->length())))
58
/* start is now sufficiently valid to pass to charpos function */
59
start= a->charpos((int) start);
61
if (start + b->length() > a->length())
64
if (!b->length()) // Found empty string at start
67
if (!cmp_collation.collation->coll->instr(cmp_collation.collation,
69
(uint32_t) (a->length()-start),
70
b->ptr(), b->length(),
73
return (int64_t) match.mb_len + start0 + 1;
77
void Item_func_locate::print(String *str, enum_query_type query_type)
79
str->append(STRING_WITH_LEN("locate("));
80
args[1]->print(str, query_type);
82
args[0]->print(str, query_type);
86
args[2]->print(str, query_type);
91
} /* namespace drizzled */