Saxonite 1.2.11.14
This commit is contained in:
@@ -505,6 +505,11 @@ namespace Sarand.Net.Standard.Base.Bus
|
|||||||
public DbQuery.Paging ResultsPaging { get; } = new DbQuery.Paging();
|
public DbQuery.Paging ResultsPaging { get; } = new DbQuery.Paging();
|
||||||
/// <summary>Sort columns.</summary>
|
/// <summary>Sort columns.</summary>
|
||||||
public List<ColumnDfn> SortColumns { get; } = new List<ColumnDfn>();
|
public List<ColumnDfn> SortColumns { get; } = new List<ColumnDfn>();
|
||||||
|
/// <summary>
|
||||||
|
/// Flag to return data in random order.
|
||||||
|
/// <para>- NB Depends on implementation for each manager and item.</para>
|
||||||
|
/// </summary>
|
||||||
|
public bool RandomOrder { get; set; } = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Sarand.Net.Standard.Base.App;
|
||||||
using Sarand.Net.Standard.Base.Core;
|
using Sarand.Net.Standard.Base.Core;
|
||||||
|
using Sarand.Net.Standard.Base.Dbas;
|
||||||
using Sarand.Net.Standard.Base.Utils;
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
|
||||||
namespace Sarand.Net.Standard.Base.Bus
|
namespace Sarand.Net.Standard.Base.Bus
|
||||||
@@ -57,6 +61,20 @@ namespace Sarand.Net.Standard.Base.Bus
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// S o r t C o l u m n s
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected void AddRandomSortColumn (SacsHierarchyItem.Params prm, HashSet<String> sortColumns)
|
||||||
|
{
|
||||||
|
if (!prm.RandomOrder) return;
|
||||||
|
if (sortColumns.Any())
|
||||||
|
{
|
||||||
|
SaLogger.Warn($"{SysUtil.Fn} RandomOrder requested with other sort columns specified. [{prm.GetType().Name}]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sortColumns.Add(DbQuery.GetRandomOrderSortColumn());
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
// methods that depend on the value (especially static ones).
|
// methods that depend on the value (especially static ones).
|
||||||
public class DbGlobalDbms
|
public class DbGlobalDbms
|
||||||
{
|
{
|
||||||
private DbGlobalDbms () { }
|
private DbGlobalDbms() { }
|
||||||
private static DbmsType dbms = DbmsType.General;
|
private static DbmsType dbms = DbmsType.General;
|
||||||
public static DbmsType Type
|
public static DbmsType Type
|
||||||
{
|
{
|
||||||
@@ -66,7 +66,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public DbQueryJoin (DbJoinType type = DbJoinType.Inner)
|
public DbQueryJoin(DbJoinType type = DbJoinType.Inner)
|
||||||
{
|
{
|
||||||
this.Type = type;
|
this.Type = type;
|
||||||
}
|
}
|
||||||
@@ -80,7 +80,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
public List<DbQueryJoin> SubJoins { get; } = new List<DbQueryJoin>();
|
public List<DbQueryJoin> SubJoins { get; } = new List<DbQueryJoin>();
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
public static String GetJoinType (DbJoinType type)
|
public static String GetJoinType(DbJoinType type)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
@@ -94,7 +94,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
public String BuildJoin (String enclosedJoin)
|
public String BuildJoin(String enclosedJoin)
|
||||||
{
|
{
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
// Select syntax.
|
// Select syntax.
|
||||||
@@ -129,7 +129,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
// Sage doesn't use 'AS' to alias tables.
|
// Sage doesn't use 'AS' to alias tables.
|
||||||
String tableAliasOperator = (DbGlobalDbms.Type == DbmsType.Sage ? " " : " AS ");
|
String tableAliasOperator = (DbGlobalDbms.Type == DbmsType.Sage ? " " : " AS ");
|
||||||
String joinType = GetJoinType(Type);
|
String joinType = GetJoinType(Type);
|
||||||
String joinTable = Table.Concat (tableAliasOperator, false);
|
String joinTable = Table.Concat(tableAliasOperator, false);
|
||||||
String subJoinData = String.Empty;
|
String subJoinData = String.Empty;
|
||||||
foreach (var subJoin in SubJoins)
|
foreach (var subJoin in SubJoins)
|
||||||
{
|
{
|
||||||
@@ -184,7 +184,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Debugging.
|
// Debugging.
|
||||||
public void Dump ()
|
public void Dump()
|
||||||
{
|
{
|
||||||
SaLogger.Debug($"{SysUtil.Fn}");
|
SaLogger.Debug($"{SysUtil.Fn}");
|
||||||
SaLogger.Debug("\tType = " + GetJoinType(Type));
|
SaLogger.Debug("\tType = " + GetJoinType(Type));
|
||||||
@@ -204,7 +204,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// List extensions.
|
// List extensions.
|
||||||
public static String BuildJoins (this List<DbQueryJoin> joins, String primaryTable)
|
public static String BuildJoins(this List<DbQueryJoin> joins, String primaryTable)
|
||||||
{
|
{
|
||||||
String joinData = primaryTable;
|
String joinData = primaryTable;
|
||||||
if (joins.Count > 0)
|
if (joins.Count > 0)
|
||||||
@@ -265,6 +265,11 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
public uint PageNo { get; set; } = 0;
|
public uint PageNo { get; set; } = 0;
|
||||||
public ushort PageLength { get; set; } = 0;
|
public ushort PageLength { get; set; } = 0;
|
||||||
public virtual bool Paged { get { return PageNo > 0 && PageLength > 0; } }
|
public virtual bool Paged { get { return PageNo > 0 && PageLength > 0; } }
|
||||||
|
public void Set(uint pageNo, ushort pageLength)
|
||||||
|
{
|
||||||
|
this.PageNo = pageNo;
|
||||||
|
this.PageLength = pageLength;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
@@ -272,7 +277,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public DbQuery (DbmsType dbms)
|
public DbQuery(DbmsType dbms)
|
||||||
{
|
{
|
||||||
DbGlobalDbms.Type = dbms;
|
DbGlobalDbms.Type = dbms;
|
||||||
}
|
}
|
||||||
@@ -297,7 +302,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
/// Format the value so that it can be used in a conditional clause.
|
/// Format the value so that it can be used in a conditional clause.
|
||||||
/// <para>- single quotes are duplicated.</para>
|
/// <para>- single quotes are duplicated.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static String FormatForCondition (String value)
|
public static String FormatForCondition(String value)
|
||||||
{
|
{
|
||||||
return StringUtil.EmptyOnNull(value).Replace("'", "''");
|
return StringUtil.EmptyOnNull(value).Replace("'", "''");
|
||||||
}
|
}
|
||||||
@@ -308,7 +313,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
/// <para>- percent ('%') is enclosed in square brackets ('[%]') unless wildcards allowed.</para>
|
/// <para>- percent ('%') is enclosed in square brackets ('[%]') unless wildcards allowed.</para>
|
||||||
/// <para>- asterisk ('*') converted to percent ('%') if wildcards allowed.</para>
|
/// <para>- asterisk ('*') converted to percent ('%') if wildcards allowed.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static String FormatForLike (String value, bool allowWildcards = false)
|
public static String FormatForLike(String value, bool allowWildcards = false)
|
||||||
{
|
{
|
||||||
value = StringUtil.EmptyOnNull(value).Replace("'", "''").Replace("[", "[[]");
|
value = StringUtil.EmptyOnNull(value).Replace("'", "''").Replace("[", "[[]");
|
||||||
if (allowWildcards)
|
if (allowWildcards)
|
||||||
@@ -327,7 +332,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
/// <para>- Format as: ('Value1','Value2','Value3') if string data, else (Value1,Value2,Value3) etc.</para>
|
/// <para>- Format as: ('Value1','Value2','Value3') if string data, else (Value1,Value2,Value3) etc.</para>
|
||||||
/// <para>- Returns empty string if list is empty.</para>
|
/// <para>- Returns empty string if list is empty.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static String FormatForIn (List<String> rawValues, bool stringData = true, bool ignoreBlanks = true)
|
public static String FormatForIn(List<String> rawValues, bool stringData = true, bool ignoreBlanks = true)
|
||||||
{
|
{
|
||||||
String result = String.Empty;
|
String result = String.Empty;
|
||||||
List<String> values = new List<String>();
|
List<String> values = new List<String>();
|
||||||
@@ -351,14 +356,14 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// D a t e V a l u e F o r m a t t i n g
|
// D a t e V a l u e F o r m a t t i n g
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
public static String GetDateDelim ()
|
public static String GetDateDelim()
|
||||||
{
|
{
|
||||||
String delim = "#"; // MS Access only?
|
String delim = "#"; // MS Access only?
|
||||||
if (DbGlobalDbms.Type == DbmsType.MsSql)
|
if (DbGlobalDbms.Type == DbmsType.MsSql)
|
||||||
delim = "'"; // MS SQL Server.
|
delim = "'"; // MS SQL Server.
|
||||||
return delim;
|
return delim;
|
||||||
}
|
}
|
||||||
public static String FormatDateForCondition (DateTime date, bool delimit = true, bool includeMidnight = false)
|
public static String FormatDateForCondition(DateTime date, bool delimit = true, bool includeMidnight = false)
|
||||||
{
|
{
|
||||||
String value = DateUtil.Format(date, "dd-MMM-yyyy");
|
String value = DateUtil.Format(date, "dd-MMM-yyyy");
|
||||||
if (includeMidnight)
|
if (includeMidnight)
|
||||||
@@ -370,9 +375,9 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
public static String FormatDateTimeForCondition (DateTime dateTime, bool delimit = true, bool precise = false)
|
public static String FormatDateTimeForCondition(DateTime dateTime, bool delimit = true, bool precise = false)
|
||||||
{
|
{
|
||||||
String value = DateUtil.Format(dateTime, "yyyy-MM-dd HH:mm:ss"+(precise?".fff":""));
|
String value = DateUtil.Format(dateTime, "yyyy-MM-dd HH:mm:ss" + (precise ? ".fff" : ""));
|
||||||
if (delimit)
|
if (delimit)
|
||||||
{
|
{
|
||||||
String delim = GetDateDelim();
|
String delim = GetDateDelim();
|
||||||
@@ -381,7 +386,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String FormatTimeForCondition (DateTime time, bool delimit = true, bool zeroSeconds = false)
|
public static String FormatTimeForCondition(DateTime time, bool delimit = true, bool zeroSeconds = false)
|
||||||
{
|
{
|
||||||
String value = String.Empty;
|
String value = String.Empty;
|
||||||
if (zeroSeconds)
|
if (zeroSeconds)
|
||||||
@@ -399,7 +404,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// F o r m a t F o r F i l t e r
|
// F o r m a t F o r F i l t e r
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
public static String FormatNullValueFilter (String expression, bool excludeNulls)
|
public static String FormatNullValueFilter(String expression, bool excludeNulls)
|
||||||
{
|
{
|
||||||
String clause = String.Empty;
|
String clause = String.Empty;
|
||||||
expression = StringUtil.EmptyOnNull(expression).Trim();
|
expression = StringUtil.EmptyOnNull(expression).Trim();
|
||||||
@@ -430,7 +435,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
}
|
}
|
||||||
// Construct 'Order By' clauses, allowing direction (ASC/DESC) and whether
|
// Construct 'Order By' clauses, allowing direction (ASC/DESC) and whether
|
||||||
// to demote NULL values (push to end of sequence) into account.
|
// to demote NULL values (push to end of sequence) into account.
|
||||||
public static List<String> FormatForOrderBy (String expression, bool ascending, DbOrderByNullMode nullMode = DbOrderByNullMode.Default, bool treatZeroAsNull = false)
|
public static List<String> FormatForOrderBy(String expression, bool ascending, DbOrderByNullMode nullMode = DbOrderByNullMode.Default, bool treatZeroAsNull = false)
|
||||||
{
|
{
|
||||||
List<String> orderBy = new List<string>();
|
List<String> orderBy = new List<string>();
|
||||||
expression = StringUtil.EmptyOnNull(expression).Trim();
|
expression = StringUtil.EmptyOnNull(expression).Trim();
|
||||||
@@ -485,25 +490,25 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// NB Many functions depend on the DBMS in use.
|
// NB Many functions depend on the DBMS in use.
|
||||||
// Default versions are for Access/SQL.
|
// Default versions are for Access/SQL.
|
||||||
public static String FormatFn_Len (String column)
|
public static String FormatFn_Len(String column)
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(column)) return "''";
|
if (String.IsNullOrEmpty(column)) return "''";
|
||||||
// MS Access.
|
// MS Access.
|
||||||
return "Len(" + column + ")";
|
return "Len(" + column + ")";
|
||||||
}
|
}
|
||||||
public static String FormatFn_Left (String column, int length)
|
public static String FormatFn_Left(String column, int length)
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(column) || length < 1) return "''";
|
if (String.IsNullOrEmpty(column) || length < 1) return "''";
|
||||||
// MS Access.
|
// MS Access.
|
||||||
return "Left(" + column + "," + length.ToString() + ")";
|
return "Left(" + column + "," + length.ToString() + ")";
|
||||||
}
|
}
|
||||||
public static String FormatFn_Right (String column, int length)
|
public static String FormatFn_Right(String column, int length)
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(column) || length < 1) return "''";
|
if (String.IsNullOrEmpty(column) || length < 1) return "''";
|
||||||
// MS Access.
|
// MS Access.
|
||||||
return "Right(" + column + "," + length.ToString() + ")";
|
return "Right(" + column + "," + length.ToString() + ")";
|
||||||
}
|
}
|
||||||
public static String FormatFn_TimeValue (String expression)
|
public static String FormatFn_TimeValue(String expression)
|
||||||
{
|
{
|
||||||
if (DbGlobalDbms.Type == DbmsType.MsSql)
|
if (DbGlobalDbms.Type == DbmsType.MsSql)
|
||||||
{
|
{
|
||||||
@@ -526,13 +531,13 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// N u m e r i c F u n c t i o n s
|
// N u m e r i c F u n c t i o n s
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
public static String FormatFn_Abs (String sExpr)
|
public static String FormatFn_Abs(String sExpr)
|
||||||
{
|
{
|
||||||
if (sExpr.IsEmpty()) return "''";
|
if (sExpr.IsEmpty()) return "''";
|
||||||
return "Abs(" + sExpr + ")";
|
return "Abs(" + sExpr + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String FormatFn_Round (String expression, int decimals = 0)
|
public static String FormatFn_Round(String expression, int decimals = 0)
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(expression) || decimals < 0) return "''";
|
if (String.IsNullOrEmpty(expression) || decimals < 0) return "''";
|
||||||
if (DbGlobalDbms.Type == DbmsType.Access)
|
if (DbGlobalDbms.Type == DbmsType.Access)
|
||||||
@@ -545,7 +550,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
return "Round(" + expression + "," + decimals.ToString() + ")";
|
return "Round(" + expression + "," + decimals.ToString() + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String FormatFn_Truncate (String expression, int decimals = 0)
|
public static String FormatFn_Truncate(String expression, int decimals = 0)
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(expression) || decimals < 0) return "''";
|
if (String.IsNullOrEmpty(expression) || decimals < 0) return "''";
|
||||||
if (DbGlobalDbms.Type == DbmsType.MsSql)
|
if (DbGlobalDbms.Type == DbmsType.MsSql)
|
||||||
@@ -554,13 +559,13 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
// MS Access.
|
// MS Access.
|
||||||
if (decimals > 0)
|
if (decimals > 0)
|
||||||
{
|
{
|
||||||
String factor = ((long)(10^decimals)).ToString();
|
String factor = ((long)(10 ^ decimals)).ToString();
|
||||||
return "Int(" + expression + "*" + factor + "," + decimals.ToString() + ")/" + factor;
|
return "Int(" + expression + "*" + factor + "," + decimals.ToString() + ")/" + factor;
|
||||||
}
|
}
|
||||||
return "Int(" + expression + "," + decimals.ToString() + ")";
|
return "Int(" + expression + "," + decimals.ToString() + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String FormatFn_FormatNumber (String expression, int decimals)
|
public static String FormatFn_FormatNumber(String expression, int decimals)
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(expression) || decimals < 0) return "''";
|
if (String.IsNullOrEmpty(expression) || decimals < 0) return "''";
|
||||||
// MS Access.
|
// MS Access.
|
||||||
@@ -571,7 +576,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
// D a t e D i f f e r e n c e
|
// D a t e D i f f e r e n c e
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Date difference: eg. DateDiff('n',Col1,Col2).
|
// Date difference: eg. DateDiff('n',Col1,Col2).
|
||||||
public static String FormatFn_DateDiff (DbDateDiffInterval dateInterval, String column1, String column2)
|
public static String FormatFn_DateDiff(DbDateDiffInterval dateInterval, String column1, String column2)
|
||||||
{
|
{
|
||||||
if (column1.IsEmpty() || column2.IsEmpty()) return "''";
|
if (column1.IsEmpty() || column2.IsEmpty()) return "''";
|
||||||
String interval = String.Empty;
|
String interval = String.Empty;
|
||||||
@@ -618,7 +623,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// B i t M a p p e d V a l u e s
|
// B i t M a p p e d V a l u e s
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
public static String BuildBitMappedValue (String column, ushort bit, bool match)
|
public static String BuildBitMappedValue(String column, ushort bit, bool match)
|
||||||
{
|
{
|
||||||
// Filter clause to test for specific bit set in field.
|
// Filter clause to test for specific bit set in field.
|
||||||
String clause = String.Empty;
|
String clause = String.Empty;
|
||||||
@@ -627,7 +632,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
if (bit > 0 && bit <= 32)
|
if (bit > 0 && bit <= 32)
|
||||||
{
|
{
|
||||||
// The operation depends on whether the value should be matched or not.
|
// The operation depends on whether the value should be matched or not.
|
||||||
String condition = (match? "<>" : "=");
|
String condition = (match ? "<>" : "=");
|
||||||
// Test is achieved by shifting the value so as to drop the target bit, shift back one bit
|
// Test is achieved by shifting the value so as to drop the target bit, shift back one bit
|
||||||
// and identify those value that then do not match the original value shifted by one place less.
|
// and identify those value that then do not match the original value shifted by one place less.
|
||||||
// Example match: abcdefgh, Test bit 3: abcde0 <> abcdef
|
// Example match: abcdefgh, Test bit 3: abcde0 <> abcdef
|
||||||
@@ -651,7 +656,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
return clause;
|
return clause;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String BuildBitMappedFilter (String column, ushort bit, bool match)
|
public static String BuildBitMappedFilter(String column, ushort bit, bool match)
|
||||||
{
|
{
|
||||||
String clause = BuildBitMappedValue(column, bit, match);
|
String clause = BuildBitMappedValue(column, bit, match);
|
||||||
if (!clause.IsEmpty())
|
if (!clause.IsEmpty())
|
||||||
@@ -662,10 +667,25 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
return clause;
|
return clause;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// S o r t C o l u m n s
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public static String GetRandomOrderSortColumn()
|
||||||
|
{
|
||||||
|
return GetRandomOrderSortColumn(DbGlobalDbms.Type);
|
||||||
|
}
|
||||||
|
public static String GetRandomOrderSortColumn(DbmsType dbms)
|
||||||
|
{
|
||||||
|
if (dbms == DbmsType.MsSql)
|
||||||
|
return "NewId()";
|
||||||
|
// ToDo: Random sort order by DBMS.
|
||||||
|
return "Random()";
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// A t t r i b u t e s
|
// A t t r i b u t e s
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
public void Clear ()
|
public void Clear()
|
||||||
{
|
{
|
||||||
Tables.Clear();
|
Tables.Clear();
|
||||||
Columns.Clear();
|
Columns.Clear();
|
||||||
@@ -674,7 +694,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
OrderBy.Clear();
|
OrderBy.Clear();
|
||||||
Joins.Clear();
|
Joins.Clear();
|
||||||
}
|
}
|
||||||
public bool IsValid ()
|
public bool IsValid()
|
||||||
{
|
{
|
||||||
return (Tables.Count > 0);
|
return (Tables.Count > 0);
|
||||||
}
|
}
|
||||||
@@ -682,7 +702,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// B u i l d Q u e r y
|
// B u i l d Q u e r y
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
public String BuildQuery (Paging paging = null)
|
public String BuildQuery(Paging paging = null)
|
||||||
{
|
{
|
||||||
if (Tables.Count < 1) return "";
|
if (Tables.Count < 1) return "";
|
||||||
|
|
||||||
@@ -696,7 +716,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// Add the tables and joins.
|
// Add the tables and joins.
|
||||||
String tableAliasOperator = DbGlobalDbms.Type == DbmsType.Sage? " " : " AS ";
|
String tableAliasOperator = DbGlobalDbms.Type == DbmsType.Sage ? " " : " AS ";
|
||||||
if (Tables.Count > 1 || Joins.Count < 1)
|
if (Tables.Count > 1 || Joins.Count < 1)
|
||||||
{
|
{
|
||||||
query += " FROM " + Tables.Concat(tableAliasOperator, false).Concat(",") + " " + Joins.BuildJoins("");
|
query += " FROM " + Tables.Concat(tableAliasOperator, false).Concat(",") + " " + Joins.BuildJoins("");
|
||||||
@@ -710,7 +730,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// Filters.
|
// Filters.
|
||||||
String filter = Filters.Concat (" AND ", "(", ")", true, true);
|
String filter = Filters.Concat(" AND ", "(", ")", true, true);
|
||||||
// Jan2019 Not required: if (Filters.Count > 1) filter = "(" + filter + ")";
|
// Jan2019 Not required: if (Filters.Count > 1) filter = "(" + filter + ")";
|
||||||
if (!filter.IsEmpty()) query += " WHERE " + filter;
|
if (!filter.IsEmpty()) query += " WHERE " + filter;
|
||||||
|
|
||||||
@@ -728,9 +748,9 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
// Must have an 'Order By' clause to use 'Offset ... Fetch Next ...'
|
// Must have an 'Order By' clause to use 'Offset ... Fetch Next ...'
|
||||||
if (orderByData.IsEmpty())
|
if (orderByData.IsEmpty())
|
||||||
throw new NotSupportedException("Query paging requires sort order to be specified");
|
throw new NotSupportedException("Query paging requires sort order to be specified");
|
||||||
if (DbGlobalDbms.Type != DbmsType.MsSql)
|
if (DbGlobalDbms.Type == DbmsType.MsSql)
|
||||||
throw new NotSupportedException("Query paging only supported for MS SQL");
|
query += " OFFSET " + ((paging.PageNo - 1) * paging.PageLength) + " ROWS FETCH NEXT " + paging.PageLength + " ROWS ONLY";
|
||||||
query += " OFFSET " + ((paging.PageNo - 1) * paging.PageLength) + " ROWS FETCH NEXT " + paging.PageLength + " ROWS ONLY";
|
else throw new NotSupportedException($"Query paging not supported for {DbGlobalDbms.Type}");
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
FoxPro,
|
FoxPro,
|
||||||
Paradox,
|
Paradox,
|
||||||
Interbase,
|
Interbase,
|
||||||
|
Postgres,
|
||||||
/// <summary>Sage db - No 'AS' in table alias, no 'OUTER' in join type.</summary>
|
/// <summary>Sage db - No 'AS' in table alias, no 'OUTER' in join type.</summary>
|
||||||
Sage,
|
Sage,
|
||||||
QBooks,
|
QBooks,
|
||||||
|
|||||||
@@ -7,11 +7,11 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CsvHelper" Version="19.0.0" />
|
<PackageReference Include="CsvHelper" Version="19.0.0" />
|
||||||
<PackageReference Include="MailKit" Version="4.7.0" />
|
<PackageReference Include="MailKit" Version="4.7.1.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
|
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
|
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
|
||||||
<PackageReference Include="ZstdNet" Version="1.4.5" />
|
<PackageReference Include="ZstdNet" Version="1.4.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
|||||||
public class TableClassConfig
|
public class TableClassConfig
|
||||||
{
|
{
|
||||||
/// <summary>Using namespaces for table classes.</summary>
|
/// <summary>Using namespaces for table classes.</summary>
|
||||||
public HashSet<String> Usings { get; } = new HashSet<String>() { "Sarand.Net.Standard.Base.Core", "Sarand.Net.Standard.Base.Dbas" };
|
public HashSet<String> Usings { get; } = new HashSet<String>() { "Sarand.Net.Standard.Base.App", "Sarand.Net.Standard.Base.Core", "Sarand.Net.Standard.Base.Dbas" };
|
||||||
public String Namespace_BaseClass { get; set; } = "Sarand.Net.Standard.Dbas.Data";
|
public String Namespace_BaseClass { get; set; } = "Sarand.Net.Standard.Dbas.Data";
|
||||||
public String Namespace { get; set; } = "Sarand.Application.Dbas";
|
public String Namespace { get; set; } = "Sarand.Application.Dbas";
|
||||||
public String BaseClass { get; set; } = "DbDataItem";
|
public String BaseClass { get; set; } = "DbDataItem";
|
||||||
@@ -672,6 +672,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
|||||||
file.WriteLine(tab2 + "// Existing columns - confirmed on database if table exists.");
|
file.WriteLine(tab2 + "// Existing columns - confirmed on database if table exists.");
|
||||||
file.WriteLine(tab2 + "public List<String> ExistingColumnNames { get { return GetExistingColumnNames(Fields); } }");
|
file.WriteLine(tab2 + "public List<String> ExistingColumnNames { get { return GetExistingColumnNames(Fields); } }");
|
||||||
file.WriteLine(tab2 + "public List<String> ExistingColumnNamesNonId { get { return GetExistingColumnNames(FieldsNonId); } }");
|
file.WriteLine(tab2 + "public List<String> ExistingColumnNamesNonId { get { return GetExistingColumnNames(FieldsNonId); } }");
|
||||||
|
file.WriteLine(tab2 + "public List<String> UpdatableColumns { get { return ExistingColumnNamesNonId.Where(item => !fieldsPrimary.ContainsCI(item) && !fieldsIgnoreOnUpdate.ContainsCI(item)).ToList(); } }");
|
||||||
|
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
// Population.
|
// Population.
|
||||||
@@ -787,7 +788,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
|||||||
// Construct update command.
|
// Construct update command.
|
||||||
file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------");
|
file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------");
|
||||||
file.WriteLine(tab2 + "// Update command.");
|
file.WriteLine(tab2 + "// Update command.");
|
||||||
file.WriteLine(tab2 + "public override bool ExecuteUpdateCommand (DbCommand dbCommand)");
|
file.WriteLine(tab2 + "public override bool ExecuteUpdateCommand (DbCommand dbCommand, List<String> columnsToUpdate = null)");
|
||||||
file.WriteLine(tab2 + "{");
|
file.WriteLine(tab2 + "{");
|
||||||
if (!String.IsNullOrEmpty(identityColumnName))
|
if (!String.IsNullOrEmpty(identityColumnName))
|
||||||
{
|
{
|
||||||
@@ -795,7 +796,12 @@ namespace Sarand.Net.Standard.Dbas.Base
|
|||||||
file.WriteLine(tab3 + "if (_" + identityColumnName + " == 0) throw new Exception(\"Invalid for Update - item has an invalid Id\"); ");
|
file.WriteLine(tab3 + "if (_" + identityColumnName + " == 0) throw new Exception(\"Invalid for Update - item has an invalid Id\"); ");
|
||||||
}
|
}
|
||||||
file.WriteLine(tab3 + "// Columns to update.");
|
file.WriteLine(tab3 + "// Columns to update.");
|
||||||
file.WriteLine(tab3 + "List<String> columnNames = ExistingColumnNamesNonId.Where(item => !fieldsPrimary.ContainsCI(item) && !fieldsIgnoreOnUpdate.ContainsCI(item)).ToList();");
|
file.WriteLine(tab3 + "List<String> columnNames = (columnsToUpdate?.Any() ?? false ? columnsToUpdate : UpdatableColumns).Where(col => UpdatableColumns.ContainsCI(col)).ToList();");
|
||||||
|
file.WriteLine(tab3 + "if (!columnNames.Any())");
|
||||||
|
file.WriteLine(tab3 + "{");
|
||||||
|
file.WriteLine(tab4 + "SaLogger.Warn($\"{SysUtil.Fn} No columns to update. [{GetType().Name}]\");");
|
||||||
|
file.WriteLine(tab4 + "return false;");
|
||||||
|
file.WriteLine(tab3 + "}");
|
||||||
file.WriteLine(tab3 + "// Construct query.");
|
file.WriteLine(tab3 + "// Construct query.");
|
||||||
file.WriteLine(tab3 + "String query = \"UPDATE \" + TableNameFmt + \" SET \";");
|
file.WriteLine(tab3 + "String query = \"UPDATE \" + TableNameFmt + \" SET \";");
|
||||||
List<String> columnsValuesToUpdate = new List<String>();
|
List<String> columnsValuesToUpdate = new List<String>();
|
||||||
|
|||||||
@@ -590,7 +590,14 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Database updates via ODBC Command.
|
// Database updates via ODBC Command.
|
||||||
public abstract bool ExecuteInsertCommand(DbCommand dbCommand);
|
public abstract bool ExecuteInsertCommand(DbCommand dbCommand);
|
||||||
public abstract bool ExecuteUpdateCommand(DbCommand dbCommand);
|
public virtual bool ExecuteUpdateCommand(DbCommand dbCommand)
|
||||||
|
{
|
||||||
|
return ExecuteUpdateCommand(dbCommand, null);
|
||||||
|
}
|
||||||
|
public virtual bool ExecuteUpdateCommand(DbCommand dbCommand, List<String> columns = null)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException($"ExecuteUpdateCommand(dbCmd,cols) not overridden. [{GetType().Name}]");
|
||||||
|
}
|
||||||
//public abstract bool ExecuteDeleteCommand (DbCommand dbCommand);
|
//public abstract bool ExecuteDeleteCommand (DbCommand dbCommand);
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
}
|
}
|
||||||
catch (Exception exc)
|
catch (Exception exc)
|
||||||
{
|
{
|
||||||
SaLogger.Error(SysUtil.Fn + " " + ExceptionUtil.GetLogMessage(exc) + "\n\tQuery: " + query, true);
|
SaLogger.Error($"{SysUtil.Fn} {ExceptionUtil.GetLogMessage(exc)}\nQuery:\n\t{String.Join("\n\t", query.ReplaceAll("\n\r", "\n").Split("\n"))}", true);
|
||||||
SetErrorState(exc.Message);
|
SetErrorState(exc.Message);
|
||||||
}
|
}
|
||||||
return new DbDataTable(dataTable);
|
return new DbDataTable(dataTable);
|
||||||
@@ -213,7 +213,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
}
|
}
|
||||||
catch (Exception exc)
|
catch (Exception exc)
|
||||||
{
|
{
|
||||||
SaLogger.Error(SysUtil.Fn + " " + ExceptionUtil.GetLogMessage(exc) + "\n\tQuery: " + query, true);
|
SaLogger.Error($"{SysUtil.Fn} {ExceptionUtil.GetLogMessage(exc)}\nQuery:\n\t{String.Join("\n\t", query.ReplaceAll("\n\r", "\n").Split("\n"))}", true);
|
||||||
SetErrorState(exc.Message);
|
SetErrorState(exc.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -241,7 +241,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
}
|
}
|
||||||
catch (Exception exc)
|
catch (Exception exc)
|
||||||
{
|
{
|
||||||
SaLogger.Error(SysUtil.Fn + " " + ExceptionUtil.GetLogMessage(exc) + "\n\tQuery: " + query, true);
|
SaLogger.Error($"{SysUtil.Fn} {ExceptionUtil.GetLogMessage(exc)}\nQuery:\n\t{String.Join("\n\t", query.ReplaceAll("\n\r", "\n").Split("\n"))}", true);
|
||||||
SetErrorState(exc.Message);
|
SetErrorState(exc.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -270,7 +270,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
}
|
}
|
||||||
catch (Exception exc)
|
catch (Exception exc)
|
||||||
{
|
{
|
||||||
SaLogger.Error(SysUtil.Fn + " " + ExceptionUtil.GetLogMessage(exc) + "\n\tQuery: " + query, true);
|
SaLogger.Error($"{SysUtil.Fn} {ExceptionUtil.GetLogMessage(exc)}\nQuery:\n\t{String.Join("\n\t", query.ReplaceAll("\n\r", "\n").Split("\n"))}", true);
|
||||||
SetErrorState(exc.Message);
|
SetErrorState(exc.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -297,7 +297,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
}
|
}
|
||||||
catch (Exception exc)
|
catch (Exception exc)
|
||||||
{
|
{
|
||||||
SaLogger.Error(SysUtil.Fn + " " + ExceptionUtil.GetLogMessage(exc) + "\n\tQuery: " + query, true);
|
SaLogger.Error($"{SysUtil.Fn} {ExceptionUtil.GetLogMessage(exc)}\nQuery:\n\t{String.Join("\n\t", query.ReplaceAll("\n\r", "\n").Split("\n"))}", true);
|
||||||
SetErrorState(exc.Message);
|
SetErrorState(exc.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
|
<PackageReference Include="DocumentFormat.OpenXml" Version="3.1.0" />
|
||||||
<PackageReference Include="NPOI" Version="2.7.0" />
|
<PackageReference Include="NPOI" Version="2.7.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user