Skip to content

.Net MEVD Sqlite: Escaping - #11534

Merged
Adam Sitnik (adamsitnik) merged 5 commits into
microsoft:feature-vector-data-preb2from
adamsitnik:sqlRefactor
Apr 18, 2025
Merged

Adam Sitnik (adamsitnik) merged 5 commits into
microsoft:feature-vector-data-preb2from
adamsitnik:sqlRefactor

Conversation

@adamsitnik

Copy link
Copy Markdown
Member

The first commit is a follow up to #11112 (comment), where I was asked to reuse some of the duplicated code.

The second commit is simply escaping and quoting everything and everywhere for Sqlite connector:

  • escape the table names when we compute them for the first time, then always use escaped values
  • escape the storage names when we compute them, so all usages of .StorageName are safe
  • quote table and column names everywhere

The third commit is conformance tests + fixes

Contributes to #11154

- escape the table names when we compute them for the first time, then always use escaped values
- escape the storage names when  we compute them, so all usages of .StorageName are safe
- quote table and column names everywhere
@adamsitnik
Adam Sitnik (adamsitnik) requested a review from a team as a code owner April 14, 2025 10:00
@markwallace-microsoft Mark Wallace (markwallace-microsoft) added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel memory labels Apr 14, 2025

this._dataTableName = this.CollectionName;
this._vectorTableName = GetVectorTableName(this._dataTableName, this._options);
// Escape both table names before exposing them to anything that may build SQL commands.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is important: both table names (one is storing data, another vectors) are escaped before being exposed to anything that builds SQL. So it's done only once (perf) and the rest of the code does not need to worry about table name escaping.


using var reader = await command.ExecuteReaderAsync(cancellationToken).ConfigureAwait(false);
while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
if (options.IncludeVectors)

@adamsitnik Adam Sitnik (adamsitnik) Apr 14, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bug fix: we respect IncludeVectors now and also reuse the code with other methods that create SELECT WHERE queries

}

Verify.True(keysList.Count > 0, "Number of provided keys should be greater than zero.");
using var connection = await this.GetConnectionAsync(cancellationToken).ConfigureAwait(false);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verify the input first (it may throw), then create the connection

}

property.StorageName = storageName;
property.StorageName = this.Options.EscapeIdentifier is not null

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is important and I want to rely on it in other PRs: it's really hard to find all the usages of StorageName to do proper escaping. Since we can now perform the escaping during model build, we can ensure that whatever StorageName returns, it's safe to be consumed. Moreover, it's done only once (perf).

…o sqlRefactor

# Conflicts:
#	dotnet/src/Connectors/Connectors.Memory.Sqlite/SqliteVectorStoreRecordCollection.cs

This branch was previously deployed

1 inactive deployment
integration — ee88eb62 Deployed Apr 18, 2025 by adamsitnik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel Issues or pull requests impacting the core kernel memory .NET Issue or Pull requests regarding .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants