Skip to content

Commit

Permalink
Proper escaping for tables and schema.
Browse files Browse the repository at this point in the history
  • Loading branch information
cincuranet committed May 15, 2024
1 parent 4f503e2 commit 4a34783
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class SqlServerClient : ISqlServerClient
public SqlServerClient(string connectionString, string schema)
{
this._connectionString = connectionString;
this._schema = schema;
this._schema = DelimitIdentifier(schema);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -245,7 +245,7 @@ ORDER BY [cosine_similarity] DESC
}
}

private string GetFullTableName(string tableName) => $"{this._schema}.[{tableName}]";
private string GetFullTableName(string tableName) => $"{this._schema}.{DelimitIdentifier(tableName)}";

private string SerializeEmbedding(ReadOnlyMemory<float> embedding) => JsonSerializer.Serialize(embedding);
private ReadOnlyMemory<float> DeserializeEmbedding(string embedding) => JsonSerializer.Deserialize<ReadOnlyMemory<float>>(embedding);
Expand All @@ -262,4 +262,7 @@ private SqlServerMemoryEntry ReadEntry(SqlDataReader reader, bool hasEmbedding)
: null;
return new SqlServerMemoryEntry() { Key = key, MetadataString = metadata, Embedding = embedding, Timestamp = timestamp };
}

private static string DelimitIdentifier(string identifier) => $"[{EscapeIdentifier(identifier)}]";
private static string EscapeIdentifier(string identifier) => identifier.Replace("]", "]]");
}

0 comments on commit 4a34783

Please sign in to comment.