00 mysql伪哈希

Post date: 2012/4/3 上午 05:54:20

在innodb中用了crc32.

drop table user_agent;

CREATE TABLE user_agent (

id int(11) unsigned NOT NULL AUTO_INCREMENT,

name varchar(32) NOT NULL,

brand varchar(32) NOT NULL,

agent varchar(1024) NOT NULL,

info varchar(1024) DEFAULT NULL,

agent_crc int unsigned NOT NULL DEFAULT '0',

PRIMARY KEY (id)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DELIMITER |

CREATE TRIGGER t_beforeinsert_on_agent

BEFORE INSERT ON user_agent

FOR EACH ROW

BEGIN

set NEW.agent_crc = crc32(NEW.agent);

END;

|

CREATE TRIGGER t_beforeupdate_on_agent

BEFORE UPDATE ON user_agent

FOR EACH ROW

BEGIN

set NEW.agent_crc = crc32(NEW.agent);

END;

|

DELIMITER ;

insert into user_agent(name, brand, agent, info) values('sogou3.0.0', 'chrome','Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.33 Safari/534.3 SE 2.X MetaSr 1.0', '');

select * from user_agent;