-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsqlparser-main.c
More file actions
49 lines (43 loc) · 1.35 KB
/
sqlparser-main.c
File metadata and controls
49 lines (43 loc) · 1.35 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
/**
* @brief This is the REPL program of tinydb, which is based on a sql parser.
*/
#include "sql-parser/sqlparser.h"
#include "common.h"
int main(int argc, char *argv[])
{
buffer_t *input = new_buffer_input();
if (argc < 2)
{
printf("You must supply a database filename.\n");
exit(EXIT_FAILURE);
}
char *filename = argv[1];
table_t *table = db_open(filename);
statement_t *stm = (statement_t *)malloc(sizeof(statement_t));
execute_result_t result;
while (1)
{
print_prompt();
read_input(input);
/* If `input` is a meta command, then it will start with '.' */
if (input->buffer[0] == '.')
{
switch (do_meta_command(input, table))
{
case META_COMMAND_SUCCESS:
continue;
case META_COMMAND_UNRECOGNIZED_COMMAND:
printf("Unrecognized meta command '%s'\n", input->buffer);
continue;
}
}
/* Parse the SQL, and put the result in statement_t `stm` */
statement_init(stm);
sql_parser(input->buffer, stm);
/* Execute the SQL statement, and log the result. */
result = vm_executor(stm, table);
vm_logger(result, stm, input);
/* Free the resources that are allocated in yyparser. */
statement_free(stm);
}
}