1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Change the OP_Insert opcode to read the key and data to insert from memory cells, not the stack. (CVS 4666)

FossilOrigin-Name: 46501f490a5f5577ea31c758df749e02c7c65f39
This commit is contained in:
danielk1977
2008-01-03 09:51:55 +00:00
parent 11641c1136
commit 1f4aa337cd
13 changed files with 108 additions and 79 deletions

View File

@@ -1,5 +1,5 @@
C Change\sthe\soutput\sof\svdbe_trace\setc.\sto\sinclude\soperands\sp3\sand\sp5.\s(CVS\s4665) C Change\sthe\sOP_Insert\sopcode\sto\sread\sthe\skey\sand\sdata\sto\sinsert\sfrom\smemory\scells,\snot\sthe\sstack.\s(CVS\s4666)
D 2008-01-03T08:18:31 D 2008-01-03T09:51:55
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in 30789bf70614bad659351660d76b8e533f3340e9 F Makefile.in 30789bf70614bad659351660d76b8e533f3340e9
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -79,24 +79,24 @@ F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
F sqlite3.def a96c1d0d39362b763d2ddba220a32da41a15c4b4 F sqlite3.def a96c1d0d39362b763d2ddba220a32da41a15c4b4
F sqlite3.pc.in abed4664817e1cd500f2276142c71958087c16bc F sqlite3.pc.in abed4664817e1cd500f2276142c71958087c16bc
F src/alter.c b58ed3becc77885e2aec6754c689255534f2734c F src/alter.c b58ed3becc77885e2aec6754c689255534f2734c
F src/analyze.c 1fb7ada6a10c252db873c0835fbd92caaaa65116 F src/analyze.c d7b4dace3823b45d0a18568dd43067f78aa0f133
F src/attach.c 4b214b411237531491e1186211e005e4de73630d F src/attach.c 4b214b411237531491e1186211e005e4de73630d
F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627 F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
F src/btmutex.c 5d39da37c9d1282f3c6f9967afae6a34ee36b7ff F src/btmutex.c 5d39da37c9d1282f3c6f9967afae6a34ee36b7ff
F src/btree.c 5164b32950cfd41f2c5c31e8ff82c4a499918aef F src/btree.c 5164b32950cfd41f2c5c31e8ff82c4a499918aef
F src/btree.h 19dcf5ad23c17b98855da548e9a8e3eb4429d5eb F src/btree.h 19dcf5ad23c17b98855da548e9a8e3eb4429d5eb
F src/btreeInt.h 1c5a9da165718ef7de81e35ce9ab5d9ba9283f76 F src/btreeInt.h 1c5a9da165718ef7de81e35ce9ab5d9ba9283f76
F src/build.c a34fc6b288115b36e7b32dc2da429cbb59c89098 F src/build.c 11cd1e6a6425893662edcdf4b39abe02a1fb2ecb
F src/callback.c 77b302b0d41468dcda78c70e706e5b84577f0fa0 F src/callback.c 77b302b0d41468dcda78c70e706e5b84577f0fa0
F src/complete.c 4cf68fd75d60257524cbe74f87351b9848399131 F src/complete.c 4cf68fd75d60257524cbe74f87351b9848399131
F src/date.c 49c5a6d2de6c12000905b4d36868b07d3011bbf6 F src/date.c 49c5a6d2de6c12000905b4d36868b07d3011bbf6
F src/delete.c 0daad58124d0dfb334c8e5d3f6ceb76f093b8723 F src/delete.c 16389863bf16fdbec6810d6b44b9236fdbf4e567
F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
F src/expr.c 24202e79a92c8b9b0b5a609d03051ff3d91e5bf4 F src/expr.c 24202e79a92c8b9b0b5a609d03051ff3d91e5bf4
F src/func.c 996071cf0af9d967e58b69fce1909555059ebc7d F src/func.c 996071cf0af9d967e58b69fce1909555059ebc7d
F src/hash.c 45a7005aac044b6c86bd7e49c44bc15d30006d6c F src/hash.c 45a7005aac044b6c86bd7e49c44bc15d30006d6c
F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53 F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53
F src/insert.c c76fbbed6f3d3721dcc528653e45ff6c08a24c83 F src/insert.c 195072a6bd6c7f31618d3e97c27166a6e71ea0e4
F src/journal.c 807bed7a158979ac8d63953e1774e8d85bff65e2 F src/journal.c 807bed7a158979ac8d63953e1774e8d85bff65e2
F src/legacy.c 4ac53191fad2e3c4d59bde1228879b2dc5a96d66 F src/legacy.c 4ac53191fad2e3c4d59bde1228879b2dc5a96d66
F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35 F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35
@@ -131,12 +131,12 @@ F src/pragma.c 61b9d171a6d53d36a77c66cb921d47a5c09a8441
F src/prepare.c f1bb8eb642082e618a359c08e3e107490eafe0e3 F src/prepare.c f1bb8eb642082e618a359c08e3e107490eafe0e3
F src/printf.c eb27822ba2eec669161409ca31279a24c26ac910 F src/printf.c eb27822ba2eec669161409ca31279a24c26ac910
F src/random.c 4a22746501bf36b0a088c66e38dde5daba6a35da F src/random.c 4a22746501bf36b0a088c66e38dde5daba6a35da
F src/select.c 1f8579efbb45c037d1b169d08ac9e4cab84e1d74 F src/select.c 539a71c9b302ac003e5be72eee007d1f2e452e43
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c 5391e889384d2062249f668110d64ed16f601c4b F src/shell.c 5391e889384d2062249f668110d64ed16f601c4b
F src/sqlite.h.in 2a7e3776534bbe6ff2cdc058f3abebe91e7e429f F src/sqlite.h.in 2a7e3776534bbe6ff2cdc058f3abebe91e7e429f
F src/sqlite3ext.h a93f59cdee3638dc0c9c086f80df743a4e68c3cb F src/sqlite3ext.h a93f59cdee3638dc0c9c086f80df743a4e68c3cb
F src/sqliteInt.h 2e30ff7e6ee65743d38447f00ef873ce058be7be F src/sqliteInt.h 4cd2cec92641cf1c292ae5bc6b07a51ee4d0f34f
F src/sqliteLimit.h ee4430f88f69bf63527967bb35ca52af7b0ccb1e F src/sqliteLimit.h ee4430f88f69bf63527967bb35ca52af7b0ccb1e
F src/table.c 1aeb9eab57b4235db86fe15a35dec76fb445a9c4 F src/table.c 1aeb9eab57b4235db86fe15a35dec76fb445a9c4
F src/tclsqlite.c 9923abeffc9b3d7dad58e92b319661521f60debf F src/tclsqlite.c 9923abeffc9b3d7dad58e92b319661521f60debf
@@ -163,16 +163,16 @@ F src/test_server.c a6ece6c835e7eae835054124e09e947e422b1ac5
F src/test_tclvar.c b2d1115e4d489179d3f029e765211b2ad527ba59 F src/test_tclvar.c b2d1115e4d489179d3f029e765211b2ad527ba59
F src/test_thread.c e297dd41db0b249646e69f97d36ec13e56e8b730 F src/test_thread.c e297dd41db0b249646e69f97d36ec13e56e8b730
F src/tokenize.c a4e04438c11fed2c67ec47fe3edbef9cca2d1b48 F src/tokenize.c a4e04438c11fed2c67ec47fe3edbef9cca2d1b48
F src/trigger.c e7642cf61056655905aaba8db1ca51d299a1003b F src/trigger.c caa971c1a9bba37b6ad705e7990316dd1e8266c9
F src/update.c 587df2777e78a47d2c4399059cdd7a2cea5e0b19 F src/update.c 9b90a5d55cba28800a40ed5f443dcc44d71c3abc
F src/utf.c ef4b7d83bae533b76c3e1bf635b113fdad86a736 F src/utf.c ef4b7d83bae533b76c3e1bf635b113fdad86a736
F src/util.c 05f31144bbd3f1a24f4139ae029c42545cb72624 F src/util.c 05f31144bbd3f1a24f4139ae029c42545cb72624
F src/vacuum.c 3f34f278809bf3eb0b62ec46ff779e9c385b28f0 F src/vacuum.c 3f34f278809bf3eb0b62ec46ff779e9c385b28f0
F src/vdbe.c 429493ced32e5bb3d17fabd4f893374ebe5ffdf2 F src/vdbe.c 5b1939189986ad44940f2a5b207f9c302b95e95a
F src/vdbe.h ad5fd7aa694928e54efa84ac8f8133b77053c97d F src/vdbe.h 433a955b0b7ef4be23564353481da998666c480b
F src/vdbeInt.h 2985f1369273e635898cf5952237efcb3fdb21f3 F src/vdbeInt.h 2985f1369273e635898cf5952237efcb3fdb21f3
F src/vdbeapi.c bf615ff2cf2b121f1609cbadd4f52720289733b5 F src/vdbeapi.c bf615ff2cf2b121f1609cbadd4f52720289733b5
F src/vdbeaux.c 8c8901e4b5d5e8a89d6c149b9bcf91facb169f18 F src/vdbeaux.c 077854f4bc5ed0fcfb42f0fab2727816c7cefcd7
F src/vdbeblob.c b90f7494c408d47ce6835000b01e40b371e27baf F src/vdbeblob.c b90f7494c408d47ce6835000b01e40b371e27baf
F src/vdbefifo.c 334c838c8f42d61a94813d136019ee566b5dc2f6 F src/vdbefifo.c 334c838c8f42d61a94813d136019ee566b5dc2f6
F src/vdbemem.c 123994fcd344993d2fb050a83b91b341bbbd08b4 F src/vdbemem.c 123994fcd344993d2fb050a83b91b341bbbd08b4
@@ -603,7 +603,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P c30f8206353f32a08ef0b323c9fd0bdbeaa28b02 P 76f2040b051e1d4d8033e354dffe277b549f7962
R 771f6ceee9c4c383810617b5c88de655 R bbd0651e2eb2956304714ff8df05e705
U danielk1977 U danielk1977
Z f7a1409cbe2afac4183b180783d9a997 Z 658c0c7b02e0a563b671cd4ff1bc5c7c

