Skip to content

Commit 29f8c71

Browse files
committed
NH-4043 - Complete keyword registration in dialects. (temporary squash)
1 parent 44f912b commit 29f8c71

File tree

13 files changed

+1691
-90
lines changed

13 files changed

+1691
-90
lines changed

src/NHibernate.Test/Tools/hbm2ddl/SchemaMetadataUpdaterTest/SchemaMetadataUpdaterFixture.cs

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Linq;
3-
using NHibernate.Cfg;
44
using NHibernate.Engine;
55
using NHibernate.Mapping;
66
using NHibernate.Tool.hbm2ddl;
77
using NUnit.Framework;
8+
using Environment = NHibernate.Cfg.Environment;
89

910
namespace NHibernate.Test.Tools.hbm2ddl.SchemaMetadataUpdaterTest
1011
{
@@ -56,9 +57,92 @@ public void UpdateReservedWordsInDialect()
5657
var sf = (ISessionFactoryImplementor) configuration.BuildSessionFactory();
5758
SchemaMetadataUpdater.Update(sf);
5859
var match = reservedDb.Intersect(sf.Dialect.Keywords);
60+
61+
// tests that nothing in the first metaData.GetReservedWords() is left out of the second metaData.GetReservedWords() call.
62+
// i.e. always passes.
5963
Assert.That(match, Is.EquivalentTo(reservedDb));
6064
}
6165

66+
[Test]
67+
public void EnsureReservedWordsHardCodedInDialect()
68+
{
69+
var reservedDb = new HashSet<string>();
70+
var configuration = TestConfigurationHelper.GetDefaultConfiguration();
71+
var dialect = Dialect.Dialect.GetDialect(configuration.Properties);
72+
var connectionHelper = new ManagedProviderConnectionHelper(configuration.Properties);
73+
connectionHelper.Prepare();
74+
try
75+
{
76+
var metaData = dialect.GetDataBaseSchema(connectionHelper.Connection);
77+
foreach (var rw in metaData.GetReservedWords())
78+
{
79+
if (rw.Contains(" ")) continue;
80+
reservedDb.Add(rw.ToLowerInvariant());
81+
}
82+
}
83+
finally
84+
{
85+
connectionHelper.Release();
86+
}
87+
88+
var sf = (ISessionFactoryImplementor)configuration.BuildSessionFactory();
89+
90+
// use the dialect as configured, with no update
91+
var match = reservedDb.Intersect(sf.Dialect.Keywords).ToList();
92+
93+
// tests that nothing in metaData.GetReservedWords() is left out of the Dialect.Keywords (without a refresh).
94+
var differences = reservedDb.Except(match).ToList();
95+
if (differences.Count > 0)
96+
{
97+
Console.WriteLine("Update Dialect {0} with RegisterKeyword:", sf.Dialect.GetType().Name);
98+
foreach (var keyword in differences.OrderBy(x => x))
99+
{
100+
Console.WriteLine(" RegisterKeyword(\"{0}\");", keyword);
101+
}
102+
}
103+
104+
Assert.That(match, Is.EquivalentTo(reservedDb));
105+
}
106+
107+
[Test]
108+
public void CheckForExcessReservedWordsHardCodedInDialect()
109+
{
110+
var reservedDb = new HashSet<string>();
111+
var configuration = TestConfigurationHelper.GetDefaultConfiguration();
112+
var dialect = Dialect.Dialect.GetDialect(configuration.Properties);
113+
var connectionHelper = new ManagedProviderConnectionHelper(configuration.Properties);
114+
connectionHelper.Prepare();
115+
try
116+
{
117+
var metaData = dialect.GetDataBaseSchema(connectionHelper.Connection);
118+
foreach (var rw in metaData.GetReservedWords())
119+
{
120+
reservedDb.Add(rw.ToLowerInvariant());
121+
}
122+
}
123+
finally
124+
{
125+
connectionHelper.Release();
126+
}
127+
128+
var sf = (ISessionFactoryImplementor)configuration.BuildSessionFactory();
129+
130+
// use the dialect as configured, with no update
131+
// tests that nothing in Dialect.Keyword is not in metaData.GetReservedWords()
132+
var differences = sf.Dialect.Keywords.Except(reservedDb).ToList();
133+
if (differences.Count > 0)
134+
{
135+
Console.WriteLine("Excess RegisterKeyword in Dialect {0}:", sf.Dialect.GetType().Name);
136+
foreach (var keyword in differences.OrderBy(x => x))
137+
{
138+
Console.WriteLine(" RegisterKeyword(\"{0}\");", keyword);
139+
}
140+
}
141+
142+
// Don't fail incase the driver returns nothing.
143+
//Assert.That(sf.Dialect.Keywords, Is.EquivalentTo(reservedDb));
144+
}
145+
62146
[Test]
63147
public void ExplicitAutoQuote()
64148
{

src/NHibernate/Dialect/Dialect.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,11 @@ protected void RegisterKeyword(string word)
22462246
Keywords.Add(word);
22472247
}
22482248

2249+
protected void RegisterKeywords(params string[] keywords)
2250+
{
2251+
Keywords.UnionWith(keywords);
2252+
}
2253+
22492254
protected void RegisterFunction(string name, ISQLFunction function)
22502255
{
22512256
_sqlFunctions[name] = function;

src/NHibernate/Dialect/FirebirdDialect.cs

Lines changed: 247 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,255 @@ public SqlString Render(IList args, ISessionFactoryImplementor factory)
268268
}
269269
}
270270

