error signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x11fd947
package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/go-sql-driver/mysql"
"github.com/tealeg/xlsx"
)
var (
dbHostsIp = ""
dbUserName = ""
dbPassword = ""
dbName = ""
)
func main() {
db, err := sql.Open("mysql", "root:univer@tcp(10.10.0.49:3306)/audit_test?charset=utf8")
if err != nil {
fmt.Println(err)
return
}
defer db.Close()
fmt.Println("")
var fileX *xlsx.File
var sheetX *xlsx.Sheet
var rowX *xlsx.Row
var cellX *xlsx.Cell
/*
v1, v2, _ := function(...)
*/
fileX, _ = xlsx.OpenFile("MyXLSXFile.xlsx")
sheetX = fileX.Sheet["Sheet1"]
rows, err := db.Query("select * from media;")
if err != nil {
log.Fatal(err)
}
defer rows.Close()
columns, err := rows.Columns()
if err != nil {
log.Fatal(err)
}
values := make([]sql.RawBytes, len(columns))
scanArgs := make([]interface{}, len(values))
for i := range values {
scanArgs[i] = &values[i]
}
for rows.Next() {
rowX = sheetX.AddRow()
err = rows.Scan(scanArgs...)
if err != nil {
log.Fatal(err)
}
var value string
for i, col := range values {
if col == nil {
value = "NULL"
} else {
value = string(col)
}
fmt.Println(columns[i], ": ", value)
cellX = rowX.AddCell()
cellX.Value = value
fileX.Save("MyXLSXFile1.xlsx")
}
fmt.Println("------------------")
}
if err = rows.Err(); err != nil {
log.Fatal(err)
}
}