@ -18,9 +18,7 @@ func getLast(station string, identifier string) (LastTs, error) {
}
}
defer db . Close ( )
defer db . Close ( )
log . Info ( "starting query..." )
err := db . QueryRow ( "SELECT UNIX_TIMESTAMP(ts) FROM wsjtx_all_txt WHERE station = ? AND identifier = ? ORDER BY ts DESC LIMIT 1" , station , identifier ) . Scan ( & result . Last )
err := db . QueryRow ( "SELECT UNIX_TIMESTAMP(ts) FROM wsjtx_all_txt WHERE station = ? AND identifier = ? ORDER BY ts DESC LIMIT 1" , station , identifier ) . Scan ( & result . Last )
log . Info ( "finished query..." )
if err != nil {
if err != nil {
// FIXME
// FIXME
if err . Error ( ) == "sql: no rows in result set" {
if err . Error ( ) == "sql: no rows in result set" {
@ -51,15 +49,12 @@ func handleMysql(result wsjtx.Result) {
if err != nil {
if err != nil {
log . WithFields ( log . Fields { "warning" : err . Error ( ) } ) . Warn ( "error while executing prepared statement.." )
log . WithFields ( log . Fields { "warning" : err . Error ( ) } ) . Warn ( "error while executing prepared statement.." )
} else {
log . Info ( "insert done! :)" )
}
}
}
}
func init_db ( ) {
func init_db ( ) {
var cnt int
var cnt int
log . Debug ( "init_db()" )
db , _ := dbConn ( )
db , _ := dbConn ( )
row := db . QueryRow ( "SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_NAME LIKE '%" + mysqlTable + "%';" )
row := db . QueryRow ( "SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_NAME LIKE '%" + mysqlTable + "%';" )
@ -74,21 +69,44 @@ func init_db() {
}
}
if cnt < 1 {
if cnt < 1 {
qry := "CREATE TABLE IF NOT EXISTS " + mysqlTable + " (" +
qry := "CREATE TABLE wsjtx_all_txt (" +
"ts timestamp NOT NULL," +
"ts datetime NOT NULL," +
"station VARCHAR(16) NOT NULL," +
"station varchar(16) NOT NULL," +
"callsign VARCHAR(16) NOT NULL," +
"callsign varchar(16) NOT NULL," +
"band VARCHAR(10) NOT NULL," +
"band varchar(10) NOT NULL," +
"continent VARCHAR(32) NOT NULL," +
"continent varchar(32) NOT NULL," +
"mode VARCHAR(16) NOT NULL," +
"mode varchar(16) NOT NULL," +
"dxcc VARCHAR(128) NOT NULL," +
"dxcc varchar(128) NOT NULL," +
"geohash VARCHAR(16) NOT NULL," +
"geohash varchar(16) NOT NULL," +
"report TINYINT NOT NULL," +
"report tinyint(4) NOT NULL," +
"cqzone INT NOT NULL," +
"cqzone int(11) NOT NULL," +
"ituzone INT NOT NULL," +
"ituzone int(11) NOT NULL," +
"rx TINYINT NOT NULL," +
"rx tinyint(4) NOT NULL," +
"PRIMARY KEY UC_" + mysqlTable + "(ts, station, callsign)," +
"identifier varchar(32) DEFAULT NULL," +
"INDEX idx_dxcc (dxcc));"
"PRIMARY KEY (ts,station,callsign)," +
"KEY idx_dxcc (dxcc)," +
"KEY idx_continent (continent)," +
"KEY idx_station (station)," +
"KEY idx_band (band)," +
"KEY idx_station_identifier (station,identifier)," +
"KEY idx_ts_station_band (ts,station,band)," +
"KEY idx_ts (ts));" ;
// qry := "CREATE TABLE IF NOT EXISTS " + mysqlTable + " (" +
// "ts timestamp NOT NULL," +
// "station VARCHAR(16) NOT NULL," +
// "callsign VARCHAR(16) NOT NULL," +
// "band VARCHAR(10) NOT NULL," +
// "continent VARCHAR(32) NOT NULL," +
// "mode VARCHAR(16) NOT NULL," +
// "dxcc VARCHAR(128) NOT NULL," +
// "geohash VARCHAR(16) NOT NULL," +
// "report TINYINT NOT NULL," +
// "cqzone INT NOT NULL," +
// "ituzone INT NOT NULL," +
// "rx TINYINT NOT NULL," +
// "PRIMARY KEY UC_" + mysqlTable + "(ts, station, callsign)," +
// "INDEX idx_dxcc (dxcc));"
log . WithFields ( log . Fields { "query" : qry } ) . Debug ( "creating database.." )
log . WithFields ( log . Fields { "query" : qry } ) . Debug ( "creating database.." )
_ , err := db . Exec ( qry )
_ , err := db . Exec ( qry )
if err != nil {
if err != nil {
@ -103,7 +121,9 @@ 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 + "?parseTime=true&time_zone=%27UTC%27")
//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" , mysqlUser + ":" + mysqlPass + "@tcp(" + mysqlHost + ")/" + mysqlDb )
dbUri := mysqlUser + ":" + mysqlPass + "@tcp(" + mysqlHost + ")/" + mysqlDb
log . Tracef ( "dbUri: %s" , dbUri )
db , er := sql . Open ( "mysql" , dbUri )
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
@ -111,7 +131,7 @@ func dbConn() (db *sql.DB, err bool){
pingerr := db . Ping ( )
pingerr := db . Ping ( )
if pingerr != nil {
if pingerr != nil {
log . Error ( "db not pingable.." )
log . Error ( "db not pingable: " , pingerr . Error ( ) )
return nil , true
return nil , true
}
}