Skip to content

Commit 2928434

Browse files
author
D. Richard Hipp
committed
Improvements to the accurancy of the fuzzinvariants.c testing module when
SQLITE_ALLOW_ROWID_IN_VIEW is defined and the test query involves rowids.
1 parent fc0d962 commit 2928434

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

test/fuzzinvariants.c

+32-3
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,18 @@ int fuzz_invariant(
223223
return SQLITE_OK;
224224
}
225225

226+
#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
227+
/*
228+
** Return TRUE if the i-th column of pStmt might be a ROWID value.
229+
*/
230+
static int column_might_be_rowid(sqlite3_stmt *pStmt, int i){
231+
const char *zColName = sqlite3_column_name(pStmt, i);
232+
if( sqlite3_strlike("%rowid%",zColName,0)==0 ) return 1;
233+
if( sqlite3_strlike("%oid%",zColName,0)==0 ) return 1;
234+
return 0;
235+
}
236+
#endif /* SQLITE_ALLOW_ROWID_IN_VIEW */
237+
226238

227239
/*
228240
** Generate SQL used to test a statement invariant.
@@ -297,9 +309,7 @@ static char *fuzz_invariant_sql(sqlite3_stmt *pStmt, int iCnt){
297309
continue;
298310
}
299311
#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
300-
if( sqlite3_strlike("%rowid%",zColName,0)==0
301-
|| sqlite3_strlike("%oid%",zColName,0)==0
302-
){
312+
if( column_might_be_rowid(pBase,i) ){
303313
/* ROWID values are unreliable if SQLITE_ALLOW_ROWID_IN_VIEW is used */
304314
continue;
305315
}
@@ -332,6 +342,11 @@ static char *fuzz_invariant_sql(sqlite3_stmt *pStmt, int iCnt){
332342

333343
/*
334344
** Return true if and only if v1 and is the same as v2.
345+
**
346+
** When compiled with SQLITE_ALLOW_ROWID_IN_VIEW, and if either
347+
** v1 or v2 has a column name that indicates that it is a rowid
348+
** then a NULL value in the rowid column will compare equal to
349+
** an integer value in the other.
335350
*/
336351
static int sameValue(
337352
sqlite3_stmt *pS1, int i1, /* Value to text on the left */
@@ -346,6 +361,20 @@ static int sameValue(
346361
|| (t1==SQLITE_FLOAT && t2==SQLITE_INTEGER)
347362
){
348363
/* Comparison of numerics is ok */
364+
#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
365+
}else
366+
if( t1==SQLITE_INTEGER
367+
&& t2==SQLITE_NULL
368+
&& column_might_be_rowid(pS2,i2)
369+
){
370+
return 1;
371+
}else
372+
if( t2==SQLITE_INTEGER
373+
&& t1==SQLITE_NULL
374+
&& column_might_be_rowid(pS1,i1)
375+
){
376+
return 1;
377+
#endif /* SQLITE_ALLOW_ROWID_IN_VIEW */
349378
}else{
350379
return 0;
351380
}

0 commit comments

Comments
 (0)