Use int64 instead of float64 for non decimal numbers

This commit is contained in:
Tobie Morgan Hitchcock 2016-10-14 07:55:53 +01:00
parent 6da2e371ca
commit f23d1e10d7
3 changed files with 11 additions and 9 deletions

View file

@ -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()}

View file

@ -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),
}}},
},
{

View file

@ -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)