Comment changes. Change the use of BTree so that either the key is
an integer or the data is empty. (CVS 337)
FossilOrigin-Name: 18e606f7486eb3a4ab128504d88a44f53d39e5b2
diff --git a/src/insert.c b/src/insert.c
index 425d864..a3f41dc 100644
--- a/src/insert.c
+++ b/src/insert.c
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
-** $Id: insert.c,v 1.29 2001/12/22 21:48:30 drh Exp $
+** $Id: insert.c,v 1.30 2001/12/31 02:48:51 drh Exp $
*/
#include "sqliteInt.h"
@@ -132,6 +132,13 @@
/* If the INSERT statement included an IDLIST term, then make sure
** all elements of the IDLIST really are columns of the table and
** remember the column indices.
+ **
+ ** If the table has an INTEGER PRIMARY KEY column and that column
+ ** is named in the IDLIST, then record in the keyColumn variable
+ ** the index into IDLIST of the primary key column. keyColumn is
+ ** the index of the primary key as it appears in IDLIST, not as
+ ** is appears in the original table. (The index of the primary
+ ** key in the original table is pTab->iPKey.)
*/
if( pColumn ){
for(i=0; i<pColumn->nId; i++){
@@ -157,7 +164,8 @@
}
/* If there is not IDLIST term but the table has an integer primary
- ** key, the set the keyColumn variable to the primary key column.
+ ** key, the set the keyColumn variable to the primary key column index
+ ** in the original table definition.
*/
if( pColumn==0 ){
keyColumn = pTab->iPKey;
@@ -205,7 +213,7 @@
sqliteVdbeAddOp(v, OP_NewRecno, base, 0);
}
- /* If there are indices, we'll need this record number again, so make
+ /* If there are indices, we'll need the new record number again, so make
** a copy.
*/
if( pTab->pIndex ){
@@ -219,7 +227,7 @@
if( i==pTab->iPKey ){
/* The value of the INTEGER PRIMARY KEY column is always a NULL.
** Whenever this column is used, the record number will be substituted
- ** in its place, so there is no point it it taking up space in
+ ** in its place, so there is no point in it taking up space in
** the data record. */
sqliteVdbeAddOp(v, OP_String, 0, 0);
continue;
diff --git a/src/select.c b/src/select.c
index cc6e174..399c563 100644
--- a/src/select.c
+++ b/src/select.c
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
-** $Id: select.c,v 1.51 2001/12/22 14:49:25 drh Exp $
+** $Id: select.c,v 1.52 2001/12/31 02:48:51 drh Exp $
*/
#include "sqliteInt.h"
@@ -130,7 +130,6 @@
sqliteVdbeAddOp(v, OP_Goto, 0, iContinue);
sqliteVdbeResolveLabel(v, lbl);
sqliteVdbeAddOp(v, OP_String, 0, 0);
- sqliteVdbeChangeP3(v, -1, "", P3_STATIC);
sqliteVdbeAddOp(v, OP_Put, distinct, 0);
}
@@ -159,7 +158,6 @@
if( eDest==SRT_Union ){
sqliteVdbeAddOp(v, OP_MakeRecord, nColumn, 0);
sqliteVdbeAddOp(v, OP_String, iParm, 0);
- sqliteVdbeChangeP3(v, -1, "", P3_STATIC);
sqliteVdbeAddOp(v, OP_Put, iParm, 0);
}else
@@ -189,7 +187,6 @@
if( eDest==SRT_Set ){
assert( nColumn==1 );
sqliteVdbeAddOp(v, OP_String, 0, 0);
- sqliteVdbeChangeP3(v, -1, "", P3_STATIC);
sqliteVdbeAddOp(v, OP_Put, iParm, 0);
}else
@@ -909,7 +906,6 @@
sqliteVdbeAddOp(v, OP_AggReset, 0, pParse->nAgg);
if( pGroupBy==0 ){
sqliteVdbeAddOp(v, OP_String, 0, 0);
- sqliteVdbeChangeP3(v, -1, "", P3_STATIC);
sqliteVdbeAddOp(v, OP_AggFocus, 0, 0);
for(i=0; i<pParse->nAgg; i++){
Expr *pE;
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index ef7021b..ead834a 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.73 2001/12/21 14:30:43 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.74 2001/12/31 02:48:51 drh Exp $
*/
#include "sqlite.h"
#include "hash.h"
@@ -230,7 +230,7 @@
char *zName; /* Name of the table */
int nCol; /* Number of columns in this table */
Column *aCol; /* Information about each column */
- int iPKey; /* Use this column as the record-number for each row */
+ int iPKey; /* If not less then 0, use aCol[iPKey] as the primary key */
Index *pIndex; /* List of SQL indexes on this table. */
int tnum; /* Page containing root for this table */
u8 readOnly; /* True if this table should not be written by the user */
diff --git a/src/update.c b/src/update.c
index 7ea634e..0bac200 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.24 2001/12/22 14:49:25 drh Exp $
+** $Id: update.c,v 1.25 2001/12/31 02:48:51 drh Exp $
*/
#include "sqliteInt.h"
@@ -49,7 +49,7 @@
/* Locate the table which we want to update. This table has to be
** put in an IdList structure because some of the subroutines we
** will be calling are designed to work with multiple tables and expect
- ** an IdList* parameter instead of just a Table* parameger.
+ ** an IdList* parameter instead of just a Table* parameter.
*/
pTabList = sqliteIdListAppend(0, pTableName);
if( pTabList==0 ) goto update_cleanup;
@@ -119,7 +119,8 @@
/* Allocate memory for the array apIdx[] and fill it with pointers to every
** index that needs to be updated. Indices only need updating if their
- ** key includes one of the columns named in pChanges.
+ ** key includes one of the columns named in pChanges or if the record
+ ** number of the original table entry is changing.
*/
for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
if( chngRecno ){
@@ -203,7 +204,12 @@
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
pIdx = apIdx[i];
for(j=0; j<pIdx->nColumn; j++){
- sqliteVdbeAddOp(v, OP_Column, base, pIdx->aiColumn[j]);
+ int x = pIdx->aiColumn[j];
+ if( x==pTab->iPKey ){
+ sqliteVdbeAddOp(v, OP_Dup, j, 0);
+ }else{
+ sqliteVdbeAddOp(v, OP_Column, base, x);
+ }
}
sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0);
sqliteVdbeAddOp(v, OP_IdxDelete, base+i+1, 0);
@@ -233,7 +239,7 @@
}
}
- /* If changing the record number, delete the hold record.
+ /* If changing the record number, delete the old record.
*/
if( chngRecno ){
sqliteVdbeAddOp(v, OP_Delete, 0, 0);
diff --git a/src/vdbe.c b/src/vdbe.c
index c8c2376..7079e17 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -30,7 +30,7 @@
** But other routines are also provided to help in building up
** a program instruction by instruction.
**
-** $Id: vdbe.c,v 1.102 2001/12/22 14:49:25 drh Exp $
+** $Id: vdbe.c,v 1.103 2001/12/31 02:48:51 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -56,11 +56,11 @@
typedef unsigned char Bool;
/*
-** A cursor is a pointer into a database file. The database file
-** can represent either an SQL table or an SQL index. Each file is
-** a bag of key/data pairs. The cursor can loop over all key/data
-** pairs (in an arbitrary order) or it can retrieve a particular
-** key/data pair given a copy of the key.
+** A cursor is a pointer into a single BTree within a database file.
+** The cursor can seek to a BTree entry with a particular key, or
+** loop over all entries of the Btree. You can also insert new BTree
+** entries or retrieve the key or data from the entry that the cursor
+** is currently pointing to.
**
** Every cursor that the virtual machine has open is represented by an
** instance of the following structure.
@@ -98,7 +98,7 @@
** layer without having to malloc. NBFS is short for Number of Bytes
** For Strings.
*/
-#define NBFS 30
+#define NBFS 32
/*
** A single level of the stack is an instance of the following
@@ -170,8 +170,8 @@
/*
** A Keylist is a bunch of keys into a table. The keylist can
-** grow without bound. The keylist stores the keys of database
-** records that need to be deleted.
+** grow without bound. The keylist stores the ROWIDs of database
+** records that need to be deleted or updated.
*/
typedef struct Keylist Keylist;
struct Keylist {
@@ -394,7 +394,7 @@
** first null byte. If n>0 then copy n+1 bytes of zP3.
**
** If n==P3_STATIC it means that zP3 is a pointer to a constant static
-** string we can just copy the pointer. n==P3_POINTER means zP3 is
+** string and we can just copy the pointer. n==P3_POINTER means zP3 is
** a pointer to some object other than a string.
**
** If addr<0 then change P3 on the most recently inserted instruction.
@@ -1177,6 +1177,7 @@
z = pOp->p3;
if( z==0 ){
zStack[i] = 0;
+ aStack[i].n = 0;
aStack[i].flags = STK_Null;
}else{
zStack[i] = z;