Skip to content

Fixing fingerprinting of table arguments #5086

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sqlite/src/tokenize.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,13 +835,14 @@ static int isLeftOperand(int tokenType){
** This function should return non-zero if the specified token type is
** a keyword that requires the next token to be a table identifier.
*/
static int requiresTableId(int tokenType){
static int requiresTableId(int tokenType, int useStrId){
switch( tokenType ){
case TK_FROM:
case TK_JOIN:
case TK_INTO:
case TK_UPDATE:
case TK_TABLE: return 1;
case TK_SPACE: return useStrId;
default: return 0;
}
}
Expand Down Expand Up @@ -964,7 +965,6 @@ char *sqlite3Normalize_alternate(
/* fall through */
}
default: {
useStrId = requiresTableId(tokenType);
if( sqlite3IsIdChar(zSql[i]) ) addSpaceSeparator(pStr);
j = pStr->nChar;
sqlite3_str_append(pStr, zSql+i, n);
Expand All @@ -975,6 +975,7 @@ char *sqlite3Normalize_alternate(
break;
}
}
useStrId = requiresTableId(tokenType, useStrId);
}
if( tokenType!=TK_SEMI ) sqlite3_str_append(pStr, ";", 1);
return sqlite3_str_finish(pStr);
Expand Down
4 changes: 4 additions & 0 deletions tests/fingerprints.test/t08.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT * FROM 'sqlite_stat1' LIMIT 0 -- should show table name
SELECT * FROM comdb2_transaction_logs('{1:0}') LIMIT 0 -- should not show arguments for hidden columns
SELECT fingerprint, normalized_sql FROM comdb2_fingerprints WHERE fingerprint='002dcfc6d511a5d625fa142f7f0df9f4'
SELECT fingerprint, normalized_sql FROM comdb2_fingerprints WHERE fingerprint='c30b0528f036eab64a7953ed7c55af40'
2 changes: 2 additions & 0 deletions tests/fingerprints.test/t08.req.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(fingerprint='002dcfc6d511a5d625fa142f7f0df9f4', normalized_sql='SELECT*FROM sqlite_stat1 LIMIT?;')
(fingerprint='c30b0528f036eab64a7953ed7c55af40', normalized_sql='SELECT*FROM comdb2_transaction_logs(?)LIMIT?;')