rpl_insert_id.result
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· RESULT 代码 · 共 445 行
RESULT
445 行
## Setup#stop slave;drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;reset master;reset slave;drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;start slave;use test;drop table if exists t1, t2, t3;## See if queries that use both auto_increment and LAST_INSERT_ID()# are replicated well## We also check how the foreign_key_check variable is replicated#create table t1(a int auto_increment, key(a));create table t2(b int auto_increment, c int, key(b));insert into t1 values (1),(2),(3);insert into t1 values (null);insert into t2 values (null,last_insert_id());select * from t1;a1234select * from t2;b c1 4drop table t1;drop table t2;create table t1(a int auto_increment, key(a)) engine=innodb;create table t2(b int auto_increment, c int, key(b), foreign key(b) references t1(a)) engine=innodb;SET FOREIGN_KEY_CHECKS=0;insert into t1 values (10);insert into t1 values (null),(null),(null);insert into t2 values (5,0);insert into t2 values (null,last_insert_id());SET FOREIGN_KEY_CHECKS=1;select * from t1;a10111213select * from t2;b c5 06 11## check if INSERT SELECT in auto_increment is well replicated (bug #490)#drop table t2;drop table t1;create table t1(a int auto_increment, key(a));create table t2(b int auto_increment, c int, key(b));insert into t1 values (10);insert into t1 values (null),(null),(null);insert into t2 values (5,0);insert into t2 (c) select * from t1;select * from t2;b c5 06 107 118 129 13select * from t1;a10111213select * from t2;b c5 06 107 118 129 13drop table t1;drop table t2;## Bug#8412: Error codes reported in binary log for CHARACTER SET,# FOREIGN_KEY_CHECKS#SET TIMESTAMP=1000000000;CREATE TABLE t1 ( a INT UNIQUE );SET FOREIGN_KEY_CHECKS=0;INSERT INTO t1 VALUES (1),(1);ERROR 23000: Duplicate entry '1' for key 1drop table t1;## Bug#14553: NULL in WHERE resets LAST_INSERT_ID#create table t1(a int auto_increment, key(a));create table t2(a int);insert into t1 (a) values (null);insert into t2 (a) select a from t1 where a is null;insert into t2 (a) select a from t1 where a is null;select * from t2;a1select * from t2;a1drop table t1;drop table t2;## End of 4.1 tests#drop function if exists bug15728;drop function if exists bug15728_insert;drop table if exists t1, t2;create table t1 (id int not null auto_increment,last_id int,primary key (id));create function bug15728() returns int(11)return last_insert_id();insert into t1 (last_id) values (0);insert into t1 (last_id) values (last_insert_id());insert into t1 (last_id) values (bug15728());create table t2 (id int not null auto_increment,last_id int,primary key (id));create function bug15728_insert() returns int(11) modifies sql databegininsert into t2 (last_id) values (bug15728());return bug15728();end|create trigger t1_bi before insert on t1 for each rowbegindeclare res int;select bug15728_insert() into res;set NEW.last_id = res;end|insert into t1 (last_id) values (0);drop trigger t1_bi;select last_insert_id();last_insert_id()4select bug15728_insert();bug15728_insert()2select last_insert_id();last_insert_id()4insert into t1 (last_id) values (bug15728());select last_insert_id();last_insert_id()5select * from t1;id last_id1 02 13 24 15 4select * from t2;id last_id1 32 4drop function bug15728;drop function bug15728_insert;drop table t1, t2;create table t1 (n int primary key auto_increment not null,b int, unique(b));set sql_log_bin=0;insert into t1 values(null,100);replace into t1 values(null,50),(null,100),(null,150);select * from t1 order by n;n b2 503 1004 150truncate table t1;set sql_log_bin=1;insert into t1 values(null,100);select * from t1 order by n;n b1 100insert into t1 values(null,200),(null,300);delete from t1 where b <> 100;select * from t1 order by n;n b1 100replace into t1 values(null,100),(null,350);select * from t1 order by n;n b2 1003 350select * from t1 order by n;n b2 1003 350insert into t1 values (NULL,400),(3,500),(NULL,600) on duplicate key UPDATE n=1000;select * from t1 order by n;n b2 1004 4001000 3501001 600select * from t1 order by n;n b2 1004 4001000 3501001 600drop table t1;create table t1 (n int primary key auto_increment not null,b int, unique(b));insert into t1 values(null,100);select * from t1 order by n;n b1 100insert into t1 values(null,200),(null,300);delete from t1 where b <> 100;select * from t1 order by n;n b1 100insert into t1 values(null,100),(null,350) on duplicate key update n=2;select * from t1 order by n;n b2 1003 350select * from t1 order by n;n b2 1003 350drop table t1;CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY AUTO_INCREMENT, b INT,UNIQUE(b));INSERT INTO t1(b) VALUES(1),(1),(2) ON DUPLICATE KEY UPDATE t1.b=10;SELECT * FROM t1;a b1 102 2SELECT * FROM t1;a b1 102 2drop table t1;CREATE TABLE t1 (id bigint(20) unsigned NOT NULL auto_increment,field_1 int(10) unsigned NOT NULL,field_2 varchar(255) NOT NULL,field_3 varchar(255) NOT NULL,PRIMARY KEY (id),UNIQUE KEY field_1 (field_1, field_2));CREATE TABLE t2 (field_a int(10) unsigned NOT NULL,field_b varchar(255) NOT NULL,field_c varchar(255) NOT NULL);INSERT INTO t2 (field_a, field_b, field_c) VALUES (1, 'a', '1a');INSERT INTO t2 (field_a, field_b, field_c) VALUES (2, 'b', '2b');INSERT INTO t2 (field_a, field_b, field_c) VALUES (3, 'c', '3c');INSERT INTO t2 (field_a, field_b, field_c) VALUES (4, 'd', '4d');INSERT INTO t2 (field_a, field_b, field_c) VALUES (5, 'e', '5e');INSERT INTO t1 (field_1, field_2, field_3)SELECT t2.field_a, t2.field_b, t2.field_cFROM t2ON DUPLICATE KEY UPDATEt1.field_3 = t2.field_c;INSERT INTO t2 (field_a, field_b, field_c) VALUES (6, 'f', '6f');INSERT INTO t1 (field_1, field_2, field_3)SELECT t2.field_a, t2.field_b, t2.field_cFROM t2ON DUPLICATE KEY UPDATEt1.field_3 = t2.field_c;SELECT * FROM t1;id field_1 field_2 field_31 1 a 1a2 2 b 2b3 3 c 3c4 4 d 4d5 5 e 5e6 6 f 6fSELECT * FROM t1;id field_1 field_2 field_31 1 a 1a2 2 b 2b3 3 c 3c4 4 d 4d5 5 e 5e6 6 f 6fdrop table t1, t2;DROP PROCEDURE IF EXISTS p1;DROP TABLE IF EXISTS t1, t2;SELECT LAST_INSERT_ID(0);LAST_INSERT_ID(0)0CREATE TABLE t1 (id INT NOT NULL DEFAULT 0,last_id INT,PRIMARY KEY (id));CREATE TABLE t2 (id INT NOT NULL AUTO_INCREMENT,last_id INT,PRIMARY KEY (id));CREATE PROCEDURE p1()BEGININSERT INTO t2 (last_id) VALUES (LAST_INSERT_ID());INSERT INTO t1 (last_id) VALUES (LAST_INSERT_ID());END|CALL p1();SELECT * FROM t1;id last_id0 1SELECT * FROM t2;id last_id1 0SELECT * FROM t1;id last_id0 1SELECT * FROM t2;id last_id1 0DROP PROCEDURE p1;DROP TABLE t1, t2;DROP PROCEDURE IF EXISTS p1;DROP FUNCTION IF EXISTS f1;DROP FUNCTION IF EXISTS f2;DROP FUNCTION IF EXISTS f3;DROP TABLE IF EXISTS t1, t2;CREATE TABLE t1 (i INT NOT NULL AUTO_INCREMENT PRIMARY KEY,j INT DEFAULT 0);CREATE TABLE t2 (i INT);CREATE PROCEDURE p1()BEGININSERT INTO t1 (i) VALUES (NULL);INSERT INTO t2 (i) VALUES (LAST_INSERT_ID());INSERT INTO t1 (i) VALUES (NULL), (NULL);INSERT INTO t2 (i) VALUES (LAST_INSERT_ID());END |CREATE FUNCTION f1() RETURNS INT MODIFIES SQL DATABEGININSERT INTO t1 (i) VALUES (NULL);INSERT INTO t2 (i) VALUES (LAST_INSERT_ID());INSERT INTO t1 (i) VALUES (NULL), (NULL);INSERT INTO t2 (i) VALUES (LAST_INSERT_ID());RETURN 0;END |CREATE FUNCTION f2() RETURNS INT NOT DETERMINISTICRETURN LAST_INSERT_ID() |CREATE FUNCTION f3() RETURNS INT MODIFIES SQL DATABEGININSERT INTO t2 (i) VALUES (LAST_INSERT_ID());RETURN 0;END |INSERT INTO t1 VALUES (NULL, -1);CALL p1();SELECT f1();f1()0INSERT INTO t1 VALUES (NULL, f2()), (NULL, LAST_INSERT_ID()),(NULL, LAST_INSERT_ID()), (NULL, f2()), (NULL, f2());INSERT INTO t1 VALUES (NULL, f2());INSERT INTO t1 VALUES (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID(5)),(NULL, @@LAST_INSERT_ID);INSERT INTO t1 VALUES (NULL, 0), (NULL, LAST_INSERT_ID());UPDATE t1 SET j= -1 WHERE i IS NULL;INSERT INTO t1 (i) VALUES (NULL);INSERT INTO t1 (i) VALUES (NULL);SELECT f3();f3()0SELECT * FROM t1;i j1 -12 03 04 05 06 07 08 39 310 311 312 313 814 1315 516 1317 -118 1419 020 0SELECT * FROM t2;i235619SELECT * FROM t1;i j1 -12 03 04 05 06 07 08 39 310 311 312 313 814 1315 516 1317 -118 1419 020 0SELECT * FROM t2;i235619DROP PROCEDURE p1;DROP FUNCTION f1;DROP FUNCTION f2;DROP FUNCTION f3;DROP TABLE t1, t2;# End of 5.0 tests
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?