From 9647ff85fee731f4f9a302be3b9b2d35e9e51ad6 Mon Sep 17 00:00:00 2001
From: drh
Date: Mon, 14 Jan 2002 02:56:24 +0000
Subject: [PATCH] Fix a bug that could cause UPDATE to fail for a table that
contains both an INTEGER PRIMARY KEY and an index. (CVS 346)
FossilOrigin-Name: 96cd07a881d7bea86a66d7dfe54713be9c81cb4c
---
manifest | 16 ++++++++--------
manifest.uuid | 2 +-
src/update.c | 4 ++--
test/intpkey.test | 24 +++++++++++++++++++++++-
www/changes.tcl | 4 +++-
5 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/manifest b/manifest
index fc3cde128b..43e64c5188 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\sproblem\swith\sthe\sway\stemporary\stables\smask\spermanent\stables.\s(CVS\s345)
-D 2002-01-10T14:31:49
+C Fix\sa\sbug\sthat\scould\scause\sUPDATE\sto\sfail\sfor\sa\stable\sthat\scontains\nboth\san\sINTEGER\sPRIMARY\sKEY\sand\san\sindex.\s(CVS\s346)
+D 2002-01-14T02:56:25
F Makefile.in 9fa4277413bf1d9cf91365f07d4108d7d87ed2af
F Makefile.template c88ffcb9c339e718f434d0c7f045bcd7eea125af
F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
@@ -47,7 +47,7 @@ F src/test1.c 41eabe255970ef947263b94145c9b2766bab8675
F src/test2.c e9f99aa5ee73872819259d6612c11e55e1644321
F src/test3.c d6775f95fd91f5b3cf0e2382a28e5aaeb68f745b
F src/tokenize.c 830e9ef684334070a26583d94770bb869e2727bf
-F src/update.c f9f48e78c13c79e32a55840414bea84479f9848d
+F src/update.c 5cb326ed4bace89cbad7d919b828da6c2a9064e4
F src/util.c 8e9ca72d8288cae39c57c6f397abd14a56b14a38
F src/vdbe.c b27b256a5930da1e8fc347a272357be72de0f853
F src/vdbe.h e5cc6fb13d1905a4339db4d6dba4ab393c0765fa
@@ -65,7 +65,7 @@ F test/in.test 9323681388be301dc73f370b4cd62c5a33f79d1e
F test/index.test c8a471243bbf878974b99baf5badd59407237cf3
F test/insert.test a5c122aa726f1cef6f07d6767e8fd6f220994c11
F test/insert2.test d6901ca931e308fea7fca8c95ebe7dc957cc9fc2
-F test/intpkey.test c5776456778f4062a8355467704df9c501ab3e1c
+F test/intpkey.test c9f427cb7b74835deeef112ed7f2af13d2ad662b
F test/ioerr.test 57d9bffaca18b34f9e976f786eadc2591d6efc6a
F test/limit.test a930f3eba2a7691c8397ccab33710b931589566a
F test/lock.test 19593689260c419efe7ced55b1418653a4b7bcd1
@@ -105,7 +105,7 @@ F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf
F www/arch.png 82ef36db1143828a7abc88b1e308a5f55d4336f4
F www/arch.tcl 72a0c80e9054cc7025a50928d28d9c75c02c2b8b
F www/c_interface.tcl 9123810452845783fac8e3184929463d9e70d609
-F www/changes.tcl adfe78519e374df4d85d93f6439c4ff9eaae0020
+F www/changes.tcl cf67e8dec21d813c48f3cecc00bbfa6bd397dd69
F www/crosscompile.tcl 3622ebbe518927a3854a12de51344673eb2dd060
F www/download.tcl 1ea61f9d89a2a5a9b2cee36b0d5cf97321bdefe0
F www/dynload.tcl 02eb8273aa78cfa9070dd4501dca937fb22b466c
@@ -119,7 +119,7 @@ F www/speed.tcl 83457b2bf6bb430900bd48ca3dd98264d9a916a5
F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279
F www/tclsqlite.tcl 880ef67cb4f2797b95bf1368fc4e0d8ca0fda956
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P 61c38f3bfef430f39aa98e9e7fa37324132b4381
-R 86d121727b37f70f571d7ff2f6e92a47
+P ba89da603135e5f63f6f97ba3adad02682375c07
+R a1a9962b00d5c92a1a7c16dd24629b0d
U drh
-Z 03a2bc05be0a98dd6da8d500e8918359
+Z aeca75f74932caada8d3a000ff881f69
diff --git a/manifest.uuid b/manifest.uuid
index 85a59a92c9..f47f5aa6b1 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-ba89da603135e5f63f6f97ba3adad02682375c07
\ No newline at end of file
+96cd07a881d7bea86a66d7dfe54713be9c81cb4c
\ No newline at end of file
diff --git a/src/update.c b/src/update.c
index 0bac200e26..ed760ff993 100644
--- a/src/update.c
+++ b/src/update.c
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle UPDATE statements.
**
-** $Id: update.c,v 1.25 2001/12/31 02:48:51 drh Exp $
+** $Id: update.c,v 1.26 2002/01/14 02:56:25 drh Exp $
*/
#include "sqliteInt.h"
@@ -101,7 +101,7 @@ void sqliteUpdate(
}
for(j=0; jnCol; j++){
if( sqliteStrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){
- if( i==pTab->iPKey ){
+ if( j==pTab->iPKey ){
chngRecno = 1;
pRecnoExpr = pChanges->a[i].pExpr;
}
diff --git a/test/intpkey.test b/test/intpkey.test
index 6660dfc476..8355116f68 100644
--- a/test/intpkey.test
+++ b/test/intpkey.test
@@ -13,7 +13,7 @@
# This file implements tests for the special processing associated
# with INTEGER PRIMARY KEY columns.
#
-# $Id: intpkey.test,v 1.4 2001/12/22 21:48:30 drh Exp $
+# $Id: intpkey.test,v 1.5 2002/01/14 02:56:26 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -411,4 +411,26 @@ do_test intpkey-7.2 {
}
} {22 b-22 c-22 30 new row}
+# Do an insert from a select statement.
+#
+do_test intpkey-8.1 {
+ execsql {
+ CREATE TABLE t2(x INTEGER PRIMARY KEY, y, z);
+ INSERT INTO t2 SELECT * FROM t1;
+ SELECT rowid FROM t2;
+ }
+} {-4 0 5 6 11 20 22 30}
+do_test intpkey-8.2 {
+ execsql {
+ SELECT x FROM t2;
+ }
+} {-4 0 5 6 11 20 22 30}
+
+do_test intpkey-9.1 {
+ execsql {
+ UPDATE t1 SET c='www' WHERE c='world';
+ SELECT rowid, a, c FROM t1 WHERE c=='www';
+ }
+} {5 5 www 11 11 www}
+
finish_test
diff --git a/www/changes.tcl b/www/changes.tcl
index 38a3aab77f..004323f3de 100644
--- a/www/changes.tcl
+++ b/www/changes.tcl
@@ -17,9 +17,11 @@ proc chng {date desc} {
puts "
"
}
-chng {2002 Jan 10 (2.2.2)} {
+chng {2002 Jan 13 (2.2.2)} {
Bug fix: An assertion was failing when a temporary table with an index
had the same name as a permanent table created by a separate process.
+Bug fix: Updates to tables containing an INTEGER PRIMARY KEY and an
+ index could fail.
}
chng {2002 Jan 9 (2.2.1)} {