-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquary.cpp
More file actions
123 lines (105 loc) · 2.54 KB
/
quary.cpp
File metadata and controls
123 lines (105 loc) · 2.54 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include<iostream>
#include<string>
#include<stdlib.h>
#include "header.hpp"
using namespace std;
class Table{
private:
std::string table_name;
std::string key;
struct Header *header=NULL;
std::string user_input();
std::string word1(std::string str);
void user_input_create(std::string str);
void user_input_primary(std::string str);
public:
void user_command();
// constractor
Table(){
table_name = "mydatabase";
header = NULL;
}
};
string Table :: user_input(){
// status: working
// taking the command string form user
// store the string in str
string str;
char c;
do{
c = getchar();
str.push_back(c);
}while(c!='\n');
return str;
}
string Table :: word1(string str){
// status: working
// fetch 1st word from user input
// return the 1st word as string
string str1;
int i=0;
while(str[i]!=' '){
str1.push_back(str[i]);
i++;
}
return str1;
}
// user input for create table
void Table :: user_input_create(string str){
int count1=0,count2=0, a=0;
string table_name, str_array[3], st="";
for(int i=13; i<str.length()-1; i++){
if(count1<1){ // table name
table_name.push_back(str[i]);
if(str[i]==' '){
count1++;
i++;
}
}
else{
if(count2<1){
if(str[i]!=','){
st.push_back(str[i]);
if(str[i]=='(') count2++;
}
}
else{
if(str[i]==')'){
if(str[i+1]!=')') count2--;
}
str_array[a++] = st;
st = "";
}
}
}
for(int j=0; j<3; j++){
cout<<"Test: "<<str_array[j]<<endl;
}
cout<<"Table name: "<<table_name<<endl;
/*
header = createHeader(header, "Name");
header = createHeader(header, "Roll");
header = createHeader(header, "Mark");
show_data(header);*/
}
// this function will call by external methods
void Table :: user_command(){
string str=user_input();
if(word1(str)=="create"){
user_input_create(str);
}
if(word1(str)=="primary"){
//user_input_primary(str);
}
if(word1(str)=="insert"){
//user_input_insert();
}
if(word1(str)=="show"){
//user_input_show();
}
}
int main(){
Table t;
t.user_command();
return 0;
}