View File

@@ -1 +1 @@
76f2040b051e1d4d8033e354dffe277b549f7962 46501f490a5f5577ea31c758df749e02c7c65f39

View File

@@ -11,7 +11,7 @@
************************************************************************* *************************************************************************
** This file contains code associated with the ANALYZE command. ** This file contains code associated with the ANALYZE command.
** **
** @(#) $Id: analyze.c,v 1.28 2008/01/03 07:54:24 danielk1977 Exp $ ** @(#) $Id: analyze.c,v 1.29 2008/01/03 09:51:55 danielk1977 Exp $
*/ */
#ifndef SQLITE_OMIT_ANALYZE #ifndef SQLITE_OMIT_ANALYZE
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -212,7 +212,7 @@ static void analyzeOneTable(
} }
} }
sqlite3VdbeAddOp4(v, OP_MakeRecord, 3, 0, 0, "aaa", 0); sqlite3VdbeAddOp4(v, OP_MakeRecord, 3, 0, 0, "aaa", 0);
sqlite3VdbeAddOp2(v, OP_Insert, iStatCur, OPFLAG_APPEND); sqlite3CodeInsert(pParse, iStatCur, OPFLAG_APPEND);
sqlite3VdbeJumpHere(v, addr); sqlite3VdbeJumpHere(v, addr);
} }
} }

