Skip to content

Commit

Permalink
Updates to the Azure SQL Database content source
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciprian Jichici committed Jan 29, 2024
1 parent b7504e8 commit 1780ba6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,30 @@ private async Task<BinaryData> GetBinaryContent(string schema, string tableName,
{
try
{
using (SqlConnection connection = new SqlConnection(_settings.ConnectionString))
using (var connection = new SqlConnection(_settings.ConnectionString))
{
await connection.OpenAsync(cancellationToken);

using (SqlCommand command = new SqlCommand($"SELECT TOP 1 {contentColumnName} FROM [{schema}].[{tableName}] WHERE {identifierColumnName} = `{identifierValue}`", connection))
// WARNING! This is for experimentation purposes only as it is not injection-safe!
// TODO: More work to sanitize and add safety layers against injection.

using (var command = new SqlCommand($"SELECT TOP 1 {contentColumnName} FROM [{schema}].[{tableName}] WHERE {identifierColumnName} = @identifierValue", connection))
{
using (SqlDataReader reader = await command.ExecuteReaderAsync(cancellationToken))
command.Parameters.Add(new SqlParameter("@identifierValue", identifierValue));

using (var reader = await command.ExecuteReaderAsync(cancellationToken))
{
if (!reader.HasRows)
throw new VectorizationException($"The file {identifierValue} was not found in the database.");
await reader.ReadAsync();
return new BinaryData(reader[contentColumnName]);
}
}
}
}
catch
catch (Exception ex)
{
throw new VectorizationException($"Error when extracting content from file identified by {identifierValue} in Azure SQL Database.");
throw new VectorizationException($"Error when extracting content from file identified by {identifierValue} in Azure SQL Database.", ex);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet/VectorizationAPI/VectorizationAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<InvariantGlobalization>false</InvariantGlobalization>
<UserSecretsId>35b5c460-a49c-4185-a169-676d90673146</UserSecretsId>
<AssemblyName>FoundationaLLM.Vectorization.API</AssemblyName>
<RootNamespace>FoundationaLLM.Vectorization.API</RootNamespace>
Expand Down

0 comments on commit 1780ba6

Please sign in to comment.