Skip to content

Commit e6a6cd6

Browse files
committed
fix save method
1 parent 243e8fd commit e6a6cd6

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

slo/src/Linq2db.Slo/SloLinq2DbContext.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,20 @@ protected override async Task<int> Save(Linq2dbClient client, SloTable sloTable,
6363
await using var db = client.Open();
6464
db.CommandTimeout = writeTimeout;
6565

66-
// rowsAffected >= 0 (для UPSERT в YDB может быть 0), поэтому страхуемся и возвращаем минимум 1
67-
var rowsAffected = await db.ExecuteAsync($@"
66+
var sql = $@"
6867
UPSERT INTO `{SloTable.Name}` (Guid, Id, PayloadStr, PayloadDouble, PayloadTimestamp)
69-
VALUES ({sloTable.Guid}, {sloTable.Id}, {sloTable.PayloadStr}, {sloTable.PayloadDouble}, {sloTable.PayloadTimestamp});
70-
");
68+
VALUES (@Guid, @Id, @PayloadStr, @PayloadDouble, @PayloadTimestamp);";
7169

72-
return rowsAffected > 0 ? rowsAffected : 1;
70+
var affected = await db.ExecuteAsync(
71+
sql,
72+
new DataParameter("Guid", sloTable.Guid, DataType.Guid),
73+
new DataParameter("Id", sloTable.Id, DataType.Int32),
74+
new DataParameter("PayloadStr", sloTable.PayloadStr, DataType.NVarChar),
75+
new DataParameter("PayloadDouble", sloTable.PayloadDouble, DataType.Double),
76+
new DataParameter("PayloadTimestamp",sloTable.PayloadTimestamp,DataType.DateTime2)
77+
);
78+
79+
return affected > 0 ? affected : 1;
7380
}
7481

7582
protected override async Task<object?> Select(Linq2dbClient client, (Guid Guid, int Id) select, int readTimeout)

0 commit comments

Comments
 (0)