SQLite

Check-in [d238694ca4]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add header comment for sqlite3_vtab_collation().
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | schemalint
Files: files | file ages | folders
SHA3-256: d238694ca445ccb4eeb3e3269a5f872f998f795945d0f9dd95c11d0e42d4d538
User & Date: dan 2017-04-15 14:30:01.495
Context
2017-04-15
15:47
Merge latest trunk changes into this branch. (check-in: 2d0c458e01 user: dan tags: schemalint)
14:30
Add header comment for sqlite3_vtab_collation(). (check-in: d238694ca4 user: dan tags: schemalint)
14:16
Fix memory leaks in the code on this branch. Make use of the sqlite3_index_constraint.usage field. Do not try to handle ORDER BY terms with explicit COLLATE clauses - they don't get passed to the vtab layer anyway. (check-in: 0cd75a872c user: dan tags: schemalint)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/sqlite.h.in.
8033
8034
8035
8036
8037
8038
8039














8040
8041
8042
8043
8044
8045
8046
** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
** of the SQL statement that triggered the call to the [xUpdate] method of the
** [virtual table].
*/
int sqlite3_vtab_on_conflict(sqlite3 *);















SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3*, int);

/*
** CAPI3REF: Conflict resolution modes
** KEYWORDS: {conflict resolution mode}
**
** These constants are returned by [sqlite3_vtab_on_conflict()] to







>
>
>
>
>
>
>
>
>
>
>
>
>
>







8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
** of the SQL statement that triggered the call to the [xUpdate] method of the
** [virtual table].
*/
int sqlite3_vtab_on_conflict(sqlite3 *);

/*
** CAPI3REF: Determine The Collation For a Virtual Table Constraint
**
** This function may only be called from within a call to the [xBestIndex]
** method of a [virtual table implementation]. 
**
** The first argument must be the database handle with which the virtual 
** table is associated (the one passed to the [xConnect] or [xCreate] method 
** to create the sqlite3_vtab object. The second argument must be an index
** into the aConstraint[] array belonging to the sqlite3_index_info structure
** passed to xBestIndex. This function returns a pointer to a buffer 
** containing the name of the collation sequence for the corresponding
** constraint.
*/
SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3*, int);

/*
** CAPI3REF: Conflict resolution modes
** KEYWORDS: {conflict resolution mode}
**
** These constants are returned by [sqlite3_vtab_on_conflict()] to
Changes to src/sqliteInt.h.
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
#endif
#ifndef SQLITE_OMIT_VIRTUALTABLE
  int nVTrans;                  /* Allocated size of aVTrans */
  Hash aModule;                 /* populated by sqlite3_create_module() */
  VtabCtx *pVtabCtx;            /* Context for active vtab connect/create */
  VTable **aVTrans;             /* Virtual tables with open transactions */
  VTable *pDisconnect;    /* Disconnect these in next sqlite3_prepare() */
  void *pVtabWC;                /* For sqlite3_vtab_collation() */
#endif
  Hash aFunc;                   /* Hash table of connection functions */
  Hash aCollSeq;                /* All collating sequences */
  BusyHandler busyHandler;      /* Busy callback */
  Db aDbStatic[2];              /* Static space for the 2 default backends */
  Savepoint *pSavepoint;        /* List of active savepoints */
  int busyTimeout;              /* Busy handler timeout, in msec */







|







1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
#endif
#ifndef SQLITE_OMIT_VIRTUALTABLE
  int nVTrans;                  /* Allocated size of aVTrans */
  Hash aModule;                 /* populated by sqlite3_create_module() */
  VtabCtx *pVtabCtx;            /* Context for active vtab connect/create */
  VTable **aVTrans;             /* Virtual tables with open transactions */
  VTable *pDisconnect;    /* Disconnect these in next sqlite3_prepare() */
  void *pBestIndexCtx;          /* For sqlite3_vtab_collation() */
#endif
  Hash aFunc;                   /* Hash table of connection functions */
  Hash aCollSeq;                /* All collating sequences */
  BusyHandler busyHandler;      /* Busy callback */
  Db aDbStatic[2];              /* Static space for the 2 default backends */
  Savepoint *pSavepoint;        /* List of active savepoints */
  int busyTimeout;              /* Busy handler timeout, in msec */
Changes to src/where.c.
3113
3114
3115
3116
3117
3118
3119




3120
3121
3122
3123
3124
3125







