Compare commits
5
Commits
e666b26d3d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ea0978d5f | ||
|
|
8e2324b80c | ||
|
|
deb125db4b | ||
|
|
28acfd8d7e | ||
|
|
23fd1d5a1e |
@@ -44,6 +44,8 @@ func Run() {
|
||||
fmt.Println("Executed.")
|
||||
case ExecuteTableFull:
|
||||
fmt.Println("Error: Table is full")
|
||||
case ExecuteFail:
|
||||
//todo
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-6
@@ -29,6 +29,7 @@ type statementType int
|
||||
const (
|
||||
StatementSelect statementType = iota
|
||||
StatementInsert
|
||||
StatementUnrecognized
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -52,6 +53,7 @@ type ExecuteResult int
|
||||
const (
|
||||
ExecuteSuccess ExecuteResult = iota
|
||||
ExecuteTableFull
|
||||
ExecuteFail
|
||||
)
|
||||
|
||||
type row struct {
|
||||
@@ -71,7 +73,8 @@ type Table struct {
|
||||
}
|
||||
|
||||
func NewStatement() *Statement {
|
||||
return &Statement{0, row{0, "", ""}}
|
||||
statement := &Statement{}
|
||||
return statement
|
||||
}
|
||||
|
||||
func NewTable() *Table {
|
||||
@@ -149,12 +152,13 @@ func DoMetaCommands(inputBuffer *InputBuffer) MetaCommandResults {
|
||||
}
|
||||
|
||||
func (statement *Statement) PrepareStatements(inputBuffer *InputBuffer) PrepareResults {
|
||||
statement.stype = StatementUnrecognized
|
||||
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)
|
||||
// if err != nil {
|
||||
// fmt.Println("error parsing insert statement")
|
||||
// fmt.Println(err.Error())
|
||||
// }
|
||||
if err != nil {
|
||||
fmt.Println("error parsing insert statement")
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
if err != nil || argsAssigned > 3 {
|
||||
return PrepareSyntaxError
|
||||
}
|
||||
@@ -169,7 +173,7 @@ func (statement *Statement) PrepareStatements(inputBuffer *InputBuffer) PrepareR
|
||||
}
|
||||
|
||||
func (statement *Statement) ExecuteStatement(table *Table) ExecuteResult {
|
||||
var result ExecuteResult
|
||||
var result ExecuteResult = ExecuteFail
|
||||
switch statement.stype {
|
||||
case StatementInsert:
|
||||
result = statement.execInsert(table)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 TakshakRamteke
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
||||
following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial
|
||||
portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
||||
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
||||
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Reference in New Issue
Block a user