@@ -6275,8 +6275,7 @@ int sqlite3_ieee_init(
62756275** step HIDDEN
62766276** );
62776277**
6278- ** The virtual table also has a rowid, logically equivalent to n+1 where
6279- ** "n" is the ascending integer in the aforesaid production definition.
6278+ ** The virtual table also has a rowid which is an alias for the value.
62806279**
62816280** Function arguments in queries against this virtual table are translated
62826281** into equality constraints against successive hidden columns. In other
@@ -6331,6 +6330,7 @@ SQLITE_EXTENSION_INIT1
63316330#include <assert.h>
63326331#include <string.h>
63336332#include <limits.h>
6333+ #include <math.h>
63346334
63356335#ifndef SQLITE_OMIT_VIRTUALTABLE
63366336/*
@@ -6491,6 +6491,7 @@ static int seriesConnect(
64916491 int rc;
64926492
64936493/* Column numbers */
6494+ #define SERIES_COLUMN_ROWID (-1)
64946495#define SERIES_COLUMN_VALUE 0
64956496#define SERIES_COLUMN_START 1
64966497#define SERIES_COLUMN_STOP 2
@@ -6578,13 +6579,11 @@ static int seriesColumn(
65786579#endif
65796580
65806581/*
6581- ** Return the rowid for the current row, logically equivalent to n+1 where
6582- ** "n" is the ascending integer in the aforesaid production definition.
6582+ ** The rowid is the same as the value.
65836583*/
65846584static int seriesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
65856585 series_cursor *pCur = (series_cursor*)cur;
6586- sqlite3_uint64 n = pCur->ss.uSeqIndexNow;
6587- *pRowid = (sqlite3_int64)((n<LARGEST_UINT64)? n+1 : 0);
6586+ *pRowid = pCur->ss.iValueNow;
65886587 return SQLITE_OK;
65896588}
65906589
@@ -6697,25 +6696,52 @@ static int seriesFilter(
66976696 ** constraints on the "value" column.
66986697 */
66996698 if( idxNum & 0x0080 ){
6700- iMin = iMax = sqlite3_value_int64(argv[i++]);
6699+ if( sqlite3_value_numeric_type(argv[i])==SQLITE_FLOAT ){
6700+ double r = sqlite3_value_double(argv[i++]);
6701+ if( r==ceil(r) ){
6702+ iMin = iMax = (sqlite3_int64)r;
6703+ }else{
6704+ returnNoRows = 1;
6705+ }
6706+ }else{
6707+ iMin = iMax = sqlite3_value_int64(argv[i++]);
6708+ }
67016709 }else{
67026710 if( idxNum & 0x0300 ){
6703- iMin = sqlite3_value_int64 (argv[i++]);
6704- if( idxNum & 0x0200 ){
6705- if( iMin==LARGEST_INT64 ){
6706- returnNoRows = 1 ;
6711+ if( sqlite3_value_numeric_type (argv[i])==SQLITE_FLOAT ){
6712+ double r = sqlite3_value_double(argv[i++]);
6713+ if( idxNum & 0x0200 && r==ceil(r) ){
6714+ iMin = (sqlite3_int64)ceil(r+1.0) ;
67076715 }else{
6708- iMin++;
6716+ iMin = (sqlite3_int64)ceil(r);
6717+ }
6718+ }else{
6719+ iMin = sqlite3_value_int64(argv[i++]);
6720+ if( idxNum & 0x0200 ){
6721+ if( iMin==LARGEST_INT64 ){
6722+ returnNoRows = 1;
6723+ }else{
6724+ iMin++;
6725+ }
67096726 }
67106727 }
67116728 }
67126729 if( idxNum & 0x3000 ){
6713- iMax = sqlite3_value_int64 (argv[i++]);
6714- if( idxNum & 0x2000 ){
6715- if( iMax==SMALLEST_INT64 ){
6716- returnNoRows = 1 ;
6730+ if( sqlite3_value_numeric_type (argv[i])==SQLITE_FLOAT ){
6731+ double r = sqlite3_value_double(argv[i++]);
6732+ if( (idxNum & 0x2000)!=0 && r==floor(r) ){
6733+ iMax = (sqlite3_int64)(r-1.0) ;
67176734 }else{
6718- iMax--;
6735+ iMax = (sqlite3_int64)floor(r);
6736+ }
6737+ }else{
6738+ iMax = sqlite3_value_int64(argv[i++]);
6739+ if( idxNum & 0x2000 ){
6740+ if( iMax==SMALLEST_INT64 ){
6741+ returnNoRows = 1;
6742+ }else{
6743+ iMax--;
6744+ }
67196745 }
67206746 }
67216747 }
@@ -6734,8 +6760,7 @@ static int seriesFilter(
67346760 pCur->ss.iBase += ((d+szStep-1)/szStep)*szStep;
67356761 }
67366762 if( pCur->ss.iTerm>iMax ){
6737- sqlite3_uint64 d = pCur->ss.iTerm - iMax;
6738- pCur->ss.iTerm -= ((d+szStep-1)/szStep)*szStep;
6763+ pCur->ss.iTerm = iMax;
67396764 }
67406765 }else{
67416766 sqlite3_int64 szStep = -pCur->ss.iStep;
@@ -6745,8 +6770,7 @@ static int seriesFilter(
67456770 pCur->ss.iBase -= ((d+szStep-1)/szStep)*szStep;
67466771 }
67476772 if( pCur->ss.iTerm<iMin ){
6748- sqlite3_uint64 d = iMin - pCur->ss.iTerm;
6749- pCur->ss.iTerm += ((d+szStep-1)/szStep)*szStep;
6773+ pCur->ss.iTerm = iMin;
67506774 }
67516775 }
67526776 }
@@ -6874,7 +6898,10 @@ static int seriesBestIndex(
68746898 continue;
68756899 }
68766900 if( pConstraint->iColumn<SERIES_COLUMN_START ){
6877- if( pConstraint->iColumn==SERIES_COLUMN_VALUE && pConstraint->usable ){
6901+ if( (pConstraint->iColumn==SERIES_COLUMN_VALUE ||
6902+ pConstraint->iColumn==SERIES_COLUMN_ROWID)
6903+ && pConstraint->usable
6904+ ){
68786905 switch( op ){
68796906 case SQLITE_INDEX_CONSTRAINT_EQ:
68806907 case SQLITE_INDEX_CONSTRAINT_IS: {
0 commit comments