@@ -312,8 +312,9 @@ static int changesColumn(
312
312
break ;
313
313
case CHANGES_SINCE_VTAB_SITE_ID :
314
314
if (sqlite3_column_type (pCur -> pChangesStmt , SITE_ID ) == SQLITE_NULL ) {
315
- sqlite3_result_blob (ctx , pCur -> pTab -> pExtData -> siteId , SITE_ID_LEN ,
316
- SQLITE_STATIC );
315
+ sqlite3_result_null (ctx );
316
+ // sqlite3_result_blob(ctx, pCur->pTab->pExtData->siteId, SITE_ID_LEN,
317
+ // SQLITE_STATIC);
317
318
} else {
318
319
sqlite3_result_value (ctx ,
319
320
sqlite3_column_value (pCur -> pChangesStmt , SITE_ID ));
@@ -374,7 +375,7 @@ static int changesFilter(sqlite3_vtab_cursor *pVtabCursor, int idxNum,
374
375
sqlite3_free (zSql );
375
376
if (rc != SQLITE_OK ) {
376
377
pTabBase -> zErrMsg = sqlite3_mprintf (
377
- "crsql internal error preparing the statement to extract changes." );
378
+ "error preparing stmt to extract changes %s" , sqlite3_errmsg ( db ) );
378
379
sqlite3_finalize (pStmt );
379
380
return rc ;
380
381
}
@@ -446,7 +447,7 @@ static int changesBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo) {
446
447
sqlite3_str * pStr = sqlite3_str_new (crsqlTab -> db );
447
448
448
449
int firstConstaint = 1 ;
449
- char * constraint = 0 ;
450
+ char * colName = 0 ;
450
451
int argvIndex = 1 ;
451
452
for (int i = 0 ; i < pIdxInfo -> nConstraint ; i ++ ) {
452
453
const struct sqlite3_index_constraint * pConstraint =
@@ -461,36 +462,44 @@ static int changesBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo) {
461
462
// the clock table has pks split out.
462
463
break ;
463
464
case CHANGES_SINCE_VTAB_CID :
464
- constraint = "cid" ;
465
+ colName = "cid" ;
465
466
break ;
466
467
case CHANGES_SINCE_VTAB_CVAL :
467
468
break ;
468
469
case CHANGES_SINCE_VTAB_COL_VRSN :
469
- constraint = "col_vrsn" ;
470
+ colName = "col_vrsn" ;
470
471
break ;
471
472
case CHANGES_SINCE_VTAB_DB_VRSN :
472
- constraint = "db_vrsn" ;
473
+ colName = "db_vrsn" ;
473
474
break ;
474
475
case CHANGES_SINCE_VTAB_SITE_ID :
475
- constraint = "site_id" ;
476
+ colName = "site_id" ;
476
477
break ;
477
478
}
478
479
479
- if (constraint != 0 ) {
480
+ if (colName != 0 ) {
480
481
const char * opString = getOperatorString (pConstraint -> op );
481
482
if (opString == 0 ) {
482
483
continue ;
483
484
}
484
485
if (firstConstaint ) {
485
486
firstConstaint = 0 ;
486
487
} else {
487
- sqlite3_str_append (pStr , " AND " , -1 );
488
+ sqlite3_str_appendall (pStr , " AND " );
489
+ }
490
+
491
+ if (pConstraint -> op == SQLITE_INDEX_CONSTRAINT_ISNOTNULL ||
492
+ pConstraint -> op == SQLITE_INDEX_CONSTRAINT_ISNULL ) {
493
+ sqlite3_str_appendf (pStr , "%s %s" , colName , opString );
494
+ pIdxInfo -> aConstraintUsage [i ].argvIndex = 0 ;
495
+ pIdxInfo -> aConstraintUsage [i ].omit = 1 ;
496
+ } else {
497
+ sqlite3_str_appendf (pStr , "%s %s ?" , colName , opString );
498
+ pIdxInfo -> aConstraintUsage [i ].argvIndex = argvIndex ;
499
+ pIdxInfo -> aConstraintUsage [i ].omit = 1 ;
500
+ argvIndex += 1 ;
488
501
}
489
- sqlite3_str_appendf (pStr , "%s %s ?" , constraint , opString );
490
- constraint = 0 ;
491
- pIdxInfo -> aConstraintUsage [i ].argvIndex = argvIndex ;
492
- pIdxInfo -> aConstraintUsage [i ].omit = 1 ;
493
- argvIndex += 1 ;
502
+ colName = 0 ;
494
503
}
495
504
496
505
switch (pConstraint -> iColumn ) {
0 commit comments