-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
61 lines (45 loc) · 1.95 KB
/
main.cpp
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
#include <QCoreApplication>
#include <QTextStream>
#include "state.h"
#include "lexer.h"
#include "item.h"
bool run(Lexer &lex, const QString &query)
{
QTextStream cout(stdout);
cout << query << endl;
bool success = lex.run(query);
cout << "Results: " << endl;
foreach (Item i, lex.items())
cout << i.value << ", start: " << i.start << ", end: " << i.end << ", typecode: " << i.type << endl;
cout << endl;
return success;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QTextStream cout(stdout);
//QString query("SELECT * FROM table;");
//QString query("INSERT INTO mytable VALUES (1, 2, 3)");
// QString query("SELECT c.[name], [address] FROM customer c ;");
//QString query("select number, count(*) from (select NumberOne as number from Results union all select NumberTwo as number from Results union select NumberThree as number from Results ) AllNumbers group by number order by number;");
//QString query("SELECT DISTINCT name FROM table;");
//QString query("SELECT Name, ProductNumber, ListPrice AS Price FROM Production.Product WHERE ProductLine = "hello" ORDER BY Name ASC;");
//
//QString query("SELECT 10 - 1 AS Price");
//QString query("SELECT 10 - 1 AS Price -- this is a query");
//QString query("SELECT 10 - 1 AS Price /* this is a query */");
Lexer lex;
QString query("SELECT c.[name], \"address\" FROM customer c ;");
bool success = run(lex, query);
if (!success)
cout << lex.error().toString() << endl;
query = "SELECT 10 - 1 AS Price /* this is a query */ FROM Product";
success = run(lex, query);
if (!success)
cout << lex.error().toString() << endl;
query = "SELECT Name, ProductNumber, ListPrice AS Price FROM Production.Product WHERE ProductLine = \"hello ORDER BY Name ASC;";
success = run(lex, query);
if (!success)
cout << lex.error().toString() << endl;
return a.exec();
}