-- 检查xq_client_log表的所有字段长度
-- 找出导致Data truncation的真正原因

-- 1. 检查所有字段的长度限制
SELECT 
    COLUMN_NAME,
    DATA_TYPE,
    CHARACTER_MAXIMUM_LENGTH,
    NUMERIC_PRECISION,
    NUMERIC_SCALE,
    IS_NULLABLE,
    COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_SCHEMA = DATABASE() 
AND TABLE_NAME = 'xq_client_log'
ORDER BY ORDINAL_POSITION;

-- 2. 检查iot_device_data表中的实际数据长度
SELECT 
    device_id,
    device_type,
    LENGTH(CAST(voltage AS CHAR)) as voltage_length,
    LENGTH(CAST(temperature AS CHAR)) as temp_length,
    LENGTH(CAST(latitude AS CHAR)) as lat_length,
    LENGTH(CAST(longitude AS CHAR)) as lng_length,
    LENGTH(CAST(steps AS CHAR)) as steps_length,
    voltage,
    temperature,
    latitude,
    longitude,
    steps
FROM iot_device_data 
WHERE device_type = 4 
ORDER BY update_time DESC
LIMIT 10;

-- 3. 检查是否有其他可能超长的字段
SELECT 
    COLUMN_NAME,
    CHARACTER_MAXIMUM_LENGTH
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_SCHEMA = DATABASE() 
AND TABLE_NAME = 'xq_client_log'
AND CHARACTER_MAXIMUM_LENGTH IS NOT NULL
AND CHARACTER_MAXIMUM_LENGTH < 1000;
