SQLite

Check-in [ceb60bd7e5]
Login

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

Overview
Comment:Fix a problem with renaming a non-temp table that has at least one temp trigger and shares its name with a temp table.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ceb60bd7e5f2a0a4247bff476fc6468227305467339ae0c24591be9d2b14bdde
User & Date: dan 2018-09-07 15:50:31.361
Context
2018-09-07
18:52
Add assert() and ALWAYS() to identify two unreachable branches. (check-in: 8fa254aa63 user: drh tags: trunk)
15:50
Fix a problem with renaming a non-temp table that has at least one temp trigger and shares its name with a temp table. (check-in: ceb60bd7e5 user: dan tags: trunk)
11:51
Minor fixes for problems revealed by releasetest.tcl. (check-in: 1a8aedc337 user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/alter.c.
1027
1028
1029
1030
1031
1032
1033

1034
1035
1036
1037
1038
1039

1040


1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
** Resolve all symbols in the trigger at pParse->pNewTrigger, assuming
** it was read from the schema of database zDb. Return SQLITE_OK if 
** successful. Otherwise, return an SQLite error code and leave an error
** message in the Parse object.
*/
static int renameResolveTrigger(Parse *pParse, const char *zDb){
  sqlite3 *db = pParse->db;

  TriggerStep *pStep;
  NameContext sNC;
  int rc = SQLITE_OK;

  memset(&sNC, 0, sizeof(sNC));
  sNC.pParse = pParse;

  pParse->pTriggerTab = sqlite3FindTable(db, pParse->pNewTrigger->table, zDb);


  pParse->eTriggerOp = pParse->pNewTrigger->op;

  /* Resolve symbols in WHEN clause */
  if( pParse->pNewTrigger->pWhen ){
    rc = sqlite3ResolveExprNames(&sNC, pParse->pNewTrigger->pWhen);
  }

  for(pStep=pParse->pNewTrigger->step_list; 
      rc==SQLITE_OK && pStep; 
      pStep=pStep->pNext
  ){
    if( pStep->pSelect ){
      sqlite3SelectPrep(pParse, pStep->pSelect, &sNC);
      if( pParse->nErr ) rc = pParse->rc;
    }
    if( rc==SQLITE_OK && pStep->zTarget ){ 
      Table *pTarget = sqlite3LocateTable(pParse, 0, pStep->zTarget, zDb);
      if( pTarget==0 ){
        rc = SQLITE_ERROR;
      }else{
        SrcList sSrc;
        memset(&sSrc, 0, sizeof(sSrc));
        sSrc.nSrc = 1;







>






>
|
>
>
|


|
|


<
|
<
<




|







1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051

1052


1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
** Resolve all symbols in the trigger at pParse->pNewTrigger, assuming
** it was read from the schema of database zDb. Return SQLITE_OK if 
** successful. Otherwise, return an SQLite error code and leave an error
** message in the Parse object.
*/
static int renameResolveTrigger(Parse *pParse, const char *zDb){
  sqlite3 *db = pParse->db;
  Trigger *pNew = pParse->pNewTrigger;
  TriggerStep *pStep;
  NameContext sNC;
  int rc = SQLITE_OK;

  memset(&sNC, 0, sizeof(sNC));
  sNC.pParse = pParse;
  assert( pNew->pTabSchema );
  pParse->pTriggerTab = sqlite3FindTable(db, pNew->table, 
      db->aDb[sqlite3SchemaToIndex(db, pNew->pTabSchema)].zDbSName
  );
  pParse->eTriggerOp = pNew->op;

  /* Resolve symbols in WHEN clause */
  if( pNew->pWhen ){
    rc = sqlite3ResolveExprNames(&sNC, pNew->pWhen);
  }


  for(pStep=pNew->step_list; rc==SQLITE_OK && pStep; pStep=pStep->pNext){


    if( pStep->pSelect ){
      sqlite3SelectPrep(pParse, pStep->pSelect, &sNC);
      if( pParse->nErr ) rc = pParse->rc;
    }
    if( rc==SQLITE_OK && pStep->zTarget ){
      Table *pTarget = sqlite3LocateTable(pParse, 0, pStep->zTarget, zDb);
      if( pTarget==0 ){
        rc = SQLITE_ERROR;
      }else{
        SrcList sSrc;
        memset(&sSrc, 0, sizeof(sSrc));
        sSrc.nSrc = 1;
Changes to test/altertab.test.
366
367
368
369
370
371
372




















373
374
375
  SELECT name, tbl_name FROM sqlite_temp_master;
} {tr t2}

do_execsql_test 11.6 {
  INSERT INTO aux.t2 VALUES(7, 8, 9);
}
do_test 11.7 { set ::trigger } {{4 5 6} {7 8 9}}





















finish_test








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



366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
  SELECT name, tbl_name FROM sqlite_temp_master;
} {tr t2}

do_execsql_test 11.6 {
  INSERT INTO aux.t2 VALUES(7, 8, 9);
}
do_test 11.7 { set ::trigger } {{4 5 6} {7 8 9}}

#-------------------------------------------------------------------------
reset_db
do_execsql_test 12.0 {
  CREATE TABLE t1(a);
  CREATE TABLE t2(w);
  CREATE TRIGGER temp.r1 AFTER INSERT ON main.t2 BEGIN
    INSERT INTO t1(a) VALUES(new.w);
  END;
  CREATE TEMP TABLE t2(x);
}

do_execsql_test 12.1 {
  ALTER TABLE main.t2 RENAME TO t3;
}

do_execsql_test 12.2 {
  INSERT INTO t3 VALUES('WWW');
  SELECT * FROM t1;
} {WWW}

finish_test

Changes to test/permutations.test.
284
285
286
287
288
289
290






291
292
293
294
295
296
297
]

test_suite "window" -prefix "" -description {
  All window function related tests .
} -files [
  test_set [glob -nocomplain $::testdir/window*.test]
]







test_suite "lsm1" -prefix "" -description {
  All LSM1 tests.
} -files [glob -nocomplain $::testdir/../ext/lsm1/test/*.test]

test_suite "nofaultsim" -prefix "" -description {
  "Very" quick test suite. Runs in less than 5 minutes on a workstation. 







>
>
>
>
>
>







284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
]

test_suite "window" -prefix "" -description {
  All window function related tests .
} -files [
  test_set [glob -nocomplain $::testdir/window*.test]
]

test_suite "alter" -prefix "" -description {
  All ALTER function related tests .
} -files [
  test_set [glob -nocomplain $::testdir/alter*.test]
]

test_suite "lsm1" -prefix "" -description {
  All LSM1 tests.
} -files [glob -nocomplain $::testdir/../ext/lsm1/test/*.test]

test_suite "nofaultsim" -prefix "" -description {
  "Very" quick test suite. Runs in less than 5 minutes on a workstation.