-C Manifest\stypes\sin\sindices.\sAt\sthe\smoment\sindices\suse\smanifest\styping,\sbut\nsome\sother\sparts\sof\sthe\sSQL\sengine\sdo\snot,\swhich\scan\slead\sto\ssome\sstrange\nresults.\s(CVS\s1368)
-D 2004-05-13T05:16:16
+C Commit\svdbeaux.c,\swhich\sshould\sof\sgone\sin\swith\sthe\sprevious\scommit.\s(CVS\s1369)
+D 2004-05-13T05:20:26
F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
F src/vdbe.c 773fb49293f0412aa65e2bcbced40bd64464529e
F src/vdbe.h 94457ca73bae972dc61bca33a4dccc2e6e14e2f8
F src/vdbeInt.h 66904cfb0b004de8441e47ce00da8c7d4c498c76
-F src/vdbeaux.c c976c7fe334a1d1c102dda410546e880549a6060
+F src/vdbeaux.c 8bf71f7ba91a208c5e0a8bcf5da03889bc858041
F src/where.c 487e55b1f64c8fbf0f46a9a90c2247fc45ae6a9a
F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
F test/attach.test cb9b884344e6cfa5e165965d5b1adea679a24c83
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P 1d52a4bb478648ef53a0dbb21865ccb9281dc24a
-R 348f622445c9bf52db446021aadee19c
+P 9f2b6d9d3a07e25fcdb7e8290da7a182a65c37b2
+R f11624c39f06ceae0abda7ba6de7cde2
U danielk1977
-Z b02892c4dfff10665b81dd53d91883c9
+Z 1145b683d60660fe323388d21c0508f8
**
** serial type bytes of data type
** -------------- --------------- ---------------
-** 0 0 NULL
+** 0 - Not a type.
** 1 1 signed integer
** 2 2 signed integer
** 3 4 signed integer
** 4 8 signed integer
** 5 8 IEEE float
-** 6..12 reserved for expansion
+** 6 0 NULL
+** 7..11 reserved for expansion
** N>=12 and even (N-12)/2 BLOB
** N>=13 and odd (N-13)/2 text
**
int flags = pMem->flags;
if( flags&MEM_Null ){
- return 0;
+ return 6;
}
if( flags&MEM_Int ){
/* Figure out whether to use 1, 2, 4 or 8 bytes. */
** Return the length of the data corresponding to the supplied serial-type.
*/
int sqlite3VdbeSerialTypeLen(u64 serial_type){
+ assert( serial_type!=0 );
switch(serial_type){
- case 0: return 0; /* NULL */
+ case 6: return 0; /* NULL */
case 1: return 1; /* 1 byte integer */
case 2: return 2; /* 2 byte integer */
case 3: return 4; /* 4 byte integer */
int sqlite3VdbeSerialPut(unsigned char *buf, const Mem *pMem){
u64 serial_type = sqlite3VdbeSerialType(pMem);
int len;
+
+ assert( serial_type!=0 );
/* NULL */
- if( serial_type==0 ){
+ if( serial_type==6 ){
return 0;
}
int sqlite3VdbeSerialGet(const unsigned char *buf, u64 serial_type, Mem *pMem){
int len;
+ assert( serial_type!=0 );
+
/* memset(pMem, 0, sizeof(pMem)); */
pMem->flags = 0;
pMem->z = 0;
/* NULL */
- if( serial_type==0 ){
+ if( serial_type==6 ){
pMem->flags = MEM_Null;
return 0;
}
** the second.
**
** This function assumes that each key consists of one or more type/blob
-** pairs, encoded using the sqlite3VdbeSerialXXX() functions above. One
-** of the keys may have some trailing data appended to it. This is OK
-** provided that the other key does not have more type/blob pairs than
-** the key with the trailing data.
+** pairs, encoded using the sqlite3VdbeSerialXXX() functions above.
+**
+** Following the type/blob pairs, each key may have a single 0x00 byte
+** followed by a varint. A key may only have this traling 0x00/varint
+** pair if it has at least as many type/blob pairs as the key it is being
+** compared to.
*/
int sqlite3VdbeKeyCompare(
void *userData, /* not used yet */
- int nKey1, const unsigned char *aKey1,
- int nKey2, const unsigned char *aKey2
+ int nKey1, const void *pKey1,
+ int nKey2, const void *pKey2
){
int offset1 = 0;
int offset2 = 0;
-
+ const unsigned char *aKey1 = (const unsigned char *)pKey1;
+ const unsigned char *aKey2 = (const unsigned char *)pKey2;
+
while( offset1<nKey1 && offset2<nKey2 ){
Mem mem1;
Mem mem2;
u64 serial_type2;
int rc;
+ /* Read the serial types for the next element in each key. */
offset1 += sqlite3GetVarint(&aKey1[offset1], &serial_type1);
offset2 += sqlite3GetVarint(&aKey2[offset2], &serial_type2);
+
+ /* If either of the varints just read in are 0 (not a type), then
+ ** this is the end of the keys. The remaining data in each key is
+ ** the varint rowid. Compare these as signed integers and return
+ ** the result.
+ */
+ if( !serial_type1 || !serial_type2 ){
+ assert( !serial_type1 && !serial_type2 );
+ sqlite3GetVarint(&aKey1[offset1], &serial_type1);
+ sqlite3GetVarint(&aKey2[offset2], &serial_type2);
+ return ( (i64)serial_type1 - (i64)serial_type2 );
+ }
+
+ /* Assert that there is enough space left in each key for the blob of
+ ** data to go with the serial type just read. This assert may fail if
+ ** the file is corrupted. Then read the value from each key into mem1
+ ** and mem2 respectively.
+ */
offset1 += sqlite3VdbeSerialGet(&aKey1[offset1], serial_type1, &mem1);
offset2 += sqlite3VdbeSerialGet(&aKey2[offset2], serial_type2, &mem2);
}
return 0;
}
+
+/*
+** pCur points at an index entry. Read the rowid (varint occuring at
+** the end of the entry and store it in *rowid. Return SQLITE_OK if
+** everything works, or an error code otherwise.
+*/
+int sqlite3VdbeIdxRowid(BtCursor *pCur, i64 *rowid){
+ i64 sz;
+ int rc;
+ char buf[9];
+ int len;
+ u64 r;
+
+ rc = sqlite3BtreeKeySize(pCur, &sz);
+ if( rc!=SQLITE_OK ){
+ return rc;
+ }
+ len = ((sz>9)?9:sz);
+ assert( len>=2 );
+
+ rc = sqlite3BtreeKey(pCur, sz-len, len, buf);
+ if( rc!=SQLITE_OK ){
+ return rc;
+ }
+
+ len = len - 2;
+ while( buf[len] && --len );
+
+ sqlite3GetVarint(buf, &r);
+ *rowid = r;
+ return SQLITE_OK;
+}
+
+int sqlite3VdbeIdxKeyCompare(
+ BtCursor *pCur,
+ int nKey, const unsigned char *pKey,
+ int ignorerowid,
+ int *res
+){
+ unsigned char *pCellKey;
+ u64 nCellKey;
+ int freeCellKey = 0;
+ int rc;
+ int len;
+
+ sqlite3BtreeKeySize(pCur, &nCellKey);
+ if( nCellKey<=0 ){
+ *res = 0;
+ return SQLITE_OK;
+ }
+
+ pCellKey = (unsigned char *)sqlite3BtreeKeyFetch(pCur, nCellKey);
+ if( !pCellKey ){
+ pCellKey = (unsigned char *)sqliteMalloc(nCellKey);
+ if( !pCellKey ){
+ return SQLITE_NOMEM;
+ }
+ freeCellKey = 1;
+ rc = sqlite3BtreeKey(pCur, 0, nCellKey, pCellKey);
+ if( rc!=SQLITE_OK ){
+ sqliteFree(pCellKey);
+ return rc;
+ }
+ }
+
+ len = nCellKey-2;
+ while( pCellKey[len] && --len );
+
+ if( ignorerowid ){
+ nKey--;
+ while( pKey[nKey] && --nKey );
+ }
+ *res = sqlite3VdbeKeyCompare(0, len, pCellKey, nKey, pKey);
+
+ if( freeCellKey ){
+ sqliteFree(pCellKey);
+ }
+ return SQLITE_OK;
+}
+
+
+