1 #ifndef ITEM_VERS_INCLUDED
2 #define ITEM_VERS_INCLUDED
3 /* Copyright (c) 2017, MariaDB Corporation.
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; version 2 of the License.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA */
17 
18 
19 /* System Versioning items */
20 
21 #ifdef USE_PRAGMA_INTERFACE
22 #pragma interface			/* gcc class implementation */
23 #endif
24 
25 class Item_func_history: public Item_bool_func
26 {
27 public:
28   /*
29      @param    a  Item_field for row_end system field
30   */
31   Item_func_history(THD *thd, Item *a): Item_bool_func(thd, a)
32   {
33     DBUG_ASSERT(a->type() == Item::FIELD_ITEM);
34   }
35 
36   virtual bool val_bool();
37   virtual longlong val_int()
38   {
39     return (val_bool() ? 1 : 0);
40   }
41   bool fix_length_and_dec()
42   {
43     maybe_null= 0;
44     null_value= 0;
45     decimals= 0;
46     max_length= 1;
47     return FALSE;
48   }
49   virtual const char* func_name() const { return "is_history"; }
50   virtual void print(String *str, enum_query_type query_type);
51   Item *get_copy(THD *thd)
52   { return get_item_copy<Item_func_history>(thd, this); }
53 };
54 
55 class Item_func_trt_ts: public Item_datetimefunc
56 {
57   TR_table::field_id_t trt_field;
58 public:
59   Item_func_trt_ts(THD *thd, Item* a, TR_table::field_id_t _trt_field);
60   const char *func_name() const
61   {
62     if (trt_field == TR_table::FLD_BEGIN_TS)
63     {
64       return "trt_begin_ts";
65     }
66     return "trt_commit_ts";
67   }
68   bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date);
69   Item *get_copy(THD *thd)
70   { return get_item_copy<Item_func_trt_ts>(thd, this); }
71   bool fix_length_and_dec()
72   { fix_attributes_datetime(decimals); return FALSE; }
73 };
74 
75 class Item_func_trt_id : public Item_longlong_func
76 {
77   TR_table::field_id_t trt_field;
78   bool backwards;
79 
80   longlong get_by_trx_id(ulonglong trx_id);
81   longlong get_by_commit_ts(MYSQL_TIME &commit_ts, bool backwards);
82 
83 public:
84   Item_func_trt_id(THD *thd, Item* a, TR_table::field_id_t _trt_field, bool _backwards= false);
85   Item_func_trt_id(THD *thd, Item* a, Item* b, TR_table::field_id_t _trt_field);
86 
87   const char *func_name() const
88   {
89     switch (trt_field)
90     {
91     case TR_table::FLD_TRX_ID:
92       return "trt_trx_id";
93     case TR_table::FLD_COMMIT_ID:
94         return "trt_commit_id";
95     case TR_table::FLD_ISO_LEVEL:
96       return "trt_iso_level";
97     default:
98       DBUG_ASSERT(0);
99     }
100     return NULL;
101   }
102 
103   bool fix_length_and_dec()
104   {
105     bool res= Item_int_func::fix_length_and_dec();
106     max_length= 20;
107     return res;
108   }
109 
110   longlong val_int();
111   Item *get_copy(THD *thd)
112   { return get_item_copy<Item_func_trt_id>(thd, this); }
113 };
114 
115 class Item_func_trt_trx_sees : public Item_bool_func
116 {
117 protected:
118   bool accept_eq;
119 
120 public:
121   Item_func_trt_trx_sees(THD *thd, Item* a, Item* b);
122   const char *func_name() const
123   {
124     return "trt_trx_sees";
125   }
126   longlong val_int();
127   Item *get_copy(THD *thd)
128   { return get_item_copy<Item_func_trt_trx_sees>(thd, this); }
129 };
130 
131 class Item_func_trt_trx_sees_eq :
132   public Item_func_trt_trx_sees
133 {
134 public:
135   Item_func_trt_trx_sees_eq(THD *thd, Item* a, Item* b) :
136     Item_func_trt_trx_sees(thd, a, b)
137   {
138     accept_eq= true;
139   }
140   const char *func_name() const
141   {
142     return "trt_trx_sees_eq";
143   }
144 };
145 
146 #endif /* ITEM_VERS_INCLUDED */
147