Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
6b36fb96
Commit
6b36fb96
authored
Oct 02, 2015
by
Alexander Barkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean-up: sharing duplicate code in Item_field::val_bool_result() and
Item_ref::val_bool_result().
parent
38f3b99d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
40 deletions
+17
-40
sql/field.h
sql/field.h
+13
-0
sql/item.cc
sql/item.cc
+4
-40
No files found.
sql/field.h
View file @
6b36fb96
...
...
@@ -738,6 +738,7 @@ class Field: public Value_source
{
return
store
(
ls
->
str
,
ls
->
length
,
cs
);
}
virtual
double
val_real
(
void
)
=
0
;
virtual
longlong
val_int
(
void
)
=
0
;
virtual
bool
val_bool
(
void
)
=
0
;
virtual
my_decimal
*
val_decimal
(
my_decimal
*
);
inline
String
*
val_str
(
String
*
str
)
{
return
val_str
(
str
,
str
);
}
/*
...
...
@@ -1491,6 +1492,7 @@ class Field_num :public Field {
bool
eq_def
(
Field
*
field
);
int
store_decimal
(
const
my_decimal
*
);
my_decimal
*
val_decimal
(
my_decimal
*
);
bool
val_bool
()
{
return
val_int
()
!=
0
;
}
uint
is_equal
(
Create_field
*
new_field
);
uint
row_pack_length
()
const
{
return
pack_length
();
}
uint32
pack_length_from_metadata
(
uint
field_metadata
)
{
...
...
@@ -1537,6 +1539,7 @@ class Field_str :public Field {
uint32
max_display_length
()
{
return
field_length
;
}
friend
class
Create_field
;
my_decimal
*
val_decimal
(
my_decimal
*
);
bool
val_bool
()
{
return
val_real
()
!=
0e0
;
}
virtual
bool
str_needs_quotes
()
{
return
TRUE
;
}
uint
is_equal
(
Create_field
*
new_field
);
bool
eq_cmp_as_binary
()
{
return
MY_TEST
(
flags
&
BINARY_FLAG
);
}
...
...
@@ -1609,6 +1612,7 @@ class Field_real :public Field_num {
int
store_time_dec
(
MYSQL_TIME
*
ltime
,
uint
dec
);
bool
get_date
(
MYSQL_TIME
*
ltime
,
ulonglong
fuzzydate
);
my_decimal
*
val_decimal
(
my_decimal
*
);
bool
val_bool
()
{
return
val_real
()
!=
0e0
;
}
uint32
max_display_length
()
{
return
field_length
;
}
uint
size_of
()
const
{
return
sizeof
(
*
this
);
}
Item
*
get_equal_const_item
(
THD
*
thd
,
const
Context
&
ctx
,
Item
*
const_item
);
...
...
@@ -1684,6 +1688,12 @@ class Field_new_decimal :public Field_num {
my_decimal
*
val_decimal
(
my_decimal
*
);
String
*
val_str
(
String
*
,
String
*
);
bool
get_date
(
MYSQL_TIME
*
ltime
,
ulonglong
fuzzydate
);
bool
val_bool
()
{
my_decimal
decimal_value
;
my_decimal
*
val
=
val_decimal
(
&
decimal_value
);
return
val
?
!
my_decimal_is_zero
(
val
)
:
0
;
}
int
cmp
(
const
uchar
*
,
const
uchar
*
);
void
sort_string
(
uchar
*
buff
,
uint
length
);
bool
zero_pack
()
const
{
return
0
;
}
...
...
@@ -2009,6 +2019,7 @@ class Field_null :public Field_str {
int
reset
(
void
)
{
return
0
;
}
double
val_real
(
void
)
{
return
0.0
;}
longlong
val_int
(
void
)
{
return
0
;}
bool
val_bool
(
void
)
{
return
false
;
}
my_decimal
*
val_decimal
(
my_decimal
*
)
{
return
0
;
}
String
*
val_str
(
String
*
value
,
String
*
value2
)
{
value2
->
length
(
0
);
return
value2
;}
...
...
@@ -2054,6 +2065,7 @@ class Field_temporal: public Field {
CHARSET_INFO
*
sort_charset
(
void
)
const
{
return
&
my_charset_bin
;
}
bool
binary
()
const
{
return
true
;
}
enum
Item_result
cmp_type
()
const
{
return
TIME_RESULT
;
}
bool
val_bool
()
{
return
val_real
()
!=
0e0
;
}
uint
is_equal
(
Create_field
*
new_field
);
bool
eq_def
(
Field
*
field
)
{
...
...
@@ -3267,6 +3279,7 @@ class Field_bit :public Field {
String
*
val_str
(
String
*
,
String
*
);
virtual
bool
str_needs_quotes
()
{
return
TRUE
;
}
my_decimal
*
val_decimal
(
my_decimal
*
);
bool
val_bool
()
{
return
val_int
()
!=
0
;
}
int
cmp
(
const
uchar
*
a
,
const
uchar
*
b
)
{
DBUG_ASSERT
(
ptr
==
a
||
ptr
==
b
);
...
...
sql/item.cc
View file @
6b36fb96
...
...
@@ -2560,27 +2560,8 @@ my_decimal *Item_field::val_decimal_result(my_decimal *decimal_value)
bool
Item_field
::
val_bool_result
()
{
if
((
null_value
=
result_field
->
is_null
()))
return
FALSE
;
switch
(
result_field
->
result_type
())
{
case
INT_RESULT
:
return
result_field
->
val_int
()
!=
0
;
case
DECIMAL_RESULT
:
{
my_decimal
decimal_value
;
my_decimal
*
val
=
result_field
->
val_decimal
(
&
decimal_value
);
if
(
val
)
return
!
my_decimal_is_zero
(
val
);
return
0
;
}
case
REAL_RESULT
:
case
STRING_RESULT
:
return
result_field
->
val_real
()
!=
0.0
;
case
ROW_RESULT
:
case
TIME_RESULT
:
DBUG_ASSERT
(
0
);
return
0
;
// Shut up compiler
}
return
0
;
return
false
;
return
result_field
->
val_bool
();
}
...
...
@@ -7204,25 +7185,8 @@ bool Item_ref::val_bool_result()
if
(
result_field
)
{
if
((
null_value
=
result_field
->
is_null
()))
return
0
;
switch
(
result_field
->
result_type
())
{
case
INT_RESULT
:
return
result_field
->
val_int
()
!=
0
;
case
DECIMAL_RESULT
:
{
my_decimal
decimal_value
;
my_decimal
*
val
=
result_field
->
val_decimal
(
&
decimal_value
);
if
(
val
)
return
!
my_decimal_is_zero
(
val
);
return
0
;
}
case
REAL_RESULT
:
case
STRING_RESULT
:
return
result_field
->
val_real
()
!=
0.0
;
case
ROW_RESULT
:
case
TIME_RESULT
:
DBUG_ASSERT
(
0
);
}
return
false
;
return
result_field
->
val_bool
();
}
return
val_bool
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment