]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Get the code back to the point where it will compile the btree.c tests.
authordrh <drh@noemail.net>
Sat, 8 May 2004 10:56:11 +0000 (10:56 +0000)
committerdrh <drh@noemail.net>
Sat, 8 May 2004 10:56:11 +0000 (10:56 +0000)
Move the default key comparison routine from btree.c into vdbeaux.c.
Commented out code in vdbe.c that will need to be fixed. (CVS 1326)

FossilOrigin-Name: 2bca92240b16a51f78661c3ba4d779d231780f8d

manifest
manifest.uuid
src/btree.c
src/vdbe.c
src/vdbe.h
src/vdbeaux.c
test/btree.test

index 04c1facef219a6c77d62fbf7971744005e53dee0..c14234b59e9df13919dc6db4e7106ca8d178a93a 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Minor\schange\sto\smain.c\sso\sthat\sit\swill\scompile\swith\sGCC\s2.96.\s(CVS\s1325)
-D 2004-05-08T10:11:37
+C Get\sthe\scode\sback\sto\sthe\spoint\swhere\sit\swill\scompile\sthe\sbtree.c\stests.\nMove\sthe\sdefault\skey\scomparison\sroutine\sfrom\sbtree.c\sinto\svdbeaux.c.\nCommented\sout\scode\sin\svdbe.c\sthat\swill\sneed\sto\sbe\sfixed.\s(CVS\s1326)
+D 2004-05-08T10:56:11
 F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -23,7 +23,7 @@ F sqlite.def fc4f5734786fe4743cfe2aa98eb2da4b089edb5f
 F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
 F src/attach.c fa9a58234406d84eeb900517d0c0adc4b2da051a
 F src/auth.c a2a46e3ed7799134cf3d2dd5ae6650115f26b653
-F src/btree.c 8c50e8f3d1dce11a43342068b3bfc88bcfb104f8
+F src/btree.c 27600f910e247c905389ecf3f246f27e9649cbea
 F src/btree.h 07a16dbb8c29291d0768b956649350d8f8c3dac3
 F src/btree_rb.c 47e5b5ec90846af392b5668b34648198ba459561
 F src/build.c 21b6645c966970dac51bcccfa8650403a3f56210
@@ -63,10 +63,10 @@ F src/update.c 475465fc0582160dadf5455b05235cb13c9e21f9
 F src/utf.c fc799748d43fe1982d157b871e3e420a19c85d4f
 F src/util.c 0c31a53b848648271d0910c2604b4d8ae516ebb1
 F src/vacuum.c 91ba5a23eca2d9a8a11191cef577d417f9318976
-F src/vdbe.c 500d5140b6f779bfcc60bef74b914e4dc6686439
-F src/vdbe.h 3cf970b0a64be04d36f4dcece3cecd28312d745c
+F src/vdbe.c 9b089e0b20e7ee4dea416eb86520dffa0c04f02a
+F src/vdbe.h 2dc4d1161b64f5684faa6a2d292e318a185ecb2e
 F src/vdbeInt.h 4563dc1c9f05a842cbbc7759e4cc7f3779f53547
-F src/vdbeaux.c 68c24aa7b7facf7412755f3807d8a3acf4e29963
+F src/vdbeaux.c 81d95af2651777f7960c2cca18613aa3aa95403e
 F src/where.c 6db0291280f2c642bae2c69a70750325b53717a4
 F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
 F test/attach.test ba8261d38da6b6a7d4f78ec543c548c4418582ef
@@ -75,7 +75,7 @@ F test/auth.test 5c4d95cdaf539c0c236e20ce1f71a93e7dde9185
 F test/bigfile.test ea904b853ce2d703b16c5ce90e2b54951bc1ae81
 F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
 F test/bind.test 56a57043b42c4664ca705f6050e56717a8a6699a
-F test/btree.test 54caf3f97934711dac9a47ac4119b033dd4caffa
+F test/btree.test d9d00f8ac8bfa4945861f92c5b14fbe884d874c4
 F test/btree2.test e3b81ec33dc2f89b3e6087436dfe605b870c9080
 F test/btree3.test e597fb59be2ac0ea69c62aaa2064e998e528b665
 F test/btree3rb.test 127efcf5cdfcc352054e7db12622b01cdd8b36ac
@@ -190,7 +190,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
 F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P 8af6474c49263ae26216dff9465b33f76b500cf4
