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();
|
||||
/// <summary>Sort columns.</summary>
|
||||
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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
|
||||
namespace Sarand.Net.Standard.Base.Bus
|
||||
@@ -57,6 +61,20 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
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());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
|
||||
@@ -265,6 +265,11 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
public uint PageNo { get; set; } = 0;
|
||||
public ushort PageLength { get; set; } = 0;
|
||||
public virtual bool Paged { get { return PageNo > 0 && PageLength > 0; } }
|
||||
public void Set(uint pageNo, ushort pageLength)
|
||||
{
|
||||
this.PageNo = pageNo;
|
||||
this.PageLength = pageLength;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
@@ -662,6 +667,21 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
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
|
||||
//-------------------------------------------------------------------
|
||||
@@ -728,9 +748,9 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
// Must have an 'Order By' clause to use 'Offset ... Fetch Next ...'
|
||||
if (orderByData.IsEmpty())
|
||||
throw new NotSupportedException("Query paging requires sort order to be specified");
|
||||
if (DbGlobalDbms.Type != DbmsType.MsSql)
|
||||
throw new NotSupportedException("Query paging only supported for MS SQL");
|
||||
if (DbGlobalDbms.Type == DbmsType.MsSql)
|
||||
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,
|
||||
Paradox,
|
||||
Interbase,
|
||||
Postgres,
|
||||
/// <summary>Sage db - No 'AS' in table alias, no 'OUTER' in join type.</summary>
|
||||
Sage,
|
||||
QBooks,
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
<ItemGroup>
|
||||
<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.StaticFiles" Version="2.2.0" />
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
public class TableClassConfig
|
||||
{
|
||||
/// <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 { get; set; } = "Sarand.Application.Dbas";
|
||||
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 + "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> UpdatableColumns { get { return ExistingColumnNamesNonId.Where(item => !fieldsPrimary.ContainsCI(item) && !fieldsIgnoreOnUpdate.ContainsCI(item)).ToList(); } }");
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// Population.
|
||||
@@ -787,7 +788,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
// Construct update command.
|
||||
file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------");
|
||||
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 + "{");
|
||||
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 + "// 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 + "String query = \"UPDATE \" + TableNameFmt + \" SET \";");
|
||||
List<String> columnsValuesToUpdate = new List<String>();
|
||||
|
||||
@@ -590,7 +590,14 @@ namespace Sarand.Net.Standard.Dbas.Data
|
||||
//-------------------------------------------------------------------
|
||||
// Database updates via ODBC Command.
|
||||
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);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
@@ -190,7 +190,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
||||
}
|
||||
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);
|
||||
}
|
||||
return new DbDataTable(dataTable);
|
||||
@@ -213,7 +213,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -241,7 +241,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -270,7 +270,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -297,7 +297,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
|
||||
<PackageReference Include="NPOI" Version="2.7.0" />
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.1.0" />
|
||||
<PackageReference Include="NPOI" Version="2.7.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user