mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Simplify the sqlite3BtreeInsert() interface by gathering the five arguments
describing the content to be inserted into the new BtreePayload structure, and thus reducing the number of parameters from eight to four. FossilOrigin-Name: 55f348cdd24c7812ea4b63345514764b69f64dc8
This commit is contained in:
18
manifest
18
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Remove\ssome\sunused\slegacy\scode\sfrom\sthe\sbtree\sinsert\slogic.
|
C Simplify\sthe\ssqlite3BtreeInsert()\sinterface\sby\sgathering\sthe\sfive\sarguments\ndescribing\sthe\scontent\sto\sbe\sinserted\sinto\sthe\snew\sBtreePayload\sstructure,\sand\nthus\sreducing\sthe\snumber\sof\sparameters\sfrom\seight\sto\sfour.
|
||||||
D 2016-05-21T19:10:21.800
|
D 2016-05-21T20:03:42.980
|
||||||
F Makefile.in f59e0763ff448719fc1bd25513882b0567286317
|
F Makefile.in f59e0763ff448719fc1bd25513882b0567286317
|
||||||
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
||||||
F Makefile.msc 306d73e854b1a92ea06e5d1e637faa5c44de53c7
|
F Makefile.msc 306d73e854b1a92ea06e5d1e637faa5c44de53c7
|
||||||
@@ -322,8 +322,8 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240
|
|||||||
F src/backup.c 6df65fdd569c901a418887a1a76f82ec35044556
|
F src/backup.c 6df65fdd569c901a418887a1a76f82ec35044556
|
||||||
F src/bitvec.c 3ee4c8b2c94ed3a7377256e18199e6ff5cf33f63
|
F src/bitvec.c 3ee4c8b2c94ed3a7377256e18199e6ff5cf33f63
|
||||||
F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73
|
F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73
|
||||||
F src/btree.c 09df167470e82b34f92d60cdd1a44f397ae8e105
|
F src/btree.c e312cc3fdff31fdcc727b973fa0f195573b86393
|
||||||
F src/btree.h a5008b9afe56e8e54ade6c436a910f112defcca9
|
F src/btree.h 1342a9b2cc2089e3534d3ef00204786783f6aea6
|
||||||
F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5
|
F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5
|
||||||
F src/build.c 785fa789319d93c6ae20efbd01d4da9ce8f8a793
|
F src/build.c 785fa789319d93c6ae20efbd01d4da9ce8f8a793
|
||||||
F src/callback.c 2e76147783386374bf01b227f752c81ec872d730
|
F src/callback.c 2e76147783386374bf01b227f752c81ec872d730
|
||||||
@@ -390,7 +390,7 @@ F src/table.c 5226df15ab9179b9ed558d89575ea0ce37b03fc9
|
|||||||
F src/tclsqlite.c 9c4c4589d078de37813ded708d8838b338ffb060
|
F src/tclsqlite.c 9c4c4589d078de37813ded708d8838b338ffb060
|
||||||
F src/test1.c c0e5b69f99e95a2c9f55fdb6e46b44f1a15292d8
|
F src/test1.c c0e5b69f99e95a2c9f55fdb6e46b44f1a15292d8
|
||||||
F src/test2.c 5586f43fcd9a1be0830793cf9d354082c261b25b
|
F src/test2.c 5586f43fcd9a1be0830793cf9d354082c261b25b
|
||||||
F src/test3.c 0df6f8dbb4cbaa7106397c70a271fa6a43659042
|
F src/test3.c d2c9efd2985ff8f5502ffd3253156984778d77d8
|
||||||
F src/test4.c d168f83cc78d02e8d35567bb5630e40dcd85ac1e
|
F src/test4.c d168f83cc78d02e8d35567bb5630e40dcd85ac1e
|
||||||
F src/test5.c 5a34feec76d9b3a86aab30fd4f6cc9c48cbab4c1
|
F src/test5.c 5a34feec76d9b3a86aab30fd4f6cc9c48cbab4c1
|
||||||
F src/test6.c 2c014d4977efd6107ec9eef3dfdec56ac516f824
|
F src/test6.c 2c014d4977efd6107ec9eef3dfdec56ac516f824
|
||||||
@@ -444,7 +444,7 @@ F src/update.c 4f05ea8cddfa367d045e03589756c02199e8f9bd
|
|||||||
F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c
|
F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c
|
||||||
F src/util.c 810ec3f22e2d1b62e66c30fe3621ebdedd23584d
|
F src/util.c 810ec3f22e2d1b62e66c30fe3621ebdedd23584d
|
||||||
F src/vacuum.c feb1eabb20987983d9350cad98299b21fa811f52
|
F src/vacuum.c feb1eabb20987983d9350cad98299b21fa811f52
|
||||||
F src/vdbe.c 975ac1d3d326bcb36b4e99255daeaf81ff6659d1
|
F src/vdbe.c f2706d5564d2b2887a27c909e8e1575250029503
|
||||||
F src/vdbe.h 5591b5add447096e31288b5a0a78ec5d7b5c5170
|
F src/vdbe.h 5591b5add447096e31288b5a0a78ec5d7b5c5170
|
||||||
F src/vdbeInt.h ddb157974436d87652de7dc641f7191496d9a8cd
|
F src/vdbeInt.h ddb157974436d87652de7dc641f7191496d9a8cd
|
||||||
F src/vdbeapi.c ba85b78fe08dc4a9ce747e62c89a2b4a4547e74c
|
F src/vdbeapi.c ba85b78fe08dc4a9ce747e62c89a2b4a4547e74c
|
||||||
@@ -1492,7 +1492,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
|||||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||||
P 1dbaf7a119edc5150a5d4be1b72f652a574e5bc5
|
P 2ce1166717ac3c0cec37b2f6d70d8359fbaefc71
|
||||||
R 46d65e39155fd1bfd348824fd7a5487b
|
R 560ed5c35c4c6718e1a252b0b3f02845
|
||||||
U drh
|
U drh
|
||||||
Z 20edc765018d44eea5900b69fe208cfe
|
Z ca823f4324bb11c74d57e3f017091386
|
||||||
|
@@ -1 +1 @@
|
|||||||
2ce1166717ac3c0cec37b2f6d70d8359fbaefc71
|
55f348cdd24c7812ea4b63345514764b69f64dc8
|
69
src/btree.c
69
src/btree.c
@@ -6072,9 +6072,7 @@ static int clearCell(
|
|||||||
static int fillInCell(
|
static int fillInCell(
|
||||||
MemPage *pPage, /* The page that contains the cell */
|
MemPage *pPage, /* The page that contains the cell */
|
||||||
unsigned char *pCell, /* Complete text of the cell */
|
unsigned char *pCell, /* Complete text of the cell */
|
||||||
const void *pKey, i64 nKey, /* The key */
|
const BtreePayload *pX, /* Payload with which to construct the cell */
|
||||||
const void *pData,int nData, /* The data */
|
|
||||||
int nZero, /* Extra zero bytes to append to pData */
|
|
||||||
int *pnSize /* Write cell size here */
|
int *pnSize /* Write cell size here */
|
||||||
){
|
){
|
||||||
int nPayload;
|
int nPayload;
|
||||||
@@ -6098,24 +6096,23 @@ static int fillInCell(
|
|||||||
|
|
||||||
/* Fill in the header. */
|
/* Fill in the header. */
|
||||||
nHeader = pPage->childPtrSize;
|
nHeader = pPage->childPtrSize;
|
||||||
nPayload = nData + nZero;
|
nPayload = pX->nData + pX->nZero;
|
||||||
if( pPage->intKeyLeaf ){
|
if( pPage->intKeyLeaf ){
|
||||||
nHeader += putVarint32(&pCell[nHeader], nPayload);
|
nHeader += putVarint32(&pCell[nHeader], nPayload);
|
||||||
}else{
|
}else{
|
||||||
assert( nData==0 );
|
assert( pX->nData==0 );
|
||||||
assert( nZero==0 );
|
assert( pX->nZero==0 );
|
||||||
}
|
}
|
||||||
nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
|
nHeader += putVarint(&pCell[nHeader], *(u64*)&pX->nKey);
|
||||||
|
|
||||||
/* Fill in the payload size */
|
/* Fill in the payload */
|
||||||
if( pPage->intKey ){
|
if( pPage->intKey ){
|
||||||
pSrc = pData;
|
pSrc = pX->pData;
|
||||||
nSrc = nData;
|
nSrc = pX->nData;
|
||||||
}else{
|
}else{
|
||||||
assert( nKey<=0x7fffffff && pKey!=0 );
|
assert( pX->nKey<=0x7fffffff && pX->pKey!=0 );
|
||||||
nPayload = (int)nKey;
|
nSrc = nPayload = (int)pX->nKey;
|
||||||
pSrc = pKey;
|
pSrc = pX->pKey;
|
||||||
nSrc = (int)nKey;
|
|
||||||
}
|
}
|
||||||
if( nPayload<=pPage->maxLocal ){
|
if( nPayload<=pPage->maxLocal ){
|
||||||
n = nHeader + nPayload;
|
n = nHeader + nPayload;
|
||||||
@@ -6154,7 +6151,7 @@ static int fillInCell(
|
|||||||
CellInfo info;
|
CellInfo info;
|
||||||
pPage->xParseCell(pPage, pCell, &info);
|
pPage->xParseCell(pPage, pCell, &info);
|
||||||
assert( nHeader==(int)(info.pPayload - pCell) );
|
assert( nHeader==(int)(info.pPayload - pCell) );
|
||||||
assert( info.nKey==nKey );
|
assert( info.nKey==pX->nKey );
|
||||||
assert( *pnSize == info.nSize );
|
assert( *pnSize == info.nSize );
|
||||||
assert( spaceLeft == info.nLocal );
|
assert( spaceLeft == info.nLocal );
|
||||||
}
|
}
|
||||||
@@ -7923,13 +7920,19 @@ static int balance(BtCursor *pCur){
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Insert a new record into the BTree. The key is given by (pKey,nKey)
|
** Insert a new record into the BTree. The content of the new record
|
||||||
** and the data is given by (pData,nData). The cursor is used only to
|
** is described by the pX object. The pCur cursor is used only to
|
||||||
** define what table the record should be inserted into. The cursor
|
** define what table the record should be inserted into, and is left
|
||||||
** is left pointing at a random location.
|
** pointing at a random location.
|
||||||
**
|
**
|
||||||
** For an INTKEY table, only the nKey value of the key is used. pKey is
|
** For a table btree (used for rowid tables), only the pX.nKey value of
|
||||||
** ignored. For a ZERODATA table, the pData and nData are both ignored.
|
** the key is used. The pX.pKey value must be NULL. The pX.nKey is the
|
||||||
|
** rowid or INTEGER PRIMARY KEY of the row. The pX.nData,pData,nZero fields
|
||||||
|
** hold the content of the row.
|
||||||
|
**
|
||||||
|
** For an index btree (used for indexes and WITHOUT ROWID tables), the
|
||||||
|
** key is an arbitrary byte sequence stored in pX.pKey,nKey. The
|
||||||
|
** pX.pData,nData,nZero fields must be zero.
|
||||||
**
|
**
|
||||||
** If the seekResult parameter is non-zero, then a successful call to
|
** If the seekResult parameter is non-zero, then a successful call to
|
||||||
** MovetoUnpacked() to seek cursor pCur to (pKey, nKey) has already
|
** MovetoUnpacked() to seek cursor pCur to (pKey, nKey) has already
|
||||||
@@ -7946,9 +7949,7 @@ static int balance(BtCursor *pCur){
|
|||||||
*/
|
*/
|
||||||
int sqlite3BtreeInsert(
|
int sqlite3BtreeInsert(
|
||||||
BtCursor *pCur, /* Insert data into the table of this cursor */
|
BtCursor *pCur, /* Insert data into the table of this cursor */
|
||||||
const void *pKey, i64 nKey, /* The key of the new record */
|
const BtreePayload *pX, /* Content of the row to be inserted */
|
||||||
const void *pData, int nData, /* The data of the new record */
|
|
||||||
int nZero, /* Number of extra 0 bytes to append to data */
|
|
||||||
int appendBias, /* True if this is likely an append */
|
int appendBias, /* True if this is likely an append */
|
||||||
int seekResult /* Result of prior MovetoUnpacked() call */
|
int seekResult /* Result of prior MovetoUnpacked() call */
|
||||||
){
|
){
|
||||||
@@ -7978,7 +7979,7 @@ int sqlite3BtreeInsert(
|
|||||||
** keys with no associated data. If the cursor was opened expecting an
|
** keys with no associated data. If the cursor was opened expecting an
|
||||||
** intkey table, the caller should be inserting integer keys with a
|
** intkey table, the caller should be inserting integer keys with a
|
||||||
** blob of associated data. */
|
** blob of associated data. */
|
||||||
assert( (pKey==0)==(pCur->pKeyInfo==0) );
|
assert( (pX->pKey==0)==(pCur->pKeyInfo==0) );
|
||||||
|
|
||||||
/* Save the positions of any other cursors open on this table.
|
/* Save the positions of any other cursors open on this table.
|
||||||
**
|
**
|
||||||
@@ -7997,38 +7998,38 @@ int sqlite3BtreeInsert(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( pCur->pKeyInfo==0 ){
|
if( pCur->pKeyInfo==0 ){
|
||||||
assert( pKey==0 );
|
assert( pX->pKey==0 );
|
||||||
/* If this is an insert into a table b-tree, invalidate any incrblob
|
/* If this is an insert into a table b-tree, invalidate any incrblob
|
||||||
** cursors open on the row being replaced */
|
** cursors open on the row being replaced */
|
||||||
invalidateIncrblobCursors(p, nKey, 0);
|
invalidateIncrblobCursors(p, pX->nKey, 0);
|
||||||
|
|
||||||
/* If the cursor is currently on the last row and we are appending a
|
/* If the cursor is currently on the last row and we are appending a
|
||||||
** new row onto the end, set the "loc" to avoid an unnecessary
|
** new row onto the end, set the "loc" to avoid an unnecessary
|
||||||
** btreeMoveto() call */
|
** btreeMoveto() call */
|
||||||
if( (pCur->curFlags&BTCF_ValidNKey)!=0 && nKey>0
|
if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0
|
||||||
&& pCur->info.nKey==nKey-1 ){
|
&& pCur->info.nKey==pX->nKey-1 ){
|
||||||
loc = -1;
|
loc = -1;
|
||||||
}else if( loc==0 ){
|
}else if( loc==0 ){
|
||||||
rc = sqlite3BtreeMovetoUnpacked(pCur, 0, nKey, appendBias, &loc);
|
rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, appendBias, &loc);
|
||||||
if( rc ) return rc;
|
if( rc ) return rc;
|
||||||
}
|
}
|
||||||
}else if( loc==0 ){
|
}else if( loc==0 ){
|
||||||
rc = btreeMoveto(pCur, pKey, nKey, appendBias, &loc);
|
rc = btreeMoveto(pCur, pX->pKey, pX->nKey, appendBias, &loc);
|
||||||
if( rc ) return rc;
|
if( rc ) return rc;
|
||||||
}
|
}
|
||||||
assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
|
assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
|
||||||
|
|
||||||
pPage = pCur->apPage[pCur->iPage];
|
pPage = pCur->apPage[pCur->iPage];
|
||||||
assert( pPage->intKey || nKey>=0 );
|
assert( pPage->intKey || pX->nKey>=0 );
|
||||||
assert( pPage->leaf || !pPage->intKey );
|
assert( pPage->leaf || !pPage->intKey );
|
||||||
|
|
||||||
TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
|
TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
|
||||||
pCur->pgnoRoot, nKey, nData, pPage->pgno,
|
pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
|
||||||
loc==0 ? "overwrite" : "new entry"));
|
loc==0 ? "overwrite" : "new entry"));
|
||||||
assert( pPage->isInit );
|
assert( pPage->isInit );
|
||||||
newCell = pBt->pTmpSpace;
|
newCell = pBt->pTmpSpace;
|
||||||
assert( newCell!=0 );
|
assert( newCell!=0 );
|
||||||
rc = fillInCell(pPage, newCell, pKey, nKey, pData, nData, nZero, &szNew);
|
rc = fillInCell(pPage, newCell, pX, &szNew);
|
||||||
if( rc ) goto end_insert;
|
if( rc ) goto end_insert;
|
||||||
assert( szNew==pPage->xCellSize(pPage, newCell) );
|
assert( szNew==pPage->xCellSize(pPage, newCell) );
|
||||||
assert( szNew <= MX_CELL_SIZE(pBt) );
|
assert( szNew <= MX_CELL_SIZE(pBt) );
|
||||||
|
32
src/btree.h
32
src/btree.h
@@ -39,6 +39,7 @@
|
|||||||
typedef struct Btree Btree;
|
typedef struct Btree Btree;
|
||||||
typedef struct BtCursor BtCursor;
|
typedef struct BtCursor BtCursor;
|
||||||
typedef struct BtShared BtShared;
|
typedef struct BtShared BtShared;
|
||||||
|
typedef struct BtreePayload BtreePayload;
|
||||||
|
|
||||||
|
|
||||||
int sqlite3BtreeOpen(
|
int sqlite3BtreeOpen(
|
||||||
@@ -250,9 +251,34 @@ int sqlite3BtreeDelete(BtCursor*, u8 flags);
|
|||||||
#define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */
|
#define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */
|
||||||
#define BTREE_AUXDELETE 0x04 /* not the primary delete operation */
|
#define BTREE_AUXDELETE 0x04 /* not the primary delete operation */
|
||||||
|
|
||||||
int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
|
/* An instance of the BtreePayload object describes the content of a single
|
||||||
const void *pData, int nData,
|
** entry in either an index or table btree.
|
||||||
int nZero, int bias, int seekResult);
|
**
|
||||||
|
** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
|
||||||
|
** an arbitrary key and no data. These btrees have pKey,nKey set to their
|
||||||
|
** key and pData,nData,nZero set to zero.
|
||||||
|
**
|
||||||
|
** Table btrees (used for rowid tables) contain an integer rowid used as
|
||||||
|
** the key and passed in the nKey field. The pKey field is zero.
|
||||||
|
** pData,nData hold the content of the new entry. nZero extra zero bytes
|
||||||
|
** are appended to the end of the content when constructing the entry.
|
||||||
|
**
|
||||||
|
** This object is used to pass information into sqlite3BtreeInsert(). The
|
||||||
|
** same information used to be passed as five separate parameters. But placing
|
||||||
|
** the information into this object helps to keep the interface more
|
||||||
|
** organized and understandable, and it also helps the resulting code to
|
||||||
|
** run a little faster by using fewer registers for parameter passing.
|
||||||
|
*/
|
||||||
|
struct BtreePayload {
|
||||||
|
const void *pKey; /* Key content for indexes. NULL for tables */
|
||||||
|
sqlite3_int64 nKey; /* Size of pKey for indexes. PRIMARY KEY for tabs */
|
||||||
|
const void *pData; /* Data for tables. NULL for indexes */
|
||||||
|
int nData; /* Size of pData. 0 if none. */
|
||||||
|
int nZero; /* Extra zero data appended after pData,nData */
|
||||||
|
};
|
||||||
|
|
||||||
|
int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
|
||||||
|
int bias, int seekResult);
|
||||||
int sqlite3BtreeFirst(BtCursor*, int *pRes);
|
int sqlite3BtreeFirst(BtCursor*, int *pRes);
|
||||||
int sqlite3BtreeLast(BtCursor*, int *pRes);
|
int sqlite3BtreeLast(BtCursor*, int *pRes);
|
||||||
int sqlite3BtreeNext(BtCursor*, int *pRes);
|
int sqlite3BtreeNext(BtCursor*, int *pRes);
|
||||||
|
16
src/test3.c
16
src/test3.c
@@ -618,27 +618,27 @@ static int btree_insert(
|
|||||||
){
|
){
|
||||||
BtCursor *pCur;
|
BtCursor *pCur;
|
||||||
int rc;
|
int rc;
|
||||||
void *pKey = 0;
|
BtreePayload x;
|
||||||
int nKey = 0;
|
|
||||||
void *pData = 0;
|
|
||||||
int nData = 0;
|
|
||||||
|
|
||||||
if( objc!=4 && objc!=3 ){
|
if( objc!=4 && objc!=3 ){
|
||||||
Tcl_WrongNumArgs(interp, 1, objv, "?-intkey? CSR KEY VALUE");
|
Tcl_WrongNumArgs(interp, 1, objv, "?-intkey? CSR KEY VALUE");
|
||||||
return TCL_ERROR;
|
return TCL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset(&x, 0, sizeof(x));
|
||||||
if( objc==4 ){
|
if( objc==4 ){
|
||||||
if( Tcl_GetIntFromObj(interp, objv[2], &nKey) ) return TCL_ERROR;
|
if( Tcl_GetIntFromObj(interp, objv[2], &rc) ) return TCL_ERROR;
|
||||||
pData = (void*)Tcl_GetByteArrayFromObj(objv[3], &nData);
|
x.nKey = rc;
|
||||||
|
x.pData = (void*)Tcl_GetByteArrayFromObj(objv[3], &x.nData);
|
||||||
}else{
|
}else{
|
||||||
pKey = (void*)Tcl_GetByteArrayFromObj(objv[2], &nKey);
|
x.pKey = (void*)Tcl_GetByteArrayFromObj(objv[2], &rc);
|
||||||
|
x.nKey = rc;
|
||||||
}
|
}
|
||||||
pCur = (BtCursor*)sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
|
pCur = (BtCursor*)sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
|
||||||
|
|
||||||
sqlite3_mutex_enter(pCur->pBtree->db->mutex);
|
sqlite3_mutex_enter(pCur->pBtree->db->mutex);
|
||||||
sqlite3BtreeEnter(pCur->pBtree);
|
sqlite3BtreeEnter(pCur->pBtree);
|
||||||
rc = sqlite3BtreeInsert(pCur, pKey, nKey, pData, nData, 0, 0, 0);
|
rc = sqlite3BtreeInsert(pCur, &x, 0, 0);
|
||||||
sqlite3BtreeLeave(pCur->pBtree);
|
sqlite3BtreeLeave(pCur->pBtree);
|
||||||
sqlite3_mutex_leave(pCur->pBtree->db->mutex);
|
sqlite3_mutex_leave(pCur->pBtree->db->mutex);
|
||||||
|
|
||||||
|
39
src/vdbe.c
39
src/vdbe.c
@@ -4285,13 +4285,12 @@ case OP_Insert:
|
|||||||
case OP_InsertInt: {
|
case OP_InsertInt: {
|
||||||
Mem *pData; /* MEM cell holding data for the record to be inserted */
|
Mem *pData; /* MEM cell holding data for the record to be inserted */
|
||||||
Mem *pKey; /* MEM cell holding key for the record */
|
Mem *pKey; /* MEM cell holding key for the record */
|
||||||
i64 iKey; /* The integer ROWID or key for the record to be inserted */
|
|
||||||
VdbeCursor *pC; /* Cursor to table into which insert is written */
|
VdbeCursor *pC; /* Cursor to table into which insert is written */
|
||||||
int nZero; /* Number of zero-bytes to append */
|
|
||||||
int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
|
int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
|
||||||
const char *zDb; /* database name - used by the update hook */
|
const char *zDb; /* database name - used by the update hook */
|
||||||
Table *pTab; /* Table structure - used by update and pre-update hooks */
|
Table *pTab; /* Table structure - used by update and pre-update hooks */
|
||||||
int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
|
int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
|
||||||
|
BtreePayload x; /* Payload to be inserted */
|
||||||
|
|
||||||
op = 0;
|
op = 0;
|
||||||
pData = &aMem[pOp->p2];
|
pData = &aMem[pOp->p2];
|
||||||
@@ -4310,10 +4309,10 @@ case OP_InsertInt: {
|
|||||||
assert( pKey->flags & MEM_Int );
|
assert( pKey->flags & MEM_Int );
|
||||||
assert( memIsValid(pKey) );
|
assert( memIsValid(pKey) );
|
||||||
REGISTER_TRACE(pOp->p3, pKey);
|
REGISTER_TRACE(pOp->p3, pKey);
|
||||||
iKey = pKey->u.i;
|
x.nKey = pKey->u.i;
|
||||||
}else{
|
}else{
|
||||||
assert( pOp->opcode==OP_InsertInt );
|
assert( pOp->opcode==OP_InsertInt );
|
||||||
iKey = pOp->p3;
|
x.nKey = pOp->p3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
|
if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
|
||||||
@@ -4334,26 +4333,28 @@ case OP_InsertInt: {
|
|||||||
&& pOp->p4type==P4_TABLE
|
&& pOp->p4type==P4_TABLE
|
||||||
&& !(pOp->p5 & OPFLAG_ISUPDATE)
|
&& !(pOp->p5 & OPFLAG_ISUPDATE)
|
||||||
){
|
){
|
||||||
sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, iKey, pOp->p2);
|
sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey, pOp->p2);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
|
if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
|
||||||
if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = iKey;
|
if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = x.nKey;
|
||||||
if( pData->flags & MEM_Null ){
|
if( pData->flags & MEM_Null ){
|
||||||
pData->z = 0;
|
x.pData = 0;
|
||||||
pData->n = 0;
|
x.nData = 0;
|
||||||
}else{
|
}else{
|
||||||
assert( pData->flags & (MEM_Blob|MEM_Str) );
|
assert( pData->flags & (MEM_Blob|MEM_Str) );
|
||||||
|
x.pData = pData->z;
|
||||||
|
x.nData = pData->n;
|
||||||
}
|
}
|
||||||
seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
|
seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
|
||||||
if( pData->flags & MEM_Zero ){
|
if( pData->flags & MEM_Zero ){
|
||||||
nZero = pData->u.nZero;
|
x.nZero = pData->u.nZero;
|
||||||
}else{
|
}else{
|
||||||
nZero = 0;
|
x.nZero = 0;
|
||||||
}
|
}
|
||||||
rc = sqlite3BtreeInsert(pC->uc.pCursor, 0, iKey,
|
x.pKey = 0;
|
||||||
pData->z, pData->n, nZero,
|
rc = sqlite3BtreeInsert(pC->uc.pCursor, &x,
|
||||||
(pOp->p5 & OPFLAG_APPEND)!=0, seekResult
|
(pOp->p5 & OPFLAG_APPEND)!=0, seekResult
|
||||||
);
|
);
|
||||||
pC->deferredMoveto = 0;
|
pC->deferredMoveto = 0;
|
||||||
@@ -4362,7 +4363,7 @@ case OP_InsertInt: {
|
|||||||
/* Invoke the update-hook if required. */
|
/* Invoke the update-hook if required. */
|
||||||
if( rc ) goto abort_due_to_error;
|
if( rc ) goto abort_due_to_error;
|
||||||
if( db->xUpdateCallback && op ){
|
if( db->xUpdateCallback && op ){
|
||||||
db->xUpdateCallback(db->pUpdateArg, op, zDb, pTab->zName, iKey);
|
db->xUpdateCallback(db->pUpdateArg, op, zDb, pTab->zName, x.nKey);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -4977,8 +4978,7 @@ next_tail:
|
|||||||
case OP_SorterInsert: /* in2 */
|
case OP_SorterInsert: /* in2 */
|
||||||
case OP_IdxInsert: { /* in2 */
|
case OP_IdxInsert: { /* in2 */
|
||||||
VdbeCursor *pC;
|
VdbeCursor *pC;
|
||||||
int nKey;
|
BtreePayload x;
|
||||||
const char *zKey;
|
|
||||||
|
|
||||||
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
|
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
|
||||||
pC = p->apCsr[pOp->p1];
|
pC = p->apCsr[pOp->p1];
|
||||||
@@ -4994,9 +4994,12 @@ case OP_IdxInsert: { /* in2 */
|
|||||||
if( pOp->opcode==OP_SorterInsert ){
|
if( pOp->opcode==OP_SorterInsert ){
|
||||||
rc = sqlite3VdbeSorterWrite(pC, pIn2);
|
rc = sqlite3VdbeSorterWrite(pC, pIn2);
|
||||||
}else{
|
}else{
|
||||||
nKey = pIn2->n;
|
x.nKey = pIn2->n;
|
||||||
zKey = pIn2->z;
|
x.pKey = pIn2->z;
|
||||||
rc = sqlite3BtreeInsert(pC->uc.pCursor, zKey, nKey, "", 0, 0, pOp->p3,
|
x.nData = 0;
|
||||||
|
x.nZero = 0;
|
||||||
|
x.pData = 0;
|
||||||
|
rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, pOp->p3,
|
||||||
((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
|
((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
|
||||||
);
|
);
|
||||||
assert( pC->deferredMoveto==0 );
|
assert( pC->deferredMoveto==0 );
|
||||||
|
Reference in New Issue
Block a user