View File

@@ -22,7 +22,7 @@
** COMMIT ** COMMIT
** ROLLBACK ** ROLLBACK
** **
** $Id: build.c,v 1.454 2008/01/03 07:54:24 danielk1977 Exp $ ** $Id: build.c,v 1.455 2008/01/03 09:51:55 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <ctype.h> #include <ctype.h>
@@ -883,7 +883,7 @@ void sqlite3StartTable(
sqlite3VdbeAddOp0(v, OP_NewRowid); sqlite3VdbeAddOp0(v, OP_NewRowid);
sqlite3VdbeAddOp0(v, OP_Dup); sqlite3VdbeAddOp0(v, OP_Dup);
sqlite3VdbeAddOp0(v, OP_Null); sqlite3VdbeAddOp0(v, OP_Null);
sqlite3VdbeAddOp2(v, OP_Insert, 0, OPFLAG_APPEND); sqlite3CodeInsert(pParse, 0, OPFLAG_APPEND);
sqlite3VdbeAddOp0(v, OP_Close); sqlite3VdbeAddOp0(v, OP_Close);
sqlite3VdbeAddOp1(v, OP_Pull, 1); sqlite3VdbeAddOp1(v, OP_Pull, 1);
} }

View File

@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser ** This file contains C code routines that are called by the parser
** in order to generate code for DELETE FROM statements. ** in order to generate code for DELETE FROM statements.
** **
** $Id: delete.c,v 1.141 2008/01/03 07:54:24 danielk1977 Exp $ ** $Id: delete.c,v 1.142 2008/01/03 09:51:55 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -60,6 +60,20 @@ int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
return 0; return 0;
} }
/*
** This function is a temporary measure required because OP_Insert now
** reads the key and data to insert from memory cells.
*/
void sqlite3CodeInsert(Parse *p, int iCur, u8 flags){
int iData = p->nMem++;
int iKey = p->nMem++;
Vdbe *v = sqlite3GetVdbe(p);
sqlite3VdbeAddOp2(v, OP_MemStore, iData, 1);
sqlite3VdbeAddOp2(v, OP_MemStore, iKey, 1);
sqlite3VdbeAddOp3(v, OP_Insert, iCur, iData, iKey);
sqlite3VdbeChangeP5(v, sqlite3VdbeCurrentAddr(v)-1, flags);
}
/* /*
** Generate code that will open a table for reading. ** Generate code that will open a table for reading.
*/ */
@@ -325,7 +339,7 @@ void sqlite3DeleteFrom(
}else{ }else{
sqlite3VdbeAddOp0(v, OP_Null); sqlite3VdbeAddOp0(v, OP_Null);
} }
sqlite3VdbeAddOp1(v, OP_Insert, oldIdx); sqlite3CodeInsert(pParse, oldIdx, 0);
/* Jump back and run the BEFORE triggers */ /* Jump back and run the BEFORE triggers */
sqlite3VdbeAddOp2(v, OP_Goto, 0, iBeginBeforeTrigger); sqlite3VdbeAddOp2(v, OP_Goto, 0, iBeginBeforeTrigger);

View File

@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser ** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite. ** to handle INSERT statements in SQLite.
** **
** $Id: insert.c,v 1.203 2008/01/03 07:54:24 danielk1977 Exp $ ** $Id: insert.c,v 1.204 2008/01/03 09:51:55 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -221,7 +221,7 @@ static void autoIncEnd(
sqlite3VdbeAddOp4(v, OP_String8, 0, 0, 0, pTab->zName, 0); sqlite3VdbeAddOp4(v, OP_String8, 0, 0, 0, pTab->zName, 0);
sqlite3VdbeAddOp2(v, OP_MemLoad, memId, 0); sqlite3VdbeAddOp2(v, OP_MemLoad, memId, 0);
sqlite3VdbeAddOp2(v, OP_MakeRecord, 2, 0); sqlite3VdbeAddOp2(v, OP_MakeRecord, 2, 0);
sqlite3VdbeAddOp2(v, OP_Insert, iCur, OPFLAG_APPEND); sqlite3CodeInsert(pParse, iCur, OPFLAG_APPEND);
sqlite3VdbeAddOp2(v, OP_Close, iCur, 0); sqlite3VdbeAddOp2(v, OP_Close, iCur, 0);
} }
} }
@@ -511,7 +511,7 @@ void sqlite3Insert(
sqlite3VdbeAddOp2(v, OP_MakeRecord, nColumn, 0); sqlite3VdbeAddOp2(v, OP_MakeRecord, nColumn, 0);
sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, 0); sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, 0);
sqlite3VdbeAddOp2(v, OP_Pull, 1, 0); sqlite3VdbeAddOp2(v, OP_Pull, 1, 0);
sqlite3VdbeAddOp2(v, OP_Insert, srcTab, OPFLAG_APPEND); sqlite3CodeInsert(pParse, srcTab, OPFLAG_APPEND);
sqlite3VdbeAddOp2(v, OP_Return, 0, 0); sqlite3VdbeAddOp2(v, OP_Return, 0, 0);
/* The following code runs first because the GOTO at the very top /* The following code runs first because the GOTO at the very top
@@ -701,7 +701,7 @@ void sqlite3Insert(
if( !isView ){ if( !isView ){
sqlite3TableAffinityStr(v, pTab); sqlite3TableAffinityStr(v, pTab);
} }
sqlite3VdbeAddOp2(v, OP_Insert, newIdx, 0); sqlite3CodeInsert(pParse, newIdx, OPFLAG_APPEND);
/* Fire BEFORE or INSTEAD OF triggers */ /* Fire BEFORE or INSTEAD OF triggers */
if( sqlite3CodeRowTrigger(pParse, TK_INSERT, 0, TRIGGER_BEFORE, pTab, if( sqlite3CodeRowTrigger(pParse, TK_INSERT, 0, TRIGGER_BEFORE, pTab,
@@ -1231,7 +1231,7 @@ void sqlite3CompleteInsertion(
if( newIdx>=0 ){ if( newIdx>=0 ){
sqlite3VdbeAddOp2(v, OP_Dup, 1, 0); sqlite3VdbeAddOp2(v, OP_Dup, 1, 0);
sqlite3VdbeAddOp2(v, OP_Dup, 1, 0); sqlite3VdbeAddOp2(v, OP_Dup, 1, 0);
sqlite3VdbeAddOp2(v, OP_Insert, newIdx, 0); sqlite3CodeInsert(pParse, newIdx, 0);
} }
#endif #endif
if( pParse->nested ){ if( pParse->nested ){
@@ -1243,7 +1243,7 @@ void sqlite3CompleteInsertion(
if( appendBias ){ if( appendBias ){
pik_flags |= OPFLAG_APPEND; pik_flags |= OPFLAG_APPEND;
} }
sqlite3VdbeAddOp2(v, OP_Insert, base, pik_flags); sqlite3CodeInsert(pParse, base, pik_flags);
if( !pParse->nested ){ if( !pParse->nested ){
sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC); sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC);
} }
@@ -1563,9 +1563,8 @@ static int xferOptimization(
assert( pDest->autoInc==0 ); assert( pDest->autoInc==0 );
} }
sqlite3VdbeAddOp2(v, OP_RowData, iSrc, 0); sqlite3VdbeAddOp2(v, OP_RowData, iSrc, 0);
sqlite3VdbeAddOp4(v, OP_Insert, iDest, 0, sqlite3CodeInsert(pParse,iDest,OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND);
OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND, sqlite3VdbeChangeP4(v, -1, pDest->zName, 0);
pDest->zName, 0);
sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1);
autoIncEnd(pParse, iDbDest, pDest, counterMem); autoIncEnd(pParse, iDbDest, pDest, counterMem);
for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){ for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){

View File

@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser ** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite. ** to handle SELECT statements in SQLite.
** **
** $Id: select.c,v 1.379 2008/01/03 07:54:24 danielk1977 Exp $ ** $Id: select.c,v 1.380 2008/01/03 09:51:55 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -613,7 +613,7 @@ static int selectInnerLoop(
}else{ }else{
sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, 0); sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, 0);
sqlite3VdbeAddOp2(v, OP_Pull, 1, 0); sqlite3VdbeAddOp2(v, OP_Pull, 1, 0);
sqlite3VdbeAddOp2(v, OP_Insert, iParm, OPFLAG_APPEND); sqlite3CodeInsert(pParse, iParm, OPFLAG_APPEND);
} }
break; break;
} }
@@ -791,7 +791,7 @@ static void generateSortTail(
case SRT_EphemTab: { case SRT_EphemTab: {
sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, 0); sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, 0);
sqlite3VdbeAddOp2(v, OP_Pull, 1, 0); sqlite3VdbeAddOp2(v, OP_Pull, 1, 0);
sqlite3VdbeAddOp2(v, OP_Insert, iParm, OPFLAG_APPEND); sqlite3CodeInsert(pParse, iParm, OPFLAG_APPEND);
break; break;
} }
#ifndef SQLITE_OMIT_SUBQUERY #ifndef SQLITE_OMIT_SUBQUERY
@@ -814,7 +814,7 @@ static void generateSortTail(
case SRT_Callback: case SRT_Callback:
case SRT_Subroutine: { case SRT_Subroutine: {
int i; int i;
sqlite3VdbeAddOp2(v, OP_Insert, pseudoTab, 0); sqlite3CodeInsert(pParse, pseudoTab, 0);
for(i=0; i<nColumn; i++){ for(i=0; i<nColumn; i++){
sqlite3VdbeAddOp2(v, OP_Column, pseudoTab, i); sqlite3VdbeAddOp2(v, OP_Column, pseudoTab, i);
} }

View File

@@ -11,7 +11,7 @@
************************************************************************* *************************************************************************
** Internal interface definitions for SQLite. ** Internal interface definitions for SQLite.
** **
** @(#) $Id: sqliteInt.h,v 1.631 2008/01/03 00:01:25 drh Exp $ ** @(#) $Id: sqliteInt.h,v 1.632 2008/01/03 09:51:55 danielk1977 Exp $
*/ */
#ifndef _SQLITEINT_H_ #ifndef _SQLITEINT_H_
#define _SQLITEINT_H_ #define _SQLITEINT_H_
@@ -1918,6 +1918,7 @@ int sqlite3OpenTempDatabase(Parse *);
void sqlite3StrAccumAppend(StrAccum*,const char*,int); void sqlite3StrAccumAppend(StrAccum*,const char*,int);
char *sqlite3StrAccumFinish(StrAccum*); char *sqlite3StrAccumFinish(StrAccum*);
void sqlite3StrAccumReset(StrAccum*); void sqlite3StrAccumReset(StrAccum*);
void sqlite3CodeInsert(Parse *, int, u8);
/* /*

View File

@@ -237,10 +237,14 @@ void sqlite3FinishTrigger(
{ OP_String8, 0, 0, 0 }, /* 6: SQL */ { OP_String8, 0, 0, 0 }, /* 6: SQL */
{ OP_Concat, 0, 0, 0 }, { OP_Concat, 0, 0, 0 },
{ OP_MakeRecord, 5, 0, 0 }, /* 8: "aaada" */ { OP_MakeRecord, 5, 0, 0 }, /* 8: "aaada" */
{ OP_MemStore, 0, 1, 0 }, /* 9: Store data */
{ OP_MemStore, 0, 1, 0 }, /* 10: Store key */
{ OP_Insert, 0, 0, 0 }, { OP_Insert, 0, 0, 0 },
}; };
int addr; int addr;
Vdbe *v; Vdbe *v;
int iKey = pParse->nMem++;
int iData = pParse->nMem++;
/* Make an entry in the sqlite_master table */ /* Make an entry in the sqlite_master table */
v = sqlite3GetVdbe(pParse); v = sqlite3GetVdbe(pParse);
@@ -254,6 +258,10 @@ void sqlite3FinishTrigger(
sqlite3VdbeChangeP4(v, addr+5, "CREATE TRIGGER ", P4_STATIC); sqlite3VdbeChangeP4(v, addr+5, "CREATE TRIGGER ", P4_STATIC);
sqlite3VdbeChangeP4(v, addr+6, (char*)pAll->z, pAll->n); sqlite3VdbeChangeP4(v, addr+6, (char*)pAll->z, pAll->n);
sqlite3VdbeChangeP4(v, addr+8, "aaada", P4_STATIC); sqlite3VdbeChangeP4(v, addr+8, "aaada", P4_STATIC);
sqlite3VdbeChangeP1(v, addr+9, iData);
sqlite3VdbeChangeP2(v, addr+11, iData);
sqlite3VdbeChangeP1(v, addr+10, iKey);
sqlite3VdbeChangeP3(v, addr+11, iKey);
sqlite3ChangeCookie(db, v, iDb); sqlite3ChangeCookie(db, v, iDb);
sqlite3VdbeAddOp2(v, OP_Close, 0, 0); sqlite3VdbeAddOp2(v, OP_Close, 0, 0);
sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 0, 0, sqlite3MPrintf( sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 0, 0, sqlite3MPrintf(

View File

@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser ** This file contains C code routines that are called by the parser
** to handle UPDATE statements. ** to handle UPDATE statements.
** **
** $Id: update.c,v 1.151 2008/01/03 08:08:40 danielk1977 Exp $ ** $Id: update.c,v 1.152 2008/01/03 09:51:55 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -410,7 +410,7 @@ void sqlite3Update(
}else{ }else{
sqlite3VdbeAddOp2(v, OP_RowData, iCur, 0); sqlite3VdbeAddOp2(v, OP_RowData, iCur, 0);
} }
sqlite3VdbeAddOp2(v, OP_Insert, oldIdx, 0); sqlite3CodeInsert(pParse, oldIdx, 0);
/* Generate the NEW table /* Generate the NEW table
*/ */
@@ -441,7 +441,7 @@ void sqlite3Update(
sqlite3TableAffinityStr(v, pTab); sqlite3TableAffinityStr(v, pTab);
} }
if( pParse->nErr ) goto update_cleanup; if( pParse->nErr ) goto update_cleanup;
sqlite3VdbeAddOp2(v, OP_Insert, newIdx, 0); sqlite3CodeInsert(pParse, newIdx, 0);
sqlite3VdbeAddOp2(v, OP_Goto, 0, iBeginBeforeTrigger); sqlite3VdbeAddOp2(v, OP_Goto, 0, iBeginBeforeTrigger);
sqlite3VdbeJumpHere(v, iEndBeforeTrigger); sqlite3VdbeJumpHere(v, iEndBeforeTrigger);

View File

@@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing ** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code. ** commenting and indentation practices when changing or adding code.
** **
** $Id: vdbe.c,v 1.667 2008/01/03 08:08:40 danielk1977 Exp $ ** $Id: vdbe.c,v 1.668 2008/01/03 09:51:55 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <ctype.h> #include <ctype.h>
@@ -2043,12 +2043,9 @@ case OP_SetNumColumns: { /* no-push */
** If the KeyAsData opcode has previously executed on this cursor, then the ** If the KeyAsData opcode has previously executed on this cursor, then the
** field might be extracted from the key rather than the data. ** field might be extracted from the key rather than the data.
** **
** If the column contains fewer than P2 fields, then extract a NULL. Or ** If the column contains fewer than P2 fields, then extract a NULL. Or,
** if the next instruction is OP_DfltValue then the P4 argument to the ** if the P4 argument is a P4_MEM use the value of the P4 argument as
** OP_DfltValue instruction will be a P4_MEM. Use the P4 argument of ** the result.
** the OP_DfltValue instruction as the extracted value instead of NULL.
** The OP_DfltValue P4 value will be a default value for a column
** that has been added using the ALTER TABLE ADD COLUMN command.
*/ */
case OP_Column: { case OP_Column: {
u32 payloadSize; /* Number of bytes in the record */ u32 payloadSize; /* Number of bytes in the record */
@@ -3560,16 +3557,16 @@ case OP_NewRowid: {
break; break;
} }
/* Opcode: Insert P1 P2 P4 /* Opcode: Insert P1 P2 P3 P4 P5
** **
** Write an entry into the table of cursor P1. A new entry is ** Write an entry into the table of cursor P1. A new entry is
** created if it doesn't already exist or the data for an existing ** created if it doesn't already exist or the data for an existing
** entry is overwritten. The data is the value on the top of the ** entry is overwritten. The data is the value stored register
** stack. The key is the next value down on the stack. The key must ** number P2. The key is stored in register P3. The key must
** be an integer. The stack is popped twice by this instruction. ** be an integer.
** **
** If the OPFLAG_NCHANGE flag of P2 is set, then the row change count is ** If the OPFLAG_NCHANGE flag of P5 is set, then the row change count is
** incremented (otherwise not). If the OPFLAG_LASTROWID flag of P2 is set, ** incremented (otherwise not). If the OPFLAG_LASTROWID flag of P5 is set,
** then rowid is stored for subsequent return by the ** then rowid is stored for subsequent return by the
** sqlite3_last_insert_rowid() function (otherwise it is unmodified). ** sqlite3_last_insert_rowid() function (otherwise it is unmodified).
** **
@@ -3581,55 +3578,56 @@ case OP_NewRowid: {
** for indices is OP_IdxInsert. ** for indices is OP_IdxInsert.
*/ */
case OP_Insert: { /* no-push */ case OP_Insert: { /* no-push */
Mem *pNos = &pTos[-1]; Mem *pData = &p->aMem[pOp->p2];
Mem *pKey = &p->aMem[pOp->p3];
int i = pOp->p1; int i = pOp->p1;
Cursor *pC; Cursor *pC;
assert( pNos>=p->aStack );
assert( i>=0 && i<p->nCursor ); assert( i>=0 && i<p->nCursor );
assert( p->apCsr[i]!=0 ); assert( p->apCsr[i]!=0 );
if( ((pC = p->apCsr[i])->pCursor!=0 || pC->pseudoTable) ){ if( ((pC = p->apCsr[i])->pCursor!=0 || pC->pseudoTable) ){
i64 iKey; /* The integer ROWID or key for the record to be inserted */ i64 iKey; /* The integer ROWID or key for the record to be inserted */
assert( pNos->flags & MEM_Int ); assert( pKey->flags & MEM_Int );
assert( pC->isTable ); assert( pC->isTable );
iKey = intToKey(pNos->u.i); iKey = intToKey(pKey->u.i);
if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++; if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
if( pOp->p2 & OPFLAG_LASTROWID ) db->lastRowid = pNos->u.i; if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = pKey->u.i;
if( pC->nextRowidValid && pNos->u.i>=pC->nextRowid ){ if( pC->nextRowidValid && pKey->u.i>=pC->nextRowid ){
pC->nextRowidValid = 0; pC->nextRowidValid = 0;
} }
if( pTos->flags & MEM_Null ){ if( pData->flags & MEM_Null ){
pTos->z = 0; pData->z = 0;
pTos->n = 0; pData->n = 0;
}else{ }else{
assert( pTos->flags & (MEM_Blob|MEM_Str) ); assert( pData->flags & (MEM_Blob|MEM_Str) );
} }
if( pC->pseudoTable ){ if( pC->pseudoTable ){
sqlite3_free(pC->pData); sqlite3_free(pC->pData);
pC->iKey = iKey; pC->iKey = iKey;
pC->nData = pTos->n; pC->nData = pData->n;
if( pTos->flags & MEM_Dyn ){ if( pData->flags & MEM_Dyn ){
pC->pData = pTos->z; pC->pData = pData->z;
pTos->flags = MEM_Null; pData->flags = MEM_Null;
}else{ }else{
pC->pData = sqlite3_malloc( pC->nData+2 ); pC->pData = sqlite3_malloc( pC->nData+2 );
if( !pC->pData ) goto no_mem; if( !pC->pData ) goto no_mem;
memcpy(pC->pData, pTos->z, pC->nData); memcpy(pC->pData, pData->z, pC->nData);
pC->pData[pC->nData] = 0; pC->pData[pC->nData] = 0;
pC->pData[pC->nData+1] = 0; pC->pData[pC->nData+1] = 0;
} }
pC->nullRow = 0; pC->nullRow = 0;
}else{ }else{
int nZero; int nZero;
if( pTos->flags & MEM_Zero ){ if( pData->flags & MEM_Zero ){
nZero = pTos->u.i; nZero = pData->u.i;
}else{ }else{
nZero = 0; nZero = 0;
} }
rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey, rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
pTos->z, pTos->n, nZero, pData->z, pData->n, nZero,
pOp->p2 & OPFLAG_APPEND); pOp->p5 & OPFLAG_APPEND);
} }
pC->rowidIsValid = 0; pC->rowidIsValid = 0;
@@ -3640,13 +3638,12 @@ case OP_Insert: { /* no-push */
if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.p ){ if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.p ){
const char *zDb = db->aDb[pC->iDb].zName; const char *zDb = db->aDb[pC->iDb].zName;
const char *zTbl = pOp->p4.p; const char *zTbl = pOp->p4.p;
int op = ((pOp->p2 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT); int op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
assert( pC->isTable ); assert( pC->isTable );
db->xUpdateCallback(db->pUpdateArg, op, zDb, zTbl, iKey); db->xUpdateCallback(db->pUpdateArg, op, zDb, zTbl, iKey);
assert( pC->iDb>=0 ); assert( pC->iDb>=0 );
} }
} }
popStack(&pTos, 2);
break; break;
} }

View File

@@ -15,7 +15,7 @@
** or VDBE. The VDBE implements an abstract machine that runs a ** or VDBE. The VDBE implements an abstract machine that runs a
** simple program to access and modify the underlying database. ** simple program to access and modify the underlying database.
** **
** $Id: vdbe.h,v 1.120 2008/01/03 07:54:24 danielk1977 Exp $ ** $Id: vdbe.h,v 1.121 2008/01/03 09:51:55 danielk1977 Exp $
*/ */
#ifndef _SQLITE_VDBE_H_ #ifndef _SQLITE_VDBE_H_
#define _SQLITE_VDBE_H_ #define _SQLITE_VDBE_H_
@@ -133,7 +133,8 @@ int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp); int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1); void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2); void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
void sqlite3VdbeChangeP3(Vdbe*, int addr, int P2); void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3);
void sqlite3VdbeChangeP5(Vdbe*, int addr, u8 P5);
void sqlite3VdbeJumpHere(Vdbe*, int addr); void sqlite3VdbeJumpHere(Vdbe*, int addr);
void sqlite3VdbeChangeToNoop(Vdbe*, int addr, int N); void sqlite3VdbeChangeToNoop(Vdbe*, int addr, int N);
void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N); void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);

