Imported Upstream version 5.3.21
[platform/upstream/libdb.git] / lang / sql / adapter / sqlite-patches / 22_unique_key.patch
1 --- src/sqliteInt.h
2 +++ src/sqliteInt.h
3 @@ -1414,7 +1414,6 @@
4    KeyInfo *pKeyInfo;  /* Collation and sort-order information */
5    u16 nField;         /* Number of entries in apMem[] */
6    u16 flags;          /* Boolean settings.  UNPACKED_... below */
7 -  i64 rowid;          /* Used by UNPACKED_PREFIX_SEARCH */
8    Mem *aMem;          /* Values */
9  };
10  
11 @@ -1426,7 +1425,6 @@
12  #define UNPACKED_IGNORE_ROWID  0x0004  /* Ignore trailing rowid on key1 */
13  #define UNPACKED_INCRKEY       0x0008  /* Make this key an epsilon larger */
14  #define UNPACKED_PREFIX_MATCH  0x0010  /* A prefix match is considered OK */
15 -#define UNPACKED_PREFIX_SEARCH 0x0020  /* A prefix match is considered OK */
16  
17  /*
18  ** Each SQL index is represented in memory by an
19 --- src/vdbe.c
20 +++ src/vdbe.c
21 @@ -3526,6 +3526,7 @@
22    Mem *aMx;
23    UnpackedRecord r;                  /* B-Tree index search key */
24    i64 R;                             /* Rowid stored in register P3 */
25 +  i64 rowid;                         /* Rowid found */
26  
27    pIn3 = &aMem[pOp->p3];
28    aMx = &aMem[pOp->p4.i];
29 @@ -3555,8 +3556,8 @@
30    if( pCrsr!=0 ){
31      /* Populate the index search key. */
32      r.pKeyInfo = pCx->pKeyInfo;
33 -    r.nField = nField + 1;
34 -    r.flags = UNPACKED_PREFIX_SEARCH;
35 +    r.nField = nField;
36 +    r.flags = UNPACKED_PREFIX_MATCH;
37      r.aMem = aMx;
38  #ifdef SQLITE_DEBUG
39      { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
40 @@ -3570,10 +3571,14 @@
41      ** to P2. Otherwise, copy the rowid of the conflicting record to
42      ** register P3 and fall through to the next instruction.  */
43      rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &pCx->seekResult);
44 -    if( (r.flags & UNPACKED_PREFIX_SEARCH) || r.rowid==R ){
45 -      pc = pOp->p2 - 1;
46 -    }else{
47 -      pIn3->u.i = r.rowid;
48 +    if( rc != SQLITE_OK || pCx->seekResult != 0 ){
49 +      pc = pOp->p2 - 1;
50 +    }else{ 
51 +      rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
52 +      if (rc == SQLITE_OK && rowid == R)
53 +        pc = pOp->p2 - 1;
54 +      else
55 +        pIn3->u.i = rowid;
56      }
57    }
58    break;
59 --- src/vdbeaux.c
60 +++ src/vdbeaux.c
61 @@ -2916,18 +2916,6 @@
62          rc = -rc;
63        }
64      
65 -      /* If the PREFIX_SEARCH flag is set and all fields except the final
66 -      ** rowid field were equal, then clear the PREFIX_SEARCH flag and set 
67 -      ** pPKey2->rowid to the value of the rowid field in (pKey1, nKey1).
68 -      ** This is used by the OP_IsUnique opcode.
69 -      */
70 -      if( (pPKey2->flags & UNPACKED_PREFIX_SEARCH) && i==(pPKey2->nField-1) ){
71 -        assert( idx1==szHdr1 && rc );
72 -        assert( mem1.flags & MEM_Int );
73 -        pPKey2->flags &= ~UNPACKED_PREFIX_SEARCH;
74 -        pPKey2->rowid = mem1.u.i;
75 -      }
76 -    
77        return rc;
78      }
79      i++;