/ Check-in [0d78ebb8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix ALTER TABLE RENAME so that it correctly handles triggers that attach to the table using the name in a different case. Ticket [ae6794effd404].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:0d78ebb8e41ba08b446b44694d9433e1e90e0a7e
User & Date: drh 2012-02-01 01:13:10
Context
2012-02-01
19:03
Very small performance enhancement and reduction in size of the sqlite3_stmt object. check-in: a38d57a4 user: drh tags: trunk
01:13
Fix ALTER TABLE RENAME so that it correctly handles triggers that attach to the table using the name in a different case. Ticket [ae6794effd404]. check-in: 0d78ebb8 user: drh tags: trunk
2012-01-31
23:34
Fix a compiler warning in FTS4. check-in: b4cad1ce user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/alter.c.

526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
#endif
          "tbl_name = %Q, "
          "name = CASE "
            "WHEN type='table' THEN %Q "
            "WHEN name LIKE 'sqlite_autoindex%%' AND type='index' THEN "
             "'sqlite_autoindex_' || %Q || substr(name,%d+18) "
            "ELSE name END "
      "WHERE tbl_name=%Q AND "
          "(type='table' OR type='index' OR type='trigger');", 
      zDb, SCHEMA_TABLE(iDb), zName, zName, zName, 
#ifndef SQLITE_OMIT_TRIGGER
      zName,
#endif
      zName, nTabName, zTabName
  );







|







526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
#endif
          "tbl_name = %Q, "
          "name = CASE "
            "WHEN type='table' THEN %Q "
            "WHEN name LIKE 'sqlite_autoindex%%' AND type='index' THEN "
             "'sqlite_autoindex_' || %Q || substr(name,%d+18) "
            "ELSE name END "
      "WHERE tbl_name=%Q COLLATE nocase AND "
          "(type='table' OR type='index' OR type='trigger');", 
      zDb, SCHEMA_TABLE(iDb), zName, zName, zName, 
#ifndef SQLITE_OMIT_TRIGGER
      zName,
#endif
      zName, nTabName, zTabName
  );

Changes to test/alter.test.

345
346
347
348
349
350
351

352
353
354
355
356
357
358
359
  set ::TRIGGER $args
}
db func trigfunc trigfunc

do_test alter-3.1.0 {
  execsql {
    CREATE TABLE t6(a, b, c);

    CREATE TRIGGER trig1 AFTER INSERT ON t6 BEGIN
      SELECT trigfunc('trig1', new.a, new.b, new.c);
    END;
  }
} {}
do_test alter-3.1.1 {
  execsql {
    INSERT INTO t6 VALUES(1, 2, 3);







>
|







345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
  set ::TRIGGER $args
}
db func trigfunc trigfunc

do_test alter-3.1.0 {
  execsql {
    CREATE TABLE t6(a, b, c);
    -- Different case for the table name in the trigger.
    CREATE TRIGGER trig1 AFTER INSERT ON T6 BEGIN
      SELECT trigfunc('trig1', new.a, new.b, new.c);
    END;
  }
} {}
do_test alter-3.1.1 {
  execsql {
    INSERT INTO t6 VALUES(1, 2, 3);

Changes to test/tkt3838.test.

33
34
35
36
37
38
39
40

















41
    ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT '999';
    ALTER TABLE t1 ADD COLUMN c REAL DEFAULT '9e99';
    ALTER TABLE t1 ADD COLUMN d TEXT DEFAULT 'xyzzy';
    UPDATE t1 SET x=x+1;
    SELECT * FROM t1;
  }
} {2 999 9e+99 xyzzy}


















finish_test








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
    ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT '999';
    ALTER TABLE t1 ADD COLUMN c REAL DEFAULT '9e99';
    ALTER TABLE t1 ADD COLUMN d TEXT DEFAULT 'xyzzy';
    UPDATE t1 SET x=x+1;
    SELECT * FROM t1;
  }
} {2 999 9e+99 xyzzy}

ifcapable trigger {
  do_test tkt3838-1.2 {
    db eval {
      CREATE TABLE log(y);
      CREATE TRIGGER r1 AFTER INSERT ON T1 BEGIN
        INSERT INTO log VALUES(new.x);
      END;
      INSERT INTO t1(x) VALUES(123);
      ALTER TABLE T1 RENAME TO XYZ2;
      INSERT INTO xyz2(x) VALUES(456);
      ALTER TABLE xyz2 RENAME TO pqr3;
      INSERT INTO pqr3(x) VALUES(789);
      SELECT * FROM log;
    }
  } {123 456 789}
}

finish_test