View File

@@ -438,8 +438,7 @@ void sqlite3VdbeChangeP2(Vdbe *p, int addr, int val){
} }
/* /*
** Change the value of the P2 operand for a specific instruction. ** Change the value of the P3 operand for a specific instruction.
** This routine is useful for setting a jump destination.
*/ */
void sqlite3VdbeChangeP3(Vdbe *p, int addr, int val){ void sqlite3VdbeChangeP3(Vdbe *p, int addr, int val){
assert( p==0 || p->magic==VDBE_MAGIC_INIT ); assert( p==0 || p->magic==VDBE_MAGIC_INIT );
@@ -448,6 +447,16 @@ void sqlite3VdbeChangeP3(Vdbe *p, int addr, int val){
} }
} }
/*
** Change the value of the P3 operand for a specific instruction.
*/
void sqlite3VdbeChangeP5(Vdbe *p, int addr, u8 val){
assert( p==0 || p->magic==VDBE_MAGIC_INIT );
if( p && addr>=0 && p->nOp>addr && p->aOp ){
p->aOp[addr].p5 = val;
}
}
/* /*
** Change the P2 operand of instruction addr so that it points to ** Change the P2 operand of instruction addr so that it points to
** the address of the next instruction to be coded. ** the address of the next instruction to be coded.