[go: up one dir, main page]

Menu

[r52]: / sql / sql.h  Maximize  Restore  History

Download this file

100 lines (79 with data), 2.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*****************************************************************************
Copyright © 2006, 2007, The Board of Trustees of the University of Illinois.
All Rights Reserved.
National Center for Data Mining (NCDM)
University of Illinois at Chicago
http://www.ncdm.uic.edu/
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 51
Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
written by
Yunhong Gu [gu@lac.uic.edu], last updated 02/23/2007
*****************************************************************************/
#ifndef __SQL_H__
#define __SQL_H__
#include <data.h>
#include <string>
#include <list>
using namespace std;
// simple SQL semnatics
// SELECT * FROM table;
// SELECT field1, field2, ... FROM table;
// SELECT * FROM table WHERE condition;
// SELECT * FROM table1, table2, ... WHERE condition;
namespace cb
{
enum SQL_TokenType {UNKNOWN, KEYWORD, CONSTANT, ARITH_OP, BOOL_OP, MARK};
enum SQL_KeyWord {SELECT, FROM, WHERE};
enum SQL_ARITH_OP {ADD, SUB, MUL, DIV, NEG};
enum SQL_BOOL_OP {AND, OR, NOT, EQ, LT, LE, GT, GE, NE};
enum SQL_MARK {COMMA, SEMICOLON, LEFT, RIGHT};
struct SQLToken
{
SQL_TokenType m_Type;
union
{
SQL_KeyWord m_KeyWord;
SQL_ARITH_OP m_Arith_OP;
SQL_BOOL_OP m_Bool_OP;
DataType m_DataType;
SQL_MARK m_Mark;
};
string m_strToken;
};
struct SQLExpr
{
vector<string> m_vstrFieldList;
vector<string> m_vstrTableList;
vector<SQLToken> m_Condition;
};
struct EvalTree
{
SQLToken m_Token;
EvalTree* m_Left;
EvalTree* m_Right;
};
class SQLParser
{
public:
static int parse(const string& expr, SQLExpr& sql);
static EvalTree* buildTree(vector<SQLToken>& expr, const int& start, const int& end);
static void releaseTree(EvalTree* tree) {}
private:
static int getToken(char** expr, SQLToken& token);
static int validateCond(vector<SQLToken>& cond);
static int buildArithTree(list<EvalTree*>& expr);
static int buildBoolTree(list<EvalTree*>& expr);
};
}; // namespace
#endif