Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/analyzer/assign_insert_casts.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func AssignInsertCasts(ctx *sql.Context, a *analyzer.Analyzer, node sql.Node, sc
}
fromColType, ok := colExprType.(*pgtypes.DoltgresType)
if !ok {
return nil, transform.NewTree, errors.Errorf("INSERT: non-Doltgres type found in values source: %s", fromColType.String())
return nil, transform.NewTree, errors.Errorf("INSERT: non-Doltgres type found in values source: %s", colExprType.String())
}
toColType := destinationTypes[columnIndex]
// We only assign the existing expression if the types perfectly match (same parameters), otherwise we'll cast
Expand Down
18 changes: 18 additions & 0 deletions server/analyzer/type_sanitizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ func sanitizeExprType(ctx *sql.Context, n sql.Node, expr sql.Expression) (sql.Ex
}
}
return expr, transform.SameTree, nil
case *expression.BindVar:
// Parameters take the type of their destination column, which is a GMS type for Dolt system tables. Bound values
// arrive as Doltgres values, since their OIDs come from the same type conversion, so only the type is replaced.
if expr.Typ == nil {
return expr, transform.SameTree, nil
}

if _, ok := expr.Typ.(*pgtypes.DoltgresType); ok {
return expr, transform.SameTree, nil
}

if _, ok := expr.Typ.(sql.DeferredType); ok {
return expr, transform.SameTree, nil
}

newBindVar := *expr
newBindVar.Typ = pgtypes.FromGmsType(expr.Typ)
return &newBindVar, transform.NewTree, nil
case *expression.Literal:
// We want to leave limit literals alone, as they are expected to be GMS types when they appear in certain
// parts of the query (subqueries in particular)
Expand Down
28 changes: 28 additions & 0 deletions testing/go/prepared_statement_test.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,34 @@ func TestPreparedPgCatalog(t *testing.T) {
}

var preparedStatementTests = []ScriptTest{
{
Name: "Insert into and update Dolt system tables with bare parameters",
Assertions: []ScriptTestAssertion{
{
Query: "INSERT INTO dolt_nonlocal_tables (table_name, target_ref, ref_table, options) VALUES ($1, $2, $3, $4)",
BindVars: []any{"cache_%", "main", "", "immediate"},
Expected: []sql.Row{},
},
{
Query: "SELECT table_name, target_ref, options FROM dolt_nonlocal_tables",
Expected: []sql.Row{{"cache_%", "main", "immediate"}},
},
{
Query: "INSERT INTO dolt_query_catalog (id, display_order, name, query, description) VALUES ($1, $2, $3, $4, $5)",
BindVars: []any{"q1", int64(3), "first", "SELECT 1", "a query"},
Expected: []sql.Row{},
},
{
Query: "UPDATE dolt_query_catalog SET display_order = $1 WHERE id = $2",
BindVars: []any{int64(7), "q1"},
Expected: []sql.Row{},
},
{
Query: "SELECT id, display_order, name FROM dolt_query_catalog",
Expected: []sql.Row{{"q1", 7, "first"}},
},
},
},
{
Name: "Expressions without tables",
Assertions: []ScriptTestAssertion{
Expand Down
Loading