I need to add INET_ATON to ip field before insert
INSERT INTO (`id`,`ip`) VALUES (NULL,'127.0.0.1');
I need the database to convert ip transparently before insert.
and in select convert it back with INET_NTOA()
I can not change the query to use
INSERT INTO (`id`,`ip`) VALUES (NULL,INET_ATON('127.0.0.1'));
because i have no control over the software that executes those queries
For the insert part you can setup a
TRIGGER BEFORE INSERTin the database:The SELECT part is a bit more tricky. There is no
AFTER SELECTtrigger in mysql which you could use to convert the IP back on the way into the application code.Instead, you could RENAME the real table and hide it behind a
VIEW:Note: when you use this
VIEW, you need to modify theTRIGGERfor theINSERTpart to usetable_name_realinstead oftable_name