-R 2ed9c287297cae4581a05c12a5103a70
+P 1a09a1ada199b76926c64bd79ad39d6d50a75011
+R 020d676c42c3c99a03395fc2bd1d45bd
 U drh
-Z 345f2d0e7e37c3a350d2d2026464612e
+Z e3b04ec339a83a6885a62a5e117d1378
index 1901801952a1901a456ceffed649f24600520935..b65f93db38fdf0a0f154bd71b6a02e13161735be 100644 (file)
@@ -1 +1 @@
-1a09a1ada199b76926c64bd79ad39d6d50a75011
\ No newline at end of file
+2bca92240b16a51f78661c3ba4d779d231780f8d
\ No newline at end of file
index 09bd56dcafc36850d17fc6953da367b9d7ea567d..fbd15440024bda28da4f5694b6edc84fd1e199ac 100644 (file)
@@ -9,7 +9,7 @@
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** $Id: btree.c,v 1.114 2004/05/08 08:23:21 danielk1977 Exp $
+** $Id: btree.c,v 1.115 2004/05/08 10:56:11 drh Exp $
 **
 ** This file implements a external (disk-based) database using BTrees.
 ** For a detailed discussion of BTrees, refer to
@@ -557,98 +557,6 @@ static void freeSpace(MemPage *pPage, int start, int size){
   assert( tsize+data[pPage->hdrOffset+5]==pPage->nFree );
 }
 