271+
#region private static readonly string[] DialectKeywords = { ... }
272+
273+
private static readonly string[] DialectKeywords =
274+
{
275+
"action",
276+
"active",
277+
"add",
278+
"admin",
279+
"after",
280+
"all",
281+
"alter",
282+
"and",
283+
"any",
284+
"array",
285+
"as",
286+
"asc",
287+
"ascending",
288+
"at",
289+
"auto",
290+
"avg",
291+
"base_name",
292+
"before",
293+
"begin",
294+
"between",
295+
"bigint",
296+
"blob sub_type 1",
297+
"blob",
298+
"break",
299+
"by",
300+
"cache",
301+
"cascade",
302+
"case",
303+
"cast",
304+
"char",
305+
"character",
306+
"check",
307+
"check_point_length",
308+
"coalesce",
309+
"collate",
310+
"column",
311+
"commit",
312+
"committed",
313+
"computed",
314+
"conditional",
315+
"connection_id",
316+
"constraint",
317+
"containing",
318+
"count",
319+
"create",
320+
"cstring",
321+
"current",
322+
"current_date",
323+
"current_role",
324+
"current_time",
325+
"current_timestamp",
326+
"current_user",
327+
"cursor",
328+
"database",
329+
"date",
330+
"day",
331+
"debug",
332+
"dec",
333+
"decimal",
334+
"declare",
335+
"default",
336+
"delete",
337+
"desc",
338+
"descending",
339+
"descriptor",
340+
"distinct",
341+
"do",
342+
"domain",
343+
"double precision",
344+
"double",
345+
"drop",
346+
"else",
347+
"end",
348+
"entry_point",
349+
"escape",
350+
"exception",
351+
"execute",
352+
"exists",
353+
"exit",
354+
"external",
355+
"extract",
356+
"file",
357+
"filter",
358+
"first",
359+
"float",
360+
"for",
361+
"foreign",
362+
"free_it",
363+
"from",
364+
"full",
365+
"function",
366+
"gdscode",
367+
"gen_id",
368+
"generator",
369+
"grant",
370+
"group",
371+
"group_commit_wait_time",
372+
"having",
373+
"hour",
374+
"if",
375+
"in",
376+
"inactive",
377+
"index",
378+
"inner",
379+
"input_type",
380+
"insert",
381+
"int",
382+
"integer",
383+
"into",
384+
"is",
385+
"isolation",
386+
"join",
387+
"key",
388+
"last",
389+
"left",
390+
"length",
391+
"level",
392+
"like",
393+
"lock",
394+
"log_buffer_size",
395+
"logfile",
396+
"long",
397+
"manual",
398+
"max",
399+
"maximum_segment",
400+
"merge",
401+
"message",
402+
"min",
403+
"minute",
404+
"module_name",
405+
"month",
406+
"names",
407+
"national",
408+
"natural",
409+
"nchar",
410+
"no",
411+
"not",
412+
"null",
413+
"nullif",
414+
"nulls",
415+
"num_log_buffers",
416+
"numeric",
417+
"of",
418+
"on",
419+
"only",
420+
"option",
421+
"or",
422+
"order",
423+
"outer",
424+
"output_type",
425+
"overflow",
426+
"page",
427+
"page_size",
428+
"pages",
429+
"parameter",
430+
"password",
431+
"plan",
432+
"position",
433+
"post_event",
434+
"precision",
435+
"primary",
436+
"privileges",
437+
"procedure",
438+
"protected",
439+
"raw_partitions",
440+
"rdb$db_key",
441+
"read",
442+
"real",
443+
"record_version",
444+
"recreate",
445+
"references",
446+
"reserv",
447+
"reserving",
448+
"restrict",
449+
"retain",
450+
"returning_values",
451+
"returns",
452+
"revoke",
453+
"right",
454+
"role",
455+
"rollback",
456+
"rows_affected",
457+
"savepoint",
458+
"schema",
459+
"second",
460+
"segment",
461+
"select",
462+
"set",
463+
"shadow",
464+
"shared",
465+
"singular",
466+
"size",
467+
"skip",
468+
"smallint",
469+
"snapshot",
470+
"some",
471+
"sort",
472+
"sqlcode",
473+
"stability",
474+
"starting",
475+
"starts",
476+
"statistics",
477+
"sub_type",
478+
"substring",
479+
"sum",
480+
"suspend",
481+
"table",
482+
"then",
483+
"time",
484+
"timestamp",
485+
"to",
486+
"transaction",
487+
"transaction_id",
488+
"trigger",
489+
"type",
490+
"uncommitted",
491+
"union",
492+
"unique",
493+
"update",
494+
"upper",
495+
"user",
496+
"using",
497+
"value",
498+
"values",
499+
"varchar",
500+
"variable",
501+
"varying",
502+
"view",
503+
"wait",
504+
"weekday",
505+
"when",
506+
"where",
507+
"while",
508+
"with",
509+
"work",
510+
"write",
511+
"year",
512+
"yearday",
513+
};
514+
515+
#endregion
516+
271517
protected virtual void RegisterKeywords()
272518
{
273-
RegisterKeyword("date");
519+
RegisterKeywords(DialectKeywords);
274520
}
275521

276522
protected virtual void RegisterColumnTypes()

0 commit comments

Comments
 (0)