fix: #2 statement.stype isn't cleared on reruns
This commit is contained in:
@@ -44,6 +44,8 @@ func Run() {
|
|||||||
fmt.Println("Executed.")
|
fmt.Println("Executed.")
|
||||||
case ExecuteTableFull:
|
case ExecuteTableFull:
|
||||||
fmt.Println("Error: Table is full")
|
fmt.Println("Error: Table is full")
|
||||||
|
case ExecuteFail:
|
||||||
|
//todo
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-6
@@ -29,6 +29,7 @@ type statementType int
|
|||||||
const (
|
const (
|
||||||
StatementSelect statementType = iota
|
StatementSelect statementType = iota
|
||||||
StatementInsert
|
StatementInsert
|
||||||
|
StatementUnrecognized
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -52,6 +53,7 @@ type ExecuteResult int
|
|||||||
const (
|
const (
|
||||||
ExecuteSuccess ExecuteResult = iota
|
ExecuteSuccess ExecuteResult = iota
|
||||||
ExecuteTableFull
|
ExecuteTableFull
|
||||||
|
ExecuteFail
|
||||||
)
|
)
|
||||||
|
|
||||||
type row struct {
|
type row struct {
|
||||||
@@ -71,7 +73,8 @@ type Table struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewStatement() *Statement {
|
func NewStatement() *Statement {
|
||||||
return &Statement{0, row{0, "", ""}}
|
statement := &Statement{}
|
||||||
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTable() *Table {
|
func NewTable() *Table {
|
||||||
@@ -149,12 +152,13 @@ func DoMetaCommands(inputBuffer *InputBuffer) MetaCommandResults {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (statement *Statement) PrepareStatements(inputBuffer *InputBuffer) PrepareResults {
|
func (statement *Statement) PrepareStatements(inputBuffer *InputBuffer) PrepareResults {
|
||||||
|
statement.stype = StatementUnrecognized
|
||||||
if strings.HasPrefix(inputBuffer.Buffer, "insert") {
|
if strings.HasPrefix(inputBuffer.Buffer, "insert") {
|
||||||
argsAssigned, err := fmt.Sscanf(inputBuffer.Buffer, "insert %d %s %s", &statement.row.id, &statement.row.username, &statement.row.email)
|
argsAssigned, err := fmt.Sscanf(inputBuffer.Buffer, "insert %d %s %s", &statement.row.id, &statement.row.username, &statement.row.email)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// fmt.Println("error parsing insert statement")
|
fmt.Println("error parsing insert statement")
|
||||||
// fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
// }
|
}
|
||||||
if err != nil || argsAssigned > 3 {
|
if err != nil || argsAssigned > 3 {
|
||||||
return PrepareSyntaxError
|
return PrepareSyntaxError
|
||||||
}
|
}
|
||||||
@@ -169,7 +173,7 @@ func (statement *Statement) PrepareStatements(inputBuffer *InputBuffer) PrepareR
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (statement *Statement) ExecuteStatement(table *Table) ExecuteResult {
|
func (statement *Statement) ExecuteStatement(table *Table) ExecuteResult {
|
||||||
var result ExecuteResult
|
var result ExecuteResult = ExecuteFail
|
||||||
switch statement.stype {
|
switch statement.stype {
|
||||||
case StatementInsert:
|
case StatementInsert:
|
||||||
result = statement.execInsert(table)
|
result = statement.execInsert(table)
|
||||||
|
|||||||
Reference in New Issue
Block a user