-#if 0
-/*
-** The following is the default comparison function for (non-integer)
-** keys in the btrees.  This function returns negative, zero, or
-** positive if the first key is less than, equal to, or greater than
-** the second.
-**
-** The key consists of multiple fields.  Each field begins with a variable
-** length integer which determines the field type and the number of bytes
-** of key data to follow for that field.
-**
-**   initial varint     bytes to follow    type
-**   --------------     ---------------    ---------------
-**      0                     0            NULL
-**      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
-**    N>=12 and even       (N-12)/2        BLOB
-**    N>=13 and odd        (N-13)/2        text
-**
-** For a particular database, text is always either UTF-8, UTF-16BE, or
-** UTF-16LE.  Which of these three formats to use is determined by one
-** of the meta values in the file header.
-**
-*/
-static int keyComp(
-  void *userData,
-  int nKey1, const unsigned char *aKey1, 
-  int nKey2, const unsigned char *aKey2,
-){
-  KeyClass *pKeyClass = (KeyClass*)userData;
-  i1 = i2 = 0;
-  for(i1=i2=0; pKeyClass!=0; pKeyClass=pKeyClass->pNext){
-    if( varint32(aKey1, &i1, nKey1, &n1) ) goto bad_key;
-    if( varint32(aKey2, &i2, nKey2, &n2) ) goto bad_key;
-    if( n1==0 ){
-      if( n2>0 ) return -1;
-      /* both values are NULL.  consider them equal for sorting purposes. */
-    }else if( n2==0 ){
-      /* right value is NULL but the left value is not.  right comes first */
-      return +1;
-    }else if( n1<=5 ){
-      if( n2>5 ) return -1;
-      /* both values are numbers.  sort them numerically */
-      ...
-    }else if( n2<=5 ){
-      /* right value is numeric and left is TEXT or BLOB.  right comes first */
-      return +1;
-    }else if( n1<12 || n2<12 ){
-      /* bad coding for either the left or the right value */
-      goto bad_key;
-    }else if( (n1&0x01)==0 ){
-      if( n2&0x01)!=0 ) return -1;
-      /* both values are BLOB.  use memcmp() */
-      n1 = (n1-12)/2;
-      n2 = (n2-12)/2;
-      if( i1+n1>nKey1 || i2+n2>nKey2 ) goto bad_key;
-      c = memcmp(&aKey1[i1], &aKey2[i2], n1<n2 ? n1 : n2);
-      if( c!=0 ){
-        return c | 1;
-      }
-      if( n1!=n2 ){
-        return (n1-n2) | 1;
-      }
-      i1 += n1;
-      i2 += n2;
-    }else if( n2&0x01)!=0 ){
-      /* right value if BLOB and left is TEXT.  BLOB comes first */
-      return +1;
-    }else{
-      /* both values are TEXT.  use the supplied comparison function */
-      n1 = (n1-13)/2;
-      n2 = (n2-13)/2;
-      if( i1+n1>nKey1 || i2+n2>nKey2 ) goto bad_key;
-      c = pKeyClass->xCompare(pKeyClass->pUser, n1, &aKey1[i1], n2, &aKey2[i2]);
-      if( c!=0 ){
-        return c | 1;
-      }
-      i1 += n1;
-      i2 += n2;
-    } 
-  }
-  return 0;
-
-bad_key:
-  return 1;
-}
-#endif
-
 /*
 ** Resize the aCell[] array of the given page so that it is able to
 ** hold at least nNewSz entries.
@@ -3253,23 +3161,27 @@ int sqlite3BtreePageDump(Btree *pBt, int pgno, int recursive){
   int i, j;
   int nFree;
   u16 idx;
-  int hdrOffset;
+  int hdr;
+  unsigned char *data;
   char range[20];
   unsigned char payload[20];
+
   rc = getPage(pBt, (Pgno)pgno, &pPage);
   if( rc ){
     return rc;
   }
+  hdr = pPage->hdrOffset;
+  data = pPage->aData;
   printf("PAGE %d:  flags=0x%02x  frag=%d\n", pgno,
-    pPage->aData[pPage->hdrOffset], pPage->aData[pPage->hdrOffset+5]);
+    data[hdr], data[hdr+5]);
   i = 0;
-  assert( pPage->hdrOffset == (pgno==1 ? 100 : 0) );
-  idx = get2byte(&pPage->aData[hdrOffset+3]);
+  assert( hdr == (pgno==1 ? 100 : 0) );
+  idx = get2byte(&data[hdr+3]);
   while( idx>0 && idx<=pBt->pageSize ){
     u64 nData, nKey;
     int nHeader;
     Pgno child;
-    unsigned char *pCell = &pPage->aData[idx];
+    unsigned char *pCell = &data[idx];
     int sz = cellSize(pPage, pCell);
     sprintf(range,"%d..%d", idx, idx+sz-1);
     parseCellHeader(pPage, pCell, &nData, &nKey, &nHeader);
@@ -3300,33 +3212,33 @@ int sqlite3BtreePageDump(Btree *pBt, int pgno, int recursive){
     printf("ERROR: next cell index out of range: %d\n", idx);
   }
   if( !pPage->leaf ){
-    printf("right_child: %d\n", get4byte(&pPage->aData[6]));
+    printf("right_child: %d\n", get4byte(&data[6]));
   }
   nFree = 0;
   i = 0;
-  idx = get2byte(&pPage->aData[hdrOffset+1]);
+  idx = get2byte(&data[hdr+1]);
   while( idx>0 && idx<pPage->pBt->pageSize ){
-    int sz = get2byte(&pPage->aData[idx+2]);
+    int sz = get2byte(&data[idx+2]);
     sprintf(range,"%d..%d", idx, idx+sz-1);
     nFree += sz;
     printf("freeblock %2d: i=%-10s size=%-4d total=%d\n",
        i, range, sz, nFree);
-    idx = get2byte(&pPage->aData[idx]);
+    idx = get2byte(&data[idx]);
     i++;
   }
   if( idx!=0 ){
     printf("ERROR: next freeblock index out of range: %d\n", idx);
   }
   if( recursive && !pPage->leaf ){
-    idx = get2byte(&pPage->aData[hdrOffset+3]);
+    idx = get2byte(&data[hdr+3]);
     while( idx>0 && idx<pBt->pageSize ){
-      unsigned char *pCell = &pPage->aData[idx];
+      unsigned char *pCell = &data[idx];
       sqlite3BtreePageDump(pBt, get4byte(&pCell[2]), 1);
       idx = get2byte(pCell);
     }
-    sqlite3BtreePageDump(pBt, get4byte(&pPage->aData[hdrOffset+6]), 1);
+    sqlite3BtreePageDump(pBt, get4byte(&data[hdr+6]), 1);
   }
-  sqlite3pager_unref(pPage->aData);
+  sqlite3pager_unref(data);
   return SQLITE_OK;
 }
 #endif
@@ -3764,40 +3676,3 @@ int sqlite3BtreeCopyFile(Btree *pBtTo, Btree *pBtFrom){
   }
   return rc;  
 }
-
-int sqlite3BtreeKeyCompare(
-  BtCursor *pCur,       /* Pointer to entry to compare against */
-  const void *pKey,     /* Key to compare against entry that pCur points to */
-  int nKey,             /* Number of bytes in pKey */
-  int nIgnore,          /* Ignore this many bytes at the end of pCur */
-  int *pResult          /* Write the result here */
-){
-  void *pCellKey;
-  u64 nCellKey;
-  int rc;
-
-  sqlite3BtreeKeySize(pCur, &nCellKey);
-  nCellKey = nCellKey - nIgnore;
-  if( nCellKey<=0 ){
-    *pResult = 0;
-    return SQLITE_OK;
-  }
-
-  pCellKey = sqlite3BtreeKeyFetch(pCur);
-  if( pCellKey ){
-    *pResult = pCur->xCompare(pCur->pArg, nCellKey, pCellKey, nKey, pKey);
-    return SQLITE_OK;
-  }
-
-  pCellKey = sqliteMalloc( nCellKey );
-  if( pCellKey==0 ) return SQLITE_NOMEM;
-
-  rc = sqlite3BtreeKey(pCur, 0, nCellKey, pCellKey);
-  *pResult = pCur->xCompare(pCur->pArg, nCellKey, pCellKey, nKey, pKey);
-  sqliteFree(pCellKey);
-
-  return rc;
-}
-
-
-
index 2078232ec4cd07907042d95113f03683b45bfb86..9b0f04bc6325317a9ce18d77f7f20e25785c3aa3 100644 (file)
@@ -43,7 +43,7 @@
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.269 2004/05/08 08:23:40 danielk1977 Exp $
+** $Id: vdbe.c,v 1.270 2004/05/08 10:56:12 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -2744,7 +2744,9 @@ case OP_IsUnique: {
         break;
       }
     }
