1 /*
2 Copyright (C) 2003-2006, 2008 MySQL AB, 2009 Sun Microsystems, Inc.
3 All rights reserved. Use is subject to license terms.
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, version 2.0,
7 as published by the Free Software Foundation.
8
9 This program is also distributed with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have included with MySQL.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License, version 2.0, for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 #ifndef SCAN_FILTER_HPP
27 #define SCAN_FILTER_HPP
28
29 /* NOTE - This code is currently broken, as old-style interpreted
30 * code definition is no longer supported for Scans.
31 * Interpreted programs for scans must be defined using the
32 * NdbInterpretedCode class
33 * TODO : Fix or remove this code.
34 */
35
36 class ScanFilter {
37 public:
38 #if 0
39 /**
40 * Create a scan filter for table tab
41 * colNo - column to filter on
42 * val - val to use when selecting valu to filter on
43 *
44 */
45 ScanFilter(const NDBT_Table& tab,
46 int colNo,
47 int val);
48 #endif
ScanFilter(int records=1000)49 ScanFilter(int records = 1000){};
~ScanFilter()50 virtual ~ScanFilter() {}
51 virtual int filterOp(NdbOperation*) = 0;
52 virtual int verifyRecord(NDBT_ResultRow&) = 0;
53 private:
54
55 // const NDBT_Table& tab;
56 };
57
58 class LessThanFilter : public ScanFilter {
59 public:
LessThanFilter(int records)60 LessThanFilter(int records){ compare_value = records / 100; };
~LessThanFilter()61 virtual ~LessThanFilter(){}
62 private:
63 Uint32 compare_value;
64 int filterOp(NdbOperation* pOp);
65 int verifyRecord(NDBT_ResultRow&);
66 };
67
68 class EqualFilter : public ScanFilter {
69 public:
~EqualFilter()70 virtual ~EqualFilter(){}
71
72 static const Uint32 compare_value = 100;
73 int filterOp(NdbOperation* pOp);
74 int verifyRecord(NDBT_ResultRow&);
75 };
76
77 class NoFilter : public ScanFilter {
78 public:
~NoFilter()79 virtual ~NoFilter(){}
80 int filterOp(NdbOperation* pOp);
81 int verifyRecord(NDBT_ResultRow&);
82 };
83
84
filterOp(NdbOperation * pOp)85 int LessThanFilter::filterOp(NdbOperation* pOp){
86
87 if (pOp->load_const_u32(1, compare_value) != 0)
88 return NDBT_FAILED;
89
90 if (pOp->read_attr("KOL2", 2) != 0)
91 return NDBT_FAILED;
92
93 if (pOp->branch_lt(1, 2, 0) != 0)
94 return NDBT_FAILED;
95
96 if (pOp->interpret_exit_nok() != 0)
97 return NDBT_FAILED;
98
99 if (pOp->def_label(0) != 0)
100 return NDBT_FAILED;
101
102 if (pOp->interpret_exit_ok() != 0)
103 return NDBT_FAILED;
104
105 return NDBT_OK;
106 }
107
verifyRecord(NDBT_ResultRow & row)108 int LessThanFilter::verifyRecord(NDBT_ResultRow& row){
109 NdbRecAttr* rec = row.attributeStore(1);
110 if (rec->u_32_value() < compare_value)
111 return NDBT_OK;
112 return NDBT_FAILED;
113 }
114
filterOp(NdbOperation * pOp)115 int EqualFilter::filterOp(NdbOperation* pOp){
116
117 if (pOp->load_const_u32(1, compare_value) != 0)
118 return NDBT_FAILED;
119
120 if (pOp->read_attr("KOL2", 2) != 0)
121 return NDBT_FAILED;
122
123 if (pOp->branch_eq(1, 2, 0) != 0)
124 return NDBT_FAILED;
125
126 if (pOp->interpret_exit_nok() != 0)
127 return NDBT_FAILED;
128
129 if (pOp->def_label(0) != 0)
130 return NDBT_FAILED;
131
132 if (pOp->interpret_exit_ok() != 0)
133 return NDBT_FAILED;
134
135 return NDBT_OK;
136 }
137
verifyRecord(NDBT_ResultRow & row)138 int EqualFilter::verifyRecord(NDBT_ResultRow& row){
139 NdbRecAttr* rec = row.attributeStore(1);
140 if (rec->u_32_value() == compare_value)
141 return NDBT_OK;
142 return NDBT_FAILED;
143 }
144
filterOp(NdbOperation * pOp)145 int NoFilter::filterOp(NdbOperation* pOp){
146 return NDBT_OK;
147 }
148
verifyRecord(NDBT_ResultRow & row)149 int NoFilter::verifyRecord(NDBT_ResultRow& row){
150 // Check if this record should be in the result set or not
151 return NDBT_OK;
152 }
153
154 #endif
155