From 90fc9811a6fd2235b74eee1032a0c8d92f873153 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 16 Jan 2020 00:06:27 +0000 Subject: [PATCH] --- server/AyaNova/biz/ObjectFields.cs | 35 +++++++++++++++++++++++++- server/AyaNova/biz/SqlSelectBuilder.cs | 23 +++-------------- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/server/AyaNova/biz/ObjectFields.cs b/server/AyaNova/biz/ObjectFields.cs index 0fd976a8..60749351 100644 --- a/server/AyaNova/biz/ObjectFields.cs +++ b/server/AyaNova/biz/ObjectFields.cs @@ -61,7 +61,10 @@ namespace AyaNova.Biz TODO: going to need some SQL hints added here - SqlIDColumn indicating what the ID column is to fetch the underlying value from - SqlColumn indicating an alternative column name as known to the sql server if it varies from the propertyname (in lowercase) + + Also: going to need a definition of the table name and the default identity column Maybe decorate with an INTERNAL ONLY bool so that we see it at the server but not at the client or when fetched as possible fields + hypothetical to help develop this: Client and head office list: {key=ClientName, propertyname=Name, idcolumn=id,} @@ -272,7 +275,7 @@ namespace AyaNova.Biz sb.Append($",\"ay\":{(int)o.AyObjectType}"); sb.Append("}"); - + } } sb.Append("]"); @@ -301,6 +304,11 @@ namespace AyaNova.Biz //then the type to open is set here public int AyObjectType { get; set; } + //For query building + //This is the equivalent of the v7 SqlColumnNameAttribute + public string SqlIdColumn { get; set; } + public string SqlColumn { get; set; } + public ObjectField() { @@ -313,6 +321,31 @@ namespace AyaNova.Biz MiniAvailable = true; //Set openable object type to no type which is the default and means it's not a link to another object AyObjectType = (int)AyaType.NoType; + + } + + public string GetSqlColumnName() + { + if (string.IsNullOrEmpty(SqlColumn)) + { + return PropertyName.ToLowerInvariant(); + } + else + { + return SqlColumn; + } + } + + public string GetSqlIdColumnName() + { + if (string.IsNullOrEmpty(SqlIdColumn)) + { + return "id"; + } + else + { + return SqlIdColumn; + } } } diff --git a/server/AyaNova/biz/SqlSelectBuilder.cs b/server/AyaNova/biz/SqlSelectBuilder.cs index 74dce8e5..728a195b 100644 --- a/server/AyaNova/biz/SqlSelectBuilder.cs +++ b/server/AyaNova/biz/SqlSelectBuilder.cs @@ -40,30 +40,13 @@ namespace AyaNova.Biz foreach (string ColumnName in templateFieldList) { + //NOPE, NOPE, NOPE....rather than this, it needs to get the names by consulting the ObjectFields list which may contain overrides for the sql name etc sb.Append(ColumnName); } - //iterate the datafilter and concatenate a sql query from it - var SortArray = JArray.Parse(dataFilter.Sort); - for (int i = 0; i < SortArray.Count; i++) - { + - var SortItem = SortArray[i]; - var fld = SortItem["fld"].Value(); - var dir = SortItem["dir"].Value(); - - sb.Append(" "); - sb.Append(fld); - sb.Append(" "); - sb.Append(dir == "+" ? "ASC" : "DESC"); - - if (i < SortArray.Count - 1) - { - sb.Append(","); - } - } - - return " ORDER BY" + sb.ToString(); + return sb.ToString(); }