+/******** FIX ME
     rc = sqlite3BtreeKeyCompare(pCrsr, zKey, nKey-4, 4, &res); 
+*/rc=SQLITE_INTERNAL;
     if( rc!=SQLITE_OK ) goto abort_due_to_error;
     if( res>0 ){
       pc = pOp->p2 - 1;
@@ -3472,7 +3474,9 @@ case OP_IdxPut: {
         int c;
         /* TODO: sqlite3BtreeKeySize(pCrsr, &n); */
         if( n==nKey
+/***** FIX ME
             && sqlite3BtreeKeyCompare(pCrsr, zKey, nKey-4, 4, &c)==SQLITE_OK
+*/
            && c==0
         ){
           rc = SQLITE_CONSTRAINT;
@@ -3593,7 +3597,9 @@ case OP_IdxGE: {
  
     Stringify(pTos);
     assert( p->aCsr[i].deferredMoveto==0 );
+/****** FIX ME
     rc = sqlite3BtreeKeyCompare(pCrsr, pTos->z, pTos->n, 4, &res);
+*/rc=SQLITE_INTERNAL;
     if( rc!=SQLITE_OK ){
       break;
     }
@@ -4908,6 +4914,3 @@ abort_due_to_interrupt:
   sqlite3SetString(&p->zErrMsg, sqlite_error_string(rc), (char*)0);
   goto vdbe_halt;
 }
-
-
-
index 02b923437238230e0c4870a1f8b28cd85c82b5d8..ea092e909f613b9a3b7c51b46bb416e366a228ac 100644 (file)
@@ -15,7 +15,7 @@
 ** or VDBE.  The VDBE implements an abstract machine that runs a
 ** simple program to access and modify the underlying database.
 **
-** $Id: vdbe.h,v 1.72 2004/05/08 08:23:45 danielk1977 Exp $
+** $Id: vdbe.h,v 1.73 2004/05/08 10:56:17 drh Exp $
 */
 #ifndef _SQLITE_VDBE_H_
 #define _SQLITE_VDBE_H_
@@ -108,8 +108,6 @@ void sqlite3VdbeTrace(Vdbe*,FILE*);
 void sqlite3VdbeCompressSpace(Vdbe*,int);
 int sqlite3VdbeReset(Vdbe*,char **);
 int sqliteVdbeSetVariables(Vdbe*,int,const char**);
+int sqlite3VdbeKeyCompare(void*,int,const u8*,int, const u8*);
 
 #endif
-
-
-
index acc974183538befb0c4014d8a6c4d249f4b2a405..cdb3f0e3434443099c90d81d9bf2fd6f89ab6fbc 100644 (file)
@@ -1061,4 +1061,94 @@ int sqlite3VdbeCursorMoveto(Cursor *p){
 }
 
 
+/*
+** The following is the comparison function for (non-integer)
+** keys in the btrees.  This function returns negative, zero, or
+** positive if the first key is less than, equal to, or greater than
+** the second.
+**
+** The key consists of multiple fields.  Each field begins with a variable
+** length integer which determines the field type and the number of bytes
+** of key data to follow for that field.
+**
+**   initial varint     bytes to follow    type
+**   --------------     ---------------    ---------------
+**      0                     0            NULL
+**      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
+**    N>=12 and even       (N-12)/2        BLOB
+**    N>=13 and odd        (N-13)/2        text
+**
+** For a particular database, text is always either UTF-8, UTF-16BE, or
+** UTF-16LE.  Which of these three formats to use is determined by one
+** of the meta values in the file header.
+**
+*/
+#if 0
+int sqlite3VdbeKeyCompare(
+  void *userData,
+  int nKey1, const unsigned char *aKey1, 
+  int nKey2, const unsigned char *aKey2,
+){
+  KeyClass *pKeyClass = (KeyClass*)userData;
+  i1 = i2 = 0;
+  for(i1=i2=0; pKeyClass!=0; pKeyClass=pKeyClass->pNext){
+    if( varint32(aKey1, &i1, nKey1, &n1) ) goto bad_key;
+    if( varint32(aKey2, &i2, nKey2, &n2) ) goto bad_key;
+    if( n1==0 ){
+      if( n2>0 ) return -1;
+      /* both values are NULL.  consider them equal for sorting purposes. */
+    }else if( n2==0 ){
+      /* right value is NULL but the left value is not.  right comes first */
+      return +1;
+    }else if( n1<=5 ){
+      if( n2>5 ) return -1;
+      /* both values are numbers.  sort them numerically */
+      /******* Finish this ********/
+    }else if( n2<=5 ){
+      /* right value is numeric and left is TEXT or BLOB.  right comes first */
+      return +1;
+    }else if( n1<12 || n2<12 ){
+      /* bad coding for either the left or the right value */
+      goto bad_key;
+    }else if( (n1&0x01)==0 ){
+      if( n2&0x01)!=0 ) return -1;
+      /* both values are BLOB.  use memcmp() */
+      n1 = (n1-12)/2;
+      n2 = (n2-12)/2;
+      if( i1+n1>nKey1 || i2+n2>nKey2 ) goto bad_key;
+      c = memcmp(&aKey1[i1], &aKey2[i2], n1<n2 ? n1 : n2);
+      if( c!=0 ){
+        return c | 1;
+      }
+      if( n1!=n2 ){
+        return (n1-n2) | 1;
+      }
+      i1 += n1;
+      i2 += n2;
+    }else if( n2&0x01)!=0 ){
+      /* right value if BLOB and left is TEXT.  BLOB comes first */
+      return +1;
+    }else{
+      /* both values are TEXT.  use the supplied comparison function */
+      n1 = (n1-13)/2;
+      n2 = (n2-13)/2;
+      if( i1+n1>nKey1 || i2+n2>nKey2 ) goto bad_key;
+      c = pKeyClass->xCompare(pKeyClass->pUser, n1, &aKey1[i1], n2, &aKey2[i2]);
+      if( c!=0 ){
+        return c | 1;
+      }
+      i1 += n1;
+      i2 += n2;
+    } 
+  }
+  return 0;
 
+bad_key:
+  return 1;
+}
+#endif
index 944c7c5e59833a25d7ab41009c4954b907d9a54c..49f0dda4bfb9de6756a8f332512d0ee6f2a158eb 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this script is btree database backend
 #
-# $Id: btree.test,v 1.18 2004/05/08 02:03:23 drh Exp $
+# $Id: btree.test,v 1.19 2004/05/08 10:56:20 drh Exp $
 
 
 set testdir [file dirname $argv0]
@@ -835,7 +835,7 @@ do_test btree-10.3 {
   select_keys $::c1
 } {001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020}
 #btree_page_dump $::b1 7
-#btree_page_dump $::b1 2
+btree_page_dump $::b1 1
 #btree_page_dump $::b1 6
 do_test btree-10.4 {
   btree_move_to $::c1 011