Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

名称的相同的表和视图进行比对,触发panic #69

Open
stildevice opened this issue Jun 20, 2023 · 1 comment
Open

名称的相同的表和视图进行比对,触发panic #69

stildevice opened this issue Jun 20, 2023 · 1 comment

Comments

@stildevice
Copy link

源库为表,目标库为视图,视图show create的时候会有4列,err := rs.Scan(&vname, &schema)需要4个入参,触发panic。

1)对于视图和表不一致,直接给出DDL?
2)跳过本次比对,继续后续的比对?

@ljluestc
Copy link

// Define your query and handle the scanning of results
query := "SHOW CREATE TABLE " + targetTableName // Or use a dynamic query if needed
rows, err := db.Query(query)
if err != nil {
    log.Fatal("Query failed: ", err)
    return
}
defer rows.Close()

var vname, schema, ddl string
for rows.Next() {
    // Handle case where source is a table and target is a view
    err := rows.Scan(&vname, &schema, &ddl)
    if err != nil {
        log.Fatal("Scan failed: ", err)
        return
    }

    // Case 1: Source is a table and target is a view
    if isView(targetTableName) { // Function to check if target is a view
        fmt.Println("Target is a view, returning DDL: ", ddl)
        return // Or handle DDL output as required
    }

    // Case 2: Source and target don't match, just skip comparison
    fmt.Println("Skipping comparison for this pair")
    continue
}

// Check for any error after scanning all rows
if err := rows.Err(); err != nil {
    log.Fatal("Rows iteration failed: ", err)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants