Commit 9d9d88bc authored by cznic's avatar cznic

add test for int8 handling via sql/driver

parent 97d7bb66
......@@ -36,7 +36,7 @@ cpu: clean
go tool pprof -lines *.test cpu.out
edit:
@ 1>/dev/null 2>/dev/null gvim -p Makefile *.l *.y *.go testdata.ql testdata.log
@ 1>/dev/null 2>/dev/null gvim -p Makefile *.l *.y *.go testdata.ql testdata.log &
edit2:
touch log
......
......@@ -4289,3 +4289,46 @@ func TestIssue195(t *testing.T) {
t.Fatal(err, " index :", index)
}
}
func Test20191218(t *testing.T) {
RegisterDriver2()
db, err := sql.Open("ql2", "memory://x")
if err != nil {
t.Fatal(err)
}
if err = tx(db, "CREATE TABLE t (f int8);"); err != nil {
t.Fatal(err)
}
if err = tx(db, "INSERT INTO t VALUES($1);", 314); err == nil {
t.Fatal("missing type checking error")
}
if err = tx(db, "INSERT INTO t VALUES(int8($1));", 42); err != nil {
t.Fatal(err)
}
var v int8
if err := db.QueryRow("SELECT * FROM t ORDER BY f;").Scan(&v); err != nil {
t.Fatal(err)
}
if g, e := v, int8(42); g != e {
t.Fatalf("got %v, expected %v", g, e)
}
}
func tx(db *sql.DB, sql string, args ...interface{}) error {
tx, err := db.Begin()
if err != nil {
return err
}
if _, err = tx.Exec(sql, args...); err != nil {
tx.Rollback()
return err
}
return tx.Commit()
}
......@@ -8,7 +8,7 @@
//
// DO NOT EDIT!
package ql // import "modernc.org/ql"
package ql
import (
"math"
......@@ -93,13 +93,13 @@ func coerce1(inVal, otherVal interface{}) (coercedInVal interface{}) {
//case idealUint:
//case bool:
case complex64:
return complex(float32(x), 0)
return complex64(complex(float32(x), 0))
case complex128:
return complex(float64(x), 0)
return complex128(complex(float64(x), 0))
case float32:
return float32(float64(x))
case float64:
return float64(x)
return float64(float64(x))
//case int8:
//case int16:
//case int32:
......@@ -130,9 +130,9 @@ func coerce1(inVal, otherVal interface{}) (coercedInVal interface{}) {
}
//case bool:
case complex64:
return complex(float32(x), 0)
return complex64(complex(float32(x), 0))
case complex128:
return complex(float64(x), 0)
return complex128(complex(float64(x), 0))
case float32:
return float32(int64(x))
case float64:
......@@ -190,9 +190,9 @@ func coerce1(inVal, otherVal interface{}) (coercedInVal interface{}) {
return idealUint(int64(x))
//case bool:
case complex64:
return complex(float32(x), 0)
return complex64(complex(float32(x), 0))
case complex128:
return complex(float64(x), 0)
return complex128(complex(float64(x), 0))
case float32:
return float32(int64(x))
case float64:
......@@ -237,9 +237,9 @@ func coerce1(inVal, otherVal interface{}) (coercedInVal interface{}) {
return idealUint(uint64(x))
//case bool:
case complex64:
return complex(float32(x), 0)
return complex64(complex(float32(x), 0))
case complex128:
return complex(float64(x), 0)
return complex128(complex(float64(x), 0))
case float32:
return float32(uint64(x))
case float64:
......
......@@ -297,7 +297,7 @@
// _tmp42
// Sales
//
// A quoted identifier is a string of any charaters beween guillmets «».
// A quoted identifier is a string of any charaters between guillmets «».
// Quoted identifiers allow QL key words or phrases with spaces to be used
// as identifiers. The guillemets were chosen because QL already uses
// double quotes, single quotes, and backticks for other quoting purposes.
......
......@@ -11,7 +11,7 @@
//
// [1]: http://modernc.org/ebnf2y
package ql // import "modernc.org/ql"
package ql
import __yyfmt__ "fmt"
......
......@@ -47,8 +47,6 @@ yystate0:
goto yystart324
}
goto yystate0 // silence unused label error
goto yyAction // silence unused label error
yyAction:
switch yyrule {
case 1:
......@@ -254,7 +252,6 @@ yyAction:
case 101:
goto yyrule101
}
goto yystate1 // silence unused label error
yystate1:
c = l.Next()
yystart1:
......@@ -4252,7 +4249,6 @@ yystate317:
l.Mark()
goto yyrule15
goto yystate318 // silence unused label error
yystate318:
c = l.Next()
yystart318:
......@@ -4331,7 +4327,6 @@ yystate323:
goto yystate319
}
goto yystate324 // silence unused label error
yystate324:
c = l.Next()
yystart324:
......@@ -4809,7 +4804,7 @@ yyrule100: // {ident}
return identifier
}
yyrule101: // ($|\?)({D}|{ident})
{
if true { // avoid go vet determining the below panic will not be reached
s := string(l.TokenBytes(nil)[1:])
lval.item, _ = strconv.Atoi(s)
if s != "" && s[0] < '1' || s[0] > '9' {
......@@ -4819,9 +4814,28 @@ yyrule101: // ($|\?)({D}|{ident})
}
panic("unreachable")
goto yyabort // silence unused label error
yyabort: // no lexem recognized
//
// silence unused label errors for build and satisfy go vet reachability analysis
//
{
if false {
goto yyabort
}
if false {
goto yystate0
}
if false {
goto yystate1
}
if false {
goto yystate318
}
if false {
goto yystate324
}
}
if c, ok := l.Abort(); ok {
return c
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment