Skip to content

Commit 5b4a645

Browse files
committed
Much understandable exeption
1 parent 980fc46 commit 5b4a645

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Orm/Xtensive.Orm.Tests.Sql/MakeNamesUnreadableTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ private void TestQueryNamesUnreadable(ISqlCompileUnit query, Schema defaultSchem
366366
if (IsMultidatabaseSupported) {
367367
var compilerConfiguration = new SqlCompilerConfiguration() { DatabaseQualifiedObjects = true, SharedStorageSchema = true };
368368

369-
_ = Assert.Throws<ArgumentNullException>(() => queryText = Driver.Compile(query, compilerConfiguration).GetCommandText());
369+
_ = Assert.Throws<InvalidOperationException>(() => queryText = Driver.Compile(query, compilerConfiguration).GetCommandText());
370370

371371
var postCompilerConfiguration = new SqlPostCompilerConfiguration(emptyMap, emptyMap);
372372

@@ -385,7 +385,7 @@ private void TestQueryNamesUnreadable(ISqlCompileUnit query, Schema defaultSchem
385385
if (IsMultischemaSupported) {
386386
var compilerConfiguration = new SqlCompilerConfiguration() { SharedStorageSchema = true };
387387

388-
_ = Assert.Throws<ArgumentNullException>(() => queryText = Driver.Compile(query, compilerConfiguration).GetCommandText());
388+
_ = Assert.Throws<InvalidOperationException>(() => queryText = Driver.Compile(query, compilerConfiguration).GetCommandText());
389389

390390
var postCompilerConfiguration = new SqlPostCompilerConfiguration(emptyMap, emptyMap);
391391
Assert.DoesNotThrow(() => queryText = Driver.Compile(query, compilerConfiguration).GetCommandText(postCompilerConfiguration));
@@ -402,7 +402,7 @@ private void TestQueryNamesUnreadable(ISqlCompileUnit query, Schema defaultSchem
402402
}
403403
else {
404404
var compilerConfiguration = new SqlCompilerConfiguration() { SharedStorageSchema = true };
405-
Assert.DoesNotThrow(() => queryText = Driver.Compile(query, compilerConfiguration).GetCommandText());
405+
_ = Assert.Throws<InvalidOperationException>(() => queryText = Driver.Compile(query, compilerConfiguration).GetCommandText());
406406

407407
var postCompilerConfiguration = new SqlPostCompilerConfiguration(emptyMap, emptyMap);
408408

Orm/Xtensive.Orm/Sql/Compiler/Internals/PostCompiler.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ internal class PostCompiler : NodeVisitor
1919

2020
private readonly StringBuilder result;
2121
private readonly SqlPostCompilerConfiguration configuration;
22+
private readonly bool canActualizeQuery;
2223

2324
private string[] currentCycleItem;
2425

@@ -59,6 +60,8 @@ public override void Visit(PlaceholderNode node)
5960

6061
private void Visit(SchemaNodePlaceholderNode node)
6162
{
63+
EnsureActualizationPossible();
64+
6265
var schema = node.SchemaNode.Schema;
6366

6467
var names = (node.DbQualified)
@@ -93,6 +96,12 @@ public override void Visit(CycleNode node)
9396

9497
#endregion
9598

99+
private void EnsureActualizationPossible()
100+
{
101+
if (!canActualizeQuery) {
102+
throw new InvalidOperationException("Query was compiled with SqlCompilerConfiguration.SharedStorageSchema option set to true, it required PostCompilerConfiguration.SchemaMapping and PostCompilerConfiguration.DatabaseMapping collections to be provided.");
103+
}
104+
}
96105

97106
// Constructors
98107

@@ -101,6 +110,7 @@ private PostCompiler(SqlPostCompilerConfiguration configuration, int estimatedRe
101110
int capacity = estimatedResultLength + ResultCapacityMargin;
102111
result = new StringBuilder(capacity < MinimalResultCapacity ? MinimalResultCapacity : capacity);
103112
this.configuration = configuration;
113+
canActualizeQuery = configuration.DatabaseMapping != null && configuration.SchemaMapping != null;
104114
}
105115
}
106116
}

0 commit comments

Comments
 (0)