-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let virtual table implementations know which SQL string is being executed #87
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8072,6 +8072,40 @@ case OP_VInitIn: { /* out2 */ | |
} | ||
#endif /* SQLITE_OMIT_VIRTUALTABLE */ | ||
|
||
#ifndef SQLITE_OMIT_VIRTUALTABLE | ||
/* Opcode: VPrepareSql P1 * * * * | ||
** | ||
** P1 is a cursor opened using VOpen. | ||
** | ||
** This opcode invokes the xPrepareSql method on the virtual table specified | ||
** by P1. The SQL text parameter to xPrepareSql is obtained from Vdbe* `p`. | ||
** | ||
*/ | ||
case OP_VPrepareSql: { | ||
const sqlite3_module *pModule; | ||
sqlite3_vtab_cursor *pVCur; | ||
sqlite3_vtab *pVtab; | ||
VdbeCursor *pCur; | ||
|
||
pCur = p->apCsr[pOp->p1]; | ||
assert( pCur!=0 ); | ||
assert( pCur->eCurType==CURTYPE_VTAB ); | ||
pVCur = pCur->uc.pVCur; | ||
pVtab = pVCur->pVtab; | ||
pModule = pVtab->pModule; | ||
|
||
/* Invoke the xPrepareSql method */ | ||
if( pModule->iVersion>=4 ){ | ||
if( pModule->xPrepareSql && p->zSql ){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question - in which cases is This is a genuine question, as I haven't implemented any virtual SQLite tables in my life (: if it doesn't make sense, then feel free to leave the code as is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added that as a sanity check. A NULL value for |
||
rc = pModule->xPrepareSql(pVCur, p->zSql); | ||
if( rc ) goto abort_due_to_error; // TODO set and test error msg | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you elaborate on the TODO? As long as the implementation of xPrepareSql assigns a proper error code, it will be properly handled and printed in the code that follows There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was a reminder to test the error path, but I ended up leaving it behind by mistake. I will remove it. |
||
} | ||
} | ||
|
||
if( rc ) goto abort_due_to_error; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line looks redundant - it's already checked in line 8101, and line 8100 is the only one in this block that assigns to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, indeed. Thanks for spotting that! |
||
break; | ||
} | ||
#endif /* SQLITE_OMIT_VIRTUALTABLE */ | ||
|
||
#ifndef SQLITE_OMIT_VIRTUALTABLE | ||
/* Opcode: VFilter P1 P2 P3 P4 * | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's going to get ambiguous if/when SQLite adds some other field and bump the current version to 4, and we'd like to keep libSQL compatible for as long as possible. There's no perfect solution here, but in an (unmerged yet) pull request I used version "700", to indicate that it's a libSQL extension, and it makes the collision less likely to happen in the next few years. Perhaps the same trick could be applied here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. HDF5 adopts a similar approach when dealing with I/O filters: a certain range of numbers is reserved for filters contributed by the community. I will follow your suggestion and will check for
iVersion >= 700
.