517 lines
16 KiB
C#
517 lines
16 KiB
C#
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Dbas;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
//---------------------------------------------------------------------------
|
|
// Code generated by Sarand Database Utilities Thu 13-Feb-2025 11:12:01
|
|
//---------------------------------------------------------------------------
|
|
namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|
{
|
|
public class SbmDbDfn_Control
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Table identifiers.
|
|
public enum TableIdx
|
|
{
|
|
Unknown = 0,
|
|
AccountRegistration,
|
|
ItemParam,
|
|
Owner,
|
|
Repository,
|
|
UserAccount,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Column identifiers.
|
|
public enum ColumnIdx
|
|
{
|
|
Unknown = 0,
|
|
AccountRegistration_Id,
|
|
AccountRegistration_EmailAddress,
|
|
AccountRegistration_FirstName,
|
|
AccountRegistration_LastName,
|
|
AccountRegistration_PhoneMain,
|
|
AccountRegistration_PhoneAlt,
|
|
AccountRegistration_RepositoryContext,
|
|
AccountRegistration_RequestAccountAt,
|
|
AccountRegistration_RegisterAccountToken,
|
|
AccountRegistration_RegisterAccountAt,
|
|
AccountRegistration_AccountPasswordSalt,
|
|
AccountRegistration_AccountPasswordHash,
|
|
AccountRegistration_Notes,
|
|
AccountRegistration_Flags,
|
|
AccountRegistration_Status,
|
|
AccountRegistration_CreateOn,
|
|
AccountRegistration_CreateBy,
|
|
AccountRegistration_CreateHost,
|
|
AccountRegistration_UpdateOn,
|
|
AccountRegistration_UpdateBy,
|
|
AccountRegistration_UpdateHost,
|
|
ItemParam_Id,
|
|
ItemParam_ItemType,
|
|
ItemParam_ItemId,
|
|
ItemParam_Context,
|
|
ItemParam_Name,
|
|
ItemParam_Value,
|
|
ItemParam_Notes,
|
|
ItemParam_Flags,
|
|
ItemParam_Status,
|
|
ItemParam_CreateOn,
|
|
ItemParam_CreateBy,
|
|
ItemParam_CreateHost,
|
|
ItemParam_UpdateOn,
|
|
ItemParam_UpdateBy,
|
|
ItemParam_UpdateHost,
|
|
Owner_Id,
|
|
Owner_Name,
|
|
Owner_ContactName,
|
|
Owner_ContactEmailAddress,
|
|
Owner_ContactPhoneMain,
|
|
Owner_ContactPhoneAlt,
|
|
Owner_Notes,
|
|
Owner_Flags,
|
|
Owner_Status,
|
|
Owner_CreateOn,
|
|
Owner_CreateBy,
|
|
Owner_CreateHost,
|
|
Owner_UpdateOn,
|
|
Owner_UpdateBy,
|
|
Owner_UpdateHost,
|
|
Repository_Id,
|
|
Repository_OwnerId,
|
|
Repository_Context,
|
|
Repository_ServerName,
|
|
Repository_InstanceName,
|
|
Repository_DatabaseName,
|
|
Repository_UserName,
|
|
Repository_Password,
|
|
Repository_Notes,
|
|
Repository_Flags,
|
|
Repository_Status,
|
|
Repository_CreateOn,
|
|
Repository_CreateBy,
|
|
Repository_CreateHost,
|
|
Repository_UpdateOn,
|
|
Repository_UpdateBy,
|
|
Repository_UpdateHost,
|
|
UserAccount_Id,
|
|
UserAccount_EmailAddress,
|
|
UserAccount_Title,
|
|
UserAccount_FirstName,
|
|
UserAccount_Initials,
|
|
UserAccount_LastName,
|
|
UserAccount_PhoneMain,
|
|
UserAccount_PhoneMobile,
|
|
UserAccount_PhoneAlt,
|
|
UserAccount_PasswordToken,
|
|
UserAccount_PasswordHashed,
|
|
UserAccount_PasswordHistory,
|
|
UserAccount_PasswordChangedAt,
|
|
UserAccount_LastLoginAt,
|
|
UserAccount_LastInvalidLoginAt,
|
|
UserAccount_InvalidLoginCount,
|
|
UserAccount_Notes,
|
|
UserAccount_Flags,
|
|
UserAccount_Status,
|
|
UserAccount_CreateOn,
|
|
UserAccount_CreateBy,
|
|
UserAccount_CreateHost,
|
|
UserAccount_UpdateOn,
|
|
UserAccount_UpdateBy,
|
|
UserAccount_UpdateHost,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private static readonly int tableCount = 5;
|
|
private static readonly int columnCount = 93;
|
|
public static ulong MaxTextLen { get; private set; }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Retrieve Table details (eg. name: 'Company').
|
|
public static int GetTableCount ()
|
|
{
|
|
return tableCount;
|
|
}
|
|
public static String GetSchemaName (TableIdx table, bool delimitReservedWords = true)
|
|
{
|
|
int tableIdx = (int)table - 1;
|
|
if (tableIdx < 0 || tableIdx >= tableCount) return String.Empty;
|
|
String schemaName = tables[(int)tableIdx].Schema;
|
|
if (delimitReservedWords) { schemaName = DelimitReservedWord(schemaName); }
|
|
return schemaName;
|
|
}
|
|
public static String GetTableName (TableIdx table, bool delimitReservedWords = true)
|
|
{
|
|
int tableIdx = (int)table - 1;
|
|
if (tableIdx < 0 || tableIdx >= tableCount) return String.Empty;
|
|
String tableName = tables[(int)tableIdx].Name;
|
|
if (delimitReservedWords) tableName = DelimitReservedWord(tableName);
|
|
return tableName;
|
|
}
|
|
public static String GetTableNameQual (TableIdx table, bool delimitReservedWords = true)
|
|
{
|
|
int tableIdx = (int)table - 1;
|
|
if (tableIdx < 0 || tableIdx >= tableCount) return String.Empty;
|
|
String schemaName = tables[(int)tableIdx].Schema;
|
|
String tableName = tables[(int)tableIdx].Name;
|
|
if (delimitReservedWords) { schemaName = DelimitReservedWord(schemaName); tableName = DelimitReservedWord(tableName); }
|
|
return (StringUtil.IsBlank(schemaName) ? "" : schemaName + ".") + tableName;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Identify the table that corresponds with the specified column.
|
|
public static TableIdx GetTableForColumn (ColumnIdx column)
|
|
{
|
|
int columnIdx = (int)column - 1;
|
|
if (columnIdx < 0 || columnIdx >= columnCount) return TableIdx.Unknown;
|
|
return columns[columnIdx].TableIdx;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Retrieve the specified Column's name (Qualified include table name: '(<Table>.Column>)').
|
|
public static String GetColumnName (ColumnIdx column, bool delimitReservedWords = true)
|
|
{
|
|
int columnIdx = (int)column - 1;
|
|
if (columnIdx < 0 || columnIdx >= columnCount) return String.Empty;
|
|
String columnName = columns[columnIdx].Name;
|
|
if (delimitReservedWords) columnName = DelimitReservedWord(columnName);
|
|
return columnName;
|
|
}
|
|
public static String GetColumnNameQual (ColumnIdx column, String tableAlias = "", bool braces = false)
|
|
{
|
|
String columnName = GetColumnName(column);
|
|
if (!String.IsNullOrEmpty(columnName))
|
|
{
|
|
String tableName = StringUtil.EmptyOnNull(tableAlias);
|
|
if (tableName.IsEmpty()) tableName = GetTableName(GetTableForColumn(column));
|
|
columnName = tableName + (tableName.Length > 0 ? "." : "") + columnName;
|
|
if (braces)
|
|
columnName = "(" + columnName + ")";
|
|
}
|
|
return columnName;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Reserved words.
|
|
private static DbReservedWordDelim reservedWordDelim = DbReservedWordDelim.SquareBrackets;
|
|
public static void SetReservedWordDelim (DbReservedWordDelim reservedWordDelim)
|
|
{
|
|
SbmDbDfn_Control.reservedWordDelim = reservedWordDelim;
|
|
}
|
|
public static bool IsReservedWord (String word)
|
|
{
|
|
if (String.IsNullOrEmpty(word)) return false;
|
|
if (reservedWords.Contains(word, StringComparer.OrdinalIgnoreCase)) return true;
|
|
return false;
|
|
}
|
|
public static String DelimitReservedWord (String word)
|
|
{
|
|
return IsReservedWord(word) ? DelimitWord(word) : word;
|
|
}
|
|
public static String DelimitWord (String word)
|
|
{
|
|
return DelimitWord(word, reservedWordDelim);
|
|
}
|
|
public static String DelimitWord (String word, DbReservedWordDelim wordDelim)
|
|
{
|
|
switch (wordDelim)
|
|
{
|
|
case DbReservedWordDelim.None:
|
|
break;
|
|
case DbReservedWordDelim.DoubleQuotes:
|
|
word = "\"" + word + "\"";
|
|
break;
|
|
case DbReservedWordDelim.SquareBrackets:
|
|
default:
|
|
word = "[" + word + "]";
|
|
break;
|
|
}
|
|
return word;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Retrieve information about the specified Column.
|
|
public static DbColumnDataType GetColDataType (ColumnIdx column)
|
|
{
|
|
int columnIdx = (int)column - 1;
|
|
if (columnIdx < 0 || columnIdx >= columnCount) return DbColumnDataType.Unknown;
|
|
return columns[columnIdx].DataType;
|
|
}
|
|
public static short GetColNativeDataType (ColumnIdx column)
|
|
{
|
|
int columnIdx = (int)column - 1;
|
|
if (columnIdx < 0 || columnIdx >= columnCount) return 0;
|
|
return columns[columnIdx].NativeDataType;
|
|
}
|
|
public static void SetMaxTextLen (ulong maxTextLen)
|
|
{
|
|
SbmDbDfn_Control.MaxTextLen = maxTextLen;
|
|
}
|
|
public static bool IsColFmtText (ColumnIdx column)
|
|
{
|
|
int columnIdx = (int)column - 1;
|
|
if (columnIdx < 0 || columnIdx >= columnCount) return false;
|
|
return (columns[columnIdx].DataType == DbColumnDataType.VarChar);
|
|
}
|
|
public static ulong GetColTextLen (ColumnIdx column)
|
|
{
|
|
int columnIdx = (int)column - 1;
|
|
if (columnIdx < 0 || columnIdx >= columnCount) return 0;
|
|
if (columns[columnIdx].DataType == DbColumnDataType.VarChar)
|
|
{
|
|
ulong textLen = columns[columnIdx].DataLen;
|
|
if (MaxTextLen > 0 && textLen > MaxTextLen) textLen = MaxTextLen;
|
|
return textLen;
|
|
}
|
|
return 0;
|
|
}
|
|
public static bool IsColFmtBool (ColumnIdx column)
|
|
{
|
|
int columnIdx = (int)column - 1;
|
|
if (columnIdx < 0 || columnIdx >= columnCount) return false;
|
|
return (columns[columnIdx].DataType == DbColumnDataType.Bit);
|
|
}
|
|
public static bool IsColFmtNumeric (ColumnIdx column)
|
|
{
|
|
int columnIdx = (int)column - 1;
|
|
if (columnIdx < 0 || columnIdx >= columnCount) return false;
|
|
switch (columns[columnIdx].DataType)
|
|
{
|
|
case DbColumnDataType.TinyInt:
|
|
case DbColumnDataType.SmallInt:
|
|
case DbColumnDataType.Int:
|
|
case DbColumnDataType.BigInt:
|
|
case DbColumnDataType.Single:
|
|
case DbColumnDataType.Double:
|
|
case DbColumnDataType.Decimal:
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Table definitions.
|
|
private class TableDfn
|
|
{
|
|
internal String Schema { get; set; }
|
|
internal String Name { get; set; }
|
|
internal TableDfn (String schema, String name)
|
|
{
|
|
this.Schema= schema;
|
|
this.Name = name;
|
|
}
|
|
}
|
|
private static readonly TableDfn[] tables =
|
|
{
|
|
new TableDfn("dbo","AccountRegistration"),
|
|
new TableDfn("dbo","ItemParam"),
|
|
new TableDfn("dbo","Owner"),
|
|
new TableDfn("dbo","Repository"),
|
|
new TableDfn("dbo","UserAccount"),
|
|
};
|
|
|
|
//-------------------------------------------------------------------
|
|
// Table column definitions.
|
|
private class ColumnDfn
|
|
{
|
|
internal TableIdx TableIdx { get; set; }
|
|
internal String Name { get; set; }
|
|
internal DbColumnDataType DataType { get; set; }
|
|
internal short NativeDataType { get; set; }
|
|
internal bool IsIdentity { get; set; }
|
|
internal ulong DataLen { get; set; }
|
|
internal ColumnDfn (int tableIdx, String name, int dataType, short nativeDataType, bool isIdentity, ulong dataLen)
|
|
{
|
|
this.TableIdx = (TableIdx)tableIdx;
|
|
this.Name = name;
|
|
this.DataType = (DbColumnDataType)dataType;
|
|
this.NativeDataType = nativeDataType;
|
|
this.IsIdentity = isIdentity;
|
|
this.DataLen = dataLen;
|
|
}
|
|
}
|
|
private static readonly ColumnDfn[] columns =
|
|
{
|
|
new ColumnDfn(1,"Id",4,4,true,10),
|
|
new ColumnDfn(1,"EmailAddress",0,-9,false,200),
|
|
new ColumnDfn(1,"FirstName",0,-9,false,100),
|
|
new ColumnDfn(1,"LastName",0,-9,false,100),
|
|
new ColumnDfn(1,"PhoneMain",0,-9,false,100),
|
|
new ColumnDfn(1,"PhoneAlt",0,-9,false,100),
|
|
new ColumnDfn(1,"RepositoryContext",0,-9,false,100),
|
|
new ColumnDfn(1,"RequestAccountAt",9,93,false,23),
|
|
new ColumnDfn(1,"RegisterAccountToken",10,-11,false,36),
|
|
new ColumnDfn(1,"RegisterAccountAt",9,93,false,23),
|
|
new ColumnDfn(1,"AccountPasswordSalt",0,-9,false,100),
|
|
new ColumnDfn(1,"AccountPasswordHash",0,-9,false,100),
|
|
new ColumnDfn(1,"Notes",0,-9,false,4000),
|
|
new ColumnDfn(1,"Flags",3,5,false,5),
|
|
new ColumnDfn(1,"Status",0,12,false,3),
|
|
new ColumnDfn(1,"CreateOn",9,93,false,23),
|
|
new ColumnDfn(1,"CreateBy",4,4,false,10),
|
|
new ColumnDfn(1,"CreateHost",0,12,false,100),
|
|
new ColumnDfn(1,"UpdateOn",9,93,false,23),
|
|
new ColumnDfn(1,"UpdateBy",4,4,false,10),
|
|
new ColumnDfn(1,"UpdateHost",0,12,false,100),
|
|
new ColumnDfn(2,"Id",4,4,true,10),
|
|
new ColumnDfn(2,"ItemType",3,5,false,5),
|
|
new ColumnDfn(2,"ItemId",5,-5,false,19),
|
|
new ColumnDfn(2,"Context",0,-9,false,200),
|
|
new ColumnDfn(2,"Name",0,-9,false,200),
|
|
new ColumnDfn(2,"Value",0,-9,false,0),
|
|
new ColumnDfn(2,"Notes",0,-9,false,4000),
|
|
new ColumnDfn(2,"Flags",3,5,false,5),
|
|
new ColumnDfn(2,"Status",0,12,false,3),
|
|
new ColumnDfn(2,"CreateOn",9,93,false,23),
|
|
new ColumnDfn(2,"CreateBy",4,4,false,10),
|
|
new ColumnDfn(2,"CreateHost",0,12,false,100),
|
|
new ColumnDfn(2,"UpdateOn",9,93,false,23),
|
|
new ColumnDfn(2,"UpdateBy",4,4,false,10),
|
|
new ColumnDfn(2,"UpdateHost",0,12,false,100),
|
|
new ColumnDfn(3,"Id",4,4,true,10),
|
|
new ColumnDfn(3,"Name",0,-9,false,200),
|
|
new ColumnDfn(3,"ContactName",0,-9,false,200),
|
|
new ColumnDfn(3,"ContactEmailAddress",0,-9,false,200),
|
|
new ColumnDfn(3,"ContactPhoneMain",0,-9,false,100),
|
|
new ColumnDfn(3,"ContactPhoneAlt",0,-9,false,100),
|
|
new ColumnDfn(3,"Notes",0,-9,false,4000),
|
|
new ColumnDfn(3,"Flags",3,5,false,5),
|
|
new ColumnDfn(3,"Status",0,12,false,3),
|
|
new ColumnDfn(3,"CreateOn",9,93,false,23),
|
|
new ColumnDfn(3,"CreateBy",4,4,false,10),
|
|
new ColumnDfn(3,"CreateHost",0,12,false,100),
|
|
new ColumnDfn(3,"UpdateOn",9,93,false,23),
|
|
new ColumnDfn(3,"UpdateBy",4,4,false,10),
|
|
new ColumnDfn(3,"UpdateHost",0,12,false,100),
|
|
new ColumnDfn(4,"Id",4,4,true,10),
|
|
new ColumnDfn(4,"OwnerId",4,4,false,10),
|
|
new ColumnDfn(4,"Context",0,-9,false,100),
|
|
new ColumnDfn(4,"ServerName",0,-9,false,200),
|
|
new ColumnDfn(4,"InstanceName",0,-9,false,200),
|
|
new ColumnDfn(4,"DatabaseName",0,-9,false,200),
|
|
new ColumnDfn(4,"UserName",0,-9,false,100),
|
|
new ColumnDfn(4,"Password",0,-9,false,100),
|
|
new ColumnDfn(4,"Notes",0,-9,false,4000),
|
|
new ColumnDfn(4,"Flags",3,5,false,5),
|
|
new ColumnDfn(4,"Status",0,12,false,3),
|
|
new ColumnDfn(4,"CreateOn",9,93,false,23),
|
|
new ColumnDfn(4,"CreateBy",4,4,false,10),
|
|
new ColumnDfn(4,"CreateHost",0,12,false,100),
|
|
new ColumnDfn(4,"UpdateOn",9,93,false,23),
|
|
new ColumnDfn(4,"UpdateBy",4,4,false,10),
|
|
new ColumnDfn(4,"UpdateHost",0,12,false,100),
|
|
new ColumnDfn(5,"Id",4,4,true,10),
|
|
new ColumnDfn(5,"EmailAddress",0,-9,false,200),
|
|
new ColumnDfn(5,"Title",0,-9,false,20),
|
|
new ColumnDfn(5,"FirstName",0,-9,false,100),
|
|
new ColumnDfn(5,"Initials",0,-9,false,10),
|
|
new ColumnDfn(5,"LastName",0,-9,false,100),
|
|
new ColumnDfn(5,"PhoneMain",0,-9,false,50),
|
|
new ColumnDfn(5,"PhoneMobile",0,-9,false,50),
|
|
new ColumnDfn(5,"PhoneAlt",0,-9,false,50),
|
|
new ColumnDfn(5,"PasswordToken",0,12,false,32),
|
|
new ColumnDfn(5,"PasswordHashed",0,-9,false,100),
|
|
new ColumnDfn(5,"PasswordHistory",0,-9,false,0),
|
|
new ColumnDfn(5,"PasswordChangedAt",9,93,false,16),
|
|
new ColumnDfn(5,"LastLoginAt",9,93,false,16),
|
|
new ColumnDfn(5,"LastInvalidLoginAt",9,93,false,16),
|
|
new ColumnDfn(5,"InvalidLoginCount",3,5,false,5),
|
|
new ColumnDfn(5,"Notes",0,-9,false,2000),
|
|
new ColumnDfn(5,"Flags",3,5,false,5),
|
|
new ColumnDfn(5,"Status",0,12,false,3),
|
|
new ColumnDfn(5,"CreateOn",9,93,false,23),
|
|
new ColumnDfn(5,"CreateBy",4,4,false,10),
|
|
new ColumnDfn(5,"CreateHost",0,12,false,100),
|
|
new ColumnDfn(5,"UpdateOn",9,93,false,23),
|
|
new ColumnDfn(5,"UpdateBy",4,4,false,10),
|
|
new ColumnDfn(5,"UpdateHost",0,12,false,100),
|
|
};
|
|
|
|
//-------------------------------------------------------------------
|
|
// Reserved words.
|
|
private static readonly HashSet<String> reservedWords = new HashSet<String>()
|
|
{
|
|
"ADD",
|
|
"ALL",
|
|
"ALTER",
|
|
"AND",
|
|
"ANY",
|
|
"AS",
|
|
"ASC",
|
|
"AVG",
|
|
"BEGIN",
|
|
"BETWEEN",
|
|
"BY",
|
|
"CASE",
|
|
"CAST",
|
|
"COLUMN",
|
|
"COMMIT",
|
|
"CONSTRAINT",
|
|
"CONVERT",
|
|
"COUNT",
|
|
"CREATE",
|
|
"CURRENCY",
|
|
"DEFAULT",
|
|
"DELETE",
|
|
"DESC",
|
|
"DISTINCT",
|
|
"DROP",
|
|
"ELSE",
|
|
"END",
|
|
"EXECUTE",
|
|
"EXISTS",
|
|
"FALSE",
|
|
"FROM",
|
|
"GRANT",
|
|
"GROUP",
|
|
"HAVING",
|
|
"IN",
|
|
"INDEX",
|
|
"INNER",
|
|
"INSERT",
|
|
"INTO",
|
|
"IS",
|
|
"JOIN",
|
|
"KEY",
|
|
"LEFT",
|
|
"LIKE",
|
|
"MAX",
|
|
"MIN",
|
|
"NOT",
|
|
"NULL",
|
|
"ON",
|
|
"OR",
|
|
"ORDER",
|
|
"OUTER",
|
|
"OUTPUT",
|
|
"PRIMARY",
|
|
"PROCEDURE",
|
|
"REVOKE",
|
|
"ROLLBACK",
|
|
"ROWCOUNT",
|
|
"SELECT",
|
|
"SET",
|
|
"SQL",
|
|
"SUM",
|
|
"TABLE",
|
|
"THEN",
|
|
"TRANSACTION",
|
|
"TRUE",
|
|
"UNION",
|
|
"UNIQUE",
|
|
"UPDATE",
|
|
"USER",
|
|
"VALUES",
|
|
"VIEW",
|
|
"WHEN",
|
|
"WHERE",
|
|
};
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
}
|