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

Commit 7475c79

Browse files
committed
Make JoinSqlBuilder test demonstrate double from bug in Oracle provider and fix bug.
1 parent 0af1405 commit 7475c79

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/ServiceStack.OrmLite.Oracle/OracleOrmLiteDialectProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Linq.Expressions;
88
using System.Reflection;
99
using System.Text;
10+
using System.Text.RegularExpressions;
1011
using System.Threading;
1112

1213
namespace ServiceStack.OrmLite.Oracle
@@ -285,7 +286,8 @@ public override string ToSelectStatement(Type tableType, string sqlFilter, para
285286

286287
if (isFullSelectStatement)
287288
{
288-
if (!sqlFilter.Trim().ToUpperInvariant().Contains(" FROM ")) sqlFilter += " FROM DUAL";
289+
if (Regex.Matches(sqlFilter.Trim().ToUpperInvariant(), @"(\b|\n)FROM(\b|\n)").Count < 1)
290+
sqlFilter += " FROM DUAL";
289291
return sqlFilter.SqlFmt(filterParams);
290292
}
291293

tests/ServiceStack.OrmLite.Tests/JoinSqlBuilderTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
using System.Text.RegularExpressions;
12
using NUnit.Framework;
2-
using System;
33
using ServiceStack.DataAnnotations;
44

55
namespace ServiceStack.OrmLite.Tests
@@ -82,6 +82,9 @@ public void DoubleWhereLeftJoinTest ()
8282
var expectedNq = "SELECT \"User\".Id,\"User\".Name,\"User\".Age \nFROM \"User\" \n LEFT OUTER JOIN Addresses ON \"User\".Id = Addresses.UserId \nWHERE (\"User\".Age > 18) AND (Addresses.Countryalias = 'Italy') \n";
8383

8484
Assert.That(joinQuery, Is.EqualTo(expected).Or.EqualTo(expectedNq));
85+
86+
var stmt = OrmLiteConfig.DialectProvider.ToSelectStatement(typeof(User), joinQuery);
87+
Assert.That(Regex.Matches(stmt, @"(\b|\n)FROM(\b|\n)", RegexOptions.IgnoreCase).Count, Is.EqualTo(1));
8588
}
86-
}
89+
}
8790
}

0 commit comments

Comments
 (0)