Saxonite 1.2.11.4. BusinessMgr.
This commit is contained in:
@@ -20,7 +20,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
{
|
||||
VS2017,
|
||||
/// <summary>
|
||||
/// Visual Studio 2019 version. StringListUtil rather than StringListUtil.
|
||||
/// Visual Studio 2019 version. StringListUtil rather than StringList.
|
||||
/// </summary>
|
||||
VS2019
|
||||
}
|
||||
@@ -36,7 +36,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
}
|
||||
public class Config
|
||||
{
|
||||
public SarandCommonVersion SarandCommonVersion { get; set; } = SarandCommonVersion.VS2017;
|
||||
public SarandCommonVersion SarandCommonVersion { get; set; } = SarandCommonVersion.VS2019;
|
||||
public DotNetVersion DotNetVersion { get; set; } = DotNetVersion.Framework;
|
||||
public SacsDatabase Database { get; set; }
|
||||
public Dbms DbmsOutput { get; set; } = Dbms.ODBC;
|
||||
@@ -46,10 +46,12 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
public class SchemaData
|
||||
{
|
||||
// Tables to be included (all others excluded) or those to be excluded.
|
||||
public List<String> Tables_Included { get; } = new List<String>();
|
||||
public List<String> Tables_Excluded { get; } = new List<String>();
|
||||
public HashSet<String> Tables_Included { get; } = new HashSet<String>(StringComparer.InvariantCultureIgnoreCase);
|
||||
public HashSet<String> Tables_Excluded { get; } = new HashSet<String>(StringComparer.InvariantCultureIgnoreCase);
|
||||
// Schema capitalisation - for class name prefix etc - where capitalising first letter is insufficient.
|
||||
public Dictionary<String, String> SchemaNameCapitalisation { get; } = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
|
||||
// Alternative table names.
|
||||
public Dictionary<String, List<String>> AlternativeTableNames { get; } = new Dictionary<string, List<string>>();
|
||||
public Dictionary<String, List<String>> AlternativeTableNames { get; } = new Dictionary<string, List<string>>(StringComparer.InvariantCultureIgnoreCase);
|
||||
public void AddAlternativeTableName(String tableName, String tableNameAlternative)
|
||||
{
|
||||
if (!AlternativeTableNames.ContainsKey(tableName)) AlternativeTableNames[tableName] = new List<string>();
|
||||
@@ -66,7 +68,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
public class DefinitionClassConfig
|
||||
{
|
||||
/// <summary>Using namespaces for database definition and table class usings.</summary>
|
||||
public List<String> Usings { get; } = new List<String>() { "Sarand.Net.Standard.Base.Core", "Sarand.Net.Standard.Base.Dbas" };
|
||||
public HashSet<String> Usings { get; } = new HashSet<String>() { "Sarand.Net.Standard.Base.Core", "Sarand.Net.Standard.Base.Dbas" };
|
||||
public String Namespace { get; set; } = "Sarand.Application.Core.Base";
|
||||
public String Classname { get; set; } = "SaDbDfn";
|
||||
}
|
||||
@@ -75,7 +77,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
public class TableClassConfig
|
||||
{
|
||||
/// <summary>Using namespaces for table classes.</summary>
|
||||
public List<String> Usings { get; } = new List<String>() { "Sarand.Net.Standard.Base.Core", "Sarand.Net.Standard.Base.Dbas" };
|
||||
public HashSet<String> Usings { get; } = new HashSet<String>() { "Sarand.Net.Standard.Base.Core", "Sarand.Net.Standard.Base.Dbas" };
|
||||
public String Namespace_BaseClass { get; set; } = "Sarand.Net.Standard.Dbas.Data";
|
||||
public String Namespace { get; set; } = "Sarand.Application.Dbas";
|
||||
public String BaseClass { get; set; } = "DbDataItem";
|
||||
@@ -89,6 +91,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private Config config = null;
|
||||
private const String DefaultSchema_MSSQL = "dbo";
|
||||
private static String /*lf = "\n",*/ crlf = "\r\n", tab1 = "\t", tab2 = "\t\t", tab3 = "\t\t\t", tab4 = "\t\t\t\t", tab5 = "\t\t\t\t\t";
|
||||
// Reserved words.
|
||||
private static readonly String[] reservedWords =
|
||||
@@ -313,10 +316,19 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
file.WriteLine(tab2 + "{");
|
||||
file.WriteLine(tab3 + "int tableIdx = (int)table - 1;");
|
||||
file.WriteLine(tab3 + "if (tableIdx < 0 || tableIdx >= tableCount) return String.Empty;");
|
||||
file.WriteLine(tab3 + "String tableName = tables[(int)tableIdx];");
|
||||
file.WriteLine(tab3 + "String tableName = tables[(int)tableIdx].Name;");
|
||||
file.WriteLine(tab3 + "if (delimitReservedWords) tableName = DelimitReservedWord(tableName);");
|
||||
file.WriteLine(tab3 + "return tableName;");
|
||||
file.WriteLine(tab2 + "}");
|
||||
file.WriteLine(tab2 + "public static String GetTableNameQual (TableIdx table, bool delimitReservedWords = true)");
|
||||
file.WriteLine(tab2 + "{");
|
||||
file.WriteLine(tab3 + "int tableIdx = (int)table - 1;");
|
||||
file.WriteLine(tab3 + "if (tableIdx < 0 || tableIdx >= tableCount) return String.Empty;");
|
||||
file.WriteLine(tab3 + "String schemaName = tables[(int)tableIdx].Schema;");
|
||||
file.WriteLine(tab3 + "String tableName = tables[(int)tableIdx].Name;");
|
||||
file.WriteLine(tab3 + "if (delimitReservedWords) { schemaName = DelimitReservedWord(schemaName); tableName = DelimitReservedWord(tableName); }");
|
||||
file.WriteLine(tab3 + "return (StringUtil.IsBlank(schemaName) ? \"\" : schemaName + \".\") + tableName;");
|
||||
file.WriteLine(tab2 + "}");
|
||||
file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------");
|
||||
|
||||
// Table for Column method.
|
||||
@@ -369,8 +381,15 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
file.WriteLine(tab2 + "}");
|
||||
file.WriteLine(tab2 + "public static String DelimitReservedWord (String word)");
|
||||
file.WriteLine(tab2 + "{");
|
||||
file.WriteLine(tab3 + "if (!IsReservedWord(word)) return word;");
|
||||
file.WriteLine(tab3 + "switch (reservedWordDelim)");
|
||||
file.WriteLine(tab3 + "return IsReservedWord(word) ? DelimitWord(word) : word;");
|
||||
file.WriteLine(tab2 + "}");
|
||||
file.WriteLine(tab2 + "public static String DelimitWord (String word)");
|
||||
file.WriteLine(tab2 + "{");
|
||||
file.WriteLine(tab3 + "return DelimitWord(word, reservedWordDelim);");
|
||||
file.WriteLine(tab2 + "}");
|
||||
file.WriteLine(tab2 + "public static String DelimitWord (String word, DbReservedWordDelim wordDelim)");
|
||||
file.WriteLine(tab2 + "{");
|
||||
file.WriteLine(tab3 + "switch (wordDelim)");
|
||||
file.WriteLine(tab3 + "{");
|
||||
file.WriteLine(tab4 + "case DbReservedWordDelim.None:");
|
||||
file.WriteLine(tab5 + "break;");
|
||||
@@ -447,12 +466,22 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
file.WriteLine(tab2 + "}");
|
||||
file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------");
|
||||
|
||||
// Table definitions.
|
||||
// Table names.
|
||||
file.WriteLine(tab2 + "// Table definitions.");
|
||||
file.WriteLine(tab2 + "private static readonly String[] tables =");
|
||||
file.WriteLine(tab2 + "private class TableDfn");
|
||||
file.WriteLine(tab2 + "{");
|
||||
file.WriteLine(tab3 + "internal String Schema { get; set; }");
|
||||
file.WriteLine(tab3 + "internal String Name { get; set; }");
|
||||
file.WriteLine(tab3 + "internal TableDfn (String schema, String name)");
|
||||
file.WriteLine(tab3 + "{");
|
||||
file.WriteLine(tab4 + "this.Schema= schema;");
|
||||
file.WriteLine(tab4 + "this.Name = name;");
|
||||
file.WriteLine(tab3 + "}");
|
||||
file.WriteLine(tab2 + "}");
|
||||
file.WriteLine(tab2 + "private static readonly TableDfn[] tables =");
|
||||
file.WriteLine(tab2 + "{");
|
||||
foreach (DbDfnTable tableDfn in tableDfns)
|
||||
file.WriteLine(tab3 + "\"" + tableDfn.Name + "\", ");
|
||||
file.WriteLine(tab3 + "new TableDfn(\"" + tableDfn.Schema + "\",\"" + tableDfn.Name + "\"),");
|
||||
file.WriteLine(tab2 + "};");
|
||||
file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------");
|
||||
|
||||
@@ -476,7 +505,6 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
file.WriteLine(tab4 + "this.DataLen = dataLen;");
|
||||
file.WriteLine(tab3 + "}");
|
||||
file.WriteLine(tab2 + "}");
|
||||
file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------");
|
||||
file.WriteLine(tab2 + "private static readonly ColumnDfn[] columns =");
|
||||
file.WriteLine(tab2 + "{");
|
||||
uint tableIdx = 0;
|
||||
@@ -505,6 +533,10 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
private void GenerateTableInterfaceClass(DbDfnTable tableDfn)
|
||||
{
|
||||
String className = tableDfn.Name + "_Db";
|
||||
if (!StringUtil.IsEmpty(tableDfn.Schema) && !tableDfn.Schema.EqualsCI("dbo"))
|
||||
{
|
||||
className = config.Schema.SchemaNameCapitalisation.GetValueOrDefault(tableDfn.Schema, StringUtil.CapitaliseFirst(tableDfn.Schema)) + "_" + className;
|
||||
}
|
||||
List<String> primaryColumnNames = tableDfn.GetPrimaryColumnNames();
|
||||
String identityColumnName = tableDfn.Columns.GetIdentityColumnName();
|
||||
String identityColumnVariableTypeName = tableDfn.Columns.GetIdentityColumnVariableTypeName();
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
if (StringUtil.IsEmpty(config.DatabaseName))
|
||||
config.DatabaseName = sqlDatabase;
|
||||
|
||||
SaLogger.Info("DatabaseConsole.GenerateConnectionString Driver: " + sqlDriver + ". Server: " + sqlServer + ". Database: " + sqlDatabase + ". Connection: " + connectionString);
|
||||
SaLogger.Info($"{SysUtil.Fn} Driver: " + sqlDriver + ". Server: " + sqlServer + ". Database: " + sqlDatabase + ". Connection: " + connectionString);
|
||||
}
|
||||
return connectionString;
|
||||
}
|
||||
@@ -219,7 +219,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
else
|
||||
{
|
||||
#if DEBUG
|
||||
SaLogger.Debug("DropDbIndex Table: " + tableName + "; Index: " + indexName + "; Exception: " + database.ErrorStateMessage);
|
||||
SaLogger.Debug($"{SysUtil.Fn} Table: " + tableName + "; Index: " + indexName + "; Exception: " + database.ErrorStateMessage);
|
||||
#endif
|
||||
SetErrorState("Failed to drop index " + indexName + " on " + tableName + " - " + database.ErrorStateMessage);
|
||||
}
|
||||
@@ -240,7 +240,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
else
|
||||
{
|
||||
#if DEBUG
|
||||
SaLogger.Debug("DropDbIndex Table: " + tableName + "; Index: " + indexName + "; Exception: " + database.ErrorStateMessage);
|
||||
SaLogger.Debug($"{SysUtil.Fn} Table: " + tableName + "; Index: " + indexName + "; Exception: " + database.ErrorStateMessage);
|
||||
#endif
|
||||
SetErrorState("Failed to drop primary key " + indexName + " on " + tableName + " - " + database.ErrorStateMessage);
|
||||
}
|
||||
@@ -288,7 +288,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
else
|
||||
{
|
||||
#if DEBUG
|
||||
SaLogger.Debug("CreatePrimaryDbIndex Table: %" + tableName + "; Index: " + indexName + "; Exception: " + database.ErrorStateMessage);
|
||||
SaLogger.Debug($"{SysUtil.Fn} Table: %" + tableName + "; Index: " + indexName + "; Exception: " + database.ErrorStateMessage);
|
||||
#endif
|
||||
SetErrorState("Failed to create primary index " + indexName + " on " + tableName + " - " + database.ErrorStateMessage);
|
||||
}
|
||||
@@ -322,7 +322,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
else
|
||||
{
|
||||
#if DEBUG
|
||||
SaLogger.Debug("CreateDbIndex Table: " + tableName + "; Index: " + indexName + "; Exception: " + database.ErrorStateMessage);
|
||||
SaLogger.Debug($"{SysUtil.Fn} Table: " + tableName + "; Index: " + indexName + "; Exception: " + database.ErrorStateMessage);
|
||||
#endif
|
||||
SetErrorState("Failed to create index " + indexName + " on " + tableName + " - " + database.ErrorStateMessage);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user