in internal/database/sqlserver/sqlserver.go [372:408]
func (h sqlServerHandler) GenerateDeleteCommentSQL(ctx context.Context, db *database.DB, tableName string, columnName string) (string, error) {
if tableName == "" || columnName == "" {
return "", fmt.Errorf("table and column names cannot be empty")
}
existingComment, err := h.GetColumnComment(ctx, db, tableName, columnName)
if err != nil {
return "", err
}
startTag := "<gemini>"
endTag := "</gemini>"
startIndex := strings.Index(existingComment, startTag)
endIndex := strings.LastIndex(existingComment, endTag)
var finalComment string
if startIndex != -1 && endIndex != -1 && endIndex > startIndex {
// Gemini tags found, remove content within tags
prefix := existingComment[:startIndex]
suffix := existingComment[endIndex+len(endTag):]
finalComment = strings.TrimSpace(prefix + suffix) // Trim leading/trailing spaces after removing gemini part
} else {
// Gemini tags not found, or invalid tags, keep original comment
finalComment = existingComment
}
escapedComment := strings.ReplaceAll(finalComment, "'", "''")
// Generate SQL to update or add extended property (same as in GenerateCommentSQL, but with the modified comment)
sqlStmt := fmt.Sprintf(
"EXEC sp_updateextendedproperty N'MS_Description', N'%s', N'SCHEMA', N'dbo', N'TABLE', %s, N'COLUMN', %s;",
escapedComment, // Use the modified comment (Gemini part removed)
h.QuoteIdentifier(tableName),
h.QuoteIdentifier(columnName),
)
return sqlStmt, nil
}