456 lines
14 KiB
C#
456 lines
14 KiB
C#
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 3-Oct-2019 15:10:58
|
|
//---------------------------------------------------------------------------
|
|
namespace Sarand.Net.Standard.Base.Interfaces
|
|
{
|
|
public class SaInterfaceDbDfn
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Table identifiers.
|
|
public enum TableIdx
|
|
{
|
|
Unknown = 0,
|
|
SaInterface,
|
|
SaInterfaceDataItem,
|
|
SaInterfaceProcess,
|
|
SaInterfaceProcessDataItem,
|
|
SaInterfaceProcessMessage,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Column identifiers.
|
|
public enum ColumnIdx
|
|
{
|
|
Unknown = 0,
|
|
SaInterface_Id,
|
|
SaInterface_Context,
|
|
SaInterface_Code,
|
|
SaInterface_Category,
|
|
SaInterface_Type,
|
|
SaInterface_Caption,
|
|
SaInterface_Notes,
|
|
SaInterface_Flags,
|
|
SaInterface_Status,
|
|
SaInterface_CreateOn,
|
|
SaInterface_CreateBy,
|
|
SaInterface_CreateHost,
|
|
SaInterface_UpdateOn,
|
|
SaInterface_UpdateBy,
|
|
SaInterface_UpdateHost,
|
|
SaInterfaceDataItem_Id,
|
|
SaInterfaceDataItem_InterfaceId,
|
|
SaInterfaceDataItem_Direction,
|
|
SaInterfaceDataItem_ExternalRef,
|
|
SaInterfaceDataItem_ItemType,
|
|
SaInterfaceDataItem_ItemId,
|
|
SaInterfaceDataItem_ProcessStatus,
|
|
SaInterfaceDataItem_ProcessStatusBy,
|
|
SaInterfaceDataItem_ProcessStatusAt,
|
|
SaInterfaceDataItem_ItemStatus,
|
|
SaInterfaceDataItem_ItemStatusBy,
|
|
SaInterfaceDataItem_ItemStatusAt,
|
|
SaInterfaceDataItem_Notes,
|
|
SaInterfaceDataItem_Flags,
|
|
SaInterfaceDataItem_CreateOn,
|
|
SaInterfaceDataItem_CreateBy,
|
|
SaInterfaceDataItem_CreateHost,
|
|
SaInterfaceDataItem_UpdateOn,
|
|
SaInterfaceDataItem_UpdateBy,
|
|
SaInterfaceDataItem_UpdateHost,
|
|
SaInterfaceProcess_Id,
|
|
SaInterfaceProcess_InterfaceId,
|
|
SaInterfaceProcess_Direction,
|
|
SaInterfaceProcess_ProcRef,
|
|
SaInterfaceProcess_ProcSeq,
|
|
SaInterfaceProcess_ProcessAt,
|
|
SaInterfaceProcess_BatchAt,
|
|
SaInterfaceProcess_ElapseSecs,
|
|
SaInterfaceProcess_ItemCount,
|
|
SaInterfaceProcess_Flags,
|
|
SaInterfaceProcess_Status,
|
|
SaInterfaceProcess_CreateOn,
|
|
SaInterfaceProcess_CreateBy,
|
|
SaInterfaceProcess_CreateHost,
|
|
SaInterfaceProcess_UpdateOn,
|
|
SaInterfaceProcess_UpdateBy,
|
|
SaInterfaceProcess_UpdateHost,
|
|
SaInterfaceProcessDataItem_ProcessId,
|
|
SaInterfaceProcessDataItem_InterfaceDataItemId,
|
|
SaInterfaceProcessDataItem_ItemData,
|
|
SaInterfaceProcessDataItem_Flags,
|
|
SaInterfaceProcessDataItem_Status,
|
|
SaInterfaceProcessDataItem_CreateOn,
|
|
SaInterfaceProcessDataItem_CreateBy,
|
|
SaInterfaceProcessDataItem_CreateHost,
|
|
SaInterfaceProcessDataItem_UpdateOn,
|
|
SaInterfaceProcessDataItem_UpdateBy,
|
|
SaInterfaceProcessDataItem_UpdateHost,
|
|
SaInterfaceProcessMessage_Id,
|
|
SaInterfaceProcessMessage_ProcessId,
|
|
SaInterfaceProcessMessage_MsgType,
|
|
SaInterfaceProcessMessage_Msg,
|
|
SaInterfaceProcessMessage_FileName,
|
|
SaInterfaceProcessMessage_LineNumber,
|
|
SaInterfaceProcessMessage_ItemType,
|
|
SaInterfaceProcessMessage_ItemId,
|
|
SaInterfaceProcessMessage_Flags,
|
|
SaInterfaceProcessMessage_Status,
|
|
SaInterfaceProcessMessage_CreateOn,
|
|
SaInterfaceProcessMessage_CreateBy,
|
|
SaInterfaceProcessMessage_CreateHost,
|
|
SaInterfaceProcessMessage_UpdateOn,
|
|
SaInterfaceProcessMessage_UpdateBy,
|
|
SaInterfaceProcessMessage_UpdateHost,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private static readonly int tableCount = 5;
|
|
private static readonly int columnCount = 79;
|
|
private static ulong maxTextLen = 0;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Retrieve Table details (eg. name: 'Company').
|
|
public static int GetTableCount ()
|
|
{
|
|
return tableCount;
|
|
}
|
|
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];
|
|
if (delimitReservedWords) tableName = DelimitReservedWord(tableName);
|
|
return 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)
|
|
{
|
|
SaInterfaceDbDfn.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)
|
|
{
|
|
if (!IsReservedWord(word)) return word;
|
|
switch (reservedWordDelim)
|
|
{
|
|
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)
|
|
{
|
|
SaInterfaceDbDfn.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 static readonly String[] tables =
|
|
{
|
|
"SaInterface",
|
|
"SaInterfaceDataItem",
|
|
"SaInterfaceProcess",
|
|
"SaInterfaceProcessDataItem",
|
|
"SaInterfaceProcessMessage",
|
|
};
|
|
|
|
//-------------------------------------------------------------------
|
|
// Table column definitions.
|
|
internal 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,false,10),
|
|
new ColumnDfn(1,"Context",0,-9,false,32),
|
|
new ColumnDfn(1,"Code",0,-9,false,32),
|
|
new ColumnDfn(1,"Category",3,5,false,5),
|
|
new ColumnDfn(1,"Type",3,5,false,5),
|
|
new ColumnDfn(1,"Caption",0,-9,false,50),
|
|
new ColumnDfn(1,"Notes",0,-9,false,255),
|
|
new ColumnDfn(1,"Flags",3,5,false,5),
|
|
new ColumnDfn(1,"Status",0,-9,false,3),
|
|
new ColumnDfn(1,"CreateOn",9,93,false,23),
|
|
new ColumnDfn(1,"CreateBy",4,4,false,10),
|
|
new ColumnDfn(1,"CreateHost",0,-9,false,64),
|
|
new ColumnDfn(1,"UpdateOn",9,93,false,23),
|
|
new ColumnDfn(1,"UpdateBy",4,4,false,10),
|
|
new ColumnDfn(1,"UpdateHost",0,-9,false,64),
|
|
new ColumnDfn(2,"Id",4,4,false,10),
|
|
new ColumnDfn(2,"InterfaceId",4,4,false,10),
|
|
new ColumnDfn(2,"Direction",3,5,false,5),
|
|
new ColumnDfn(2,"ExternalRef",0,-9,false,64),
|
|
new ColumnDfn(2,"ItemType",3,5,false,5),
|
|
new ColumnDfn(2,"ItemId",4,4,false,10),
|
|
new ColumnDfn(2,"ProcessStatus",0,-9,false,3),
|
|
new ColumnDfn(2,"ProcessStatusBy",4,4,false,10),
|
|
new ColumnDfn(2,"ProcessStatusAt",9,93,false,23),
|
|
new ColumnDfn(2,"ItemStatus",0,-9,false,3),
|
|
new ColumnDfn(2,"ItemStatusBy",4,4,false,10),
|
|
new ColumnDfn(2,"ItemStatusAt",9,93,false,23),
|
|
new ColumnDfn(2,"Notes",0,-9,false,255),
|
|
new ColumnDfn(2,"Flags",3,5,false,5),
|
|
new ColumnDfn(2,"CreateOn",9,93,false,23),
|
|
new ColumnDfn(2,"CreateBy",4,4,false,10),
|
|
new ColumnDfn(2,"CreateHost",0,-9,false,64),
|
|
new ColumnDfn(2,"UpdateOn",9,93,false,23),
|
|
new ColumnDfn(2,"UpdateBy",4,4,false,10),
|
|
new ColumnDfn(2,"UpdateHost",0,-9,false,64),
|
|
new ColumnDfn(3,"Id",4,4,false,10),
|
|
new ColumnDfn(3,"InterfaceId",4,4,false,10),
|
|
new ColumnDfn(3,"Direction",3,5,false,5),
|
|
new ColumnDfn(3,"ProcRef",0,-9,false,32),
|
|
new ColumnDfn(3,"ProcSeq",4,4,false,10),
|
|
new ColumnDfn(3,"ProcessAt",9,93,false,23),
|
|
new ColumnDfn(3,"BatchAt",9,93,false,23),
|
|
new ColumnDfn(3,"ElapseSecs",4,4,false,10),
|
|
new ColumnDfn(3,"ItemCount",4,4,false,10),
|
|
new ColumnDfn(3,"Flags",3,5,false,5),
|
|
new ColumnDfn(3,"Status",0,-9,false,3),
|
|
new ColumnDfn(3,"CreateOn",9,93,false,23),
|
|
new ColumnDfn(3,"CreateBy",4,4,false,10),
|
|
new ColumnDfn(3,"CreateHost",0,-9,false,64),
|
|
new ColumnDfn(3,"UpdateOn",9,93,false,23),
|
|
new ColumnDfn(3,"UpdateBy",4,4,false,10),
|
|
new ColumnDfn(3,"UpdateHost",0,-9,false,64),
|
|
new ColumnDfn(4,"ProcessId",4,4,false,10),
|
|
new ColumnDfn(4,"InterfaceDataItemId",4,4,false,10),
|
|
new ColumnDfn(4,"ItemData",0,-9,false,64),
|
|
new ColumnDfn(4,"Flags",3,5,false,5),
|
|
new ColumnDfn(4,"Status",0,-9,false,3),
|
|
new ColumnDfn(4,"CreateOn",9,93,false,23),
|
|
new ColumnDfn(4,"CreateBy",4,4,false,10),
|
|
new ColumnDfn(4,"CreateHost",0,-9,false,64),
|
|
new ColumnDfn(4,"UpdateOn",9,93,false,23),
|
|
new ColumnDfn(4,"UpdateBy",4,4,false,10),
|
|
new ColumnDfn(4,"UpdateHost",0,-9,false,64),
|
|
new ColumnDfn(5,"Id",4,4,false,10),
|
|
new ColumnDfn(5,"ProcessId",4,4,false,10),
|
|
new ColumnDfn(5,"MsgType",0,12,false,3),
|
|
new ColumnDfn(5,"Msg",0,-9,false,1024),
|
|
new ColumnDfn(5,"FileName",0,-9,false,64),
|
|
new ColumnDfn(5,"LineNumber",4,4,false,10),
|
|
new ColumnDfn(5,"ItemType",3,5,false,5),
|
|
new ColumnDfn(5,"ItemId",4,4,false,10),
|
|
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,-9,false,64),
|
|
new ColumnDfn(5,"UpdateOn",9,93,false,23),
|
|
new ColumnDfn(5,"UpdateBy",4,4,false,10),
|
|
new ColumnDfn(5,"UpdateHost",0,-9,false,64),
|
|
};
|
|
|
|
//-------------------------------------------------------------------
|
|
// Reserved words.
|
|
private static readonly List<String> reservedWords = new List<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",
|
|
};
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
}
|