Add the "phase" output column on the COMPLETION table-valued function, for

debugging.  Improved comments on the implementation.

FossilOrigin-Name: 0e2135552757cc6566ac959475d3b87254b6d462425ee6c457c743001f3370e2
This commit is contained in:
drh 2017-07-11 02:05:21 +00:00
parent dc4dde6bd9
commit f3c0009d8b
3 changed files with 46 additions and 10 deletions

View File

@ -13,6 +13,25 @@
** This file implements an eponymous virtual table that returns suggested
** completions for a partial SQL input.
**
** Suggested usage:
**
** SELECT DISTINCT candidate COLLATE nocase
** FROM completion($prefix,$wholeline)
** ORDER BY 1;
**
** The two query parameters are optional. $prefix is the text of the
** current word being typed and that is to be completed. $wholeline is
** the complete input line, used for context.
**
** The raw completion() table might return the same candidate multiple
** times, for example if the same column name is used to two or more
** tables. And the candidates are returned in an arbitrary order. Hence,
** the DISTINCT and ORDER BY are recommended.
**
** This virtual table operates at the speed of human typing, and so there
** is no attempt to make it fast. Even a slow implementation will be much
** faster than any human can type.
**
*/
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_COMPLETIONVTAB)
#if !defined(SQLITEINT_H)
@ -94,12 +113,14 @@ static int completionConnect(
#define COMPLETION_COLUMN_CANDIDATE 0 /* Suggested completion of the input */
#define COMPLETION_COLUMN_PREFIX 1 /* Prefix of the word to be completed */
#define COMPLETION_COLUMN_WHOLELINE 2 /* Entire line seen so far */
#define COMPLETION_COLUMN_PHASE 3 /* ePhase - used for debugging only */
rc = sqlite3_declare_vtab(db,
"CREATE TABLE x("
" candidate TEXT,"
" prefix TEXT HIDDEN,"
" wholeline TEXT HIDDEN"
" wholeline TEXT HIDDEN,"
" phase INT HIDDEN" /* Used for debugging only */
")");
if( rc==SQLITE_OK ){
pNew = sqlite3_malloc( sizeof(*pNew) );
@ -177,11 +198,22 @@ static const char *completionKwrds[] = {
/*
** Advance a completion_cursor to its next row of output.
**
** The ->ePhase, ->j, and ->pStmt fields of the completion_cursor object
** record the current state of the scan. This routine sets ->zCurrentRow
** to the current row of output and then returns. If no more rows remain,
** then ->ePhase is set to COMPLETION_EOF which will signal the virtual
** table that has reached the end of its scan.
**
** The current implementation just lists potential identifiers and
** keywords and filters them by zPrefix. Future enhancements should
** take zLine into account to try to restrict the set of identifiers and
** keywords based on what would be legal at the current point of input.
*/
static int completionNext(sqlite3_vtab_cursor *cur){
completion_cursor *pCur = (completion_cursor*)cur;
int eNextPhase = 0;/* Next phase to try if current phase reaches end */
int iCol = -1; /* If >=0 then step pCur->pStmt and use the i-th column */
int eNextPhase = 0; /* Next phase to try if current phase reaches end */
int iCol = -1; /* If >=0, step pCur->pStmt and use the i-th column */
pCur->iRowid++;
while( pCur->ePhase!=COMPLETION_EOF ){
switch( pCur->ePhase ){
@ -303,6 +335,10 @@ static int completionColumn(
sqlite3_result_text(ctx, pCur->zLine, -1, SQLITE_TRANSIENT);
break;
}
case COMPLETION_COLUMN_PHASE: {
sqlite3_result_int(ctx, pCur->ePhase);
break;
}
}
return SQLITE_OK;
}

View File

@ -1,5 +1,5 @@
C The\sCOMPLETION\svirtual\stable\snow\slooks\sat\sthe\snames\sof\sdatabases,\stables,\nand\scolumns\sin\saddition\sto\sSQL\skeywords.
D 2017-07-11T01:38:45.049
C Add\sthe\s"phase"\soutput\scolumn\son\sthe\sCOMPLETION\stable-valued\sfunction,\sfor\ndebugging.\s\sImproved\scomments\son\sthe\simplementation.
D 2017-07-11T02:05:21.668
F Makefile.in 081e48dfe7f995d57ce1a88ddf4d2917b4349158648a6cd45b42beae30de3a12
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc 20850e3e8d4d4791e0531955852d768eb06f24138214870d543abb1a47346fba
@ -256,7 +256,7 @@ F ext/misc/amatch.c 6db4607cb17c54b853a2d7c7c36046d004853f65b9b733e6f019d543d5df
F ext/misc/anycollseq.c 5ffdfde9829eeac52219136ad6aa7cd9a4edb3b15f4f2532de52f4a22525eddb
F ext/misc/carray.c 40c27641010a4dc67e3690bdb7c9d36ca58b3c2d
F ext/misc/closure.c 0d2a038df8fbae7f19de42e7c7d71f2e4dc88704
F ext/misc/completion.c 813c7faecc8fe3dd5c5503b87d4bb44ed6b841ff3398d19fbccec251da0af25f
F ext/misc/completion.c 637c016977809c2c3174472e7a416c9dbefc89dadb0efbd33f1516114b43900e
F ext/misc/compress.c 122faa92d25033d6c3f07c39231de074ab3d2e83
F ext/misc/csv.c d91c0388445b08f6e373dd0e8fc024d4551b1fcaf64e876a1c3f4fac8a63adc2
F ext/misc/dbdump.c 3509fa6b8932d04e932d6b6b827b6a82ca362781b8e8f3c77336f416793e215e
@ -1629,7 +1629,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P caefbc723b5f67afc5ef10b92b20400cbb76cb03e7e75e18d2726cc552083e09
R 1115796824efacad1a0f50faf8b6a73d
P 1cc97711fa86a3938f0930200476d1b0991e4b893a8be3a19015423a3de56bef
R 5f96666448f8bc2a00b6b737201e92f6
U drh
Z e368c5a978df04c5e378d21fe41e060f
Z 37fc96f83608b2443df93123a3a88569

View File

@ -1 +1 @@
1cc97711fa86a3938f0930200476d1b0991e4b893a8be3a19015423a3de56bef
0e2135552757cc6566ac959475d3b87254b6d462425ee6c457c743001f3370e2