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

Commit 4644b28

Browse files
committed
Add ExecuteSql overload that takes DictionaryObjects
1 parent 3b69327 commit 4644b28

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/ServiceStack.OrmLite/OrmLiteWriteApi.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ public static int ExecuteSql(this IDbConnection dbConn, string sql, object dbPar
5555
return dbConn.Exec(dbCmd => dbCmd.ExecuteSql(sql, dbParams));
5656
}
5757

58+
/// <summary>
59+
/// Execute any arbitrary raw SQL with db params.
60+
/// </summary>
61+
/// <returns>number of rows affected</returns>
62+
public static int ExecuteSql(this IDbConnection dbConn, string sql, Dictionary<string,object> dbParams)
63+
{
64+
return dbConn.Exec(dbCmd => dbCmd.ExecuteSql(sql, dbParams));
65+
}
66+
5867
/// <summary>
5968
/// Insert 1 POCO, use selectIdentity to retrieve the last insert AutoIncrement id (if any). E.g:
6069
/// <para>var id = db.Insert(new Person { Id = 1, FirstName = "Jimi }, selectIdentity:true)</para>

tests/ServiceStack.OrmLite.Tests/OrmLiteUpdateTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,13 @@ public void Can_updated_with_ExecuteSql_and_db_params()
377377

378378
var row = db.SingleById<Poco>(2);
379379
Assert.That(row.Name, Is.EqualTo("UPDATED"));
380+
381+
sql = "UPDATE poco SET name = {0}name WHERE id = {0}id".Fmt(OrmLiteConfig.DialectProvider.ParamString);
382+
result = db.ExecuteSql(sql, new Dictionary<string, object> { {"id", 2}, {"name", "RE-UPDATED" } });
383+
Assert.That(result, Is.EqualTo(1));
384+
385+
row = db.SingleById<Poco>(2);
386+
Assert.That(row.Name, Is.EqualTo("RE-UPDATED"));
380387
}
381388
}
382389

0 commit comments

Comments
 (0)