Skip to content

Commit

Permalink
constrain parameters to their field size (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Nagy authored and Aaronontheweb committed Jan 20, 2020
1 parent cb05d97 commit 5e4f617
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public BatchingSqlServerJournal(Config config) : this(new BatchingSqlServerJourn
var c = Setup.NamingConventions;

ByTagSql = ByTagSql = $@"
DECLARE @Tag_sized NVARCHAR(100);
SET @Tag_sized = @Tag;
SELECT TOP (@Take)
e.{c.PersistenceIdColumnName} as PersistenceId,
e.{c.SequenceNrColumnName} as SequenceNr,
Expand All @@ -63,7 +65,7 @@ SELECT TOP (@Take)
e.{c.SerializerIdColumnName} as SerializerId,
e.{c.OrderingColumnName} as Ordering
FROM {c.FullJournalTableName} e
WHERE e.{c.OrderingColumnName} > @Ordering AND e.{c.TagsColumnName} LIKE @Tag
WHERE e.{c.OrderingColumnName} > @Ordering AND e.{c.TagsColumnName} LIKE @Tag_sized
ORDER BY {c.OrderingColumnName} ASC
";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public SqlServerQueryExecutor(QueryConfiguration configuration, Akka.Serializati
: base(configuration, serialization, timestampProvider)
{
ByTagSql = $@"
DECLARE @Tag_sized NVARCHAR(100);
SET @Tag_sized = @Tag;
SELECT TOP (@Take)
e.{Configuration.PersistenceIdColumnName} as PersistenceId,
e.{Configuration.SequenceNrColumnName} as SequenceNr,
Expand All @@ -27,7 +29,7 @@ SELECT TOP (@Take)
e.{Configuration.SerializerIdColumnName} as SerializerId,
e.{Configuration.OrderingColumnName} as Ordering
FROM {Configuration.FullJournalTableName} e
WHERE e.{Configuration.OrderingColumnName} > @Ordering AND e.{Configuration.TagsColumnName} LIKE @Tag
WHERE e.{Configuration.OrderingColumnName} > @Ordering AND e.{Configuration.TagsColumnName} LIKE @Tag_sized
ORDER BY {Configuration.OrderingColumnName} ASC
";
CreateEventsJournalSql = $@"
Expand Down
22 changes: 15 additions & 7 deletions src/Akka.Persistence.SqlServer/Snapshot/SqlServerQueryExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,47 @@ CREATE INDEX IX_{configuration.SnapshotTableName}_{configuration.TimestampColumn
";

InsertSnapshotSql = $@"
DECLARE @Manifest_sized NVARCHAR(500);
DECLARE @Payload_sized VARBINARY(MAX);
DECLARE @PersistenceId_sized NVARCHAR(255);
SET @Manifest_sized = @Manifest;
SET @Payload_sized = @Payload;
SET @PersistenceId_sized = @PersistenceId;
IF (
SELECT COUNT(*)
FROM {configuration.FullSnapshotTableName}
WHERE {configuration.SequenceNrColumnName} = @SequenceNr
AND {configuration.PersistenceIdColumnName} = @PersistenceId) > 0
AND {configuration.PersistenceIdColumnName} = @PersistenceId_sized) > 0
UPDATE {configuration.FullSnapshotTableName}
SET
{configuration.PersistenceIdColumnName} = @PersistenceId,
{configuration.PersistenceIdColumnName} = @PersistenceId_sized,
{configuration.SequenceNrColumnName} = @SequenceNr,
{configuration.TimestampColumnName} = @Timestamp,
{configuration.ManifestColumnName} = @Manifest,
{configuration.PayloadColumnName} = @Payload,
{configuration.ManifestColumnName} = @Manifest_sized,
{configuration.PayloadColumnName} = @Payload_sized,
{configuration.SerializerIdColumnName} = @SerializerId
WHERE {configuration.SequenceNrColumnName} = @SequenceNr
AND {configuration.PersistenceIdColumnName} = @PersistenceId ELSE
AND {configuration.PersistenceIdColumnName} = @PersistenceId_sized ELSE
INSERT INTO {configuration.FullSnapshotTableName} (
{configuration.PersistenceIdColumnName},
{configuration.SequenceNrColumnName},
{configuration.TimestampColumnName},
{configuration.ManifestColumnName},
{configuration.PayloadColumnName},
{configuration.SerializerIdColumnName})
VALUES (@PersistenceId, @SequenceNr, @Timestamp, @Manifest, @Payload, @SerializerId);";
VALUES (@PersistenceId_sized, @SequenceNr, @Timestamp, @Manifest_sized, @Payload_sized, @SerializerId);";

SelectSnapshotSql = $@"
DECLARE @PersistenceId_sized NVARCHAR(255);
SET @PersistenceId_sized = @PersistenceId;
SELECT TOP 1 {Configuration.PersistenceIdColumnName},
{Configuration.SequenceNrColumnName},
{Configuration.TimestampColumnName},
{Configuration.ManifestColumnName},
{Configuration.PayloadColumnName},
{Configuration.SerializerIdColumnName}
FROM {Configuration.FullSnapshotTableName}
WHERE {Configuration.PersistenceIdColumnName} = @PersistenceId
WHERE {Configuration.PersistenceIdColumnName} = @PersistenceId_sized
AND {Configuration.SequenceNrColumnName} <= @SequenceNr
AND {Configuration.TimestampColumnName} <= @Timestamp
ORDER BY {Configuration.SequenceNrColumnName} DESC";
Expand Down

0 comments on commit 5e4f617

Please sign in to comment.