MySQL INET_ATON error during update, message is “Incorrect string value”

后端 未结 2 615
天涯浪人
天涯浪人 2021-01-15 20:44

MySQL is 5.7.23.

IFNULL(INET_ATON(\'\'),0) returns a 0 in a plain select, but ERRORS during update ... set assignment

Q: Is there a

2条回答
  •  野的像风
    2021-01-15 21:06

    Thanks for the insight Bill.

    Turns out there are only a dozen places in the app where INET_ATON is used, so I'm going to push admin to let me change those to APP_INET_ATON which will only call system INET_ATON when the IP_STRING is 'legitimate'.

    DROP FUNCTION IF EXISTS APP_INET_ATON;
    CREATE FUNCTION APP_INET_ATON(IP_STRING VARCHAR(50)) RETURNS bigint DETERMINISTIC
      RETURN 
        CASE 
          WHEN IP_STRING IS NULL THEN 0
          WHEN IP_STRING NOT REGEXP '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' THEN 0
          ELSE INET_ATON (IP_STRING)
        END;
    

    Figuring out where the 'bad' IP_STRING values are coming from is for another day.

提交回复
热议问题