-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
100 lines (53 loc) · 1.65 KB
/
test.cpp
File metadata and controls
100 lines (53 loc) · 1.65 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
100
/*
* test.cpp
* sqlstl
*
* Created by Shakthi Prasad G S on 09/01/12.
* Copyright 2012 Shakthi. All rights reserved.
*
*/
#include "test.h"
#include "sqlstl.h"
#include <iostream>
#define SHOULD_PASS(x) assert((x) );
#define SHOULD_FAIL(x) assert(!(x) );
struct Player:tableTuple<int> {
int playerid()const
{
return primaryKey;
}
Player(int playerid,string name)
:tableTuple<int>(playerid),name(name)
{}
string name;
};
struct Score:tableTuple<int,tuple<int> > {
Score(int score,int playerid)
:tableTuple<int,tuple<int> >(score,make_tuple(playerid))
{}
};
bool nameequaltoshakthi(const Player & invalue)
{
return invalue.name == "shakthi";
}
int main()
{
table<Player> b;
SHOULD_PASS(b.insert(Player(1,"shakthi")));
SHOULD_PASS(b.insert(Player(4,"ganesh")));
SHOULD_PASS(b.insert(Player(6,"prasad")));
SHOULD_FAIL(b.insert(Player(6,"prasad")));//primary key constaint
table<Score,tuple<tableForiegn<Player>* > > s(make_tuple(&b));
SHOULD_PASS(s.insert(Score(100,1)));
SHOULD_FAIL(s.insert(Score(200,2)));//cause:foreign key constraint
SHOULD_PASS(s.insert(Score(200,6)));
SHOULD_PASS(b.deleteKey(6)); //cause:foreign key delete cascade
SHOULD_FAIL(s.insert(Score(300,6)));//cause: foreign key constraint
//creates view based on the player table; iterates rows with name==shakhti
tableview<table<Player>,bool (*)(const Player& )> view(b,nameequaltoshakthi);
typedef tableview<table<Player>,bool (*)(const Player &)>::iterator titer;
for (titer i= view.begin(); i!= view.end(); i++) {
std::cout << "Playerid:"<<i->second.playerid() <<" name:"<<i->second.name;
}
return 0;
}