Skip to content

Commit

Permalink
fix: (close #98) correctly parse negative number in queries
Browse files Browse the repository at this point in the history
  • Loading branch information
proullon committed Jan 2, 2024
1 parent 328fe36 commit cad5547
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,8 @@ func TestFloat(t *testing.T) {
`INSERT INTO user (name, surname, age) VALUES (Homer, Simpson, 40);`,
`INSERT INTO user (name, surname, age) VALUES (Marge, Simpson, 40);`,
`INSERT INTO user (name, surname, age) VALUES (Bruce, Wayne, 3333);`,
`INSERT INTO user (name, surname, age) VALUES (Bruce, Future, -3333);`,
`INSERT INTO user (name, surname, age) VALUES (Bruce, Demo, -1.0);`,
}

db, err := sql.Open("ramsql", "TestFloat")
Expand Down Expand Up @@ -1295,6 +1297,14 @@ func TestFloat(t *testing.T) {
if err != nil {
t.Fatalf("Cannot run UPDATE query with AND: %s\n", err)
}

db.QueryRow(`SELECT age FROM user WHERE surname = 'Demo'`).Scan(&age)
if err != nil {
t.Fatalf("Cannot load negative age: %s", err)
}
if age != -1.0 {
t.Fatalf("Expected age to be -1.0, got %f", age)
}
}

func TestDrop(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion engine/parser/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (l *lexer) MatchStringToken() bool {
func (l *lexer) MatchFloatToken() bool {

i := l.pos
for i < l.instructionLen && (unicode.IsDigit(rune(l.instruction[i]))) {
for i < l.instructionLen && (unicode.IsDigit(rune(l.instruction[i])) || l.instruction[i] == '-') {
i++
}
if i == l.pos || i >= l.instructionLen {
Expand Down

0 comments on commit cad5547

Please sign in to comment.