Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 1e9f86b

Browse files
committed
Remove exceptions from control flow
1 parent 777af6a commit 1e9f86b

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

src/ServiceStack.OrmLite/OrmLiteDialectProviderBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,8 @@ public virtual void PrepareParameterizedUpdateStatement<T>(IDbCommand cmd, IColl
689689
}
690690
}
691691

692-
if (sql.Length < 1) throw new InvalidOperationException("No columns to update");
692+
if (sql.Length < 1)
693+
return;
693694

694695
cmd.CommandText = string.Format("UPDATE {0} SET {1} {2}",
695696
GetQuotedTableName(modelDef), sql, (sqlFilter.Length > 0 ? "WHERE " + sqlFilter : ""));

src/ServiceStack.OrmLite/OrmLiteWriteExtensions.cs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,9 @@ internal static int Update<T>(this IDbCommand dbCmd, T obj)
370370
if (OrmLiteConfig.UpdateFilter != null)
371371
OrmLiteConfig.UpdateFilter(dbCmd, obj);
372372

373-
try
374-
{
375-
OrmLiteConfig.DialectProvider.PrepareParameterizedUpdateStatement<T>(dbCmd);
376-
}
377-
catch (InvalidOperationException ex)
378-
{
379-
Log.Debug(ex.Message);
373+
OrmLiteConfig.DialectProvider.PrepareParameterizedUpdateStatement<T>(dbCmd);
374+
if (dbCmd.CommandText == null)
380375
return 0;
381-
}
382376

383377
OrmLiteConfig.DialectProvider.SetParameterValues<T>(dbCmd, obj);
384378

@@ -402,15 +396,9 @@ internal static int UpdateAll<T>(this IDbCommand dbCmd, IEnumerable<T> objs)
402396

403397
var dialectProvider = OrmLiteConfig.DialectProvider;
404398

405-
try
406-
{
407-
dialectProvider.PrepareParameterizedUpdateStatement<T>(dbCmd);
408-
}
409-
catch (InvalidOperationException ex)
410-
{
411-
Log.Debug(ex.Message);
412-
return count;
413-
}
399+
dialectProvider.PrepareParameterizedUpdateStatement<T>(dbCmd);
400+
if (dbCmd.CommandText == null)
401+
return 0;
414402

415403
foreach (var obj in objs)
416404
{

tests/ServiceStack.OrmLite.Tests/OrmLiteSaveTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,13 @@ public void Can_Save_Update_Into_Table_With_Id_Only()
227227
{
228228
using (var db = OpenDbConnection())
229229
{
230-
db.CreateTable<ModelWithIdOnly>(true);
230+
db.DropAndCreateTable<ModelWithIdOnly>();
231+
231232
db.Save(new ModelWithIdOnly(1));
232233

233234
db.Save(new ModelWithIdOnly(1));
235+
236+
db.Update(new ModelWithIdOnly(1));
234237
}
235238
}
236239
}

0 commit comments

Comments
 (0)