/ Check-in [876d09d9]
Login

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

Overview
Comment:Fix an infinite loop in the code generator for INSERT. Ticket #1140. (CVS 2410)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:876d09d9145775956913e975c29e81d7553839ac
User & Date: drh 2005-03-21 01:20:58
Context
2005-03-21
01:24
fix typo in CREATE VIEW documentation. Ticket #1135. (CVS 2411) check-in: 38897a50 user: drh tags: trunk
01:20
Fix an infinite loop in the code generator for INSERT. Ticket #1140. (CVS 2410) check-in: 876d09d9 user: drh tags: trunk
00:47
README file updated to suggest running "make install". Ticket #1168. (CVS 2409) check-in: b48784cf user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/insert.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
** $Id: insert.c,v 1.137 2005/03/16 12:15:21 danielk1977 Exp $
*/
#include "sqliteInt.h"

/*
** Set P3 of the most recently inserted opcode to a column affinity
** string for index pIdx. A column affinity string has one character
** for each column in the table, according to the affinity of the column:
................................................................................
*/
static int selectReadsTable(Select *p, int iDb, int iTab){
  int i;
  struct SrcList_item *pItem;
  if( p->pSrc==0 ) return 0;
  for(i=0, pItem=p->pSrc->a; i<p->pSrc->nSrc; i++, pItem++){
    if( pItem->pSelect ){
      if( selectReadsTable(p, iDb, iTab) ) return 1;
    }else{
      if( pItem->pTab->iDb==iDb && pItem->pTab->tnum==iTab ) return 1;
    }
  }
  return 0;
}








|







 







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
** $Id: insert.c,v 1.138 2005/03/21 01:20:58 drh Exp $
*/
#include "sqliteInt.h"

/*
** Set P3 of the most recently inserted opcode to a column affinity
** string for index pIdx. A column affinity string has one character
** for each column in the table, according to the affinity of the column:
................................................................................
*/
static int selectReadsTable(Select *p, int iDb, int iTab){
  int i;
  struct SrcList_item *pItem;
  if( p->pSrc==0 ) return 0;
  for(i=0, pItem=p->pSrc->a; i<p->pSrc->nSrc; i++, pItem++){
    if( pItem->pSelect ){
      if( selectReadsTable(pItem->pSelect, iDb, iTab) ) return 1;
    }else{
      if( pItem->pTab->iDb==iDb && pItem->pTab->tnum==iTab ) return 1;
    }
  }
  return 0;
}

Changes to test/insert.test.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
335
336
337
338
339
340
341











342
343
344
345
#    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 the INSERT statement.
#
# $Id: insert.test,v 1.23 2005/01/21 03:12:16 danielk1977 Exp $

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

# Try to insert into a non-existant table.
#
do_test insert-1.1 {
................................................................................
  }
} {}
do_test insert-7.3 {
  execsql {
    SELECT a FROM t1;
  }
} {1 2 2}












integrity_check insert-99.0

finish_test







|







 







>
>
>
>
>
>
>
>
>
>
>




7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#    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 the INSERT statement.
#
# $Id: insert.test,v 1.24 2005/03/21 01:20:58 drh Exp $

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

# Try to insert into a non-existant table.
#
do_test insert-1.1 {
................................................................................
  }
} {}
do_test insert-7.3 {
  execsql {
    SELECT a FROM t1;
  }
} {1 2 2}

# Ticket #1140:  Check for an infinite loop in the algorithm that tests
# to see if the right-hand side of an INSERT...SELECT references the left-hand
# side.
#
do_test insert-8.1 {
  execsql {
    INSERT INTO t3 SELECT * FROM (SELECT * FROM t3 UNION ALL SELECT 1,2,3)
  }
} {}


integrity_check insert-99.0

finish_test