/ Check-in [e6f02aa5]
Login

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

Overview
Comment:When parsing CREATE INDEX statements from the sqlite_master table, do not search the temp database schema for the corresponding table. Only consider the database for which the schema is being parsed. Ticket #2817. (CVS 4587)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e6f02aa5ae6da0befdf98fdd5884345f3cb7f5ea
User & Date: danielk1977 2007-12-02 11:46:35
Context
2007-12-03
21:52
Do not require os_other.h if compiling with -DOS_OTHER=1. (CVS 4588) check-in: 96ec3903 user: drh tags: trunk
2007-12-02
11:46
When parsing CREATE INDEX statements from the sqlite_master table, do not search the temp database schema for the corresponding table. Only consider the database for which the schema is being parsed. Ticket #2817. (CVS 4587) check-in: e6f02aa5 user: danielk1977 tags: trunk
2007-12-01
19:25
Another fix to Makefile.in for mingw. (CVS 4586) check-in: cfaeb025 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
....
2316
2317
2318
2319
2320
2321
2322
2323

2324

2325
2326
2327

2328
2329
2330
2331
2332
2333
2334
**     CREATE INDEX
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
**
** $Id: build.c,v 1.448 2007/11/12 09:50:26 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.
................................................................................
    */
    assert( pName1 && pName2 );
    iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
    if( iDb<0 ) goto exit_create_index;

#ifndef SQLITE_OMIT_TEMPDB
    /* If the index name was unqualified, check if the the table
    ** is a temp table. If so, set the database to 1.

    */

    pTab = sqlite3SrcListLookup(pParse, pTblName);
    if( pName2 && pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
      iDb = 1;

    }
#endif

    if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) &&
        sqlite3FixSrcList(&sFix, pTblName)
    ){
      /* Because the parser constructs pTblName from a single identifier,







|







 







|
>

>
|
|
|
>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
....
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
**     CREATE INDEX
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
**
** $Id: build.c,v 1.449 2007/12/02 11:46:35 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.
................................................................................
    */
    assert( pName1 && pName2 );
    iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
    if( iDb<0 ) goto exit_create_index;

#ifndef SQLITE_OMIT_TEMPDB
    /* If the index name was unqualified, check if the the table
    ** is a temp table. If so, set the database to 1. Do not do this
    ** if initialising a database schema.
    */
    if( !db->init.busy ){
      pTab = sqlite3SrcListLookup(pParse, pTblName);
      if( pName2 && pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
        iDb = 1;
      }
    }
#endif

    if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) &&
        sqlite3FixSrcList(&sFix, pTblName)
    ){
      /* Because the parser constructs pTblName from a single identifier,

Added test/tkt2817.test.



















































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
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
31
32
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 2007 December 02 
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    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.
#
# Specifically, it tests that bug 2817 is fixed.
#
# $Id: tkt2817.test,v 1.1 2007/12/02 11:46:35 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

do_test tkt2817-1.0 {
  execsql {
    CREATE TEMP TABLE tbl(a, b, c);
    -- INSERT INTO tbl VALUES(1, 'abc', 'def');
    -- INSERT INTO tbl VALUES(2, 'ghi', 'jkl');
  }
} {}
do_test tkt2817-1.1 {
  execsql {
    CREATE TABLE main.tbl(a, b, c); 
    CREATE INDEX main.tbli ON tbl(a, b, c);
    INSERT INTO main.tbl SELECT a, b, c FROM temp.tbl;
  }
} {}

# When bug #2817 existed, this test was failing.
#
integrity_check tkt2817-1.2

# So was this one.
#
db close
sqlite3 db test.db
integrity_check tkt2817-1.3


# These tests - tkt2817-2.* - are the same as the previous block, except
# for the fact that the temp-table and the main table do not share the
# same name. #2817 did not cause a problem with these tests.
#
db close
file delete -force test.db
sqlite3 db test.db
do_test tkt2817-2.0 {
  execsql {
    CREATE TEMP TABLE tmp(a, b, c);
    INSERT INTO tmp VALUES(1, 'abc', 'def');
    INSERT INTO tmp VALUES(2, 'ghi', 'jkl');
  }
} {}
do_test tkt2817-2.1 {
  execsql {
    CREATE TABLE main.tbl(a, b, c); 
    CREATE INDEX main.tbli ON tbl(a, b, c);
    INSERT INTO main.tbl SELECT a, b, c FROM temp.tmp;
  }
} {}
integrity_check tkt2817-2.2
db close
sqlite3 db test.db
integrity_check tkt2817-2.3

finish_test