/ Check-in [90acdbfce9]
Login

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

Overview
Comment:Enhance the rtreenode() function of rtree (used for testing) so that it uses the newer sqlite3_str object for better performance and improved error reporting. Test cases added to TH3.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 90acdbfce9c088582d5165589f7eac462b00062bbfffacdcc786eb9cf3ea5377
User & Date: drh 2019-03-20 11:16:09
Original Comment: Enhance the rtreenode() function of rtree (used for testing) so that it uses the newer sqlite3_str object for better performance and improved error reporting.
Context
2019-03-20
12:08
Fix harmless compiler warnings from MSVC. check-in: f0f02d46e4 user: drh tags: trunk
11:16
Enhance the rtreenode() function of rtree (used for testing) so that it uses the newer sqlite3_str object for better performance and improved error reporting. Test cases added to TH3. check-in: 90acdbfce9 user: drh tags: trunk
2019-03-19
20:42
Enhance the VACUUM INTO command so that it works on read-only databases. check-in: 55be6d0a9f user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/rtree/rtree.c.

  3751   3751   **
  3752   3752   ** The human readable string takes the form of a Tcl list with one
  3753   3753   ** entry for each cell in the r-tree node. Each entry is itself a
  3754   3754   ** list, containing the 8-byte rowid/pageno followed by the 
  3755   3755   ** <num-dimension>*2 coordinates.
  3756   3756   */
  3757   3757   static void rtreenode(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
  3758         -  char *zText = 0;
  3759   3758     RtreeNode node;
  3760   3759     Rtree tree;
  3761   3760     int ii;
         3761  +  int nData;
         3762  +  int errCode;
         3763  +  sqlite3_str *pOut;
  3762   3764   
  3763   3765     UNUSED_PARAMETER(nArg);
  3764   3766     memset(&node, 0, sizeof(RtreeNode));
  3765   3767     memset(&tree, 0, sizeof(Rtree));
  3766   3768     tree.nDim = (u8)sqlite3_value_int(apArg[0]);
         3769  +  if( tree.nDim<1 || tree.nDim>5 ) return;
  3767   3770     tree.nDim2 = tree.nDim*2;
  3768   3771     tree.nBytesPerCell = 8 + 8 * tree.nDim;
  3769   3772     node.zData = (u8 *)sqlite3_value_blob(apArg[1]);
         3773  +  nData = sqlite3_value_bytes(apArg[1]);
         3774  +  if( nData<4 ) return;
         3775  +  if( nData<NCELL(&node)*tree.nBytesPerCell ) return;
  3770   3776   
         3777  +  pOut = sqlite3_str_new(0);
  3771   3778     for(ii=0; ii<NCELL(&node); ii++){
  3772         -    char zCell[512];
  3773         -    int nCell = 0;
  3774   3779       RtreeCell cell;
  3775   3780       int jj;
  3776   3781   
  3777   3782       nodeGetCell(&tree, &node, ii, &cell);
  3778         -    sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid);
  3779         -    nCell = (int)strlen(zCell);
         3783  +    if( ii>0 ) sqlite3_str_append(pOut, " ", 1);
         3784  +    sqlite3_str_appendf(pOut, "{%lld", cell.iRowid);
  3780   3785       for(jj=0; jj<tree.nDim2; jj++){
  3781   3786   #ifndef SQLITE_RTREE_INT_ONLY
  3782         -      sqlite3_snprintf(512-nCell,&zCell[nCell], " %g",
  3783         -                       (double)cell.aCoord[jj].f);
         3787  +      sqlite3_str_appendf(pOut, " %g", (double)cell.aCoord[jj].f);
  3784   3788   #else
  3785         -      sqlite3_snprintf(512-nCell,&zCell[nCell], " %d",
  3786         -                       cell.aCoord[jj].i);
         3789  +      sqlite3_str_appendf(pOut, " %d", cell.aCoord[jj].i);
  3787   3790   #endif
  3788         -      nCell = (int)strlen(zCell);
  3789   3791       }
  3790         -
  3791         -    if( zText ){
  3792         -      char *zTextNew = sqlite3_mprintf("%s {%s}", zText, zCell);
  3793         -      sqlite3_free(zText);
  3794         -      zText = zTextNew;
  3795         -    }else{
  3796         -      zText = sqlite3_mprintf("{%s}", zCell);
  3797         -    }
         3792  +    sqlite3_str_append(pOut, "}", 1);
  3798   3793     }
  3799         -  
  3800         -  sqlite3_result_text(ctx, zText, -1, sqlite3_free);
         3794  +  errCode = sqlite3_str_errcode(pOut);
         3795  +  sqlite3_result_text(ctx, sqlite3_str_finish(pOut), -1, sqlite3_free);
         3796  +  sqlite3_result_error_code(ctx, errCode);
  3801   3797   }
  3802   3798   
  3803   3799   /* This routine implements an SQL function that returns the "depth" parameter
  3804   3800   ** from the front of a blob that is an r-tree node.  For example:
  3805   3801   **
  3806   3802   **     SELECT rtreedepth(data) FROM rt_node WHERE nodeno=1;
  3807   3803   **