~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/test/ndbapi/ScanFilter.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifndef SCAN_FILTER_HPP
 
17
#define SCAN_FILTER_HPP
 
18
 
 
19
class ScanFilter {
 
20
public:
 
21
#if 0
 
22
  /**
 
23
   * Create a scan filter for table tab
 
24
   * colNo - column to filter on
 
25
   * val - val to use when selecting valu to filter on
 
26
   *
 
27
   */
 
28
  ScanFilter(const NDBT_Table& tab, 
 
29
             int colNo,
 
30
             int val);
 
31
#endif
 
32
  ScanFilter(int records = 1000){};
 
33
  virtual int filterOp(NdbOperation*) = 0;
 
34
  virtual int verifyRecord(NDBT_ResultRow&) = 0;
 
35
private:
 
36
 
 
37
  //  const NDBT_Table& tab;
 
38
};
 
39
 
 
40
class LessThanFilter : public ScanFilter {
 
41
public:
 
42
  LessThanFilter(int records){ compare_value = records / 100; };
 
43
private:
 
44
  Uint32 compare_value;
 
45
  int filterOp(NdbOperation* pOp);
 
46
  int verifyRecord(NDBT_ResultRow&);
 
47
};
 
48
 
 
49
class EqualFilter : public ScanFilter {
 
50
  static const Uint32 compare_value = 100;
 
51
  int filterOp(NdbOperation* pOp);
 
52
  int verifyRecord(NDBT_ResultRow&);
 
53
};
 
54
 
 
55
class NoFilter : public ScanFilter {
 
56
  int filterOp(NdbOperation* pOp);
 
57
  int verifyRecord(NDBT_ResultRow&);
 
58
};
 
59
 
 
60
 
 
61
int LessThanFilter::filterOp(NdbOperation* pOp){
 
62
  
 
63
  if (pOp->load_const_u32(1, compare_value) != 0)
 
64
    return NDBT_FAILED;
 
65
 
 
66
  if (pOp->read_attr("KOL2", 2) != 0)
 
67
    return NDBT_FAILED;
 
68
 
 
69
  if (pOp->branch_lt(1, 2, 0) != 0)
 
70
    return NDBT_FAILED;
 
71
 
 
72
  if (pOp->interpret_exit_nok() != 0)
 
73
    return NDBT_FAILED;
 
74
  
 
75
  if (pOp->def_label(0) != 0)
 
76
    return NDBT_FAILED;
 
77
 
 
78
  if (pOp->interpret_exit_ok() != 0)
 
79
    return NDBT_FAILED;
 
80
 
 
81
  return NDBT_OK;
 
82
}
 
83
 
 
84
int LessThanFilter::verifyRecord(NDBT_ResultRow& row){
 
85
  NdbRecAttr* rec = row.attributeStore(1);
 
86
  if (rec->u_32_value() < compare_value)
 
87
    return NDBT_OK;
 
88
  return NDBT_FAILED;
 
89
}
 
90
 
 
91
int EqualFilter::filterOp(NdbOperation* pOp){
 
92
  
 
93
  if (pOp->load_const_u32(1, compare_value) != 0)
 
94
    return NDBT_FAILED;
 
95
 
 
96
  if (pOp->read_attr("KOL2", 2) != 0)
 
97
    return NDBT_FAILED;
 
98
 
 
99
  if (pOp->branch_eq(1, 2, 0) != 0)
 
100
    return NDBT_FAILED;
 
101
 
 
102
  if (pOp->interpret_exit_nok() != 0)
 
103
    return NDBT_FAILED;
 
104
  
 
105
  if (pOp->def_label(0) != 0)
 
106
    return NDBT_FAILED;
 
107
 
 
108
  if (pOp->interpret_exit_ok() != 0)
 
109
    return NDBT_FAILED;
 
110
 
 
111
  return NDBT_OK;
 
112
}
 
113
 
 
114
int EqualFilter::verifyRecord(NDBT_ResultRow& row){
 
115
  NdbRecAttr* rec = row.attributeStore(1);
 
116
  if (rec->u_32_value() == compare_value)
 
117
    return NDBT_OK;
 
118
  return NDBT_FAILED;
 
119
}
 
120
 
 
121
int NoFilter::filterOp(NdbOperation* pOp){
 
122
  return NDBT_OK;
 
123
}
 
124
 
 
125
int NoFilter::verifyRecord(NDBT_ResultRow& row){
 
126
  // Check if this record should be in the result set or not
 
127
  return NDBT_OK;
 
128
}
 
129
 
 
130
#endif