Skip to content

Commit

Permalink
fix sql_mode column access for dbs created before it was added to dol…
Browse files Browse the repository at this point in the history
…t_schemas table (#6956)
  • Loading branch information
jennifersp authored Nov 7, 2023
1 parent c5710b4 commit 1d17128
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions go/cmd/dolt/commands/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (cmd DumpCmd) Description() string {
return "Export all tables in the working set into a file."
}

// CreateMarkdown creates a markdown file containing the help text for the command at the given path
// Docs returns the documentation for this command, or nil if it's undocumented
func (cmd DumpCmd) Docs() *cli.CommandDocumentation {
ap := cmd.ArgParser()
return cli.NewCommandDocumentation(dumpDocs, ap)
Expand Down Expand Up @@ -269,6 +269,7 @@ func dumpProcedures(sqlCtx *sql.Context, engine *engine.SqlEngine, root *doltdb.
}

stmtColIdx := sch.IndexOfColName(doltdb.ProceduresTableCreateStmtCol)
// Note: 'sql_mode' column of `dolt_procedures` table is not present in databases that were created before this column got added
sqlModeIdx := sch.IndexOfColName(doltdb.ProceduresTableSqlModeCol)

defer func(iter sql.RowIter, context *sql.Context) {
Expand All @@ -287,7 +288,7 @@ func dumpProcedures(sqlCtx *sql.Context, engine *engine.SqlEngine, root *doltdb.
}

sqlMode := ""
if len(row) >= sqlModeIdx {
if sqlModeIdx >= 0 {
if s, ok := row[sqlModeIdx].(string); ok {
sqlMode = s
}
Expand Down Expand Up @@ -340,6 +341,7 @@ func dumpTriggers(sqlCtx *sql.Context, engine *engine.SqlEngine, root *doltdb.Ro

typeColIdx := sch.IndexOfColName(doltdb.SchemasTablesTypeCol)
fragColIdx := sch.IndexOfColName(doltdb.SchemasTablesFragmentCol)
// Note: some columns of `dolt_schemas` table are not present in databases that were created before those columns got added
sqlModeIdx := sch.IndexOfColName(doltdb.SchemasTablesSqlModeCol)

defer func(iter sql.RowIter, context *sql.Context) {
Expand All @@ -362,8 +364,10 @@ func dumpTriggers(sqlCtx *sql.Context, engine *engine.SqlEngine, root *doltdb.Ro
}

sqlMode := ""
if s, ok := row[sqlModeIdx].(string); ok {
sqlMode = s
if sqlModeIdx >= 0 {
if s, ok := row[sqlModeIdx].(string); ok {
sqlMode = s
}
}

modeChanged, err := changeSqlMode(sqlCtx, writer, sqlMode)
Expand Down Expand Up @@ -404,6 +408,7 @@ func dumpViews(ctx *sql.Context, engine *engine.SqlEngine, root *doltdb.RootValu
typeColIdx := sch.IndexOfColName(doltdb.SchemasTablesTypeCol)
fragColIdx := sch.IndexOfColName(doltdb.SchemasTablesFragmentCol)
nameColIdx := sch.IndexOfColName(doltdb.SchemasTablesNameCol)
// Note: some columns of `dolt_schemas` table are not present in databases that were created before those columns got added
sqlModeIdx := sch.IndexOfColName(doltdb.SchemasTablesSqlModeCol)

defer func(iter sql.RowIter, context *sql.Context) {
Expand All @@ -426,8 +431,10 @@ func dumpViews(ctx *sql.Context, engine *engine.SqlEngine, root *doltdb.RootValu
}

sqlMode := ""
if s, ok := row[sqlModeIdx].(string); ok {
sqlMode = s
if sqlModeIdx >= 0 {
if s, ok := row[sqlModeIdx].(string); ok {
sqlMode = s
}
}

opts := sql.NewSqlModeFromString(sqlMode).ParserOptions()
Expand Down

0 comments on commit 1d17128

Please sign in to comment.