1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-01 06:27:03 +03:00

RowIDs are now always expressed in native byte order. (CVS 263)

FossilOrigin-Name: bb4313a94bc079d072078f353e54f3804971060d
This commit is contained in:
drh
2001-09-23 20:17:55 +00:00
parent 90bfcdace3
commit f3256d2c82
4 changed files with 47 additions and 28 deletions

View File

@ -1,5 +1,5 @@
C Additional\stest\scases\swith\slocking\sfixes.\s\sAlso,\smake\sthe\scode\sthread-safe.\s(CVS\s262)
D 2001-09-23T19:46:52
C RowIDs\sare\snow\salways\sexpressed\sin\snative\sbyte\sorder.\s(CVS\s263)
D 2001-09-23T20:17:55
F Makefile.in 18eea9a3486939fced70aa95b691be766c2c995d
F README 51f6a4e7408b34afa5bc1c0485f61b6a4efb6958
F VERSION 6942aa44940d2972bd72f671a631060106e77f7e
@ -16,7 +16,7 @@ F src/expr.c 343a515a4abaf60e9e26c7412aa8c43fd3eae97d
F src/hash.c bf36fb4cba114015123b0050f137d2c4553778a1
F src/hash.h 5f6e7c04c46ed015ab4e01797c2049b4af5b006d
F src/insert.c 061e531d19869e26ba9202c6d069385237b4c102
F src/main.c 49af06b7327c8b23b9331ce80b7e4bc9536ed2e1
F src/main.c 00ff61d82189ad23fe2f2e6c355951f514cb1b5c
F src/md5.c 52f677bfc590e09f71d07d7e327bd59da738d07c
F src/os.c 45376582c41dc8829330816d56b8e9e6cd1b7972
F src/os.h 0f478e2fef5ec1612f94b59b163d4807d4c77d6d
@ -38,7 +38,7 @@ F src/test3.c 4a0d7b882fdae731dbb759f512ad867122452f96
F src/tokenize.c 2ab07b85fde38d8fa2b4e73417b93e94f9cf8f5f
F src/update.c 8de22957017e17c5e751ba71c4ea76c60f93aa2f
F src/util.c 9c888445c1fd7896dab38fa62efc532f2364010a
F src/vdbe.c b36ba796eca369d3dbd9272b277d520af03b9ae4
F src/vdbe.c c5cd3a5340871a44236aba41d4265a23b5353859
F src/vdbe.h dc1d441494ba560a1ff464e1c56beb8ca03844fc
F src/where.c cce952b6a2459ac2296e3432876a4252d2fe3b87
F test/all.test a2320eb40b462f25bd3e33115b1cabf3791450dd
@ -97,7 +97,7 @@ F www/opcode.tcl 60222aeb57a7855b2582c374b8753cb5bb53c4ab
F www/sqlite.tcl cb0d23d8f061a80543928755ec7775da6e4f362f
F www/tclsqlite.tcl 13d50723f583888fc80ae1a38247c0ab415066fa
F www/vdbe.tcl 0c8aaa529dd216ccbf7daaabd80985e413d5f9ad
P 337b3d3b2a903328d9744c111979909a284b8348
R e078b3cf3fce42ca9d1080ff6c3cabcb
P bd7d6a64afa03cc64f6537f828d6c94975bf5f02
R b2b493528f723aceed9a16e2be55169a
U drh
Z f237ccfe6f0011261f7c6612613f9d4f
Z 2820f142fe995c5556d69539be23c55f

View File

@ -1 +1 @@
bd7d6a64afa03cc64f6537f828d6c94975bf5f02
bb4313a94bc079d072078f353e54f3804971060d

View File

