|
@ -4,7 +4,7 @@ import ( |
|
|
log "github.com/sirupsen/logrus" |
|
|
log "github.com/sirupsen/logrus" |
|
|
"database/sql" |
|
|
"database/sql" |
|
|
_ "github.com/go-sql-driver/mysql" |
|
|
_ "github.com/go-sql-driver/mysql" |
|
|
"github.com/denzs/wsjtx_dashboards/shared/wsjtx" |
|
|
"github.com/denzs/wsjtx-dashboards/shared/wsjtx" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func handleMysql(result wsjtx.Result) { |
|
|
func handleMysql(result wsjtx.Result) { |
|
@ -14,10 +14,10 @@ func handleMysql(result wsjtx.Result) { |
|
|
} |
|
|
} |
|
|
defer db.Close() |
|
|
defer db.Close() |
|
|
|
|
|
|
|
|
stmt, err := db.Prepare("INSERT INTO wsjtx_all_txt(ts, station, callsign, band, mode, report, dxcc, geohash, continent, cqzone, ituzone, rx) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)") |
|
|
stmt, err := db.Prepare("INSERT INTO wsjtx_all_txt(ts, station, callsign, band, mode, report, dxcc, geohash, continent, cqzone, ituzone, rx) VALUES(FROM_UNIXTIME(?),?,?,?,?,?,?,?,?,?,?,?)") |
|
|
defer stmt.Close() |
|
|
defer stmt.Close() |
|
|
|
|
|
|
|
|
_, err = stmt.Exec(result.Timestamp, station, result.Call, result.Band, result.Mode, result.Signal, result.Ent.Entity, result.GeoHash, result.Ent.Continent, result.Ent.CQZone, result.Ent.ITUZone, result.Rx) |
|
|
_, err = stmt.Exec(result.Timestamp.Unix(), station, result.Call, result.Band, result.Mode, result.Signal, result.Ent.Entity, result.GeoHash, result.Ent.Continent, result.Ent.CQZone, result.Ent.ITUZone, result.Rx) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.WithFields(log.Fields{"err":err.Error()}).Warn("error while executing prepared statement..") |
|
|
log.WithFields(log.Fields{"err":err.Error()}).Warn("error while executing prepared statement..") |
|
@ -70,7 +70,8 @@ func init_db() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func dbConn() (db *sql.DB, err bool){ |
|
|
func dbConn() (db *sql.DB, err bool){ |
|
|
db, er := sql.Open("mysql", mysql_user+":"+mysql_pass+"@tcp("+mysql_host+")/"+mysql_db) |
|
|
//db, er := sql.Open("mysql", mysql_user + ":" + mysql_pass + "@tcp(" + mysql_host + ")/" + mysql_db + "?parseTime=true&time_zone=%27UTC%27")
|
|
|
|
|
|
db, er := sql.Open("mysql", mysql_user + ":" + mysql_pass + "@tcp(" + mysql_host + ")/" + mysql_db) |
|
|
if er != nil { |
|
|
if er != nil { |
|
|
log.Error("db not reachable: %s",err) |
|
|
log.Error("db not reachable: %s",err) |
|
|
return nil, true |
|
|
return nil, true |
|
|