Skip to content

Commit 041cca5

Browse files
committed
Passing context through
1 parent f466802 commit 041cca5

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

server/handler_test.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
)
3939

4040
func TestHandlerOutput(t *testing.T) {
41-
4241
e := setupMemDB(require.New(t))
4342
dummyConn := newConn(1)
4443
handler := &Handler{
@@ -655,7 +654,26 @@ func TestSchemaToFields(t *testing.T) {
655654

656655
require.Equal(len(schema), len(expected))
657656

658-
fields := schemaToFields(schema)
657+
handler := &Handler{
658+
e: setupMemDB(require),
659+
sm: NewSessionManager(
660+
testSessionBuilder,
661+
sql.NoopTracer,
662+
func(ctx *sql.Context, db string) bool { return db == "test" },
663+
sql.NewMemoryManager(nil),
664+
sqle.NewProcessList(),
665+
"foo",
666+
),
667+
readTimeout: time.Second,
668+
}
669+
670+
conn := newConn(1)
671+
handler.NewConnection(conn)
672+
673+
ctx, err := handler.sm.NewContextWithQuery(conn, "SELECT 1")
674+
require.NoError(err)
675+
676+
fields := schemaToFields(ctx, schema)
659677
for i := 0; i < len(fields); i++ {
660678
t.Run(schema[i].Name, func(t *testing.T) {
661679
assert.Equal(t, expected[i], fields[i])

sql/analyzer/validate_create_table.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func resolveAlterColumn(ctx *sql.Context, a *Analyzer, n sql.Node, scope *Scope,
159159
if err != nil {
160160
return nil, transform.SameTree, err
161161
}
162-
sch, err = validatePrimaryKey(initialSch, sch, n.(*plan.AlterPK))
162+
sch, err = validatePrimaryKey(ctx, initialSch, sch, n.(*plan.AlterPK))
163163
if err != nil {
164164
return nil, transform.SameTree, err
165165
}
@@ -610,7 +610,7 @@ func validateIndexes(ctx *sql.Context, tableSpec *plan.TableSpec) error {
610610
if !ok {
611611
return sql.ErrUnknownIndexColumn.New(idxCol.Name, idx.IndexName)
612612
}
613-
err := validatePrefixLength(schCol, idxCol)
613+
err := validatePrefixLength(ctx, schCol, idxCol)
614614
if err != nil {
615615
return err
616616
}
@@ -683,7 +683,7 @@ func getTableIndexNames(ctx *sql.Context, a *Analyzer, table sql.Node) ([]string
683683
}
684684

685685
// validatePrimaryKey validates a primary key add or drop operation.
686-
func validatePrimaryKey(initialSch, sch sql.Schema, ai *plan.AlterPK) (sql.Schema, error) {
686+
func validatePrimaryKey(ctx *sql.Context, initialSch, sch sql.Schema, ai *plan.AlterPK) (sql.Schema, error) {
687687
tableName := getTableName(ai.Table)
688688
switch ai.Action {
689689
case plan.PrimaryKeyAction_Create:
@@ -698,7 +698,7 @@ func validatePrimaryKey(initialSch, sch sql.Schema, ai *plan.AlterPK) (sql.Schem
698698

699699
for _, idxCol := range ai.Columns {
700700
schCol := sch[sch.IndexOf(idxCol.Name, tableName)]
701-
err := validatePrefixLength(schCol, idxCol)
701+
err := validatePrefixLength(ctx, schCol, idxCol)
702702
if err != nil {
703703
return nil, err
704704
}

0 commit comments

Comments
 (0)