| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package sqlparser |
| 18 |
|
| 19 |
import ( |
| 20 |
"bytes" |
| 21 |
"testing" |
| 22 |
|
| 23 |
"github.com/xwb1989/sqlparser/dependency/sqltypes" |
| 24 |
) |
| 25 |
|
| 26 |
func TestEncodable(t *testing.T) { |
| 27 |
tcases := []struct { |
| 28 |
in Encodable |
| 29 |
out string |
| 30 |
}{{ |
| 31 |
in: InsertValues{{ |
| 32 |
sqltypes.NewInt64(1), |
| 33 |
sqltypes.NewVarBinary("foo('a')"), |
| 34 |
}, { |
| 35 |
sqltypes.NewInt64(2), |
| 36 |
sqltypes.NewVarBinary("bar(`b`)"), |
| 37 |
}}, |
| 38 |
out: "(1, 'foo(\\'a\\')'), (2, 'bar(`b`)')", |
| 39 |
}, { |
| 40 |
|
| 41 |
in: &TupleEqualityList{ |
| 42 |
Columns: []ColIdent{NewColIdent("pk")}, |
| 43 |
Rows: [][]sqltypes.Value{ |
| 44 |
{sqltypes.NewInt64(1)}, |
| 45 |
{sqltypes.NewVarBinary("aa")}, |
| 46 |
}, |
| 47 |
}, |
| 48 |
out: "pk in (1, 'aa')", |
| 49 |
}, { |
| 50 |
|
| 51 |
in: &TupleEqualityList{ |
| 52 |
Columns: []ColIdent{NewColIdent("pk1"), NewColIdent("pk2")}, |
| 53 |
Rows: [][]sqltypes.Value{ |
| 54 |
{ |
| 55 |
sqltypes.NewInt64(1), |
| 56 |
sqltypes.NewVarBinary("aa"), |
| 57 |
}, |
| 58 |
{ |
| 59 |
sqltypes.NewInt64(2), |
| 60 |
sqltypes.NewVarBinary("bb"), |
| 61 |
}, |
| 62 |
}, |
| 63 |
}, |
| 64 |
out: "(pk1 = 1 and pk2 = 'aa') or (pk1 = 2 and pk2 = 'bb')", |
| 65 |
}} |
| 66 |
for _, tcase := range tcases { |
| 67 |
buf := new(bytes.Buffer) |
| 68 |
tcase.in.EncodeSQL(buf) |
| 69 |
if out := buf.String(); out != tcase.out { |
| 70 |
t.Errorf("EncodeSQL(%v): %s, want %s", tcase.in, out, tcase.out) |
| 71 |
} |
| 72 |
} |
| 73 |
} |