/ Check-in [a09518ab]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remove some unused code from the sessions module.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sessions-rebase
Files: files | file ages | folders
SHA3-256: a09518ab63a1ef1b7f56b9f9b16269fd83920469d4c4e179b1f68b35df4e0c4b
User & Date: dan 2018-03-22 11:15:59
Context
2018-03-22
14:07
Add tests to ensure that patchsets are handled correctly by the session rebase APIs. check-in: 0e45baae user: dan tags: sessions-rebase
11:15
Remove some unused code from the sessions module. check-in: a09518ab user: dan tags: sessions-rebase
2018-03-21
20:13
Merge latest trunk changes into this branch. check-in: d00b71ec user: dan tags: sessions-rebase
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/session/sqlite3session.c.

  3791   3791       rc = sqlite3_step(pSelect);
  3792   3792       if( rc!=SQLITE_ROW ) rc = sqlite3_reset(pSelect);
  3793   3793     }
  3794   3794   
  3795   3795     return rc;
  3796   3796   }
  3797   3797   
         3798  +/*
         3799  +** This function is called from within sqlite3changset_apply_v2() when
         3800  +** a conflict is encountered and resolved using conflict resolution
         3801  +** mode eType (either SQLITE_CHANGESET_OMIT or SQLITE_CHANGESET_REPLACE)..
         3802  +** It adds a conflict resolution record to the buffer in 
         3803  +** SessionApplyCtx.rebase, which will eventually be returned to the caller
         3804  +** of apply_v2() as the "rebase" buffer.
         3805  +**
         3806  +** Return SQLITE_OK if successful, or an SQLite error code otherwise.
         3807  +*/
  3798   3808   static int sessionRebaseAdd(
  3799         -  SessionApplyCtx *p, 
  3800         -  int eType, 
  3801         -  sqlite3_changeset_iter *pIter
         3809  +  SessionApplyCtx *p,             /* Apply context */
         3810  +  int eType,                      /* Conflict resolution (OMIT or REPLACE) */
         3811  +  sqlite3_changeset_iter *pIter   /* Iterator pointing at current change */
  3802   3812   ){
  3803   3813     int rc = SQLITE_OK;
  3804   3814     int i;
  3805   3815     int eOp = pIter->op;
  3806   3816     if( p->bRebaseStarted==0 ){
  3807   3817       /* Append a table-header to the rebase buffer */
  3808   3818       const char *zTab = pIter->zTab;
................................................................................
  4395   4405     sqlite3_free((char*)sApply.azCol);  /* cast works around VC++ bug */
  4396   4406     sqlite3_free((char*)sApply.constraints.aBuf);
  4397   4407     sqlite3_free((char*)sApply.rebase.aBuf);
  4398   4408     sqlite3_mutex_leave(sqlite3_db_mutex(db));
  4399   4409     return rc;
  4400   4410   }
  4401   4411   
         4412  +/*
         4413  +** Apply the changeset passed via pChangeset/nChangeset to the main 
         4414  +** database attached to handle "db".
         4415  +*/
  4402   4416   int sqlite3changeset_apply_v2(
  4403   4417     sqlite3 *db,                    /* Apply change to "main" db of this handle */
  4404   4418     int nChangeset,                 /* Size of changeset in bytes */
  4405   4419     void *pChangeset,               /* Changeset blob */
  4406   4420     int(*xFilter)(
  4407   4421       void *pCtx,                   /* Copy of sixth arg to _apply() */
  4408   4422       const char *zTab              /* Table name */
................................................................................
  5013   5027   struct sqlite3_rebaser {
  5014   5028     sqlite3_changegroup grp;        /* Hash table */
  5015   5029   };
  5016   5030   
  5017   5031   /*
  5018   5032   ** Buffers a1 and a2 must both contain a sessions module record nCol
  5019   5033   ** fields in size. This function appends an nCol sessions module 
  5020         -** record to buffer pBuf that is a copy of a1, except that:
  5021         -**
  5022         -**   + If bUndefined is 0, for each field that is not "undefined" in either
  5023         -**     a1[] or a2[], swap in the field from a2[].
  5024         -**
  5025         -**   + If bUndefined is 1, for each field that is "undefined" in a1[]
  5026         -**     swap in the field from a2[].
         5034  +** record to buffer pBuf that is a copy of a1, except that for
         5035  +** each field that is undefined in a1[], swap in the field from a2[].
  5027   5036   */
  5028   5037   static void sessionAppendRecordMerge(
  5029         -  SessionBuffer *pBuf,
  5030         -  int nCol,
  5031         -  int bUndefined,
  5032         -  u8 *a1, int n1,
  5033         -  u8 *a2, int n2,
  5034         -  int *pRc
         5038  +  SessionBuffer *pBuf,            /* Buffer to append to */
         5039  +  int nCol,                       /* Number of columns in each record */
         5040  +  u8 *a1, int n1,                 /* Record 1 */
         5041  +  u8 *a2, int n2,                 /* Record 2 */
         5042  +  int *pRc                        /* IN/OUT: error code */
  5035   5043   ){
  5036   5044     sessionBufferGrow(pBuf, n1+n2, pRc);
  5037   5045     if( *pRc==SQLITE_OK ){
  5038   5046       int i;
  5039   5047       u8 *pOut = &pBuf->aBuf[pBuf->nBuf];
  5040   5048       for(i=0; i<nCol; i++){
  5041   5049         int nn1 = sessionSerialLen(a1);
  5042   5050         int nn2 = sessionSerialLen(a2);
  5043         -      if( bUndefined==0 ){
  5044         -        if( *a1 && *a2 ){
  5045         -          memcpy(pOut, a2, nn2);
  5046         -          pOut += nn2;
  5047         -        }else{
  5048         -          memcpy(pOut, a1, nn1);
  5049         -          pOut += nn1;
  5050         -        }
         5051  +      if( *a1==0 || *a1==0xFF ){
         5052  +        memcpy(pOut, a2, nn2);
         5053  +        pOut += nn2;
  5051   5054         }else{
  5052         -        if( *a1==0 || *a1==0xFF ){
  5053         -          memcpy(pOut, a2, nn2);
  5054         -          pOut += nn2;
  5055         -        }else{
  5056         -          memcpy(pOut, a1, nn1);
  5057         -          pOut += nn1;
  5058         -        }
         5055  +        memcpy(pOut, a1, nn1);
         5056  +        pOut += nn1;
  5059   5057         }
  5060   5058         a1 += nn1;
  5061   5059         a2 += nn2;
  5062   5060       }
  5063   5061   
  5064   5062       pBuf->nBuf = pOut-pBuf->aBuf;
  5065   5063       assert( pBuf->nBuf<=pBuf->nAlloc );
................................................................................
  5187   5185             bDone = 1;
  5188   5186             if( pChange->op==SQLITE_DELETE ){
  5189   5187               if( pChange->bIndirect==0 ){
  5190   5188                 u8 *pCsr = aRec;
  5191   5189                 sessionSkipRecord(&pCsr, pIter->nCol);
  5192   5190                 sessionAppendByte(&sOut, SQLITE_INSERT, &rc);
  5193   5191                 sessionAppendByte(&sOut, pIter->bIndirect, &rc);
  5194         -              sessionAppendRecordMerge(&sOut, pIter->nCol, 1,
         5192  +              sessionAppendRecordMerge(&sOut, pIter->nCol,
  5195   5193                     pCsr, nRec-(pCsr-aRec), 
  5196   5194                     pChange->aRecord, pChange->nRecord, &rc
  5197   5195                 );
  5198   5196               }
  5199   5197             }else{
  5200   5198               sessionAppendPartialUpdate(&sOut, pIter,
  5201   5199                   aRec, nRec, pChange->aRecord, pChange->nRecord, &rc
................................................................................
  5205   5203   
  5206   5204           default:
  5207   5205             assert( pIter->op==SQLITE_DELETE );
  5208   5206             bDone = 1;
  5209   5207             if( pChange->op==SQLITE_INSERT ){
  5210   5208               sessionAppendByte(&sOut, SQLITE_DELETE, &rc);
  5211   5209               sessionAppendByte(&sOut, pIter->bIndirect, &rc);
  5212         -            sessionAppendRecordMerge(&sOut, pIter->nCol, 1,
         5210  +            sessionAppendRecordMerge(&sOut, pIter->nCol,
  5213   5211                   pChange->aRecord, pChange->nRecord, aRec, nRec, &rc
  5214   5212               );
  5215   5213             }
  5216   5214             break;
  5217   5215         }
  5218   5216       }
  5219   5217