mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Fixes to the UPDATE logic in Geopoly.
FossilOrigin-Name: 7c3cee0a2a5ccacff27400c38bd708f7b9b968eb013a8fa685d876dfe85e12a6
This commit is contained in:
@@ -1122,7 +1122,8 @@ static int geopolyInit(
|
||||
*/
|
||||
pSql = sqlite3_str_new(db);
|
||||
sqlite3_str_appendf(pSql, "CREATE TABLE x(_shape");
|
||||
pRtree->nAux = 1; /* Add one for _shape */
|
||||
pRtree->nAux = 1; /* Add one for _shape */
|
||||
pRtree->nAuxNotNull = 1; /* The _shape column is always not-null */
|
||||
for(ii=3; ii<argc; ii++){
|
||||
pRtree->nAux++;
|
||||
sqlite3_str_appendf(pSql, ",%s", argv[ii]);
|
||||
@@ -1396,6 +1397,7 @@ static int geopolyColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
|
||||
|
||||
if( rc ) return rc;
|
||||
if( p==0 ) return SQLITE_OK;
|
||||
if( i==0 && sqlite3_vtab_nochange(ctx) ) return SQLITE_OK;
|
||||
if( i<=pRtree->nAux ){
|
||||
if( !pCsr->bAuxValid ){
|
||||
if( pCsr->pReadAux==0 ){
|
||||
@@ -1465,7 +1467,6 @@ static int geopolyUpdate(
|
||||
rtreeReference(pRtree);
|
||||
assert(nData>=1);
|
||||
|
||||
rc = SQLITE_ERROR;
|
||||
oldRowidValid = sqlite3_value_type(aData[0])!=SQLITE_NULL;;
|
||||
oldRowid = oldRowidValid ? sqlite3_value_int64(aData[0]) : 0;
|
||||
newRowidValid = nData>1 && sqlite3_value_type(aData[1])!=SQLITE_NULL;
|
||||
@@ -1489,7 +1490,7 @@ static int geopolyUpdate(
|
||||
|
||||
/* If a rowid value was supplied, check if it is already present in
|
||||
** the table. If so, the constraint has failed. */
|
||||
if( newRowidValid ){
|
||||
if( newRowidValid && (!oldRowidValid || oldRowid!=newRowid) ){
|
||||
int steprc;
|
||||
sqlite3_bind_int64(pRtree->pReadRowid, 1, cell.iRowid);
|
||||
steprc = sqlite3_step(pRtree->pReadRowid);
|
||||
@@ -1543,8 +1544,15 @@ static int geopolyUpdate(
|
||||
int jj;
|
||||
int nChange = 0;
|
||||
sqlite3_bind_int64(pUp, 1, cell.iRowid);
|
||||
for(jj=0; jj<pRtree->nAux; jj++){
|
||||
if( !sqlite3_value_nochange(aData[jj+2]) ) nChange++;
|
||||
assert( pRtree->nAux>=1 );
|
||||
if( sqlite3_value_nochange(aData[2]) ){
|
||||
sqlite3_bind_null(pUp, 2);
|
||||
}else{
|
||||
sqlite3_bind_value(pUp, 2, aData[2]);
|
||||
nChange = 1;
|
||||
}
|
||||
for(jj=1; jj<pRtree->nAux; jj++){
|
||||
nChange++;
|
||||
sqlite3_bind_value(pUp, jj+2, aData[jj+2]);
|
||||
}
|
||||
if( nChange ){
|
||||
|
@@ -127,6 +127,7 @@ struct Rtree {
|
||||
u8 nBytesPerCell; /* Bytes consumed per cell */
|
||||
u8 inWrTrans; /* True if inside write transaction */
|
||||
u8 nAux; /* # of auxiliary columns in %_rowid */
|
||||
u8 nAuxNotNull; /* Number of initial not-null aux columns */
|
||||
int iDepth; /* Current depth of the r-tree structure */
|
||||
char *zDb; /* Name of database containing r-tree table */
|
||||
char *zName; /* Name of r-tree table */
|
||||
@@ -3453,7 +3454,11 @@ static int rtreeSqlInit(
|
||||
sqlite3_str_appendf(p, "UPDATE \"%w\".\"%w_rowid\"SET ", zDb, zPrefix);
|
||||
for(ii=0; ii<pRtree->nAux; ii++){
|
||||
if( ii ) sqlite3_str_append(p, ",", 1);
|
||||
sqlite3_str_appendf(p,"a%d=?%d",ii,ii+2);
|
||||
if( ii<pRtree->nAuxNotNull ){
|
||||
sqlite3_str_appendf(p,"a%d=coalesce(?%d,a%d)",ii,ii+2,ii);
|
||||
}else{
|
||||
sqlite3_str_appendf(p,"a%d=?%d",ii,ii+2);
|
||||
}
|
||||
}
|
||||
sqlite3_str_appendf(p, " WHERE rowid=?1");
|
||||
zSql = sqlite3_str_finish(p);
|
||||
|
@@ -536,4 +536,40 @@ SELECT geopoly_svg(poly,
|
||||
)
|
||||
FROM querypoly;
|
||||
.print '</svg>'
|
||||
|
||||
.print '<h1>Color-Change For Overlapping Elements</h1>'
|
||||
BEGIN;
|
||||
UPDATE geo1
|
||||
SET clr=CASE WHEN rowid IN (SELECT geo1.rowid FROM geo1, querypoly
|
||||
WHERE geopoly_overlap(_shape,poly))
|
||||
THEN 'red' ELSE 'blue' END;
|
||||
.print '<svg width="1000" height="800" style="border:1px solid black">'
|
||||
SELECT geopoly_svg(_shape,
|
||||
printf('style="fill:none;stroke:%s;stroke-width:1"',geo1.clr)
|
||||
)
|
||||
FROM geo1;
|
||||
SELECT geopoly_svg(poly,'style="fill:none;stroke:black;stroke-width:2"')
|
||||
FROM querypoly;
|
||||
ROLLBACK;
|
||||
.print '</svg>'
|
||||
|
||||
.print '<h1>Color-Change And Move Overlapping Elements</h1>'
|
||||
BEGIN;
|
||||
UPDATE geo1
|
||||
SET clr=CASE WHEN rowid IN (SELECT geo1.rowid FROM geo1, querypoly
|
||||
WHERE geopoly_overlap(_shape,poly))
|
||||
THEN 'red' ELSE 'blue' END;
|
||||
UPDATE geo1
|
||||
SET _shape=geopoly_xform(_shape,1,0,0,1,300,0)
|
||||
WHERE geopoly_overlap(_shape,(SELECT poly FROM querypoly));
|
||||
.print '<svg width="1000" height="800" style="border:1px solid black">'
|
||||
SELECT geopoly_svg(_shape,
|
||||
printf('style="fill:none;stroke:%s;stroke-width:1"',geo1.clr)
|
||||
)
|
||||
FROM geo1;
|
||||
SELECT geopoly_svg(poly,'style="fill:none;stroke:black;stroke-width:2"')
|
||||
FROM querypoly;
|
||||
ROLLBACK;
|
||||
.print '</svg>'
|
||||
|
||||
.print '</html>'
|
||||
|
Reference in New Issue
Block a user