diff --git a/sql/ast.go b/sql/ast.go index dfcf4cef..2c3b9329 100644 --- a/sql/ast.go +++ b/sql/ast.go @@ -390,7 +390,9 @@ func (this Thing) String() string { func NewThing(TB string, ID interface{}) *Thing { if str, ok := ID.(string); ok { - if cnv, err := strconv.ParseFloat(str, 64); err == nil { + if cnv, err := strconv.ParseInt(str, 10, 64); err == nil { + return &Thing{TB: TB, ID: cnv} + } else if cnv, err := strconv.ParseFloat(str, 64); err == nil { return &Thing{TB: TB, ID: cnv} } else if cnv, err := time.Parse(RFCDate, str); err == nil { return &Thing{TB: TB, ID: cnv.UTC()} diff --git a/sql/sql_test.go b/sql/sql_test.go index e512f7b9..d5a3ce3e 100644 --- a/sql/sql_test.go +++ b/sql/sql_test.go @@ -390,21 +390,21 @@ func Test_Parse_Queries_Select(t *testing.T) { sql: `SELECT * FROM @person:123456`, res: &Query{Statements: []Statement{&SelectStatement{ Expr: []*Field{{Expr: &All{}, Alias: "*"}}, - What: []Expr{&Thing{TB: "person", ID: float64(123456)}}, + What: []Expr{&Thing{TB: "person", ID: int64(123456)}}, }}}, }, { sql: `SELECT * FROM @person:⟨123456⟩`, res: &Query{Statements: []Statement{&SelectStatement{ Expr: []*Field{{Expr: &All{}, Alias: "*"}}, - What: []Expr{&Thing{TB: "person", ID: float64(123456)}}, + What: []Expr{&Thing{TB: "person", ID: int64(123456)}}, }}}, }, { sql: `SELECT * FROM @person:{123456}`, res: &Query{Statements: []Statement{&SelectStatement{ Expr: []*Field{{Expr: &All{}, Alias: "*"}}, - What: []Expr{&Thing{TB: "person", ID: float64(123456)}}, + What: []Expr{&Thing{TB: "person", ID: int64(123456)}}, }}}, }, { @@ -628,7 +628,7 @@ func Test_Parse_Queries_Select(t *testing.T) { res: &Query{Statements: []Statement{&SelectStatement{ Expr: []*Field{{Expr: &All{}, Alias: "*"}}, What: []Expr{&Table{"person"}}, - Cond: []Expr{&BinaryExpression{LHS: &Ident{"id"}, Op: EQ, RHS: float64(1)}}, + Cond: []Expr{&BinaryExpression{LHS: &Ident{"id"}, Op: EQ, RHS: int64(1)}}, }}}, }, { @@ -739,8 +739,8 @@ func Test_Parse_Queries_Select(t *testing.T) { Cond: []Expr{ &BinaryExpression{LHS: &Ident{"id"}, Op: NEQ, RHS: &Null{}}, &BinaryExpression{LHS: &Ident{"id"}, Op: GT, RHS: float64(13.9)}, - &BinaryExpression{LHS: &Ident{"id"}, Op: LT, RHS: float64(31)}, - &BinaryExpression{LHS: &Ident{"id"}, Op: GTE, RHS: float64(15)}, + &BinaryExpression{LHS: &Ident{"id"}, Op: LT, RHS: int64(31)}, + &BinaryExpression{LHS: &Ident{"id"}, Op: GTE, RHS: int64(15)}, &BinaryExpression{LHS: &Ident{"id"}, Op: LTE, RHS: float64(29.9)}, }, }}}, @@ -1519,7 +1519,7 @@ func Test_Parse_Queries_Define(t *testing.T) { Name: "temp", What: []string{"person"}, Type: "any", - Default: float64(100), + Default: int64(100), }}}, }, { diff --git a/sql/util.go b/sql/util.go index 46ec5109..63c7901b 100644 --- a/sql/util.go +++ b/sql/util.go @@ -121,7 +121,7 @@ func (p *parser) declare(tok Token, lit string) (interface{}, error) { return regexp.Compile(lit) case NUMBER: - return strconv.ParseFloat(lit, 64) + return strconv.ParseInt(lit, 10, 64) case DOUBLE: return strconv.ParseFloat(lit, 64)