@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.40 2001/09/22 18:12:10 drh Exp $
** $Id: main.c,v 1.41 2001/09/23 20:17:55 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@ -251,6 +251,7 @@ sqlite *sqlite_open(const char *zFilename, int mode, char **pzErrMsg){
if( db==0 ) goto no_mem_on_open;
sqliteHashInit(&db->tblHash, SQLITE_HASH_STRING, 0);
sqliteHashInit(&db->idxHash, SQLITE_HASH_STRING, 0);
db->nextRowid = sqliteRandomInteger(db);
/* Open the backend database driver */
rc = sqliteBtreeOpen(zFilename, mode, MAX_PAGES, &db->pBe);

View File

@ -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.75 2001/09/23 19:46:52 drh Exp $
** $Id: vdbe.c,v 1.76 2001/09/23 20:17:55 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -905,6 +905,22 @@ static Sorter *Merge(Sorter *pLeft, Sorter *pRight){
return sHead.pNext;
}
/*
** Convert an integer into a big-endian integer. In other words,
** make sure the most significant byte comes first.
*/
static int bigEndian(int x){
union {
char zBuf[sizeof(int)];
int i;
} ux;
ux.zBuf[3] = x&0xff;
ux.zBuf[2] = (x>>8)&0xff;
ux.zBuf[1] = (x>>16)&0xff;
ux.zBuf[0] = (x>>24)&0xff;
return ux.i;
}
/*
** Code contained within the VERIFY() macro is not needed for correct
** execution. It is there only to catch errors. So when we compile
@ -1834,6 +1850,7 @@ case OP_MakeIdxKey: {
int nByte;
int nField;
int i, j;
u32 iKey;
nField = pOp->p1;
VERIFY( if( p->tos+1<nField ) goto not_enough_stack; )
@ -1862,7 +1879,8 @@ case OP_MakeIdxKey: {
}
}
Integerify(p, p->tos-nField);
memcpy(&zNewKey[j], &aStack[p->tos-nField].i, sizeof(u32));
iKey = bigEndian(aStack[p->tos-nField].i);
memcpy(&zNewKey[j], &iKey, sizeof(u32));
PopStack(p, nField+1);
VERIFY( NeedStack(p, p->tos+1); )
p->tos++;
@ -2156,8 +2174,9 @@ case OP_MoveTo: {
if( i>=0 && i<p->nCursor && p->aCsr[i].pCursor ){
int res;
if( aStack[tos].flags & STK_Int ){
int iKey = bigEndian(aStack[tos].i);
sqliteBtreeMoveto(p->aCsr[i].pCursor,
(char*)&aStack[tos].i, sizeof(int), &res);
(char*)&iKey, sizeof(int), &res);
p->aCsr[i].lastRecno = aStack[tos].i;
p->aCsr[i].recnoIsValid = 1;
}else{
@ -2231,8 +2250,9 @@ case OP_Found: {
if( VERIFY( i>=0 && i<p->nCursor && ) p->aCsr[i].pCursor ){
int res, rx;
if( aStack[tos].flags & STK_Int ){
int iKey = bigEndian(aStack[tos].i);
rx = sqliteBtreeMoveto(p->aCsr[i].pCursor,
(char*)&aStack[tos].i, sizeof(int), &res);
(char*)&iKey, sizeof(int), &res);
}else{
if( Stringify(p, tos) ) goto no_mem;
rx = sqliteBtreeMoveto(p->aCsr[i].pCursor,
@ -2280,30 +2300,25 @@ case OP_NewRecno: {
** larger than the previous rowid. This has been shown experimentally
** to double the speed of the COPY operation.
*/
int res, rx, cnt;
int x;
int res, rx, cnt, x;
union {
char zBuf[sizeof(int)];
int i;
} ux;
cnt = 0;
x = db->nextRowid;
v = db->nextRowid;
do{
if( cnt>5 ){
x = sqliteRandomInteger(db);
v = sqliteRandomInteger(db);
}else{
x += sqliteRandomByte(db) + 1;
v += sqliteRandomByte(db) + 1;
}
if( x==0 ) continue;
ux.zBuf[3] = x&0xff;
ux.zBuf[2] = (x>>8)&0xff;
ux.zBuf[1] = (x>>16)&0xff;
ux.zBuf[0] = (x>>24)&0xff;
v = ux.i;
rx = sqliteBtreeMoveto(p->aCsr[i].pCursor, &v, sizeof(v), &res);
if( v==0 ) continue;
x = bigEndian(v);
rx = sqliteBtreeMoveto(p->aCsr[i].pCursor, &x, sizeof(int), &res);
cnt++;
}while( cnt<1000 && rx==SQLITE_OK && res==0 );
db->nextRowid = x;
db->nextRowid = v;
if( rx==SQLITE_OK && res==0 ){
rc = SQLITE_FULL;
goto abort_due_to_error;
@ -2331,14 +2346,15 @@ case OP_Put: {
VERIFY( if( nos<0 ) goto not_enough_stack; )
if( VERIFY( i>=0 && i<p->nCursor && ) p->aCsr[i].pCursor!=0 ){
char *zKey;
int nKey;
int nKey, iKey;
if( (aStack[nos].flags & STK_Int)==0 ){
if( Stringify(p, nos) ) goto no_mem;
nKey = aStack[nos].n;
zKey = zStack[nos];
}else{
nKey = sizeof(int);
zKey = (char*)&aStack[nos].i;
iKey = bigEndian(aStack[nos].i);
zKey = (char*)&iKey;
}
rc = sqliteBtreeInsert(p->aCsr[i].pCursor, zKey, nKey,
zStack[tos], aStack[tos].n);
@ -2496,6 +2512,7 @@ case OP_Recno: {
v = p->aCsr[i].lastRecno;
}else{
sqliteBtreeKey(pCrsr, 0, sizeof(u32), (char*)&v);
v = bigEndian(v);
}
aStack[tos].i = v;
aStack[tos].flags = STK_Int;
@ -2657,6 +2674,7 @@ case OP_NextIdx: {
}else{
int recno;
sqliteBtreeKey(pCur, pCrsr->nKey, sizeof(u32), (char*)&recno);
recno = bigEndian(recno);
p->aCsr[i].lastRecno = aStack[tos].i = recno;
p->aCsr[i].recnoIsValid = 1;
aStack[tos].flags = STK_Int;