fix: query tdengine raw frames with literals
This commit is contained in:
@@ -137,41 +137,38 @@ func normalizeRawFrameQuery(query RawFrameQuery) RawFrameQuery {
|
||||
|
||||
func buildRawFrameSQL(table string, query RawFrameQuery) (string, []any) {
|
||||
var where []string
|
||||
var args []any
|
||||
add := func(clause string, value any) {
|
||||
add := func(clause string) {
|
||||
where = append(where, clause)
|
||||
args = append(args, value)
|
||||
}
|
||||
if query.Protocol != "" {
|
||||
add("protocol = ?", query.Protocol)
|
||||
add("protocol = '" + quote(query.Protocol) + "'")
|
||||
}
|
||||
if query.VIN != "" {
|
||||
add("vin = ?", query.VIN)
|
||||
add("vin = '" + quote(query.VIN) + "'")
|
||||
}
|
||||
if query.Phone != "" {
|
||||
add("phone = ?", query.Phone)
|
||||
add("phone = '" + quote(query.Phone) + "'")
|
||||
}
|
||||
if query.DeviceID != "" {
|
||||
add("device_id = ?", query.DeviceID)
|
||||
add("device_id = '" + quote(query.DeviceID) + "'")
|
||||
}
|
||||
if query.MessageID != "" {
|
||||
if parsed, ok := parseMessageID(query.MessageID); ok {
|
||||
add("message_id = ?", parsed)
|
||||
add("message_id = " + strconv.FormatInt(parsed, 10))
|
||||
}
|
||||
}
|
||||
if query.DateFrom != "" {
|
||||
add("ts >= ?", query.DateFrom)
|
||||
add("ts >= '" + quote(query.DateFrom) + "'")
|
||||
}
|
||||
if query.DateTo != "" {
|
||||
add("ts <= ?", query.DateTo)
|
||||
add("ts <= '" + quote(query.DateTo) + "'")
|
||||
}
|
||||
sqlText := `SELECT ts, frame_id, event_id, message_id, event_time, received_at, raw_size_bytes, raw_hex, raw_text, parsed_json, fields_json, parse_status, parse_error, source_endpoint, protocol, vehicle_key, vin, phone, device_id FROM ` + table
|
||||
if len(where) > 0 {
|
||||
sqlText += " WHERE " + strings.Join(where, " AND ")
|
||||
}
|
||||
sqlText += " ORDER BY ts DESC LIMIT ? OFFSET ?"
|
||||
args = append(args, query.Limit, query.Offset)
|
||||
return sqlText, args
|
||||
sqlText += " ORDER BY ts DESC LIMIT " + strconv.Itoa(query.Limit) + " OFFSET " + strconv.Itoa(query.Offset)
|
||||
return sqlText, nil
|
||||
}
|
||||
|
||||
type RawFrameHandler struct {
|
||||
|
||||
Reference in New Issue
Block a user