492.3.16
by Lee
break out item_func_bit, item_func_char_length, item_func_coercibility, item_func_locate, item_func_units into functions directory |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2008 Sun Microsystems, Inc.
|
492.3.16
by Lee
break out item_func_bit, item_func_char_length, item_func_coercibility, item_func_locate, item_func_units into functions directory |
5 |
*
|
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.
|
|
9 |
*
|
|
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.
|
|
14 |
*
|
|
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
|
|
18 |
*/
|
|
19 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
20 |
#include <config.h> |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
21 |
|
2154.2.4
by Brian Aker
This fixes 716459 |
22 |
#include <drizzled/charset_info.h> |
670.1.20
by Monty Taylor
Renamed functions to function... everything else is singular. |
23 |
#include <drizzled/function/locate.h> |
2154.2.4
by Brian Aker
This fixes 716459 |
24 |
#include <drizzled/lex_string.h> |
492.3.16
by Lee
break out item_func_bit, item_func_char_length, item_func_coercibility, item_func_locate, item_func_units into functions directory |
25 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
26 |
namespace drizzled |
27 |
{
|
|
28 |
||
492.3.16
by Lee
break out item_func_bit, item_func_char_length, item_func_coercibility, item_func_locate, item_func_units into functions directory |
29 |
void Item_func_locate::fix_length_and_dec() |
30 |
{
|
|
31 |
max_length= MY_INT32_NUM_DECIMAL_DIGITS; |
|
32 |
agg_arg_charsets(cmp_collation, args, 2, MY_COLL_CMP_CONV, 1); |
|
33 |
}
|
|
34 |
||
35 |
int64_t Item_func_locate::val_int() |
|
36 |
{
|
|
37 |
assert(fixed == 1); |
|
38 |
String *a=args[0]->val_str(&value1); |
|
39 |
String *b=args[1]->val_str(&value2); |
|
40 |
if (!a || !b) |
|
41 |
{
|
|
42 |
null_value=1; |
|
971.6.11
by Eric Day
Removed purecov messages. |
43 |
return 0; |
492.3.16
by Lee
break out item_func_bit, item_func_char_length, item_func_coercibility, item_func_locate, item_func_units into functions directory |
44 |
}
|
45 |
null_value=0; |
|
46 |
/* must be int64_t to avoid truncation */
|
|
47 |
int64_t start= 0; |
|
48 |
int64_t start0= 0; |
|
49 |
my_match_t match; |
|
50 |
||
51 |
if (arg_count == 3) |
|
52 |
{
|
|
53 |
start0= start= args[2]->val_int() - 1; |
|
54 |
||
1816.3.1
by Brian Aker
Convert sql_string to use size_t (this should clean up ICC warnings). |
55 |
if ((start < 0) || (start > static_cast<int64_t>(a->length()))) |
492.3.16
by Lee
break out item_func_bit, item_func_char_length, item_func_coercibility, item_func_locate, item_func_units into functions directory |
56 |
return 0; |
57 |
||
58 |
/* start is now sufficiently valid to pass to charpos function */
|
|
59 |
start= a->charpos((int) start); |
|
60 |
||
61 |
if (start + b->length() > a->length()) |
|
62 |
return 0; |
|
63 |
}
|
|
64 |
if (!b->length()) // Found empty string at start |
|
65 |
return start + 1; |
|
66 |
||
67 |
if (!cmp_collation.collation->coll->instr(cmp_collation.collation, |
|
68 |
a->ptr()+start, |
|
895
by Brian Aker
Completion (?) of uint conversion. |
69 |
(uint32_t) (a->length()-start), |
492.3.16
by Lee
break out item_func_bit, item_func_char_length, item_func_coercibility, item_func_locate, item_func_units into functions directory |
70 |
b->ptr(), b->length(), |
71 |
&match, 1)) |
|
72 |
return 0; |
|
73 |
return (int64_t) match.mb_len + start0 + 1; |
|
74 |
}
|
|
75 |
||
76 |
||
2215.2.1
by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing. |
77 |
void Item_func_locate::print(String *str) |
492.3.16
by Lee
break out item_func_bit, item_func_char_length, item_func_coercibility, item_func_locate, item_func_units into functions directory |
78 |
{
|
79 |
str->append(STRING_WITH_LEN("locate(")); |
|
2215.2.1
by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing. |
80 |
args[1]->print(str); |
492.3.16
by Lee
break out item_func_bit, item_func_char_length, item_func_coercibility, item_func_locate, item_func_units into functions directory |
81 |
str->append(','); |
2215.2.1
by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing. |
82 |
args[0]->print(str); |
492.3.16
by Lee
break out item_func_bit, item_func_char_length, item_func_coercibility, item_func_locate, item_func_units into functions directory |
83 |
if (arg_count == 3) |
84 |
{
|
|
85 |
str->append(','); |
|
2215.2.1
by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing. |
86 |
args[2]->print(str); |
492.3.16
by Lee
break out item_func_bit, item_func_char_length, item_func_coercibility, item_func_locate, item_func_units into functions directory |
87 |
}
|
88 |
str->append(')'); |
|
89 |
}
|
|
90 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
91 |
} /* namespace drizzled */ |