fix: while connected to MySQL if internet was lost no qso would be logged anymore

This commit is contained in:
2026-07-12 18:01:03 +02:00
parent 7398261c50
commit a00817b93e
16 changed files with 850 additions and 9 deletions
+26
View File
@@ -1011,6 +1011,32 @@ func FilterableFields() []string {
}
// columnExpr resolves a filter field to a safe SQL expression — either a
// OfflineQueueKey is the ADIF extras key stamped on a QSO that was parked in the
// offline safety file. It survives the ADIF round-trip and makes the replay
// IDEMPOTENT: if the app dies between "inserted into the DB" and "removed from
// the file", the next replay sees the id already in the log and skips it instead
// of creating a duplicate.
const OfflineQueueKey = "APP_OPSLOG_QUEUEID"
// ExistsByQueueID reports whether a QSO carrying this offline-queue id is already
// in the logbook — the guard that makes replaying the safety file safe to repeat.
func (r *Repo) ExistsByQueueID(ctx context.Context, qid string) (bool, error) {
qid = strings.TrimSpace(qid)
if qid == "" {
return false, nil
}
expr := "json_extract(extras_json, '$." + OfflineQueueKey + "')"
if db.IsMySQL() {
expr = "JSON_UNQUOTE(JSON_EXTRACT(NULLIF(extras_json,''), '$." + OfflineQueueKey + "'))"
}
var n int
if err := r.db.QueryRowContext(ctx,
`SELECT COUNT(*) FROM qso WHERE `+expr+` = ?`, qid).Scan(&n); err != nil {
return false, err
}
return n > 0, nil
}
// whitelisted column name or a json_extract over extras_json.
func columnExpr(field string) (string, bool) {
f := strings.ToLower(strings.TrimSpace(field))