Lines Matching refs:pRtree

218429     (pRtree->eCoordType==RTREE_COORD_REAL32) ?      \
218733 static void nodeZero(Rtree *pRtree, RtreeNode *p){ argument
218734 memset(&p->zData[2], 0, pRtree->iNodeSize-2);
218750 static RtreeNode *nodeHashLookup(Rtree *pRtree, i64 iNode){ argument
218752 for(p=pRtree->aHash[nodeHash(iNode)]; p && p->iNode!=iNode; p=p->pNext);
218759 static void nodeHashInsert(Rtree *pRtree, RtreeNode *pNode){ argument
218763 pNode->pNext = pRtree->aHash[iHash];
218764 pRtree->aHash[iHash] = pNode;
218770 static void nodeHashDelete(Rtree *pRtree, RtreeNode *pNode){ argument
218773 pp = &pRtree->aHash[nodeHash(pNode->iNode)];
218786 static RtreeNode *nodeNew(Rtree *pRtree, RtreeNode *pParent){ argument
218788 pNode = (RtreeNode *)sqlite3_malloc64(sizeof(RtreeNode) + pRtree->iNodeSize);
218790 memset(pNode, 0, sizeof(RtreeNode) + pRtree->iNodeSize);
218793 pRtree->nNodeRef++;
218804 static void nodeBlobReset(Rtree *pRtree){ argument
218805 sqlite3_blob *pBlob = pRtree->pNodeBlob;
218806 pRtree->pNodeBlob = 0;
218814 Rtree *pRtree, /* R-tree structure */ argument
218825 if( (pNode = nodeHashLookup(pRtree, iNode))!=0 ){
218827 RTREE_IS_CORRUPT(pRtree);
218835 if( pRtree->pNodeBlob ){
218836 sqlite3_blob *pBlob = pRtree->pNodeBlob;
218837 pRtree->pNodeBlob = 0;
218839 pRtree->pNodeBlob = pBlob;
218841 nodeBlobReset(pRtree);
218845 if( pRtree->pNodeBlob==0 ){
218846 rc = sqlite3_blob_open(pRtree->db, pRtree->zDb, pRtree->zNodeName,
218848 &pRtree->pNodeBlob);
218856 RTREE_IS_CORRUPT(pRtree);
218858 }else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){
218859 pNode = (RtreeNode *)sqlite3_malloc64(sizeof(RtreeNode)+pRtree->iNodeSize);
218866 pRtree->nNodeRef++;
218870 rc = sqlite3_blob_read(pRtree->pNodeBlob, pNode->zData,
218871 pRtree->iNodeSize, 0);
218882 pRtree->iDepth = readInt16(pNode->zData);
218883 if( pRtree->iDepth>RTREE_MAX_DEPTH ){
218885 RTREE_IS_CORRUPT(pRtree);
218894 if( NCELL(pNode)>((pRtree->iNodeSize-4)/pRtree->nBytesPerCell) ){
218896 RTREE_IS_CORRUPT(pRtree);
218903 nodeHashInsert(pRtree, pNode);
218906 RTREE_IS_CORRUPT(pRtree);
218910 nodeBlobReset(pRtree);
218912 pRtree->nNodeRef--;
218925 Rtree *pRtree, /* The overall R-Tree */ argument
218931 u8 *p = &pNode->zData[4 + pRtree->nBytesPerCell*iCell];
218933 for(ii=0; ii<pRtree->nDim2; ii++){
218942 static void nodeDeleteCell(Rtree *pRtree, RtreeNode *pNode, int iCell){ argument
218943 u8 *pDst = &pNode->zData[4 + pRtree->nBytesPerCell*iCell];
218944 u8 *pSrc = &pDst[pRtree->nBytesPerCell];
218945 int nByte = (NCELL(pNode) - iCell - 1) * pRtree->nBytesPerCell;
218958 Rtree *pRtree, /* The overall R-Tree */ argument
218965 nMaxCell = (pRtree->iNodeSize-4)/pRtree->nBytesPerCell;
218970 nodeOverwriteCell(pRtree, pNode, pCell, nCell);
218981 static int nodeWrite(Rtree *pRtree, RtreeNode *pNode){ argument
218984 sqlite3_stmt *p = pRtree->pWriteNode;
218990 sqlite3_bind_blob(p, 2, pNode->zData, pRtree->iNodeSize, SQLITE_STATIC);
218996 pNode->iNode = sqlite3_last_insert_rowid(pRtree->db);
218997 nodeHashInsert(pRtree, pNode);
219007 static int nodeRelease(Rtree *pRtree, RtreeNode *pNode){ argument
219011 assert( pRtree->nNodeRef>0 );
219014 pRtree->nNodeRef--;
219016 pRtree->iDepth = -1;
219019 rc = nodeRelease(pRtree, pNode->pParent);
219022 rc = nodeWrite(pRtree, pNode);
219024 nodeHashDelete(pRtree, pNode);
219037 Rtree *pRtree, /* The overall R-Tree */ argument
219042 return readInt64(&pNode->zData[4 + pRtree->nBytesPerCell*iCell]);
219049 Rtree *pRtree, /* The overall R-Tree */ argument
219056 readCoord(&pNode->zData[12 + pRtree->nBytesPerCell*iCell + 4*iCoord], pCoord);
219064 Rtree *pRtree, /* The overall R-Tree */ argument
219072 pCell->iRowid = nodeGetRowid(pRtree, pNode, iCell);
219073 pData = pNode->zData + (12 + pRtree->nBytesPerCell*iCell);
219080 }while( ii<pRtree->nDim2 );
219120 static void rtreeReference(Rtree *pRtree){ argument
219121 pRtree->nBusy++;
219128 static void rtreeRelease(Rtree *pRtree){ argument
219129 pRtree->nBusy--;
219130 if( pRtree->nBusy==0 ){
219131 pRtree->inWrTrans = 0;
219132 assert( pRtree->nCursor==0 );
219133 nodeBlobReset(pRtree);
219134 if( pRtree->nNodeRef ){
219136 assert( pRtree->bCorrupt );
219138 while( pRtree->aHash[i] ){
219139 RtreeNode *pNext = pRtree->aHash[i]->pNext;
219140 sqlite3_free(pRtree->aHash[i]);
219141 pRtree->aHash[i] = pNext;
219145 sqlite3_finalize(pRtree->pWriteNode);
219146 sqlite3_finalize(pRtree->pDeleteNode);
219147 sqlite3_finalize(pRtree->pReadRowid);
219148 sqlite3_finalize(pRtree->pWriteRowid);
219149 sqlite3_finalize(pRtree->pDeleteRowid);
219150 sqlite3_finalize(pRtree->pReadParent);
219151 sqlite3_finalize(pRtree->pWriteParent);
219152 sqlite3_finalize(pRtree->pDeleteParent);
219153 sqlite3_finalize(pRtree->pWriteAux);
219154 sqlite3_free(pRtree->zReadAuxSql);
219155 sqlite3_free(pRtree);
219171 Rtree *pRtree = (Rtree *)pVtab; local
219177 pRtree->zDb, pRtree->zName,
219178 pRtree->zDb, pRtree->zName,
219179 pRtree->zDb, pRtree->zName
219184 nodeBlobReset(pRtree);
219185 rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0);
219189 rtreeRelease(pRtree);
219200 Rtree *pRtree = (Rtree *)pVTab; local
219208 pRtree->nCursor++;
219220 Rtree *pRtree = (Rtree *)(pCsr->base.pVtab); local
219235 for(ii=0; ii<RTREE_CACHE_SZ; ii++) nodeRelease(pRtree, pCsr->aNode[ii]);
219239 pCsr->base.pVtab = (sqlite3_vtab*)pRtree;
219254 Rtree *pRtree = (Rtree *)(cur->pVtab); local
219256 assert( pRtree->nCursor>0 );
219260 pRtree->nCursor--;
219261 if( pRtree->nCursor==0 && pRtree->inWrTrans==0 ){
219262 nodeBlobReset(pRtree);
219492 Rtree *pRtree, argument
219501 if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){
219506 RTREE_IS_CORRUPT(pRtree);
219514 static int nodeParentIndex(Rtree *pRtree, RtreeNode *pNode, int *piIndex){ argument
219517 return nodeRowidIndex(pRtree, pParent, pNode->iNode, piIndex);
219745 Rtree *pRtree = RTREE_OF_CURSOR(pCur); local
219755 eInt = pRtree->eCoordType==RTREE_COORD_INT32;
219762 pCellData = pNode->zData + (4+pRtree->nBytesPerCell*p->iCell);
219779 pCellData += pRtree->nBytesPerCell;
219790 RTREE_IS_CORRUPT(pRtree);
219861 Rtree *pRtree = (Rtree *)cur->pVtab; local
219872 sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell));
219873 }else if( i<=pRtree->nDim2 ){
219874 nodeGetCoord(pRtree, pNode, p->iCell, i-1, &c);
219876 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
219881 assert( pRtree->eCoordType==RTREE_COORD_INT32 );
219887 rc = sqlite3_prepare_v3(pRtree->db, pRtree->zReadAuxSql, -1, 0,
219892 nodeGetRowid(pRtree, pNode, p->iCell));
219903 sqlite3_column_value(pCsr->pReadAux, i - pRtree->nDim2 + 1));
219916 Rtree *pRtree, /* RTree to search */ argument
219923 sqlite3_bind_int64(pRtree->pReadRowid, 1, iRowid);
219924 if( sqlite3_step(pRtree->pReadRowid)==SQLITE_ROW ){
219925 i64 iNode = sqlite3_column_int64(pRtree->pReadRowid, 0);
219927 rc = nodeAcquire(pRtree, iNode, 0, ppLeaf);
219928 sqlite3_reset(pRtree->pReadRowid);
219930 rc = sqlite3_reset(pRtree->pReadRowid);
219978 Rtree *pRtree = (Rtree *)pVtabCursor->pVtab; local
219985 rtreeReference(pRtree);
220002 rc = findLeafNode(pRtree, iRowid, &pLeaf, &iNode);
220013 rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &iCell);
220023 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
220031 memset(pCsr->anQueue, 0, sizeof(u32)*(pRtree->iDepth + 1));
220048 p->pInfo->nCoord = pRtree->nDim2;
220050 p->pInfo->mxLevel = pRtree->iDepth + 1;
220086 pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, (u8)(pRtree->iDepth+1));
220101 nodeRelease(pRtree, pRoot);
220102 rtreeRelease(pRtree);
220141 Rtree *pRtree = (Rtree*)tab; local
220191 && ((p->iColumn>0 && p->iColumn<=pRtree->nDim2)
220224 nRow = pRtree->nRowEst >> (iIdx/2);
220234 static RtreeDValue cellArea(Rtree *pRtree, RtreeCell *p){ argument
220236 assert( pRtree->nDim>=1 && pRtree->nDim<=5 );
220238 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
220239 switch( pRtree->nDim ){
220249 switch( pRtree->nDim ){
220264 static RtreeDValue cellMargin(Rtree *pRtree, RtreeCell *p){ argument
220266 int ii = pRtree->nDim2 - 2;
220277 static void cellUnion(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){ argument
220279 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
220284 }while( ii<pRtree->nDim2 );
220290 }while( ii<pRtree->nDim2 );
220298 static int cellContains(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){ argument
220300 if( pRtree->eCoordType==RTREE_COORD_INT32 ){
220301 for(ii=0; ii<pRtree->nDim2; ii+=2){
220307 for(ii=0; ii<pRtree->nDim2; ii+=2){
220317 Rtree *pRtree, argument
220327 for(jj=0; jj<pRtree->nDim2; jj+=2){
220349 Rtree *pRtree, /* Rtree table */ argument
220357 rc = nodeAcquire(pRtree, 1, 0, &pNode);
220359 for(ii=0; rc==SQLITE_OK && ii<(pRtree->iDepth-iHeight); ii++){
220374 nodeGetCell(pRtree, pNode, iCell, &cell);
220375 if( cellContains(pRtree, &cell, pCell) ){
220376 RtreeDValue area = cellArea(pRtree, &cell);
220393 nodeGetCell(pRtree, pNode, iCell, &cell);
220394 area = cellArea(pRtree, &cell);
220395 cellUnion(pRtree, &cell, pCell);
220396 growth = cellArea(pRtree, &cell)-area;
220408 rc = nodeAcquire(pRtree, iBest, pNode, &pChild);
220409 nodeRelease(pRtree, pNode);
220423 Rtree *pRtree, /* Rtree table */ argument
220437 RTREE_IS_CORRUPT(pRtree);
220440 rc = nodeParentIndex(pRtree, p, &iCell);
220442 RTREE_IS_CORRUPT(pRtree);
220446 nodeGetCell(pRtree, pParent, iCell, &cell);
220447 if( !cellContains(pRtree, &cell, pCell) ){
220448 cellUnion(pRtree, &cell, pCell);
220449 nodeOverwriteCell(pRtree, pParent, &cell, iCell);
220460 static int rowidWrite(Rtree *pRtree, sqlite3_int64 iRowid, sqlite3_int64 iNode){ argument
220461 sqlite3_bind_int64(pRtree->pWriteRowid, 1, iRowid);
220462 sqlite3_bind_int64(pRtree->pWriteRowid, 2, iNode);
220463 sqlite3_step(pRtree->pWriteRowid);
220464 return sqlite3_reset(pRtree->pWriteRowid);
220470 static int parentWrite(Rtree *pRtree, sqlite3_int64 iNode, sqlite3_int64 iPar){ argument
220471 sqlite3_bind_int64(pRtree->pWriteParent, 1, iNode);
220472 sqlite3_bind_int64(pRtree->pWriteParent, 2, iPar);
220473 sqlite3_step(pRtree->pWriteParent);
220474 return sqlite3_reset(pRtree->pWriteParent);
220493 Rtree *pRtree, argument
220510 SortByDimension(pRtree, aLeft, nLeft, iDim, aCell, aSpare);
220511 SortByDimension(pRtree, aRight, nRight, iDim, aCell, aSpare);
220552 Rtree *pRtree, argument
220568 sqlite3_int64 nByte = (pRtree->nDim+1)*(sizeof(int*)+nCell*sizeof(int));
220575 aSpare = &((int *)&aaSorted[pRtree->nDim])[pRtree->nDim*nCell];
220577 for(ii=0; ii<pRtree->nDim; ii++){
220579 aaSorted[ii] = &((int *)&aaSorted[pRtree->nDim])[ii*nCell];
220583 SortByDimension(pRtree, aaSorted[ii], nCell, ii, aCell, aSpare);
220586 for(ii=0; ii<pRtree->nDim; ii++){
220594 nLeft=RTREE_MINCELLS(pRtree);
220595 nLeft<=(nCell-RTREE_MINCELLS(pRtree));
220608 cellUnion(pRtree, &left, &aCell[aaSorted[ii][kk]]);
220610 cellUnion(pRtree, &right, &aCell[aaSorted[ii][kk]]);
220613 margin += cellMargin(pRtree, &left);
220614 margin += cellMargin(pRtree, &right);
220615 overlap = cellOverlap(pRtree, &left, &right, 1);
220616 area = cellArea(pRtree, &left) + cellArea(pRtree, &right);
220617 if( (nLeft==RTREE_MINCELLS(pRtree))
220640 nodeInsertCell(pRtree, pTarget, pCell);
220641 cellUnion(pRtree, pBbox, pCell);
220650 Rtree *pRtree, argument
220658 RtreeNode *pChild = nodeHashLookup(pRtree, iRowid);
220664 nodeRelease(pRtree, pChild->pParent);
220670 return xSetMapping(pRtree, iRowid, pNode->iNode);
220674 Rtree *pRtree, argument
220704 nodeGetCell(pRtree, pNode, i, &aCell[i]);
220706 nodeZero(pRtree, pNode);
220711 pRight = nodeNew(pRtree, pNode);
220712 pLeft = nodeNew(pRtree, pNode);
220713 pRtree->iDepth++;
220715 writeInt16(pNode->zData, pRtree->iDepth);
220718 pRight = nodeNew(pRtree, pLeft->pParent);
220727 memset(pLeft->zData, 0, pRtree->iNodeSize);
220728 memset(pRight->zData, 0, pRtree->iNodeSize);
220730 rc = splitNodeStartree(pRtree, aCell, nCell, pLeft, pRight,
220741 if( SQLITE_OK!=(rc = nodeWrite(pRtree, pRight))
220742 || (0==pLeft->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pLeft)))
220751 rc = rtreeInsertCell(pRtree, pLeft->pParent, &leftbbox, iHeight+1);
220758 rc = nodeParentIndex(pRtree, pLeft, &iCell);
220760 nodeOverwriteCell(pRtree, pParent, &leftbbox, iCell);
220761 rc = AdjustTree(pRtree, pParent, &leftbbox);
220768 if( (rc = rtreeInsertCell(pRtree, pRight->pParent, &rightbbox, iHeight+1)) ){
220773 i64 iRowid = nodeGetRowid(pRtree, pRight, i);
220774 rc = updateMapping(pRtree, iRowid, pRight, iHeight);
220784 i64 iRowid = nodeGetRowid(pRtree, pLeft, i);
220785 rc = updateMapping(pRtree, iRowid, pLeft, iHeight);
220791 rc = updateMapping(pRtree, pCell->iRowid, pLeft, iHeight);
220795 nodeRelease(pRtree, pRight);
220796 nodeRelease(pRtree, pLeft);
220812 static int fixLeafParent(Rtree *pRtree, RtreeNode *pLeaf){ argument
220817 sqlite3_bind_int64(pRtree->pReadParent, 1, pChild->iNode);
220818 rc = sqlite3_step(pRtree->pReadParent);
220828 iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
220831 rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
220834 rc = sqlite3_reset(pRtree->pReadParent);
220837 RTREE_IS_CORRUPT(pRtree);
220847 static int removeNode(Rtree *pRtree, RtreeNode *pNode, int iHeight){ argument
220856 rc = nodeParentIndex(pRtree, pNode, &iCell);
220860 rc = deleteCell(pRtree, pParent, iCell, iHeight+1);
220863 rc2 = nodeRelease(pRtree, pParent);
220872 sqlite3_bind_int64(pRtree->pDeleteNode, 1, pNode->iNode);
220873 sqlite3_step(pRtree->pDeleteNode);
220874 if( SQLITE_OK!=(rc = sqlite3_reset(pRtree->pDeleteNode)) ){
220879 sqlite3_bind_int64(pRtree->pDeleteParent, 1, pNode->iNode);
220880 sqlite3_step(pRtree->pDeleteParent);
220881 if( SQLITE_OK!=(rc = sqlite3_reset(pRtree->pDeleteParent)) ){
220888 nodeHashDelete(pRtree, pNode);
220890 pNode->pNext = pRtree->pDeleted;
220892 pRtree->pDeleted = pNode;
220897 static int fixBoundingBox(Rtree *pRtree, RtreeNode *pNode){ argument
220904 nodeGetCell(pRtree, pNode, 0, &box);
220907 nodeGetCell(pRtree, pNode, ii, &cell);
220908 cellUnion(pRtree, &box, &cell);
220911 rc = nodeParentIndex(pRtree, pNode, &ii);
220913 nodeOverwriteCell(pRtree, pParent, &box, ii);
220914 rc = fixBoundingBox(pRtree, pParent);
220924 static int deleteCell(Rtree *pRtree, RtreeNode *pNode, int iCell, int iHeight){ argument
220928 if( SQLITE_OK!=(rc = fixLeafParent(pRtree, pNode)) ){
220935 nodeDeleteCell(pRtree, pNode, iCell);
220945 if( NCELL(pNode)<RTREE_MINCELLS(pRtree) ){
220946 rc = removeNode(pRtree, pNode, iHeight);
220948 rc = fixBoundingBox(pRtree, pNode);
220960 Rtree *pRtree, argument
220967 RtreeNode *pChild = nodeHashLookup(pRtree, pCell->iRowid);
220969 nodeRelease(pRtree, pChild->pParent);
220974 if( nodeInsertCell(pRtree, pNode, pCell) ){
220975 rc = SplitNode(pRtree, pNode, pCell, iHeight);
220977 rc = AdjustTree(pRtree, pNode, pCell);
220980 rc = rowidWrite(pRtree, pCell->iRowid, pNode->iNode);
220982 rc = parentWrite(pRtree, pCell->iRowid, pNode->iNode);
220989 static int reinsertNodeContent(Rtree *pRtree, RtreeNode *pNode){ argument
220997 nodeGetCell(pRtree, pNode, ii, &cell);
221002 rc = ChooseLeaf(pRtree, &cell, (int)pNode->iNode, &pInsert);
221005 rc = rtreeInsertCell(pRtree, pInsert, &cell, (int)pNode->iNode);
221006 rc2 = nodeRelease(pRtree, pInsert);
221018 static int rtreeNewRowid(Rtree *pRtree, i64 *piRowid){ argument
221020 sqlite3_bind_null(pRtree->pWriteRowid, 1);
221021 sqlite3_bind_null(pRtree->pWriteRowid, 2);
221022 sqlite3_step(pRtree->pWriteRowid);
221023 rc = sqlite3_reset(pRtree->pWriteRowid);
221024 *piRowid = sqlite3_last_insert_rowid(pRtree->db);
221031 static int rtreeDeleteRowid(Rtree *pRtree, sqlite3_int64 iDelete){ argument
221039 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
221045 rc = findLeafNode(pRtree, iDelete, &pLeaf, 0);
221055 rc = nodeRowidIndex(pRtree, pLeaf, iDelete, &iCell);
221057 rc = deleteCell(pRtree, pLeaf, iCell, 0);
221059 rc2 = nodeRelease(pRtree, pLeaf);
221067 sqlite3_bind_int64(pRtree->pDeleteRowid, 1, iDelete);
221068 sqlite3_step(pRtree->pDeleteRowid);
221069 rc = sqlite3_reset(pRtree->pDeleteRowid);
221080 if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
221083 i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
221084 rc = nodeAcquire(pRtree, iChild, pRoot, &pChild); /* tag-20210916a */
221086 rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
221088 rc2 = nodeRelease(pRtree, pChild);
221091 pRtree->iDepth--;
221092 writeInt16(pRoot->zData, pRtree->iDepth);
221098 for(pLeaf=pRtree->pDeleted; pLeaf; pLeaf=pRtree->pDeleted){
221100 rc = reinsertNodeContent(pRtree, pLeaf);
221102 pRtree->pDeleted = pLeaf->pNext;
221103 pRtree->nNodeRef--;
221109 rc = nodeRelease(pRtree, pRoot);
221111 nodeRelease(pRtree, pRoot);
221159 static int rtreeConstraintError(Rtree *pRtree, int iCol){ argument
221165 zSql = sqlite3_mprintf("SELECT * FROM %Q.%Q", pRtree->zDb, pRtree->zName);
221167 rc = sqlite3_prepare_v2(pRtree->db, zSql, -1, &pStmt, 0);
221176 pRtree->base.zErrMsg = sqlite3_mprintf(
221177 "UNIQUE constraint failed: %s.%s", pRtree->zName, zCol
221182 pRtree->base.zErrMsg = sqlite3_mprintf(
221183 "rtree constraint failed: %s.(%s<=%s)", pRtree->zName, zCol1, zCol2
221203 Rtree *pRtree = (Rtree *)pVtab; local
221208 if( pRtree->nNodeRef ){
221214 rtreeReference(pRtree);
221234 if( nn > pRtree->nDim2 ) nn = pRtree->nDim2;
221245 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
221250 rc = rtreeConstraintError(pRtree, ii+1);
221261 rc = rtreeConstraintError(pRtree, ii+1);
221275 sqlite3_bind_int64(pRtree->pReadRowid, 1, cell.iRowid);
221276 steprc = sqlite3_step(pRtree->pReadRowid);
221277 rc = sqlite3_reset(pRtree->pReadRowid);
221279 if( sqlite3_vtab_on_conflict(pRtree->db)==SQLITE_REPLACE ){
221280 rc = rtreeDeleteRowid(pRtree, cell.iRowid);
221282 rc = rtreeConstraintError(pRtree, 0);
221296 rc = rtreeDeleteRowid(pRtree, sqlite3_value_int64(aData[0]));
221309 rc = rtreeNewRowid(pRtree, &cell.iRowid);
221314 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
221318 rc = rtreeInsertCell(pRtree, pLeaf, &cell, 0);
221319 rc2 = nodeRelease(pRtree, pLeaf);
221324 if( rc==SQLITE_OK && pRtree->nAux ){
221325 sqlite3_stmt *pUp = pRtree->pWriteAux;
221328 for(jj=0; jj<pRtree->nAux; jj++){
221329 sqlite3_bind_value(pUp, jj+2, aData[pRtree->nDim2+3+jj]);
221337 rtreeRelease(pRtree);
221345 Rtree *pRtree = (Rtree *)pVtab; local
221346 assert( pRtree->inWrTrans==0 );
221347 pRtree->inWrTrans = 1;
221356 Rtree *pRtree = (Rtree *)pVtab; local
221357 pRtree->inWrTrans = 0;
221358 nodeBlobReset(pRtree);
221369 Rtree *pRtree = (Rtree *)pVtab; local
221375 , pRtree->zDb, pRtree->zName, zNewName
221376 , pRtree->zDb, pRtree->zName, zNewName
221377 , pRtree->zDb, pRtree->zName, zNewName
221380 nodeBlobReset(pRtree);
221381 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
221402 Rtree *pRtree = (Rtree *)pVtab; local
221403 u8 iwt = pRtree->inWrTrans;
221405 pRtree->inWrTrans = 0;
221406 nodeBlobReset(pRtree);
221407 pRtree->inWrTrans = iwt;
221416 static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){ argument
221424 db, pRtree->zDb, "sqlite_stat1",0,0,0,0,0,0
221427 pRtree->nRowEst = RTREE_DEFAULT_ROWEST;
221430 zSql = sqlite3_mprintf(zFmt, pRtree->zDb, pRtree->zName);
221441 pRtree->nRowEst = MAX(nRow, RTREE_MIN_ROWEST);
221493 Rtree *pRtree, argument
221521 pRtree->db = db;
221530 for(ii=0; ii<pRtree->nAux; ii++){
221541 zDb, zPrefix, pRtree->iNodeSize);
221553 appStmt[0] = &pRtree->pWriteNode;
221554 appStmt[1] = &pRtree->pDeleteNode;
221555 appStmt[2] = &pRtree->pReadRowid;
221556 appStmt[3] = &pRtree->pWriteRowid;
221557 appStmt[4] = &pRtree->pDeleteRowid;
221558 appStmt[5] = &pRtree->pReadParent;
221559 appStmt[6] = &pRtree->pWriteParent;
221560 appStmt[7] = &pRtree->pDeleteParent;
221562 rc = rtreeQueryStat1(db, pRtree);
221566 if( i!=3 || pRtree->nAux==0 ){
221582 if( pRtree->nAux && rc!=SQLITE_NOMEM ){
221583 pRtree->zReadAuxSql = sqlite3_mprintf(
221586 if( pRtree->zReadAuxSql==0 ){
221593 for(ii=0; ii<pRtree->nAux; ii++){
221596 if( ii<pRtree->nAuxNotNull ){
221609 rc = sqlite3_prepare_v3(db, zSql, -1, f, &pRtree->pWriteAux, 0);
221657 Rtree *pRtree, /* Rtree handle */ argument
221665 zSql = sqlite3_mprintf("PRAGMA %Q.page_size", pRtree->zDb);
221668 pRtree->iNodeSize = iPageSize-64;
221669 if( (4+pRtree->nBytesPerCell*RTREE_MAXCELLS)<pRtree->iNodeSize ){
221670 pRtree->iNodeSize = 4+pRtree->nBytesPerCell*RTREE_MAXCELLS;
221678 pRtree->zDb, pRtree->zName
221680 rc = getIntFromStmt(db, zSql, &pRtree->iNodeSize);
221683 }else if( pRtree->iNodeSize<(512-64) ){
221685 RTREE_IS_CORRUPT(pRtree);
221687 pRtree->zName);
221721 Rtree *pRtree; local
221751 pRtree = (Rtree *)sqlite3_malloc64(sizeof(Rtree)+nDb+nName*2+8);
221752 if( !pRtree ){
221755 memset(pRtree, 0, sizeof(Rtree)+nDb+nName*2+8);
221756 pRtree->nBusy = 1;
221757 pRtree->base.pModule = &rtreeModule;
221758 pRtree->zDb = (char *)&pRtree[1];
221759 pRtree->zName = &pRtree->zDb[nDb+1];
221760 pRtree->zNodeName = &pRtree->zName[nName+1];
221761 pRtree->eCoordType = (u8)eCoordType;
221762 memcpy(pRtree->zDb, argv[1], nDb);
221763 memcpy(pRtree->zName, argv[2], nName);
221764 memcpy(pRtree->zNodeName, argv[2], nName);
221765 memcpy(&pRtree->zNodeName[nName], "_node", 6);
221778 pRtree->nAux++;
221780 }else if( pRtree->nAux>0 ){
221784 pRtree->nDim2++;
221801 pRtree->nDim = pRtree->nDim2/2;
221802 if( pRtree->nDim<1 ){
221804 }else if( pRtree->nDim2>RTREE_MAX_DIMENSIONS*2 ){
221806 }else if( pRtree->nDim2 % 2 ){
221815 pRtree->nBytesPerCell = 8 + pRtree->nDim2*4;
221818 rc = getNodeSize(db, pRtree, isCreate, pzErr);
221820 rc = rtreeSqlInit(pRtree, db, argv[1], argv[2], isCreate);
221826 *ppVtab = (sqlite3_vtab *)pRtree;
221832 assert( pRtree->nBusy==1 );
221833 rtreeRelease(pRtree);
222322 Rtree *pRtree = (Rtree*)pVtab; local
222328 rc = rtreeCheckTable(pRtree->db, pRtree->zDb, pRtree->zName, pzErr);
222331 pRtree->zDb, pRtree->zName, *pzErr);
223649 Rtree *pRtree; local
223663 pRtree = (Rtree *)sqlite3_malloc64(sizeof(Rtree)+nDb+nName*2+8);
223664 if( !pRtree ){
223667 memset(pRtree, 0, sizeof(Rtree)+nDb+nName*2+8);
223668 pRtree->nBusy = 1;
223669 pRtree->base.pModule = &rtreeModule;
223670 pRtree->zDb = (char *)&pRtree[1];
223671 pRtree->zName = &pRtree->zDb[nDb+1];
223672 pRtree->zNodeName = &pRtree->zName[nName+1];
223673 pRtree->eCoordType = RTREE_COORD_REAL32;
223674 pRtree->nDim = 2;
223675 pRtree->nDim2 = 4;
223676 memcpy(pRtree->zDb, argv[1], nDb);
223677 memcpy(pRtree->zName, argv[2], nName);
223678 memcpy(pRtree->zNodeName, argv[2], nName);
223679 memcpy(&pRtree->zNodeName[nName], "_node", 6);
223688 pRtree->nAux = 1; /* Add one for _shape */
223689 pRtree->nAuxNotNull = 1; /* The _shape column is always not-null */
223691 pRtree->nAux++;
223703 pRtree->nBytesPerCell = 8 + pRtree->nDim2*4;
223706 rc = getNodeSize(db, pRtree, isCreate, pzErr);
223708 rc = rtreeSqlInit(pRtree, db, argv[1], argv[2], isCreate);
223714 *ppVtab = (sqlite3_vtab *)pRtree;
223720 assert( pRtree->nBusy==1 );
223721 rtreeRelease(pRtree);
223771 Rtree *pRtree = (Rtree *)pVtabCursor->pVtab; local
223778 rtreeReference(pRtree);
223790 rc = findLeafNode(pRtree, iRowid, &pLeaf, &iNode);
223797 rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &iCell);
223807 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
223823 memset(pCsr->anQueue, 0, sizeof(u32)*(pRtree->iDepth + 1));
223863 pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, (u8)(pRtree->iDepth+1));
223880 nodeRelease(pRtree, pRoot);
223881 rtreeRelease(pRtree);
223952 Rtree *pRtree = (Rtree *)cur->pVtab; local
223961 if( i<=pRtree->nAux ){
223964 rc = sqlite3_prepare_v3(pRtree->db, pRtree->zReadAuxSql, -1, 0,
223969 nodeGetRowid(pRtree, pNode, p->iCell));
224012 Rtree *pRtree = (Rtree *)pVtab; local
224021 if( pRtree->nNodeRef ){
224027 rtreeReference(pRtree);
224056 sqlite3_bind_int64(pRtree->pReadRowid, 1, cell.iRowid);
224057 steprc = sqlite3_step(pRtree->pReadRowid);
224058 rc = sqlite3_reset(pRtree->pReadRowid);
224060 if( sqlite3_vtab_on_conflict(pRtree->db)==SQLITE_REPLACE ){
224061 rc = rtreeDeleteRowid(pRtree, cell.iRowid);
224063 rc = rtreeConstraintError(pRtree, 0);
224074 rc = rtreeDeleteRowid(pRtree, oldRowid);
224085 rc = rtreeNewRowid(pRtree, &cell.iRowid);
224089 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
224093 rc = rtreeInsertCell(pRtree, pLeaf, &cell, 0);
224094 rc2 = nodeRelease(pRtree, pLeaf);
224103 sqlite3_stmt *pUp = pRtree->pWriteAux;
224107 assert( pRtree->nAux>=1 );
224134 rtreeRelease(pRtree);