-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Description
Setup:
CREATE TABLE bit_columns (
bit1_col BIT(1),
bit8_col BIT(8),
bit16_col BIT(16),
bit64_col BIT(64)
);Example:
package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/go-sql-driver/mysql"
)
func main() {
db, err := sql.Open("mysql", "user:pass@tcp(127.0.0.1:3306)/dbname")
if err != nil {
log.Fatal(err)
}
defer db.Close()
rows, err := db.Query("SELECT * FROM bit_columns LIMIT 1")
if err != nil {
log.Fatal(err)
}
defer rows.Close()
colTypes, err := rows.ColumnTypes()
if err != nil {
log.Fatal(err)
}
for _, colType := range colTypes {
fmt.Println(colType.Name())
fmt.Println(colType.DecimalSize())
fmt.Println(colType.DatabaseTypeName())
fmt.Println(colType.Length())
}
}Output:
bit1_col
0 0 false
BIT
0 false // <- why 0?
bit8_col
0 0 false
BIT
0 false // <- why 0?
bit16_col
0 0 false
BIT
0 false // <- why 0?
bit64_col
0 0 false
BIT
0 false // <- why 0?
I would expect that the Length() method would return the mysql specified bit size, or at least have some way to get that piece of information from *sql.ColumnType.
I'm using github.com/go-sql-driver/mysql v1.8.1.
Metadata
Metadata
Assignees
Labels
No labels