Skip to content

Commit

Permalink
Better tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmu committed Jan 5, 2024
1 parent c88bdad commit b684aa1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions server/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,20 +428,20 @@ func extractBindVarTypes(queryPlan sql.Node) ([]int32, error) {

types := make([]int32, 0)
var err error
transform.InspectExpressions(inspectNode, func(expr sql.Expression) bool{
transform.InspectExpressions(inspectNode, func(expr sql.Expression) bool {
if bindVar, ok := expr.(*expression.BindVar); ok {
var id int32
id, err = messages.VitessTypeToObjectID(bindVar.Type().Type())
if err != nil {
// TODO
types = append(types, messages.OidInt4)
return false
} else {
types = append(types, id)
}
}
return true
})
return types, nil

return types, err
}

func convertBindParameters(types []int32, values []messages.BindParameterValue) (map[string]*querypb.BindVariable, error) {
Expand Down
14 changes: 7 additions & 7 deletions testing/go/prepared_statement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ var preparedStatementTests = []ScriptTest {
Name: "String update",
SetUpScript: []string{
"drop table if exists test",
"CREATE TABLE test (pk BIGINT PRIMARY KEY, s character varying);",
"CREATE TABLE test (pk BIGINT PRIMARY KEY, s character varying(20));",
},
Assertions: []ScriptTestAssertion{
{
Expand All @@ -215,16 +215,16 @@ var preparedStatementTests = []ScriptTest {
Name: "String delete",
SetUpScript: []string{
"drop table if exists test",
"CREATE TABLE test (pk BIGINT PRIMARY KEY, s character varying);",
"CREATE TABLE test (pk BIGINT PRIMARY KEY, s character varying(20));",
},
Assertions: []ScriptTestAssertion{
{
Query: "INSERT INTO test VALUES ($1, $2), ($3, $4);",
BindVars: []any{1, "hello", 3, "goodbye"},
},
{
Query: "DELETE FROM test WHERE pk = $1;",
BindVars: []any{1},
Query: "DELETE FROM test WHERE s = $1;",
BindVars: []any{"hello"},
},
{
Query: "SELECT * FROM test ORDER BY 1;",
Expand Down Expand Up @@ -288,8 +288,8 @@ var preparedStatementTests = []ScriptTest {
BindVars: []any{1, 1.1, 3, 3.3},
},
{
Query: "UPDATE test set f1 = $1 WHERE pk = $2;",
BindVars: []any{2.2, 1},
Query: "UPDATE test set f1 = $1 WHERE f1 = $2;",
BindVars: []any{2.2, 1.1},
},
{
Query: "SELECT * FROM test WHERE f1 = $1;",
Expand Down Expand Up @@ -372,7 +372,7 @@ func TestErrorHandling(t *testing.T) {
}

func TestPreparedStatement(t *testing.T) {
for _, script := range preparedStatementTests[4:5] {
for _, script := range preparedStatementTests[:] {
RunScriptPrepared(t, script)
}
}
Expand Down

0 comments on commit b684aa1

Please sign in to comment.