-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysqlite.c
50 lines (49 loc) · 1.59 KB
/
mysqlite.c
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
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
#include "header.h"
int main(int argc, char* argv[]) {
Table* table = new_table();
InputBuffer* input_buffer = new_input_buffer();
while (true)
{
print_prompt();
read_input(input_buffer);
if(input_buffer->buffer[0] == '.') {
switch (do_meta_command(input_buffer, table))
{
case META_COMMAND_SUCCESS:
continue;
case META_COMMAND_UNRECOGNIZED_COMMAND:
printf("unrecognized command '%s'\n", input_buffer->buffer);
continue;
}
}
Statement statement;
switch(prepare_statement(input_buffer, &statement)) {
case PREPARE_SUCCESS:
break;
case PREPARE_STRING_TOO_LONG:
printf("String is too long.\n");
continue;
case PREPARE_NEGATIVE_ID:
printf("ID must be positive.\n");
continue;
case PREPARE_SYNTAX_ERROR:
printf("Syntax error. Couldn't parse statement.\n");
continue;
case PREPARE_UNRECOGNIZED_STATEMENT:
printf("Unrecognized statement command '%s'\n", input_buffer->buffer);
continue;
}
switch (execute_statement(&statement, table)) {
case EXECUTE_SUCCESS:
printf("Executed!\n");
break;
case EXECUTE_TABLE_FULL:
printf("Error: Table already full!\n");
break;
}
}
}