/ Check-in [ca359a3e]
Login

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

Overview
Comment:Do not crash when compiling an "INSERT INTO tbl DEFAULT VALUES" when tbl has either BEFORE or INSTEAD OF triggers attached to it. Ticket [f3162063fd].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ca359a3e8048bd11605c41c4b48134c0343e543b
User & Date: dan 2010-03-30 12:40:33
Context
2010-03-30
15:51
Add a NEVER macro around a test in btree.c that can not longer be true. check-in: c117f992 user: drh tags: trunk
12:40
Do not crash when compiling an "INSERT INTO tbl DEFAULT VALUES" when tbl has either BEFORE or INSTEAD OF triggers attached to it. Ticket [f3162063fd]. check-in: ca359a3e user: dan tags: trunk
11:57
Change an #if into an #ifdef. check-in: 371bab5d user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/insert.c.

842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
      if( pColumn==0 ){
        j = i;
      }else{
        for(j=0; j<pColumn->nId; j++){
          if( pColumn->a[j].idx==i ) break;
        }
      }
      if( pColumn && j>=pColumn->nId ){
        sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regCols+i+1);
      }else if( useTempTable ){
        sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, regCols+i+1); 
      }else{
        assert( pSelect==0 ); /* Otherwise useTempTable is true */
        sqlite3ExprCodeAndCache(pParse, pList->a[j].pExpr, regCols+i+1);
      }







|







842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
      if( pColumn==0 ){
        j = i;
      }else{
        for(j=0; j<pColumn->nId; j++){
          if( pColumn->a[j].idx==i ) break;
        }
      }
      if( (!useTempTable && !pList) || (pColumn && j>=pColumn->nId) ){
        sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regCols+i+1);
      }else if( useTempTable ){
        sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, regCols+i+1); 
      }else{
        assert( pSelect==0 ); /* Otherwise useTempTable is true */
        sqlite3ExprCodeAndCache(pParse, pList->a[j].pExpr, regCols+i+1);
      }

Changes to test/triggerC.test.

850
851
852
853
854
855
856
857



858



























































859
  # 1 written to column "updatecnt" was clobbered by the old value 0).
  #
  execsql {
    UPDATE t11 SET c4=35, c33=22, c1=5;
    SELECT * FROM t11;
  } 
} {5 2 3 35 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 32 33 22 34 35 36 37 38 39 40}
































































finish_test








>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
  # 1 written to column "updatecnt" was clobbered by the old value 0).
  #
  execsql {
    UPDATE t11 SET c4=35, c33=22, c1=5;
    SELECT * FROM t11;
  } 
} {5 2 3 35 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 32 33 22 34 35 36 37 38 39 40}

#-------------------------------------------------------------------------
# Test that bug [371bab5d65] has been fixed. BEFORE INSERT and INSTEAD OF
# INSERT triggers with the DEFAULT VALUES INSERT syntax.
#
do_test triggerC-11.0 {
  catchsql { DROP TABLE log }
  execsql  { CREATE TABLE log(a, b) }
} {}

foreach {testno tbl defaults} {
  1 "CREATE TABLE t1(a, b)"                          {{} {}}
  2 "CREATE TABLE t1(a DEFAULT 1, b DEFAULT 'abc')"  {1 abc}
  3 "CREATE TABLE t1(a, b DEFAULT 4.5)"              {{} 4.5}
} {
  do_test triggerC-11.$testno.1 {
    catchsql { DROP TABLE t1 }
    execsql { DELETE FROM log }
    execsql $tbl
    execsql {
      CREATE TRIGGER tt1 BEFORE INSERT ON t1 BEGIN 
        INSERT INTO log VALUES(new.a, new.b);
      END;
      INSERT INTO t1 DEFAULT VALUES;
      SELECT * FROM log;
    }
  } $defaults

  do_test triggerC-11.$testno.2 {
    execsql { DELETE FROM log }
    execsql {
      CREATE TRIGGER tt2 AFTER INSERT ON t1 BEGIN 
        INSERT INTO log VALUES(new.a, new.b);
      END;
      INSERT INTO t1 DEFAULT VALUES;
      SELECT * FROM log;
    }
  } [concat $defaults $defaults]

  do_test triggerC-11.$testno.3 {
    execsql { DROP TRIGGER tt1 }
    execsql { DELETE FROM log }
    execsql {
      INSERT INTO t1 DEFAULT VALUES;
      SELECT * FROM log;
    }
  } $defaults
} 
do_test triggerC-11.4 {
  catchsql { DROP TABLE t2 }
  execsql {
    DELETE FROM log;
    CREATE TABLE t2(a, b);
    CREATE VIEW v2 AS SELECT * FROM t2;
    CREATE TRIGGER tv2 INSTEAD OF INSERT ON v2 BEGIN
      INSERT INTO log VALUES(new.a, new.b);
    END;
    INSERT INTO v2 DEFAULT VALUES;
    SELECT a, b, a IS NULL, b IS NULL FROM log;
  }
} {{} {} 1 1}



finish_test