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

Commit 102f0e9

Browse files
committed
Also log SQL when using ExecLongScalar
1 parent e8eb4d2 commit 102f0e9

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

src/ServiceStack.OrmLite/OrmLiteResultsFilterExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ public static long ExecLongScalar(this IDbCommand dbCmd, string sql = null)
246246
if (sql != null)
247247
dbCmd.CommandText = sql;
248248

249+
if (Log.IsDebugEnabled)
250+
Log.DebugCommand(dbCmd);
251+
249252
if (OrmLiteConfig.ResultsFilter != null)
250253
return OrmLiteConfig.ResultsFilter.GetLongScalar(dbCmd);
251254

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using NUnit.Framework;
2+
using ServiceStack.Logging;
3+
using ServiceStack.OrmLite.Tests.Shared;
4+
5+
namespace ServiceStack.OrmLite.Tests.Issues
6+
{
7+
public class NoSqlLoggingIssue : OrmLiteTestBase
8+
{
9+
[Test]
10+
public void Does_log_SQL_Insert_for_Saves()
11+
{
12+
var sbLogFactory = new StringBuilderLogFactory();
13+
LogManager.LogFactory = sbLogFactory;
14+
15+
using (var db = OpenDbConnection())
16+
{
17+
db.DropAndCreateTable<PersonWithAutoId>();
18+
19+
db.Save(new Person { Id = 1, FirstName = "first", LastName = "last", Age = 27 });
20+
}
21+
22+
var sql = sbLogFactory.GetLogs();
23+
24+
Assert.That(sql, Does.Contain("INSERT INTO"));
25+
}
26+
27+
[Test]
28+
public void Does_log_SQL_Insert_for_Saves_with_Auto_Ids()
29+
{
30+
var sbLogFactory = new StringBuilderLogFactory();
31+
LogManager.LogFactory = sbLogFactory;
32+
33+
using (var db = OpenDbConnection())
34+
{
35+
db.DropAndCreateTable<PersonWithAutoId>();
36+
37+
db.Save(new PersonWithAutoId { Id = 1, FirstName = "first", LastName = "last", Age = 27 });
38+
}
39+
40+
var sql = sbLogFactory.GetLogs();
41+
42+
Assert.That(sql, Does.Contain("INSERT INTO"));
43+
}
44+
}
45+
}

tests/ServiceStack.OrmLite.Tests/ServiceStack.OrmLite.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
<Compile Include="Issues\LoadReferencesNullReferenceIssue.cs" />
148148
<Compile Include="Issues\MergeParamsIssue.cs" />
149149
<Compile Include="Issues\MultiThreadedUpdateTransactionIssue.cs" />
150+
<Compile Include="Issues\NoSqlLoggingIssue.cs" />
150151
<Compile Include="Issues\ParamNameIssues.cs" />
151152
<Compile Include="MultipleConnectionIdTests.cs" />
152153
<Compile Include="Shared\DefaultValues.cs" />

0 commit comments

Comments
 (0)