/ Check-in [f5341529]
Login

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

Overview
Comment:Detect circularly defined views and issue an error message. Ticket #1658. (CVS 3055)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:f5341529d0cdbd63ce4c33606858158b6093969a
User & Date: drh 2006-02-05 18:55:20
Context
2006-02-06
13:59
Update the per-thread bytes allocated counter with the number of bytes actually allocated, not the number requested. Ticket #1660. (CVS 3056) check-in: 3f0a0ff1 user: danielk1977 tags: trunk
2006-02-05
18:55
Detect circularly defined views and issue an error message. Ticket #1658. (CVS 3055) check-in: f5341529 user: drh tags: trunk
2006-02-01
14:39
Typecast to silence (incorrect) compiler warning. (CVS 3054) check-in: 3a04fc45 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/build.c.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
....
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
**     CREATE INDEX
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
**
** $Id: build.c,v 1.383 2006/01/24 12:09:19 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** This routine is called when a new SQL statement is beginning to
** be parsed.  Initialize the pParse structure as needed.
................................................................................
  **
  **     CREATE VIEW one AS SELECT * FROM two;
  **     CREATE VIEW two AS SELECT * FROM one;
  **
  ** Actually, this error is caught previously and so the following test
  ** should always fail.  But we will leave it in place just to be safe.
  */
#if 0
  if( pTable->nCol<0 ){
    sqlite3ErrorMsg(pParse, "view %s is circularly defined", pTable->zName);
    return 1;
  }
#endif
  assert( pTable->nCol>=0 );

  /* If we get this far, it means we need to compute the table names.
  ** Note that the call to sqlite3ResultSetOfSelect() will expand any
  ** "*" elements in the results set of the view and will assign cursors
  ** to the elements of the FROM clause.  But we do not want these changes
  ** to be permanent.  So the computation is done on a copy of the SELECT







|







 







<




<







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
....
1658
1659
1660
1661
1662
1663
1664

1665
1666
1667
1668

1669
1670
1671
1672
1673
1674
1675
**     CREATE INDEX
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
**
** $Id: build.c,v 1.384 2006/02/05 18:55:20 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** This routine is called when a new SQL statement is beginning to
** be parsed.  Initialize the pParse structure as needed.
................................................................................
  **
  **     CREATE VIEW one AS SELECT * FROM two;
  **     CREATE VIEW two AS SELECT * FROM one;
  **
  ** Actually, this error is caught previously and so the following test
  ** should always fail.  But we will leave it in place just to be safe.
  */

  if( pTable->nCol<0 ){
    sqlite3ErrorMsg(pParse, "view %s is circularly defined", pTable->zName);
    return 1;
  }

  assert( pTable->nCol>=0 );

  /* If we get this far, it means we need to compute the table names.
  ** Note that the call to sqlite3ResultSetOfSelect() will expand any
  ** "*" elements in the results set of the view and will assign cursors
  ** to the elements of the FROM clause.  But we do not want these changes
  ** to be permanent.  So the computation is done on a copy of the SELECT

Changes to test/view.test.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
455
456
457
458
459
460
461









462
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing VIEW statements.
#
# $Id: view.test,v 1.28 2006/01/14 08:02:29 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Omit this entire file if the library is not configured with views enabled.
ifcapable !view {
  finish_test
  return
................................................................................
  catchsql {
    ATTACH 'test2.db' AS two;
    CREATE TABLE two.t2(x,y);
    CREATE VIEW v13 AS SELECT y FROM two.t2;
  }
} {1 {view v13 cannot reference objects in database two}}










finish_test







|







 







>
>
>
>
>
>
>
>
>

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing VIEW statements.
#
# $Id: view.test,v 1.29 2006/02/05 18:55:21 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Omit this entire file if the library is not configured with views enabled.
ifcapable !view {
  finish_test
  return
................................................................................
  catchsql {
    ATTACH 'test2.db' AS two;
    CREATE TABLE two.t2(x,y);
    CREATE VIEW v13 AS SELECT y FROM two.t2;
  }
} {1 {view v13 cannot reference objects in database two}}

# Ticket #1658
#
do_test view-14.1 {
  catchsql {
    CREATE TEMP VIEW t1 AS SELECT a,b FROM t1;
    SELECT * FROM temp.t1;
  }
} {1 {view t1 is circularly defined}}

finish_test