-- 检查所有项圈设备的所有字段长度
-- 找出真正导致Data truncation的字段

-- 1. 检查所有字段的长度
SELECT 
    device_id,
    latitude,
    longitude,
    voltage,
    temperature,
    steps,
    same_day_steps,
    LENGTH(CAST(latitude AS CHAR)) as lat_length,
    LENGTH(CAST(longitude AS CHAR)) as lng_length,
    LENGTH(CAST(voltage AS CHAR)) as voltage_length,
    LENGTH(CAST(temperature AS CHAR)) as temp_length,
    LENGTH(CAST(steps AS CHAR)) as steps_length,
    LENGTH(CAST(same_day_steps AS CHAR)) as same_day_steps_length
FROM iot_device_data 
WHERE device_type = 4 
ORDER BY LENGTH(CAST(latitude AS CHAR)) DESC
LIMIT 10;

-- 2. 检查是否有超长字段
SELECT 
    'latitude' as field_name,
    MAX(LENGTH(CAST(latitude AS CHAR))) as max_length
FROM iot_device_data 
WHERE device_type = 4
UNION ALL
SELECT 
    'longitude' as field_name,
    MAX(LENGTH(CAST(longitude AS CHAR))) as max_length
FROM iot_device_data 
WHERE device_type = 4
UNION ALL
SELECT 
    'voltage' as field_name,
    MAX(LENGTH(CAST(voltage AS CHAR))) as max_length
FROM iot_device_data 
WHERE device_type = 4
UNION ALL
SELECT 
    'temperature' as field_name,
    MAX(LENGTH(CAST(temperature AS CHAR))) as max_length
FROM iot_device_data 
WHERE device_type = 4
UNION ALL
SELECT 
    'steps' as field_name,
    MAX(LENGTH(CAST(steps AS CHAR))) as max_length
FROM iot_device_data 
WHERE device_type = 4
UNION ALL
SELECT 
    'same_day_steps' as field_name,
    MAX(LENGTH(CAST(same_day_steps AS CHAR))) as max_length
FROM iot_device_data 
WHERE device_type = 4;

-- 3. 检查xq_client_log表的字段长度限制
SELECT 
    COLUMN_NAME,
    DATA_TYPE,
    CHARACTER_MAXIMUM_LENGTH,
    NUMERIC_PRECISION,
    NUMERIC_SCALE
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_SCHEMA = DATABASE() 
AND TABLE_NAME = 'xq_client_log'
AND COLUMN_NAME IN ('latitude', 'longitude', 'device_voltage', 'device_temp', 'walk_steps', 'y_walk_steps')
ORDER BY ORDINAL_POSITION;