3126
3127
3128
3129
3130
3131
3132
3133
3134
                      *pbIn, (sqlite3_uint64)mPrereq,
                      (sqlite3_uint64)(pNew->prereq & ~mPrereq)));

  return rc;
}






struct BestIndexCtx {
  WhereClause *pWC;
  sqlite3_index_info *pIdxInfo;
  Parse *pParse;
};








const char *sqlite3_vtab_collation(sqlite3 *db, int iCons){
  struct BestIndexCtx *p = (struct BestIndexCtx*)db->pVtabWC;
  const char *zRet = 0;
  if( p && iCons>=0 && iCons<p->pIdxInfo->nConstraint ){
    int iTerm = p->pIdxInfo->aConstraint[iCons].iTermOffset;
    Expr *pX = p->pWC->a[iTerm].pExpr;
    CollSeq *pC = sqlite3BinaryCompareCollSeq(p->pParse,pX->pLeft,pX->pRight);
    zRet = (pC ? pC->zName : "BINARY");
  }







>
>
>
>






>
>
>
>
>
>
>

|







3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
                      *pbIn, (sqlite3_uint64)mPrereq,
                      (sqlite3_uint64)(pNew->prereq & ~mPrereq)));

  return rc;
}


/*
** Context object used to pass information from whereLoopAddVirtual()
** to sqlite3_vtab_collation().
*/
struct BestIndexCtx {
  WhereClause *pWC;
  sqlite3_index_info *pIdxInfo;
  Parse *pParse;
};

/*
** If this function is invoked from within an xBestIndex() callback, it
** returns a pointer to a buffer containing the name of the collation
** sequence associated with element iCons of the sqlite3_index_info.aConstraint
** array. Or, if iCons is out of range or there is no active xBestIndex
** call, return NULL.
*/
const char *sqlite3_vtab_collation(sqlite3 *db, int iCons){
  struct BestIndexCtx *p = (struct BestIndexCtx*)db->pBestIndexCtx;
  const char *zRet = 0;
  if( p && iCons>=0 && iCons<p->pIdxInfo->nConstraint ){
    int iTerm = p->pIdxInfo->aConstraint[iCons].iTermOffset;
    Expr *pX = p->pWC->a[iTerm].pExpr;
    CollSeq *pC = sqlite3BinaryCompareCollSeq(p->pParse,pX->pLeft,pX->pRight);
    zRet = (pC ? pC->zName : "BINARY");
  }
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
    sqlite3DbFree(pParse->db, p);
    return SQLITE_NOMEM_BKPT;
  }

  bic.pWC = pWC;
  bic.pIdxInfo = p;
  bic.pParse = pParse;
  pSaved = pParse->db->pVtabWC;
  pParse->db->pVtabWC = (void*)&bic;

  /* First call xBestIndex() with all constraints usable. */
  WHERETRACE(0x40, ("  VirtualOne: all usable\n"));
  rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn);

  /* If the call to xBestIndex() with all terms enabled produced a plan
  ** that does not require any source tables (IOW: a plan with mBest==0),







|
|







3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
    sqlite3DbFree(pParse->db, p);
    return SQLITE_NOMEM_BKPT;
  }

  bic.pWC = pWC;
  bic.pIdxInfo = p;
  bic.pParse = pParse;
  pSaved = pParse->db->pBestIndexCtx;
  pParse->db->pBestIndexCtx = (void*)&bic;

  /* First call xBestIndex() with all constraints usable. */
  WHERETRACE(0x40, ("  VirtualOne: all usable\n"));
  rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn);

  /* If the call to xBestIndex() with all terms enabled produced a plan
  ** that does not require any source tables (IOW: a plan with mBest==0),
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
      rc = whereLoopAddVirtualOne(
          pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
    }
  }

  if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
  sqlite3DbFreeNN(pParse->db, p);
  pParse->db->pVtabWC = pSaved;
  return rc;
}
#endif /* SQLITE_OMIT_VIRTUALTABLE */

/*
** Add WhereLoop entries to handle OR terms.  This works for either
** btrees or virtual tables.







|







3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
      rc = whereLoopAddVirtualOne(
          pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
    }
  }

  if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
  sqlite3DbFreeNN(pParse->db, p);
  pParse->db->pBestIndexCtx = pSaved;
  return rc;
}
#endif /* SQLITE_OMIT_VIRTUALTABLE */

/*
** Add WhereLoop entries to handle OR terms.  This works for either
** btrees or virtual tables.