| 24 | } |
| 25 | |
| 26 | func GenerateRestoreSQL(ctx context.Context, rCtx base.RestoreContext, statement string, backupItem *storepb.PriorBackupDetail_Item) (string, error) { |
| 27 | originalSQL, err := extractStatement(statement, backupItem) |
| 28 | if err != nil { |
| 29 | return "", errors.Errorf("failed to extract single SQL: %v", err) |
| 30 | } |
| 31 | |
| 32 | // Parse the filtered SQL and find the first DML node. |
| 33 | matchingNode, err := findFirstDML(originalSQL) |
| 34 | if err != nil { |
| 35 | return "", err |
| 36 | } |
| 37 | if matchingNode == nil { |
| 38 | return "", errors.Errorf("no DML statement found in extracted SQL") |
| 39 | } |
| 40 | |
| 41 | sqlForComment, truncated := common.TruncateString(originalSQL, maxCommentLength) |
| 42 | if truncated { |
| 43 | sqlForComment += "..." |
| 44 | } |
| 45 | return doGenerate(ctx, rCtx, sqlForComment, matchingNode, backupItem) |
| 46 | } |
| 47 | |
| 48 | func findFirstDML(statement string) (ast.Node, error) { |
| 49 | stmtList, err := ParseMySQLOmni(statement) |