|
14 | 14 | */
|
15 | 15 | module hibernated.dialect;
|
16 | 16 |
|
| 17 | +import std.algorithm.iteration : uniq; |
| 18 | +import std.array; |
17 | 19 | import std.stdio;
|
18 | 20 | import std.string;
|
19 | 21 |
|
20 | 22 | import hibernated.metadata;
|
21 | 23 |
|
| 24 | +/// Reserved words in the international SQL standard (ISO/IEC 9075) from 2016 |
| 25 | +// See the SQL-2016 list on https://en.wikipedia.org/wiki/SQL_reserved_words |
| 26 | +const string[] SQL_RESERVED_WORDS = uniq([ |
| 27 | + "ABS", "ACOS", "ALL", "ALLOCATE", "ALTER", "AND", "ANY", "ARE", "ARRAY", "ARRAY_AGG", "ARRAY_MAX_CARDINALITY", |
| 28 | + "AS", "ASENSITIVE", "ASIN", "ASYMMETRIC", "AT", |
| 29 | + "BEGIN", "BEGIN_FRAME", "BEGIN_PARTITION", "BETWEEN", "BIGINT", "BINARY", "BLOB", "BOOLEAN", "BOTH", "BY", |
| 30 | + "CALL", "CASE", "CHECK", "COLUMN", |
| 31 | + "CONSTRAINT", "CREATE", |
| 32 | + "DATABASE", "DEFAULT", "DELETE", "DESC", "DISTENCT", "DROP", |
| 33 | + "EXEC", "EXISTS", |
| 34 | + "FROM", |
| 35 | + "HAVING", |
| 36 | + "IN", "INDEX", |
| 37 | + "JOIN", |
| 38 | + "LIKE", "LIMIT", |
| 39 | + "NOT", |
| 40 | + "OR", |
| 41 | + "ROWNUM", |
| 42 | + "SELECT", "SET", |
| 43 | + "TABLE", "TOP", |
| 44 | + "UNION", "UNIQUE", "UPDATE", |
| 45 | + "VALUES", "VIEW", |
| 46 | + "WHERE" |
| 47 | +]).array; |
| 48 | + |
| 49 | +unittest { |
| 50 | + import std.algorithm.searching : canFind; |
| 51 | + assert(canFind(SQL_RESERVED_WORDS, "AND")); |
| 52 | + assert(canFind(SQL_RESERVED_WORDS, "BIGINT")); |
| 53 | + assert(canFind(SQL_RESERVED_WORDS, "COLUMN")); |
| 54 | + assert(canFind(SQL_RESERVED_WORDS, "DATABASE")); |
| 55 | + assert(canFind(SQL_RESERVED_WORDS, "DELETE")); |
| 56 | + assert(canFind(SQL_RESERVED_WORDS, "INDEX")); |
| 57 | + assert(canFind(SQL_RESERVED_WORDS, "NOT")); |
| 58 | + assert(canFind(SQL_RESERVED_WORDS, "OR")); |
| 59 | + assert(canFind(SQL_RESERVED_WORDS, "JOIN")); |
| 60 | + assert(canFind(SQL_RESERVED_WORDS, "SELECT")); |
| 61 | + assert(canFind(SQL_RESERVED_WORDS, "UNION")); |
| 62 | + assert(canFind(SQL_RESERVED_WORDS, "WHERE")); |
| 63 | + |
| 64 | + assert(!canFind(SQL_RESERVED_WORDS, "ABSOLUTE")); |
| 65 | + assert(!canFind(SQL_RESERVED_WORDS, "ADD")); // this in MySQL, Oracle, SQL Server |
| 66 | + assert(!canFind(SQL_RESERVED_WORDS, "ASC")); // this in MySQL, PostgreSQL, Oracle, SQL Server |
| 67 | + assert(!canFind(SQL_RESERVED_WORDS, "LONG")); |
| 68 | + assert(!canFind(SQL_RESERVED_WORDS, "PRIVILEGES")); // PRIVILEGES is an ODBC thing |
| 69 | + assert(!canFind(SQL_RESERVED_WORDS, "VARCHAR2")); |
| 70 | +} |
| 71 | + |
22 | 72 | /// Represents a dialect of SQL implemented by a particular RDBMS. -- generated from JavaDocs on org.hibernate.dialect.Dialect
|
23 | 73 | abstract class Dialect {
|
24 | 74 |
|
@@ -56,7 +106,7 @@ abstract class Dialect {
|
56 | 106 |
|
57 | 107 | protected int[string] keywordList;
|
58 | 108 |
|
59 |
| - protected void addKeywords(string[] keywords) { |
| 109 | + protected void addKeywords(const(string[]) keywords) { |
60 | 110 | foreach(s; keywords) {
|
61 | 111 | keywordList[s] = 1;
|
62 | 112 | }
|
@@ -406,7 +456,9 @@ abstract class Dialect {
|
406 | 456 | version (USE_MYSQL) {
|
407 | 457 | } else version (USE_SQLITE) {
|
408 | 458 | } else version (USE_PGSQL) {
|
| 459 | +} else version (USE_PLSQL) { |
| 460 | +} else version (USE_TSQL) { |
409 | 461 | } else {
|
410 |
| - pragma(msg, "No DB type version definition specified. Add one or more versions to command line: USE_MYSQL, USE_PGSQL, USE_SQLITE"); |
| 462 | + pragma(msg, "No DB type version definition specified. Add one or more versions to command line: USE_SQLITE, USE_MYSQL, USE_PGSQL, USE_PLSQL, USE_TSQL"); |
411 | 463 | }
|
412 | 464 |
|
0 commit comments