/ Check-in [6fc4fbfa]
Login

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

Overview
Comment:Fix a problem with the pre-update hook on this branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trim-nulls
Files: files | file ages | folders
SHA1: 6fc4fbfa29cfa795edf32e4a1f2d0eceb3007f68
User & Date: dan 2017-01-25 17:44:13
Context
2017-01-25
18:12
Fix a test script problem in exclusive2.test causing it to fail on this branch. check-in: f66614dc user: dan tags: trim-nulls
17:44
Fix a problem with the pre-update hook on this branch. check-in: 6fc4fbfa user: dan tags: trim-nulls
14:58
Experimental enhancement to automatically trim NULL values from the end of records, for a reduced disk footprint. This change also involves increasing the P5 operand from 8 to 16 bits. check-in: 118ded40 user: drh tags: trim-nulls
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbeapi.c.

  1772   1772         pUnpack = vdbeUnpackRecord(&p->keyinfo, pData->n, pData->z);
  1773   1773         if( !pUnpack ){
  1774   1774           rc = SQLITE_NOMEM;
  1775   1775           goto preupdate_new_out;
  1776   1776         }
  1777   1777         p->pNewUnpacked = pUnpack;
  1778   1778       }
  1779         -    if( iIdx>=pUnpack->nField ){
         1779  +    pMem = &pUnpack->aMem[iIdx];
         1780  +    if( iIdx==p->pTab->iPKey ){
         1781  +      sqlite3VdbeMemSetInt64(pMem, p->iKey2);
         1782  +    }else if( iIdx>=pUnpack->nField ){
  1780   1783         pMem = (sqlite3_value *)columnNullValue();
  1781         -    }else{
  1782         -      pMem = &pUnpack->aMem[iIdx];
  1783         -      if( iIdx==p->pTab->iPKey ){
  1784         -        sqlite3VdbeMemSetInt64(pMem, p->iKey2);
  1785         -      }
  1786   1784       }
  1787   1785     }else{
  1788   1786       /* For an UPDATE, memory cell (p->iNewReg+1+iIdx) contains the required
  1789   1787       ** value. Make a copy of the cell contents and return a pointer to it.
  1790   1788       ** It is not safe to return a pointer to the memory cell itself as the
  1791   1789       ** caller may modify the value text encoding.
  1792   1790       */

Changes to src/vdbeaux.c.

  4581   4581   ** If the second argument is not NULL, release any allocations associated 
  4582   4582   ** with the memory cells in the p->aMem[] array. Also free the UnpackedRecord
  4583   4583   ** structure itself, using sqlite3DbFree().
  4584   4584   **
  4585   4585   ** This function is used to free UnpackedRecord structures allocated by
  4586   4586   ** the vdbeUnpackRecord() function found in vdbeapi.c.
  4587   4587   */
  4588         -static void vdbeFreeUnpacked(sqlite3 *db, UnpackedRecord *p){
         4588  +static void vdbeFreeUnpacked(sqlite3 *db, int nField, UnpackedRecord *p){
  4589   4589     if( p ){
  4590   4590       int i;
  4591         -    for(i=0; i<p->nField; i++){
         4591  +    for(i=0; i<nField; i++){
  4592   4592         Mem *pMem = &p->aMem[i];
  4593   4593         if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem);
  4594   4594       }
  4595   4595       sqlite3DbFree(db, p);
  4596   4596     }
  4597   4597   }
  4598   4598   #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
................................................................................
  4643   4643     preupdate.iKey2 = iKey2;
  4644   4644     preupdate.pTab = pTab;
  4645   4645   
  4646   4646     db->pPreUpdate = &preupdate;
  4647   4647     db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2);
  4648   4648     db->pPreUpdate = 0;
  4649   4649     sqlite3DbFree(db, preupdate.aRecord);
  4650         -  vdbeFreeUnpacked(db, preupdate.pUnpacked);
  4651         -  vdbeFreeUnpacked(db, preupdate.pNewUnpacked);
         4650  +  vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pUnpacked);
         4651  +  vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pNewUnpacked);
  4652   4652     if( preupdate.aNew ){
  4653   4653       int i;
  4654   4654       for(i=0; i<pCsr->nField; i++){
  4655   4655         sqlite3VdbeMemRelease(&preupdate.aNew[i]);
  4656   4656       }
  4657   4657       sqlite3DbFree(db, preupdate.aNew);
  4658   4658     }
  4659   4659   }
  4660   4660   #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */

Changes to test/hook.test.

   849    849   }
   850    850   
   851    851   # No preupdate callbacks for modifying sqlite_master.
   852    852   do_preupdate_test 8.1 {
   853    853     CREATE TABLE x1(x, y);
   854    854   } {
   855    855   }
          856  +
          857  +#-------------------------------------------------------------------------
          858  +reset_db
          859  +db preupdate hook preupdate_hook
          860  +do_execsql_test 9.0 {
          861  +  CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
          862  +  CREATE TABLE t2(a, b INTEGER PRIMARY KEY);
          863  +}
          864  +do_preupdate_test 9.1 {
          865  +  INSERT INTO t1 VALUES(456, NULL, NULL);
          866  +} {
          867  +  INSERT main t1 456 456  0  456 {} {}
          868  +}
          869  +do_execsql_test 9.2 {
          870  +  ALTER TABLE t1 ADD COLUMN d;
          871  +}
          872  +do_preupdate_test 9.3 {
          873  +  INSERT INTO t1(a, b, c) VALUES(457, NULL, NULL);
          874  +} {
          875  +  INSERT main t1 457 457  0  457 {} {} {}
          876  +}
          877  +do_preupdate_test 9.4 {
          878  +  DELETE FROM t1 WHERE a=456
          879  +} {
          880  +  DELETE main t1 456 456  0  456 {} {} {}
          881  +}
          882  +do_preupdate_test 9.5 {
          883  +  INSERT INTO t2 DEFAULT VALUES;
          884  +} {
          885  +  INSERT main t2 1 1  0  {} 1
          886  +} 
          887  +do_preupdate_test 9.6 {
          888  +  INSERT INTO t1 DEFAULT VALUES;
          889  +} {
          890  +  INSERT main t1 458 458  0  458 {} {} {}
          891  +} 
   856    892   
   857    893   finish_test

Changes to test/tester.tcl.

   457    457           foreach {dummy cmdlinearg(malloctrace)} [split $a =] break
   458    458           if {$cmdlinearg(malloctrace)} {
   459    459             sqlite3_memdebug_log start
   460    460           }
   461    461         }
   462    462         {^-+backtrace=.+$} {
   463    463           foreach {dummy cmdlinearg(backtrace)} [split $a =] break
   464         -        sqlite3_memdebug_backtrace $value
          464  +        sqlite3_memdebug_backtrace $cmdlinearg(backtrace)
   465    465         }
   466    466         {^-+binarylog=.+$} {
   467    467           foreach {dummy cmdlinearg(binarylog)} [split $a =] break
   468    468           set cmdlinearg(binarylog) [file normalize $cmdlinearg(binarylog)]
   469    469         }
   470    470         {^-+soak=.+$} {
   471    471           foreach {dummy cmdlinearg(soak)} [split $a =] break