Lines Matching defs:pRtree

201259 ** variable pRtree points to the Rtree structure associated with the
201266 (pRtree->eCoordType==RTREE_COORD_REAL32) ? \
201560 static void nodeZero(Rtree *pRtree, RtreeNode *p){
201561 memset(&p->zData[2], 0, pRtree->iNodeSize-2);
201577 static RtreeNode *nodeHashLookup(Rtree *pRtree, i64 iNode){
201579 for(p=pRtree->aHash[nodeHash(iNode)]; p && p->iNode!=iNode; p=p->pNext);
201586 static void nodeHashInsert(Rtree *pRtree, RtreeNode *pNode){
201590 pNode->pNext = pRtree->aHash[iHash];
201591 pRtree->aHash[iHash] = pNode;
201597 static void nodeHashDelete(Rtree *pRtree, RtreeNode *pNode){
201600 pp = &pRtree->aHash[nodeHash(pNode->iNode)];
201613 static RtreeNode *nodeNew(Rtree *pRtree, RtreeNode *pParent){
201615 pNode = (RtreeNode *)sqlite3_malloc64(sizeof(RtreeNode) + pRtree->iNodeSize);
201617 memset(pNode, 0, sizeof(RtreeNode) + pRtree->iNodeSize);
201620 pRtree->nNodeRef++;
201631 static void nodeBlobReset(Rtree *pRtree){
201632 if( pRtree->pNodeBlob && pRtree->inWrTrans==0 && pRtree->nCursor==0 ){
201633 sqlite3_blob *pBlob = pRtree->pNodeBlob;
201634 pRtree->pNodeBlob = 0;
201643 Rtree *pRtree, /* R-tree structure */
201654 if( (pNode = nodeHashLookup(pRtree, iNode))!=0 ){
201656 RTREE_IS_CORRUPT(pRtree);
201664 if( pRtree->pNodeBlob ){
201665 sqlite3_blob *pBlob = pRtree->pNodeBlob;
201666 pRtree->pNodeBlob = 0;
201668 pRtree->pNodeBlob = pBlob;
201670 nodeBlobReset(pRtree);
201674 if( pRtree->pNodeBlob==0 ){
201675 char *zTab = sqlite3_mprintf("%s_node", pRtree->zName);
201677 rc = sqlite3_blob_open(pRtree->db, pRtree->zDb, zTab, "data", iNode, 0,
201678 &pRtree->pNodeBlob);
201682 nodeBlobReset(pRtree);
201688 RTREE_IS_CORRUPT(pRtree);
201690 }else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){
201691 pNode = (RtreeNode *)sqlite3_malloc64(sizeof(RtreeNode)+pRtree->iNodeSize);
201698 pRtree->nNodeRef++;
201702 rc = sqlite3_blob_read(pRtree->pNodeBlob, pNode->zData,
201703 pRtree->iNodeSize, 0);
201707 /* If the root node was just loaded, set pRtree->iDepth to the height
201714 pRtree->iDepth = readInt16(pNode->zData);
201715 if( pRtree->iDepth>RTREE_MAX_DEPTH ){
201717 RTREE_IS_CORRUPT(pRtree);
201726 if( NCELL(pNode)>((pRtree->iNodeSize-4)/pRtree->nBytesPerCell) ){
201728 RTREE_IS_CORRUPT(pRtree);
201735 nodeHashInsert(pRtree, pNode);
201738 RTREE_IS_CORRUPT(pRtree);
201743 pRtree->nNodeRef--;
201756 Rtree *pRtree, /* The overall R-Tree */
201762 u8 *p = &pNode->zData[4 + pRtree->nBytesPerCell*iCell];
201764 for(ii=0; ii<pRtree->nDim2; ii++){
201773 static void nodeDeleteCell(Rtree *pRtree, RtreeNode *pNode, int iCell){
201774 u8 *pDst = &pNode->zData[4 + pRtree->nBytesPerCell*iCell];
201775 u8 *pSrc = &pDst[pRtree->nBytesPerCell];
201776 int nByte = (NCELL(pNode) - iCell - 1) * pRtree->nBytesPerCell;
201789 Rtree *pRtree, /* The overall R-Tree */
201796 nMaxCell = (pRtree->iNodeSize-4)/pRtree->nBytesPerCell;
201801 nodeOverwriteCell(pRtree, pNode, pCell, nCell);
201812 static int nodeWrite(Rtree *pRtree, RtreeNode *pNode){
201815 sqlite3_stmt *p = pRtree->pWriteNode;
201821 sqlite3_bind_blob(p, 2, pNode->zData, pRtree->iNodeSize, SQLITE_STATIC);
201827 pNode->iNode = sqlite3_last_insert_rowid(pRtree->db);
201828 nodeHashInsert(pRtree, pNode);
201838 static int nodeRelease(Rtree *pRtree, RtreeNode *pNode){
201842 assert( pRtree->nNodeRef>0 );
201845 pRtree->nNodeRef--;
201847 pRtree->iDepth = -1;
201850 rc = nodeRelease(pRtree, pNode->pParent);
201853 rc = nodeWrite(pRtree, pNode);
201855 nodeHashDelete(pRtree, pNode);
201868 Rtree *pRtree, /* The overall R-Tree */
201873 return readInt64(&pNode->zData[4 + pRtree->nBytesPerCell*iCell]);
201880 Rtree *pRtree, /* The overall R-Tree */
201886 readCoord(&pNode->zData[12 + pRtree->nBytesPerCell*iCell + 4*iCoord], pCoord);
201894 Rtree *pRtree, /* The overall R-Tree */
201902 pCell->iRowid = nodeGetRowid(pRtree, pNode, iCell);
201903 pData = pNode->zData + (12 + pRtree->nBytesPerCell*iCell);
201910 }while( ii<pRtree->nDim2 );
201950 static void rtreeReference(Rtree *pRtree){
201951 pRtree->nBusy++;
201958 static void rtreeRelease(Rtree *pRtree){
201959 pRtree->nBusy--;
201960 if( pRtree->nBusy==0 ){
201961 pRtree->inWrTrans = 0;
201962 assert( pRtree->nCursor==0 );
201963 nodeBlobReset(pRtree);
201964 assert( pRtree->nNodeRef==0 || pRtree->bCorrupt );
201965 sqlite3_finalize(pRtree->pWriteNode);
201966 sqlite3_finalize(pRtree->pDeleteNode);
201967 sqlite3_finalize(pRtree->pReadRowid);
201968 sqlite3_finalize(pRtree->pWriteRowid);
201969 sqlite3_finalize(pRtree->pDeleteRowid);
201970 sqlite3_finalize(pRtree->pReadParent);
201971 sqlite3_finalize(pRtree->pWriteParent);
201972 sqlite3_finalize(pRtree->pDeleteParent);
201973 sqlite3_finalize(pRtree->pWriteAux);
201974 sqlite3_free(pRtree->zReadAuxSql);
201975 sqlite3_free(pRtree);
201991 Rtree *pRtree = (Rtree *)pVtab;
201997 pRtree->zDb, pRtree->zName,
201998 pRtree->zDb, pRtree->zName,
201999 pRtree->zDb, pRtree->zName
202004 nodeBlobReset(pRtree);
202005 rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0);
202009 rtreeRelease(pRtree);
202020 Rtree *pRtree = (Rtree *)pVTab;
202028 pRtree->nCursor++;
202040 Rtree *pRtree = (Rtree *)(pCsr->base.pVtab);
202055 for(ii=0; ii<RTREE_CACHE_SZ; ii++) nodeRelease(pRtree, pCsr->aNode[ii]);
202059 pCsr->base.pVtab = (sqlite3_vtab*)pRtree;
202068 Rtree *pRtree = (Rtree *)(cur->pVtab);
202070 assert( pRtree->nCursor>0 );
202074 pRtree->nCursor--;
202075 nodeBlobReset(pRtree);
202304 Rtree *pRtree,
202313 if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){
202318 RTREE_IS_CORRUPT(pRtree);
202326 static int nodeParentIndex(Rtree *pRtree, RtreeNode *pNode, int *piIndex){
202329 return nodeRowidIndex(pRtree, pParent, pNode->iNode, piIndex);
202557 Rtree *pRtree = RTREE_OF_CURSOR(pCur);
202567 eInt = pRtree->eCoordType==RTREE_COORD_INT32;
202574 pCellData = pNode->zData + (4+pRtree->nBytesPerCell*p->iCell);
202591 pCellData += pRtree->nBytesPerCell;
202602 RTREE_IS_CORRUPT(pRtree);
202669 Rtree *pRtree = (Rtree *)cur->pVtab;
202679 sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell));
202680 }else if( i<=pRtree->nDim2 ){
202681 nodeGetCoord(pRtree, pNode, p->iCell, i-1, &c);
202683 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
202688 assert( pRtree->eCoordType==RTREE_COORD_INT32 );
202694 rc = sqlite3_prepare_v3(pRtree->db, pRtree->zReadAuxSql, -1, 0,
202699 nodeGetRowid(pRtree, pNode, p->iCell));
202710 sqlite3_column_value(pCsr->pReadAux, i - pRtree->nDim2 + 1));
202723 Rtree *pRtree, /* RTree to search */
202730 sqlite3_bind_int64(pRtree->pReadRowid, 1, iRowid);
202731 if( sqlite3_step(pRtree->pReadRowid)==SQLITE_ROW ){
202732 i64 iNode = sqlite3_column_int64(pRtree->pReadRowid, 0);
202734 rc = nodeAcquire(pRtree, iNode, 0, ppLeaf);
202735 sqlite3_reset(pRtree->pReadRowid);
202737 rc = sqlite3_reset(pRtree->pReadRowid);
202783 Rtree *pRtree = (Rtree *)pVtabCursor->pVtab;
202790 rtreeReference(pRtree);
202806 rc = findLeafNode(pRtree, iRowid, &pLeaf, &iNode);
202817 rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &iCell);
202827 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
202835 memset(pCsr->anQueue, 0, sizeof(u32)*(pRtree->iDepth + 1));
202852 p->pInfo->nCoord = pRtree->nDim2;
202854 p->pInfo->mxLevel = pRtree->iDepth + 1;
202877 pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, (u8)(pRtree->iDepth+1));
202892 nodeRelease(pRtree, pRoot);
202893 rtreeRelease(pRtree);
202932 Rtree *pRtree = (Rtree*)tab;
202982 && ((p->iColumn>0 && p->iColumn<=pRtree->nDim2)
203010 nRow = pRtree->nRowEst >> (iIdx/2);
203020 static RtreeDValue cellArea(Rtree *pRtree, RtreeCell *p){
203022 assert( pRtree->nDim>=1 && pRtree->nDim<=5 );
203024 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
203025 switch( pRtree->nDim ){
203035 switch( pRtree->nDim ){
203050 static RtreeDValue cellMargin(Rtree *pRtree, RtreeCell *p){
203052 int ii = pRtree->nDim2 - 2;
203063 static void cellUnion(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){
203065 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
203070 }while( ii<pRtree->nDim2 );
203076 }while( ii<pRtree->nDim2 );
203084 static int cellContains(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){
203086 int isInt = (pRtree->eCoordType==RTREE_COORD_INT32);
203087 for(ii=0; ii<pRtree->nDim2; ii+=2){
203102 static RtreeDValue cellGrowth(Rtree *pRtree, RtreeCell *p, RtreeCell *pCell){
203106 area = cellArea(pRtree, &cell);
203107 cellUnion(pRtree, &cell, pCell);
203108 return (cellArea(pRtree, &cell)-area);
203112 Rtree *pRtree,
203122 for(jj=0; jj<pRtree->nDim2; jj+=2){
203144 Rtree *pRtree, /* Rtree table */
203152 rc = nodeAcquire(pRtree, 1, 0, &pNode);
203154 for(ii=0; rc==SQLITE_OK && ii<(pRtree->iDepth-iHeight); ii++){
203175 nodeGetCell(pRtree, pNode, iCell, &cell);
203176 growth = cellGrowth(pRtree, &cell, pCell);
203177 area = cellArea(pRtree, &cell);
203189 rc = nodeAcquire(pRtree, iBest, pNode, &pChild);
203190 nodeRelease(pRtree, pNode);
203204 Rtree *pRtree, /* Rtree table */
203218 RTREE_IS_CORRUPT(pRtree);
203221 rc = nodeParentIndex(pRtree, p, &iCell);
203223 RTREE_IS_CORRUPT(pRtree);
203227 nodeGetCell(pRtree, pParent, iCell, &cell);
203228 if( !cellContains(pRtree, &cell, pCell) ){
203229 cellUnion(pRtree, &cell, pCell);
203230 nodeOverwriteCell(pRtree, pParent, &cell, iCell);
203241 static int rowidWrite(Rtree *pRtree, sqlite3_int64 iRowid, sqlite3_int64 iNode){
203242 sqlite3_bind_int64(pRtree->pWriteRowid, 1, iRowid);
203243 sqlite3_bind_int64(pRtree->pWriteRowid, 2, iNode);
203244 sqlite3_step(pRtree->pWriteRowid);
203245 return sqlite3_reset(pRtree->pWriteRowid);
203251 static int parentWrite(Rtree *pRtree, sqlite3_int64 iNode, sqlite3_int64 iPar){
203252 sqlite3_bind_int64(pRtree->pWriteParent, 1, iNode);
203253 sqlite3_bind_int64(pRtree->pWriteParent, 2, iPar);
203254 sqlite3_step(pRtree->pWriteParent);
203255 return sqlite3_reset(pRtree->pWriteParent);
203345 Rtree *pRtree,
203362 SortByDimension(pRtree, aLeft, nLeft, iDim, aCell, aSpare);
203363 SortByDimension(pRtree, aRight, nRight, iDim, aCell, aSpare);
203404 Rtree *pRtree,
203420 sqlite3_int64 nByte = (pRtree->nDim+1)*(sizeof(int*)+nCell*sizeof(int));
203427 aSpare = &((int *)&aaSorted[pRtree->nDim])[pRtree->nDim*nCell];
203429 for(ii=0; ii<pRtree->nDim; ii++){
203431 aaSorted[ii] = &((int *)&aaSorted[pRtree->nDim])[ii*nCell];
203435 SortByDimension(pRtree, aaSorted[ii], nCell, ii, aCell, aSpare);
203438 for(ii=0; ii<pRtree->nDim; ii++){
203446 nLeft=RTREE_MINCELLS(pRtree);
203447 nLeft<=(nCell-RTREE_MINCELLS(pRtree));
203460 cellUnion(pRtree, &left, &aCell[aaSorted[ii][kk]]);
203462 cellUnion(pRtree, &right, &aCell[aaSorted[ii][kk]]);
203465 margin += cellMargin(pRtree, &left);
203466 margin += cellMargin(pRtree, &right);
203467 overlap = cellOverlap(pRtree, &left, &right, 1);
203468 area = cellArea(pRtree, &left) + cellArea(pRtree, &right);
203469 if( (nLeft==RTREE_MINCELLS(pRtree))
203492 nodeInsertCell(pRtree, pTarget, pCell);
203493 cellUnion(pRtree, pBbox, pCell);
203502 Rtree *pRtree,
203510 RtreeNode *pChild = nodeHashLookup(pRtree, iRowid);
203516 nodeRelease(pRtree, pChild->pParent);
203522 return xSetMapping(pRtree, iRowid, pNode->iNode);
203526 Rtree *pRtree,
203556 nodeGetCell(pRtree, pNode, i, &aCell[i]);
203558 nodeZero(pRtree, pNode);
203563 pRight = nodeNew(pRtree, pNode);
203564 pLeft = nodeNew(pRtree, pNode);
203565 pRtree->iDepth++;
203567 writeInt16(pNode->zData, pRtree->iDepth);
203570 pRight = nodeNew(pRtree, pLeft->pParent);
203579 memset(pLeft->zData, 0, pRtree->iNodeSize);
203580 memset(pRight->zData, 0, pRtree->iNodeSize);
203582 rc = splitNodeStartree(pRtree, aCell, nCell, pLeft, pRight,
203593 if( SQLITE_OK!=(rc = nodeWrite(pRtree, pRight))
203594 || (0==pLeft->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pLeft)))
203603 rc = rtreeInsertCell(pRtree, pLeft->pParent, &leftbbox, iHeight+1);
203610 rc = nodeParentIndex(pRtree, pLeft, &iCell);
203612 nodeOverwriteCell(pRtree, pParent, &leftbbox, iCell);
203613 rc = AdjustTree(pRtree, pParent, &leftbbox);
203620 if( (rc = rtreeInsertCell(pRtree, pRight->pParent, &rightbbox, iHeight+1)) ){
203625 i64 iRowid = nodeGetRowid(pRtree, pRight, i);
203626 rc = updateMapping(pRtree, iRowid, pRight, iHeight);
203636 i64 iRowid = nodeGetRowid(pRtree, pLeft, i);
203637 rc = updateMapping(pRtree, iRowid, pLeft, iHeight);
203643 rc = updateMapping(pRtree, pCell->iRowid, pLeft, iHeight);
203647 rc = nodeRelease(pRtree, pRight);
203651 rc = nodeRelease(pRtree, pLeft);
203656 nodeRelease(pRtree, pRight);
203657 nodeRelease(pRtree, pLeft);
203673 static int fixLeafParent(Rtree *pRtree, RtreeNode *pLeaf){
203678 sqlite3_bind_int64(pRtree->pReadParent, 1, pChild->iNode);
203679 rc = sqlite3_step(pRtree->pReadParent);
203689 iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
203692 rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
203695 rc = sqlite3_reset(pRtree->pReadParent);
203698 RTREE_IS_CORRUPT(pRtree);
203708 static int removeNode(Rtree *pRtree, RtreeNode *pNode, int iHeight){
203717 rc = nodeParentIndex(pRtree, pNode, &iCell);
203721 rc = deleteCell(pRtree, pParent, iCell, iHeight+1);
203724 rc2 = nodeRelease(pRtree, pParent);
203733 sqlite3_bind_int64(pRtree->pDeleteNode, 1, pNode->iNode);
203734 sqlite3_step(pRtree->pDeleteNode);
203735 if( SQLITE_OK!=(rc = sqlite3_reset(pRtree->pDeleteNode)) ){
203740 sqlite3_bind_int64(pRtree->pDeleteParent, 1, pNode->iNode);
203741 sqlite3_step(pRtree->pDeleteParent);
203742 if( SQLITE_OK!=(rc = sqlite3_reset(pRtree->pDeleteParent)) ){
203749 nodeHashDelete(pRtree, pNode);
203751 pNode->pNext = pRtree->pDeleted;
203753 pRtree->pDeleted = pNode;
203758 static int fixBoundingBox(Rtree *pRtree, RtreeNode *pNode){
203765 nodeGetCell(pRtree, pNode, 0, &box);
203768 nodeGetCell(pRtree, pNode, ii, &cell);
203769 cellUnion(pRtree, &box, &cell);
203772 rc = nodeParentIndex(pRtree, pNode, &ii);
203774 nodeOverwriteCell(pRtree, pParent, &box, ii);
203775 rc = fixBoundingBox(pRtree, pParent);
203785 static int deleteCell(Rtree *pRtree, RtreeNode *pNode, int iCell, int iHeight){
203789 if( SQLITE_OK!=(rc = fixLeafParent(pRtree, pNode)) ){
203796 nodeDeleteCell(pRtree, pNode, iCell);
203806 if( NCELL(pNode)<RTREE_MINCELLS(pRtree) ){
203807 rc = removeNode(pRtree, pNode, iHeight);
203809 rc = fixBoundingBox(pRtree, pNode);
203817 Rtree *pRtree,
203858 nodeGetCell(pRtree, pNode, ii, &aCell[ii]);
203861 for(iDim=0; iDim<pRtree->nDim; iDim++){
203866 for(iDim=0; iDim<pRtree->nDim; iDim++){
203872 for(iDim=0; iDim<pRtree->nDim; iDim++){
203880 nodeZero(pRtree, pNode);
203882 for(ii=0; rc==SQLITE_OK && ii<(nCell-(RTREE_MINCELLS(pRtree)+1)); ii++){
203884 nodeInsertCell(pRtree, pNode, p);
203887 rc = rowidWrite(pRtree, p->iRowid, pNode->iNode);
203889 rc = parentWrite(pRtree, p->iRowid, pNode->iNode);
203894 rc = fixBoundingBox(pRtree, pNode);
203902 rc = ChooseLeaf(pRtree, p, iHeight, &pInsert);
203905 rc = rtreeInsertCell(pRtree, pInsert, p, iHeight);
203906 rc2 = nodeRelease(pRtree, pInsert);
203922 Rtree *pRtree,
203929 RtreeNode *pChild = nodeHashLookup(pRtree, pCell->iRowid);
203931 nodeRelease(pRtree, pChild->pParent);
203936 if( nodeInsertCell(pRtree, pNode, pCell) ){
203937 if( iHeight<=pRtree->iReinsertHeight || pNode->iNode==1){
203938 rc = SplitNode(pRtree, pNode, pCell, iHeight);
203940 pRtree->iReinsertHeight = iHeight;
203941 rc = Reinsert(pRtree, pNode, pCell, iHeight);
203944 rc = AdjustTree(pRtree, pNode, pCell);
203947 rc = rowidWrite(pRtree, pCell->iRowid, pNode->iNode);
203949 rc = parentWrite(pRtree, pCell->iRowid, pNode->iNode);
203956 static int reinsertNodeContent(Rtree *pRtree, RtreeNode *pNode){
203964 nodeGetCell(pRtree, pNode, ii, &cell);
203969 rc = ChooseLeaf(pRtree, &cell, (int)pNode->iNode, &pInsert);
203972 rc = rtreeInsertCell(pRtree, pInsert, &cell, (int)pNode->iNode);
203973 rc2 = nodeRelease(pRtree, pInsert);
203985 static int rtreeNewRowid(Rtree *pRtree, i64 *piRowid){
203987 sqlite3_bind_null(pRtree->pWriteRowid, 1);
203988 sqlite3_bind_null(pRtree->pWriteRowid, 2);
203989 sqlite3_step(pRtree->pWriteRowid);
203990 rc = sqlite3_reset(pRtree->pWriteRowid);
203991 *piRowid = sqlite3_last_insert_rowid(pRtree->db);
203998 static int rtreeDeleteRowid(Rtree *pRtree, sqlite3_int64 iDelete){
204006 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
204012 rc = findLeafNode(pRtree, iDelete, &pLeaf, 0);
204022 rc = nodeRowidIndex(pRtree, pLeaf, iDelete, &iCell);
204024 rc = deleteCell(pRtree, pLeaf, iCell, 0);
204026 rc2 = nodeRelease(pRtree, pLeaf);
204034 sqlite3_bind_int64(pRtree->pDeleteRowid, 1, iDelete);
204035 sqlite3_step(pRtree->pDeleteRowid);
204036 rc = sqlite3_reset(pRtree->pDeleteRowid);
204047 if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
204050 i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
204051 rc = nodeAcquire(pRtree, iChild, pRoot, &pChild); /* tag-20210916a */
204053 rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
204055 rc2 = nodeRelease(pRtree, pChild);
204058 pRtree->iDepth--;
204059 writeInt16(pRoot->zData, pRtree->iDepth);
204065 for(pLeaf=pRtree->pDeleted; pLeaf; pLeaf=pRtree->pDeleted){
204067 rc = reinsertNodeContent(pRtree, pLeaf);
204069 pRtree->pDeleted = pLeaf->pNext;
204070 pRtree->nNodeRef--;
204076 rc = nodeRelease(pRtree, pRoot);
204078 nodeRelease(pRtree, pRoot);
204116 ** (at pRtree->base.zErrMsg) to an appropriate value and returns
204126 static int rtreeConstraintError(Rtree *pRtree, int iCol){
204132 zSql = sqlite3_mprintf("SELECT * FROM %Q.%Q", pRtree->zDb, pRtree->zName);
204134 rc = sqlite3_prepare_v2(pRtree->db, zSql, -1, &pStmt, 0);
204143 pRtree->base.zErrMsg = sqlite3_mprintf(
204144 "UNIQUE constraint failed: %s.%s", pRtree->zName, zCol
204149 pRtree->base.zErrMsg = sqlite3_mprintf(
204150 "rtree constraint failed: %s.(%s<=%s)", pRtree->zName, zCol1, zCol2
204170 Rtree *pRtree = (Rtree *)pVtab;
204175 if( pRtree->nNodeRef ){
204181 rtreeReference(pRtree);
204201 if( nn > pRtree->nDim2 ) nn = pRtree->nDim2;
204212 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
204217 rc = rtreeConstraintError(pRtree, ii+1);
204228 rc = rtreeConstraintError(pRtree, ii+1);
204242 sqlite3_bind_int64(pRtree->pReadRowid, 1, cell.iRowid);
204243 steprc = sqlite3_step(pRtree->pReadRowid);
204244 rc = sqlite3_reset(pRtree->pReadRowid);
204246 if( sqlite3_vtab_on_conflict(pRtree->db)==SQLITE_REPLACE ){
204247 rc = rtreeDeleteRowid(pRtree, cell.iRowid);
204249 rc = rtreeConstraintError(pRtree, 0);
204263 rc = rtreeDeleteRowid(pRtree, sqlite3_value_int64(aData[0]));
204276 rc = rtreeNewRowid(pRtree, &cell.iRowid);
204281 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
204285 pRtree->iReinsertHeight = -1;
204286 rc = rtreeInsertCell(pRtree, pLeaf, &cell, 0);
204287 rc2 = nodeRelease(pRtree, pLeaf);
204292 if( rc==SQLITE_OK && pRtree->nAux ){
204293 sqlite3_stmt *pUp = pRtree->pWriteAux;
204296 for(jj=0; jj<pRtree->nAux; jj++){
204297 sqlite3_bind_value(pUp, jj+2, aData[pRtree->nDim2+3+jj]);
204305 rtreeRelease(pRtree);
204313 Rtree *pRtree = (Rtree *)pVtab;
204314 assert( pRtree->inWrTrans==0 );
204315 pRtree->inWrTrans++;
204324 Rtree *pRtree = (Rtree *)pVtab;
204325 pRtree->inWrTrans = 0;
204326 nodeBlobReset(pRtree);
204334 Rtree *pRtree = (Rtree *)pVtab;
204340 , pRtree->zDb, pRtree->zName, zNewName
204341 , pRtree->zDb, pRtree->zName, zNewName
204342 , pRtree->zDb, pRtree->zName, zNewName
204345 nodeBlobReset(pRtree);
204346 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
204367 Rtree *pRtree = (Rtree *)pVtab;
204368 u8 iwt = pRtree->inWrTrans;
204370 pRtree->inWrTrans = 0;
204371 nodeBlobReset(pRtree);
204372 pRtree->inWrTrans = iwt;
204377 ** This function populates the pRtree->nRowEst variable with an estimate
204381 static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
204389 db, pRtree->zDb, "sqlite_stat1",0,0,0,0,0,0
204392 pRtree->nRowEst = RTREE_DEFAULT_ROWEST;
204395 zSql = sqlite3_mprintf(zFmt, pRtree->zDb, pRtree->zName);
204406 pRtree->nRowEst = MAX(nRow, RTREE_MIN_ROWEST);
204454 Rtree *pRtree,
204482 pRtree->db = db;
204491 for(ii=0; ii<pRtree->nAux; ii++){
204502 zDb, zPrefix, pRtree->iNodeSize);
204514 appStmt[0] = &pRtree->pWriteNode;
204515 appStmt[1] = &pRtree->pDeleteNode;
204516 appStmt[2] = &pRtree->pReadRowid;
204517 appStmt[3] = &pRtree->pWriteRowid;
204518 appStmt[4] = &pRtree->pDeleteRowid;
204519 appStmt[5] = &pRtree->pReadParent;
204520 appStmt[6] = &pRtree->pWriteParent;
204521 appStmt[7] = &pRtree->pDeleteParent;
204523 rc = rtreeQueryStat1(db, pRtree);
204527 if( i!=3 || pRtree->nAux==0 ){
204543 if( pRtree->nAux ){
204544 pRtree->zReadAuxSql = sqlite3_mprintf(
204547 if( pRtree->zReadAuxSql==0 ){
204554 for(ii=0; ii<pRtree->nAux; ii++){
204557 if( ii<pRtree->nAuxNotNull ){
204570 rc = sqlite3_prepare_v3(db, zSql, -1, f, &pRtree->pWriteAux, 0);
204604 ** to. If successful, pRtree->iNodeSize is populated and SQLITE_OK returned.
204618 Rtree *pRtree, /* Rtree handle */
204626 zSql = sqlite3_mprintf("PRAGMA %Q.page_size", pRtree->zDb);
204629 pRtree->iNodeSize = iPageSize-64;
204630 if( (4+pRtree->nBytesPerCell*RTREE_MAXCELLS)<pRtree->iNodeSize ){
204631 pRtree->iNodeSize = 4+pRtree->nBytesPerCell*RTREE_MAXCELLS;
204639 pRtree->zDb, pRtree->zName
204641 rc = getIntFromStmt(db, zSql, &pRtree->iNodeSize);
204644 }else if( pRtree->iNodeSize<(512-64) ){
204646 RTREE_IS_CORRUPT(pRtree);
204648 pRtree->zName);
204682 Rtree *pRtree;
204710 pRtree = (Rtree *)sqlite3_malloc64(sizeof(Rtree)+nDb+nName+2);
204711 if( !pRtree ){
204714 memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2);
204715 pRtree->nBusy = 1;
204716 pRtree->base.pModule = &rtreeModule;
204717 pRtree->zDb = (char *)&pRtree[1];
204718 pRtree->zName = &pRtree->zDb[nDb+1];
204719 pRtree->eCoordType = (u8)eCoordType;
204720 memcpy(pRtree->zDb, argv[1], nDb);
204721 memcpy(pRtree->zName, argv[2], nName);
204734 pRtree->nAux++;
204736 }else if( pRtree->nAux>0 ){
204740 pRtree->nDim2++;
204757 pRtree->nDim = pRtree->nDim2/2;
204758 if( pRtree->nDim<1 ){
204760 }else if( pRtree->nDim2>RTREE_MAX_DIMENSIONS*2 ){
204762 }else if( pRtree->nDim2 % 2 ){
204771 pRtree->nBytesPerCell = 8 + pRtree->nDim2*4;
204774 rc = getNodeSize(db, pRtree, isCreate, pzErr);
204776 rc = rtreeSqlInit(pRtree, db, argv[1], argv[2], isCreate);
204782 *ppVtab = (sqlite3_vtab *)pRtree;
204788 assert( pRtree->nBusy==1 );
204789 rtreeRelease(pRtree);
206580 Rtree *pRtree;
206592 pRtree = (Rtree *)sqlite3_malloc64(sizeof(Rtree)+nDb+nName+2);
206593 if( !pRtree ){
206596 memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2);
206597 pRtree->nBusy = 1;
206598 pRtree->base.pModule = &rtreeModule;
206599 pRtree->zDb = (char *)&pRtree[1];
206600 pRtree->zName = &pRtree->zDb[nDb+1];
206601 pRtree->eCoordType = RTREE_COORD_REAL32;
206602 pRtree->nDim = 2;
206603 pRtree->nDim2 = 4;
206604 memcpy(pRtree->zDb, argv[1], nDb);
206605 memcpy(pRtree->zName, argv[2], nName);
206614 pRtree->nAux = 1; /* Add one for _shape */
206615 pRtree->nAuxNotNull = 1; /* The _shape column is always not-null */
206617 pRtree->nAux++;
206629 pRtree->nBytesPerCell = 8 + pRtree->nDim2*4;
206632 rc = getNodeSize(db, pRtree, isCreate, pzErr);
206634 rc = rtreeSqlInit(pRtree, db, argv[1], argv[2], isCreate);
206640 *ppVtab = (sqlite3_vtab *)pRtree;
206646 assert( pRtree->nBusy==1 );
206647 rtreeRelease(pRtree);
206697 Rtree *pRtree = (Rtree *)pVtabCursor->pVtab;
206703 rtreeReference(pRtree);
206715 rc = findLeafNode(pRtree, iRowid, &pLeaf, &iNode);
206722 rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &iCell);
206732 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
206748 memset(pCsr->anQueue, 0, sizeof(u32)*(pRtree->iDepth + 1));
206788 pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, (u8)(pRtree->iDepth+1));
206805 nodeRelease(pRtree, pRoot);
206806 rtreeRelease(pRtree);
206876 Rtree *pRtree = (Rtree *)cur->pVtab;
206885 if( i<=pRtree->nAux ){
206888 rc = sqlite3_prepare_v3(pRtree->db, pRtree->zReadAuxSql, -1, 0,
206893 nodeGetRowid(pRtree, pNode, p->iCell));
206936 Rtree *pRtree = (Rtree *)pVtab;
206945 if( pRtree->nNodeRef ){
206951 rtreeReference(pRtree);
206980 sqlite3_bind_int64(pRtree->pReadRowid, 1, cell.iRowid);
206981 steprc = sqlite3_step(pRtree->pReadRowid);
206982 rc = sqlite3_reset(pRtree->pReadRowid);
206984 if( sqlite3_vtab_on_conflict(pRtree->db)==SQLITE_REPLACE ){
206985 rc = rtreeDeleteRowid(pRtree, cell.iRowid);
206987 rc = rtreeConstraintError(pRtree, 0);
206998 rc = rtreeDeleteRowid(pRtree, oldRowid);
207009 rc = rtreeNewRowid(pRtree, &cell.iRowid);
207013 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
207017 pRtree->iReinsertHeight = -1;
207018 rc = rtreeInsertCell(pRtree, pLeaf, &cell, 0);
207019 rc2 = nodeRelease(pRtree, pLeaf);
207028 sqlite3_stmt *pUp = pRtree->pWriteAux;
207032 assert( pRtree->nAux>=1 );
207059 rtreeRelease(pRtree);