377 lines
11 KiB
C#
377 lines
11 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 Tue 6-Aug-2024 14:50:13
|
|
//---------------------------------------------------------------------------
|
|
namespace Saxonite.Base.App
|
|
{
|
|
public class SaxDbDfn_Support
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Table identifiers.
|
|
public enum TableIdx
|
|
{
|
|
Unknown = 0,
|
|
UserReport,
|
|
UserReportComment,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Column identifiers.
|
|
public enum ColumnIdx
|
|
{
|
|
Unknown = 0,
|
|
UserReport_Id,
|
|
UserReport_UserAccountId,
|
|
UserReport_ReportType,
|
|
UserReport_Title,
|
|
UserReport_Report,
|
|
UserReport_RecordedOn,
|
|
UserReport_ReportData,
|
|
UserReport_Notes,
|
|
UserReport_Flags,
|
|
UserReport_Status,
|
|
UserReport_CreateOn,
|
|
UserReport_CreateBy,
|
|
UserReport_CreateHost,
|
|
UserReport_UpdateOn,
|
|
UserReport_UpdateBy,
|
|
UserReport_UpdateHost,
|
|
UserReportComment_Id,
|
|
UserReportComment_UserReportId,
|
|
UserReportComment_RecordedAt,
|
|
UserReportComment_UserAccountId,
|
|
UserReportComment_CommentData,
|
|
UserReportComment_Notes,
|
|
UserReportComment_Flags,
|
|
UserReportComment_Status,
|
|
UserReportComment_CreateOn,
|
|
UserReportComment_CreateBy,
|
|
UserReportComment_CreateHost,
|
|
UserReportComment_UpdateOn,
|
|
UserReportComment_UpdateBy,
|
|
UserReportComment_UpdateHost,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private static readonly int tableCount = 2;
|
|
private static readonly int columnCount = 30;
|
|
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].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)
|
|
{
|
|
SaxDbDfn_Support.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)
|
|
{
|
|
SaxDbDfn_Support.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","UserReport"),
|
|
new TableDfn("dbo","UserReportComment"),
|
|
};
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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",5,-5,true,19),
|
|
new ColumnDfn(1,"UserAccountId",4,4,false,10),
|
|
new ColumnDfn(1,"ReportType",3,5,false,5),
|
|
new ColumnDfn(1,"Title",0,-9,false,1000),
|
|
new ColumnDfn(1,"Report",0,-9,false,0),
|
|
new ColumnDfn(1,"RecordedOn",9,93,false,16),
|
|
new ColumnDfn(1,"ReportData",0,-9,false,0),
|
|
new ColumnDfn(1,"Notes",0,-9,false,2000),
|
|
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",5,-5,true,19),
|
|
new ColumnDfn(2,"UserReportId",5,-5,false,19),
|
|
new ColumnDfn(2,"RecordedAt",9,93,false,23),
|
|
new ColumnDfn(2,"UserAccountId",4,4,false,10),
|
|
new ColumnDfn(2,"CommentData",0,-9,false,0),
|
|
new ColumnDfn(2,"Notes",0,-9,false,2000),
|
|
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),
|
|
};
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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",
|
|
};
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
}
|