Home > OS >  error in Go MySQL: func (*Rows) Scan returns panic: (func() string)
error in Go MySQL: func (*Rows) Scan returns panic: (func() string)

Time:12-22

I am trying to scan the rows returned by a Query, but I get this error

panic: (func() string) 0xc0000ac108

goroutine 1 [running]:
main.main()
        C:/Users/User/OneDrive/Dokumente/AIR/go/access/showAccess.go:35  0x445
exit status 2

, which I do not understand. All the variables are of correct type, Scan should convert the types directly. Here is the code:

    var (
        id int
        operation string 
        time string
        operator int
    )

    // query for all records in accesses table
    rows, err := DBClient.Query("SELECT * FROM accesses")

    if err != nil {
        panic(err.Error)
    }

    defer rows.Close()

    // printing each record formatted
    for rows.Next() {
        if err := rows.Scan(&id, &operation, &time, &operator); err != nil {
            panic(err.Error) // here the error comes
        }
        fmt.Printf("ID: =, operation:  s, time:  s, operator: %d\n", 
        id, operation, time, operator)
    }

appreciate your time.

CodePudding user response:

I imagine your columns are coming back in an order that is different from what you put in your Scan call. Try removing the '*', and putting the actual column names, or reordering your arguments to the Scan call.

CodePudding user response:

I forgot putting braces after the Error, like Yinon Eliraz mentioned. Writing panic(err.Error()) solved the problem

  • Related