You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need the interface type variables to hold the query results to make library functions.
Suppose that a database table name "test" has the fields: id(int =1), name(varchar), f2(double). Run the following program:
var id, name, f2 interface{} // I need the interface type to make library functions
rows, err := db.Query("SELECT id, name, f2 FROM test where id=?", 1)
if err != nil {
fmt.Println(err)
}
for rows.Next() {
if err = rows.Scan(&id, &name, &f2); err != nil {
fmt.Println(err)
}
fmt.Printf("%t %t %t\n", id, name, f2)
}
if err = rows.Err(); err != nil {
fmt.Println(err)
}
The program show the type of id is int64, name is []byte, f2 is float64. This is fine. But if I change the query to:
rows, err := db.Query("SELECT id, name, f2 FROM test where id=1")
All the types become []byte (I think this is not good).
Is this a bug of the driver?
I think it may be better that the result types can be as the former(with placeholder) case.
Thank you very much.
The text was updated successfully, but these errors were encountered:
That is expected.
When the text protocol is used (no query arguments, no prepared statement) the driver receives data in string format and returns them as byte slices. The driver tries to keep conversions down to a minimum and just returns what it receives. This is part of the protocol and sent by the server, not a driver specific behaviour.
Hello,
I need the interface type variables to hold the query results to make library functions.
Suppose that a database table name "test" has the fields: id(int =1), name(varchar), f2(double). Run the following program:
The program show the type of id is int64, name is []byte, f2 is float64. This is fine. But if I change the query to:
rows, err := db.Query("SELECT id, name, f2 FROM test where id=1")
All the types become []byte (I think this is not good).
Is this a bug of the driver?
I think it may be better that the result types can be as the former(with placeholder) case.
Thank you very much.
The text was updated successfully, but these errors were encountered: