mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
Minor refactoring of variable names and fixes to comments in insert.c.
FossilOrigin-Name: ae61a34378d3ed2f454ba8768029d6f5fef849e4
This commit is contained in:
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Progress\stoward\sgetting\sUPDATE\sto\swork\sin\sWITHOUT\sROWID\stables.
|
C Minor\srefactoring\sof\svariable\snames\sand\sfixes\sto\scomments\sin\sinsert.c.
|
||||||
D 2013-10-25T19:17:17.511
|
D 2013-10-26T00:58:34.188
|
||||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||||
F Makefile.in 0522b53cdc1fcfc18f3a98e0246add129136c654
|
F Makefile.in 0522b53cdc1fcfc18f3a98e0246add129136c654
|
||||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||||
@@ -182,7 +182,7 @@ F src/global.c 5caf4deab621abb45b4c607aad1bd21c20aac759
|
|||||||
F src/hash.c ac3470bbf1ca4ae4e306a8ecb0fdf1731810ffe4
|
F src/hash.c ac3470bbf1ca4ae4e306a8ecb0fdf1731810ffe4
|
||||||
F src/hash.h 8890a25af81fb85a9ad7790d32eedab4b994da22
|
F src/hash.h 8890a25af81fb85a9ad7790d32eedab4b994da22
|
||||||
F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08
|
F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08
|
||||||
F src/insert.c 976fc5c9b3ab32995b22f87ba3be52d11c9e50b9
|
F src/insert.c 684154a70880e8a8b6f390227440db336ae6172c
|
||||||
F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d
|
F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d
|
||||||
F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12
|
F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12
|
||||||
F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b
|
F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b
|
||||||
@@ -1127,7 +1127,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
|
|||||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||||
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
|
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
|
||||||
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
|
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
|
||||||
P 9eafafa31c4a2bbcf48418743e0fcb17c374e9a6
|
P e557b7d80f1ede63427a31b16757bf5d8dbfb66d
|
||||||
R bcff8223a4c38fdc4478f7b14868c2a5
|
R 8ecb8965e88397a72e81a0bfa7fd01e8
|
||||||
U drh
|
U drh
|
||||||
Z 45e2a3e25d194ae58eddf07aeb33a8d9
|
Z ed26d40c375e5bd903fb1bf3e632fe62
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
e557b7d80f1ede63427a31b16757bf5d8dbfb66d
|
ae61a34378d3ed2f454ba8768029d6f5fef849e4
|
||||||
76
src/insert.c
76
src/insert.c
@@ -435,7 +435,7 @@ static int xferOptimization(
|
|||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** This routine is call to handle SQL of the following forms:
|
** This routine is called to handle SQL of the following forms:
|
||||||
**
|
**
|
||||||
** insert into TABLE (IDLIST) values(EXPRLIST)
|
** insert into TABLE (IDLIST) values(EXPRLIST)
|
||||||
** insert into TABLE (IDLIST) select
|
** insert into TABLE (IDLIST) select
|
||||||
@@ -450,7 +450,7 @@ static int xferOptimization(
|
|||||||
** data for the insert.
|
** data for the insert.
|
||||||
**
|
**
|
||||||
** The code generated follows one of four templates. For a simple
|
** The code generated follows one of four templates. For a simple
|
||||||
** select with data coming from a VALUES clause, the code executes
|
** insert with data coming from a VALUES clause, the code executes
|
||||||
** once straight down through. Pseudo-code follows (we call this
|
** once straight down through. Pseudo-code follows (we call this
|
||||||
** the "1st template"):
|
** the "1st template"):
|
||||||
**
|
**
|
||||||
@@ -554,7 +554,7 @@ void sqlite3Insert(
|
|||||||
int nColumn; /* Number of columns in the data */
|
int nColumn; /* Number of columns in the data */
|
||||||
int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
|
int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
|
||||||
int baseCur = 0; /* VDBE Cursor number for pTab */
|
int baseCur = 0; /* VDBE Cursor number for pTab */
|
||||||
int keyColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
|
int ipkColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
|
||||||
int endOfLoop; /* Label for the end of the insertion loop */
|
int endOfLoop; /* Label for the end of the insertion loop */
|
||||||
int useTempTable = 0; /* Store SELECT results in intermediate table */
|
int useTempTable = 0; /* Store SELECT results in intermediate table */
|
||||||
int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
|
int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
|
||||||
@@ -625,16 +625,13 @@ void sqlite3Insert(
|
|||||||
assert( (pTrigger && tmask) || (pTrigger==0 && tmask==0) );
|
assert( (pTrigger && tmask) || (pTrigger==0 && tmask==0) );
|
||||||
|
|
||||||
/* If pTab is really a view, make sure it has been initialized.
|
/* If pTab is really a view, make sure it has been initialized.
|
||||||
** ViewGetColumnNames() is a no-op if pTab is not a view (or virtual
|
** ViewGetColumnNames() is a no-op if pTab is not a view.
|
||||||
** module table).
|
|
||||||
*/
|
*/
|
||||||
if( sqlite3ViewGetColumnNames(pParse, pTab) ){
|
if( sqlite3ViewGetColumnNames(pParse, pTab) ){
|
||||||
goto insert_cleanup;
|
goto insert_cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure that:
|
/* Cannot insert into a read-only table.
|
||||||
* (a) the table is not read-only,
|
|
||||||
* (b) that if it is a view then ON INSERT triggers exist
|
|
||||||
*/
|
*/
|
||||||
if( sqlite3IsReadOnly(pParse, pTab, tmask) ){
|
if( sqlite3IsReadOnly(pParse, pTab, tmask) ){
|
||||||
goto insert_cleanup;
|
goto insert_cleanup;
|
||||||
@@ -675,8 +672,7 @@ void sqlite3Insert(
|
|||||||
** co-routine is the common header to the 3rd and 4th templates.
|
** co-routine is the common header to the 3rd and 4th templates.
|
||||||
*/
|
*/
|
||||||
if( pSelect ){
|
if( pSelect ){
|
||||||
/* Data is coming from a SELECT. Generate a co-routine to run that
|
/* Data is coming from a SELECT. Generate a co-routine to run the SELECT */
|
||||||
** SELECT. */
|
|
||||||
int rc = sqlite3CodeCoroutine(pParse, pSelect, &dest);
|
int rc = sqlite3CodeCoroutine(pParse, pSelect, &dest);
|
||||||
if( rc ) goto insert_cleanup;
|
if( rc ) goto insert_cleanup;
|
||||||
|
|
||||||
@@ -688,7 +684,7 @@ void sqlite3Insert(
|
|||||||
|
|
||||||
/* Set useTempTable to TRUE if the result of the SELECT statement
|
/* Set useTempTable to TRUE if the result of the SELECT statement
|
||||||
** should be written into a temporary table (template 4). Set to
|
** should be written into a temporary table (template 4). Set to
|
||||||
** FALSE if each* row of the SELECT can be written directly into
|
** FALSE if each output row of the SELECT can be written directly into
|
||||||
** the destination table (template 3).
|
** the destination table (template 3).
|
||||||
**
|
**
|
||||||
** A temp table must be used if the table being updated is also one
|
** A temp table must be used if the table being updated is also one
|
||||||
@@ -771,11 +767,11 @@ void sqlite3Insert(
|
|||||||
** remember the column indices.
|
** remember the column indices.
|
||||||
**
|
**
|
||||||
** If the table has an INTEGER PRIMARY KEY column and that column
|
** If the table has an INTEGER PRIMARY KEY column and that column
|
||||||
** is named in the IDLIST, then record in the keyColumn variable
|
** is named in the IDLIST, then record in the ipkColumn variable
|
||||||
** the index into IDLIST of the primary key column. keyColumn is
|
** the index into IDLIST of the primary key column. ipkColumn is
|
||||||
** the index of the primary key as it appears in IDLIST, not as
|
** the index of the primary key as it appears in IDLIST, not as
|
||||||
** is appears in the original table. (The index of the primary
|
** is appears in the original table. (The index of the INTEGER
|
||||||
** key in the original table is pTab->iPKey.)
|
** PRIMARY KEY in the original table is pTab->iPKey.)
|
||||||
*/
|
*/
|
||||||
if( pColumn ){
|
if( pColumn ){
|
||||||
for(i=0; i<pColumn->nId; i++){
|
for(i=0; i<pColumn->nId; i++){
|
||||||
@@ -786,14 +782,14 @@ void sqlite3Insert(
|
|||||||
if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
|
if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
|
||||||
pColumn->a[i].idx = j;
|
pColumn->a[i].idx = j;
|
||||||
if( j==pTab->iPKey ){
|
if( j==pTab->iPKey ){
|
||||||
keyColumn = i; assert( !withoutRowid );
|
ipkColumn = i; assert( !withoutRowid );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( j>=pTab->nCol ){
|
if( j>=pTab->nCol ){
|
||||||
if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
|
if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
|
||||||
keyColumn = i;
|
ipkColumn = i;
|
||||||
}else{
|
}else{
|
||||||
sqlite3ErrorMsg(pParse, "table %S has no column named %s",
|
sqlite3ErrorMsg(pParse, "table %S has no column named %s",
|
||||||
pTabList, 0, pColumn->a[i].zName);
|
pTabList, 0, pColumn->a[i].zName);
|
||||||
@@ -805,11 +801,11 @@ void sqlite3Insert(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If there is no IDLIST term but the table has an integer primary
|
/* If there is no IDLIST term but the table has an integer primary
|
||||||
** key, the set the keyColumn variable to the primary key column index
|
** key, the set the ipkColumn variable to the integer primary key
|
||||||
** in the original table definition.
|
** column index in the original table definition.
|
||||||
*/
|
*/
|
||||||
if( pColumn==0 && nColumn>0 ){
|
if( pColumn==0 && nColumn>0 ){
|
||||||
keyColumn = pTab->iPKey;
|
ipkColumn = pTab->iPKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the count of rows to be inserted
|
/* Initialize the count of rows to be inserted
|
||||||
@@ -884,16 +880,16 @@ void sqlite3Insert(
|
|||||||
** we do not know what the unique ID will be (because the insert has
|
** we do not know what the unique ID will be (because the insert has
|
||||||
** not happened yet) so we substitute a rowid of -1
|
** not happened yet) so we substitute a rowid of -1
|
||||||
*/
|
*/
|
||||||
if( keyColumn<0 ){
|
if( ipkColumn<0 ){
|
||||||
sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
|
sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
|
||||||
}else{
|
}else{
|
||||||
int j1;
|
int j1;
|
||||||
assert( !withoutRowid );
|
assert( !withoutRowid );
|
||||||
if( useTempTable ){
|
if( useTempTable ){
|
||||||
sqlite3VdbeAddOp3(v, OP_Column, srcTab, keyColumn, regCols);
|
sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regCols);
|
||||||
}else{
|
}else{
|
||||||
assert( pSelect==0 ); /* Otherwise useTempTable is true */
|
assert( pSelect==0 ); /* Otherwise useTempTable is true */
|
||||||
sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr, regCols);
|
sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regCols);
|
||||||
}
|
}
|
||||||
j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols);
|
j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols);
|
||||||
sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
|
sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
|
||||||
@@ -943,24 +939,22 @@ void sqlite3Insert(
|
|||||||
sqlite3ReleaseTempRange(pParse, regCols, pTab->nCol+1);
|
sqlite3ReleaseTempRange(pParse, regCols, pTab->nCol+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Push the record number for the new entry onto the stack. The
|
/* Compute the content of the next row to insert into a range of
|
||||||
** record number is a randomly generate integer created by NewRowid
|
** registers beginning at regIns.
|
||||||
** except when the table has an INTEGER PRIMARY KEY column, in which
|
|
||||||
** case the record number is the same as that column.
|
|
||||||
*/
|
*/
|
||||||
if( !isView ){
|
if( !isView ){
|
||||||
if( IsVirtual(pTab) ){
|
if( IsVirtual(pTab) ){
|
||||||
/* The row that the VUpdate opcode will delete: none */
|
/* The row that the VUpdate opcode will delete: none */
|
||||||
sqlite3VdbeAddOp2(v, OP_Null, 0, regIns);
|
sqlite3VdbeAddOp2(v, OP_Null, 0, regIns);
|
||||||
}
|
}
|
||||||
if( keyColumn>=0 ){
|
if( ipkColumn>=0 ){
|
||||||
if( useTempTable ){
|
if( useTempTable ){
|
||||||
sqlite3VdbeAddOp3(v, OP_Column, srcTab, keyColumn, regRowid);
|
sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regRowid);
|
||||||
}else if( pSelect ){
|
}else if( pSelect ){
|
||||||
sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+keyColumn, regRowid);
|
sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+ipkColumn, regRowid);
|
||||||
}else{
|
}else{
|
||||||
VdbeOp *pOp;
|
VdbeOp *pOp;
|
||||||
sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr, regRowid);
|
sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid);
|
||||||
pOp = sqlite3VdbeGetOp(v, -1);
|
pOp = sqlite3VdbeGetOp(v, -1);
|
||||||
if( ALWAYS(pOp) && pOp->opcode==OP_Null && !IsVirtual(pTab) ){
|
if( ALWAYS(pOp) && pOp->opcode==OP_Null && !IsVirtual(pTab) ){
|
||||||
appendFlag = 1;
|
appendFlag = 1;
|
||||||
@@ -993,7 +987,7 @@ void sqlite3Insert(
|
|||||||
}
|
}
|
||||||
autoIncStep(pParse, regAutoinc, regRowid);
|
autoIncStep(pParse, regAutoinc, regRowid);
|
||||||
|
|
||||||
/* Push onto the stack, data for all columns of the new entry, beginning
|
/* Compute data for all columns of the new entry, beginning
|
||||||
** with the first column.
|
** with the first column.
|
||||||
*/
|
*/
|
||||||
nHidden = 0;
|
nHidden = 0;
|
||||||
@@ -1001,8 +995,8 @@ void sqlite3Insert(
|
|||||||
int iRegStore = regRowid+1+i;
|
int iRegStore = regRowid+1+i;
|
||||||
if( i==pTab->iPKey ){
|
if( i==pTab->iPKey ){
|
||||||
/* The value of the INTEGER PRIMARY KEY column is always a NULL.
|
/* The value of the INTEGER PRIMARY KEY column is always a NULL.
|
||||||
** Whenever this column is read, the record number will be substituted
|
** Whenever this column is read, the rowid will be substituted
|
||||||
** in its place. So will fill this column with a NULL to avoid
|
** in its place. Hence, fill this column with a NULL to avoid
|
||||||
** taking up data space with information that will never be used. */
|
** taking up data space with information that will never be used. */
|
||||||
sqlite3VdbeAddOp2(v, OP_Null, 0, iRegStore);
|
sqlite3VdbeAddOp2(v, OP_Null, 0, iRegStore);
|
||||||
continue;
|
continue;
|
||||||
@@ -1046,7 +1040,7 @@ void sqlite3Insert(
|
|||||||
{
|
{
|
||||||
int isReplace; /* Set to true if constraints may cause a replace */
|
int isReplace; /* Set to true if constraints may cause a replace */
|
||||||
sqlite3GenerateConstraintChecks(pParse, pTab, baseCur, regIns, aRegIdx,
|
sqlite3GenerateConstraintChecks(pParse, pTab, baseCur, regIns, aRegIdx,
|
||||||
keyColumn>=0, 0, onError, endOfLoop, &isReplace
|
ipkColumn>=0, 0, onError, endOfLoop, &isReplace
|
||||||
);
|
);
|
||||||
sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
|
sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
|
||||||
sqlite3CompleteInsertion(
|
sqlite3CompleteInsertion(
|
||||||
@@ -1135,7 +1129,8 @@ insert_cleanup:
|
|||||||
**
|
**
|
||||||
** The input is a range of consecutive registers as follows:
|
** The input is a range of consecutive registers as follows:
|
||||||
**
|
**
|
||||||
** 1. The rowid of the row after the update.
|
** 1. The rowid of the row after the update. (This register
|
||||||
|
** contains a NULL for WITHOUT ROWID tables.)
|
||||||
**
|
**
|
||||||
** 2. The data in the first column of the entry after the update.
|
** 2. The data in the first column of the entry after the update.
|
||||||
**
|
**
|
||||||
@@ -1146,13 +1141,14 @@ insert_cleanup:
|
|||||||
** The regRowid parameter is the index of the register containing (1).
|
** The regRowid parameter is the index of the register containing (1).
|
||||||
**
|
**
|
||||||
** If isUpdate is true and pkChng is non-zero, then pkChng contains
|
** If isUpdate is true and pkChng is non-zero, then pkChng contains
|
||||||
** the address of a register containing the rowid before the update takes
|
** the address of a range of registers containing the rowid or PRIMARY KEY
|
||||||
** place. isUpdate is true for UPDATEs and false for INSERTs. If isUpdate
|
** value before the update takes place. isUpdate is true for UPDATEs and
|
||||||
** is false, indicating an INSERT statement, then a non-zero pkChng
|
** false for INSERTs. If isUpdate is false then a non-zero pkChng
|
||||||
** indicates that the rowid was explicitly specified as part of the
|
** indicates that the rowid was explicitly specified as part of the
|
||||||
** INSERT statement. If pkChng is false, it means that the rowid is
|
** INSERT statement. If pkChng is false, it means that the rowid is
|
||||||
** computed automatically in an insert or that the rowid value is not
|
** computed automatically in an insert or that the rowid value is not
|
||||||
** modified by an update.
|
** modified by an update. The pkChng parameter is always false for inserts
|
||||||
|
** into a WITHOUT ROWID table.
|
||||||
**
|
**
|
||||||
** The code generated by this routine should store new index entries into
|
** The code generated by this routine should store new index entries into
|
||||||
** registers identified by aRegIdx[]. No index entry is created for
|
** registers identified by aRegIdx[]. No index entry is created for
|
||||||
|
|||||||
Reference in New Issue
Block a user