Compare commits

...
3 Commits
Author SHA1 Message Date
TakshakRamteke 8e2324b80c fix: added test command to readme 2026-07-25 23:57:31 +05:30
TakshakRamteke deb125db4b fix: #2 statement.stype isn't cleared on reruns 2026-07-25 23:55:24 +05:30
TakshakRamteke 23fd1d5a1e feat: added licence 2026-07-25 13:28:00 +05:30
4 changed files with 37 additions and 6 deletions
+2
View File
@@ -44,6 +44,8 @@ func Run() {
fmt.Println("Executed.")
case ExecuteTableFull:
fmt.Println("Error: Table is full")
case ExecuteFail:
//todo
}
}
+10 -6
View File
@@ -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)
+19
View File
@@ -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.
+6
View File
@@ -21,3 +21,9 @@ Start
Cleanup
```make clean```
Test
```make test```