/ Check-in [d238694c]
Login

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

Overview
Comment:Add header comment for sqlite3_vtab_collation().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | schemalint
Files: files | file ages | folders
SHA3-256: d238694ca445ccb4eeb3e3269a5f872f998f795945d0f9dd95c11d0e42d4d538
User & Date: dan 2017-04-15 14:30:01
Context
2017-04-15
15:47
Merge latest trunk changes into this branch. check-in: 2d0c458e user: dan tags: schemalint
14:30
Add header comment for sqlite3_vtab_collation(). check-in: d238694c 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: 0cd75a87 user: dan tags: schemalint
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/sqlite.h.in.

  8033   8033   ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
  8034   8034   ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
  8035   8035   ** of the SQL statement that triggered the call to the [xUpdate] method of the
  8036   8036   ** [virtual table].
  8037   8037   */
  8038   8038   int sqlite3_vtab_on_conflict(sqlite3 *);
  8039   8039   
         8040  +/*
         8041  +** CAPI3REF: Determine The Collation For a Virtual Table Constraint
         8042  +**
         8043  +** This function may only be called from within a call to the [xBestIndex]
         8044  +** method of a [virtual table implementation]. 
         8045  +**
         8046  +** The first argument must be the database handle with which the virtual 
         8047  +** table is associated (the one passed to the [xConnect] or [xCreate] method 
         8048  +** to create the sqlite3_vtab object. The second argument must be an index
         8049  +** into the aConstraint[] array belonging to the sqlite3_index_info structure
         8050  +** passed to xBestIndex. This function returns a pointer to a buffer 
         8051  +** containing the name of the collation sequence for the corresponding
         8052  +** constraint.
         8053  +*/
  8040   8054   SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3*, int);
  8041   8055   
  8042   8056   /*
  8043   8057   ** CAPI3REF: Conflict resolution modes
  8044   8058   ** KEYWORDS: {conflict resolution mode}
  8045   8059   **
  8046   8060   ** These constants are returned by [sqlite3_vtab_on_conflict()] to

Changes to src/sqliteInt.h.

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

Changes to src/where.c.

  3113   3113                         *pbIn, (sqlite3_uint64)mPrereq,
  3114   3114                         (sqlite3_uint64)(pNew->prereq & ~mPrereq)));
  3115   3115   
  3116   3116     return rc;
  3117   3117   }
  3118   3118   
  3119   3119   
         3120  +/*
         3121  +** Context object used to pass information from whereLoopAddVirtual()
         3122  +** to sqlite3_vtab_collation().
         3123  +*/
  3120   3124   struct BestIndexCtx {
  3121   3125     WhereClause *pWC;
  3122   3126     sqlite3_index_info *pIdxInfo;
  3123   3127     Parse *pParse;
  3124   3128   };
  3125   3129   
         3130  +/*
         3131  +** If this function is invoked from within an xBestIndex() callback, it
         3132  +** returns a pointer to a buffer containing the name of the collation
         3133  +** sequence associated with element iCons of the sqlite3_index_info.aConstraint
         3134  +** array. Or, if iCons is out of range or there is no active xBestIndex
         3135  +** call, return NULL.
         3136  +*/
  3126   3137   const char *sqlite3_vtab_collation(sqlite3 *db, int iCons){
  3127         -  struct BestIndexCtx *p = (struct BestIndexCtx*)db->pVtabWC;
         3138  +  struct BestIndexCtx *p = (struct BestIndexCtx*)db->pBestIndexCtx;
  3128   3139     const char *zRet = 0;
  3129   3140     if( p && iCons>=0 && iCons<p->pIdxInfo->nConstraint ){
  3130   3141       int iTerm = p->pIdxInfo->aConstraint[iCons].iTermOffset;
  3131   3142       Expr *pX = p->pWC->a[iTerm].pExpr;
  3132   3143       CollSeq *pC = sqlite3BinaryCompareCollSeq(p->pParse,pX->pLeft,pX->pRight);
  3133   3144       zRet = (pC ? pC->zName : "BINARY");
  3134   3145     }
................................................................................
  3198   3209       sqlite3DbFree(pParse->db, p);
  3199   3210       return SQLITE_NOMEM_BKPT;
  3200   3211     }
  3201   3212   
  3202   3213     bic.pWC = pWC;
  3203   3214     bic.pIdxInfo = p;
  3204   3215     bic.pParse = pParse;
  3205         -  pSaved = pParse->db->pVtabWC;
  3206         -  pParse->db->pVtabWC = (void*)&bic;
         3216  +  pSaved = pParse->db->pBestIndexCtx;
         3217  +  pParse->db->pBestIndexCtx = (void*)&bic;
  3207   3218   
  3208   3219     /* First call xBestIndex() with all constraints usable. */
  3209   3220     WHERETRACE(0x40, ("  VirtualOne: all usable\n"));
  3210   3221     rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn);
  3211   3222   
  3212   3223     /* If the call to xBestIndex() with all terms enabled produced a plan
  3213   3224     ** that does not require any source tables (IOW: a plan with mBest==0),
................................................................................
  3277   3288         rc = whereLoopAddVirtualOne(
  3278   3289             pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
  3279   3290       }
  3280   3291     }
  3281   3292   
  3282   3293     if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
  3283   3294     sqlite3DbFreeNN(pParse->db, p);
  3284         -  pParse->db->pVtabWC = pSaved;
         3295  +  pParse->db->pBestIndexCtx = pSaved;
  3285   3296     return rc;
  3286   3297   }
  3287   3298   #endif /* SQLITE_OMIT_VIRTUALTABLE */
  3288   3299   
  3289   3300   /*
  3290   3301   ** Add WhereLoop entries to handle OR terms.  This works for either
  3291   3302   ** btrees or virtual tables.