-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateQueryParser.c
More file actions
63 lines (52 loc) · 1.36 KB
/
updateQueryParser.c
File metadata and controls
63 lines (52 loc) · 1.36 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "consts.h"
#include "column_types.h"
#include "table.h"
#include "query_types.h"
#include "compiled_query.h"
#include "compiled_column.h"
extern int readHeadTable(FILE * headerFile, Table * table);
extern FILE * getHeaderFile(char * tableName, char * mode);
extern void removeFirstLastChar(char * temp);
extern void log(char * msg);
void getRequestFromUpdateQuery(char queryParts[10][50], Table * table, CompiledQuery * compiledQuery)
{
FILE * headerFile = getHeaderFile(queryParts[1], "rb");
if (headerFile == NULL)
{
log("Table not found");
return;
}
readHeadTable(headerFile, table);
compiledQuery->type = UPDATE;
compiledQuery->target = queryParts[1];
if (strcmp(queryParts[2], "set") != 0)
{
log("SET keyword not found");
return;
}
int i = 0;
char * token;
char * rest = queryParts[3];
int j = 0;
while((token = strtok_r(rest, ",=", &rest)))
{
char * temp = token;
if (temp[0] == 34 || temp[0] == 39)
{
removeFirstLastChar(temp);
}
if (j % 2 == 0)
{
compiledQuery->queryColumns[j/2]->name = temp;
}
else
{
compiledQuery->queryColumns[j/2]->value = temp;
}
j += 1;
}
printf("out");
}