-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
65 lines (56 loc) · 1.34 KB
/
main.go
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
package main
import (
"fmt"
"os"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Must supply a database filename.")
os.Exit(1)
}
filename := os.Args[1]
table := db_open(filename)
input_buffer := new_input_buffer()
for {
print_prompt()
read_input(input_buffer)
if len(input_buffer.buffer) == 0 {
continue
}
if string(input_buffer.buffer[0]) == "." {
switch do_meta_command(input_buffer, table) {
case META_COMMAND_SUCCESS:
fmt.Println("success")
continue
case META_COMMAND_UNRECOGNIZED_COMMAND:
fmt.Printf("unrecognized command")
continue
}
}
statement := NewStatement()
switch prepare_statement(input_buffer, statement) {
case PREPARE_STRING_TOO_LONG:
fmt.Println("String is too long")
continue
case PREPARE_NEGATIVE_ID:
fmt.Println("ID must be positive")
continue
case PREPARE_SYNTAX_ERROR:
fmt.Println("syntax error. could not parse statement")
continue
case PREPARE_UNRECOGNIZED_STATEMENT:
s := fmt.Sprintf("unrecognized at start of %#v", input_buffer.buffer)
fmt.Println(s)
continue
}
switch execute_statement(statement, table) {
case EXECUTE_SUCCESS:
fmt.Println("Executed")
case EXECUTE_DUPLICATE_KEY:
fmt.Println("Error: Duplicate Key")
case EXECUTE_TABLE_FULL:
fmt.Println("Error: Table Full")
}
fmt.Println("execution finished")
}
}