예제 #1
0
        private void RenameColumnAlias(ColumnAlias col, int slnMode, string renameFormat, int cntRepetition)
        {
            const int    limitColumnLen = 30;
            const string finalNoFmt     = "{0}${1}";
            string       tryName;

            switch (slnMode)
            {
            case 0:                             // Try to use just the ColumnName directly
                break;

            case 1:                             // Try to use "TableName$ColumnName" if the total length <= 30 (for compatibility Oracle)
                tryName = string.Format(renameFormat, col.TableName, col.ColumnName);
                if (tryName.Length <= limitColumnLen)
                {
                    col.Alias = tryName;
                }
                break;

            case 2:                             // Try to use "TableAlias$ColumnName"
                col.Alias = string.Format(renameFormat, col.TableAlias, col.ColumnName);
                break;

            case 3:                             // Reset Column Alias for slnMode 4
                col.Alias = null;
                break;

            case 4:                             // Still not been solved by above, Rename as "ColumnName$123" ...
                col.Alias = string.Format(finalNoFmt, col.ColumnName, cntRepetition);
                break;
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ce"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static ColumnReference Interpret(ColumnExpression ce)
        {
            var exp = ce.FindDescendant <Expression>();

            var cr = new ColumnReference();

            if (exp.IsSingleColumn)
            {
                cr.isComplexExpression = false;
                cr = Interpret(exp.FindDescendantRecursive <ColumnIdentifier>());
            }
            else
            {
                cr.isComplexExpression = true;
            }

            ColumnAlias ca = ce.FindDescendant <ColumnAlias>();

            if (ca != null)
            {
                cr.columnAlias = ca.Value;
            }

            cr.columnExpression = ce;

            return(cr);
        }
예제 #3
0
 public override string ToString()
 {
     if (ColumnAlias.HasValue())
     {
         return($"SqlExpression.Number({Value}), {ColumnAlias.Quoted()}");
     }
     else
     {
         return($"SqlExpression.Number({Value})");
     }
 }
예제 #4
0
 public override string ToString()
 {
     if (ToStringUseExpression || ColumnAlias.HasValue())
     {
         return($"SqlExpression.Null(), {ColumnAlias.Quoted()}");
     }
     else
     {
         return("SqlExpression.Null()");
     }
 }
예제 #5
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = (PropertyFragment != null ? PropertyFragment.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (TableName != null ? TableName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ColumnName != null ? ColumnName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ColumnAlias != null ? ColumnAlias.GetHashCode() : 0);
         return(hashCode);
     }
 }
        public QueryIdentifier CreateColumnAlias(string path)
        {
            if (ColumnAlias.ContainsKey(path))
            {
                return(ColumnAlias[path]);
            }

            var alias = CreateAlias(QueryIdentifier.QueryIdTypes.Column);

            ColumnAlias.Add(path, alias);
            return(alias);
        }
예제 #7
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            string getFinalSqlStr = GetBinarySql(this);

            if (ColumnAlias.HasValue())
            {
                sb.Append($"SqlExpression.Raw(\"{getFinalSqlStr}\"), {ColumnAlias.Quoted()}");
            }
            else
            {
                sb.Append($"SqlExpression.Raw(\"{getFinalSqlStr}\")");
            }

            return(sb.ToString());
        }
예제 #8
0
 public override string ToString()
 {
     if (ToStringUseExpression)
     {
         return($"SqlExpression.Field({ColumnName.Quoted()}{(Table != null ? ", " + Table.ToString() : string.Empty)})");
     }
     else
     {
         if (Table == null && ColumnAlias.HasValue())
         {
             return($"SqlExpression.Field({ColumnName.Quoted()}){(ColumnAlias.HasValue() ? ", " + ColumnAlias.Quoted() : string.Empty)}");
         }
         else
         {
             return($"{ColumnName.Quoted()}{(Table != null ? ", " + Table.ToString() : string.Empty)}{(ColumnAlias.HasValue() ? ", " + ColumnAlias.Quoted() : string.Empty)}");
         }
     }
 }
예제 #9
0
        public override string ToString()
        {
            string tmpColumnName = ColumnName.Quoted();
            string fieldExpression;

            if (!tmpColumnName.HasValue())   // A literal may have been used
            {
                int intLiteral;
                if (int.TryParse(Convert.ToString(Value), out intLiteral))
                {
                    fieldExpression = $"SqlExpression.Number({Value})";
                }
                else
                {
                    fieldExpression = $"SqlExpression.String({Value.ToString().Quoted()})";
                }
            }
            else
            {
                fieldExpression = $"SqlExpression.Field({ColumnName.Quoted()}{(Table != null ? ", " + Table.ToString() : string.Empty)})";
            }

            if (ToStringUseExpression)
            {
                return($"SqlExpression.Function(SqlAggregationFunction.{Function.ToString()}, {fieldExpression})");
            }
            else
            {
                if (!ColumnAlias.HasValue())
                {
                    ColumnAlias = "col" + GetNextID();
                }

                if (Table == null)
                {
                    return($"SqlExpression.Function(SqlAggregationFunction.{Function.ToString()}, {fieldExpression}){(ColumnAlias.HasValue() ? ", " + ColumnAlias.Quoted() : string.Empty)}");
                }
                else
                {
                    return($"{ColumnName.Quoted()}{(Table != null ? ", " + Table.ToString() : string.Empty)}{(ColumnAlias.HasValue() ? ", " + ColumnAlias.Quoted() : string.Empty)}, SqlAggregationFunction.{Function.ToString()}");
                }
            }
        }
예제 #10
0
 public virtual ColumnAlias Put(ColumnAlias columnAlias)
 {
     _columnAliasCommands.ActiveUser = Models.ApiContext.ActiveUser;
     return(_columnAliasCommands.Put(columnAlias));
 }
예제 #11
0
        public override string ToString()
        {
            string columnSqlOm;

            // Always use Coalesce
            //if (Columns.Count > 2) {
            string[] columnValues = new string[Columns.Count];

            for (int i = 0; i < Columns.Count; i++)
            {
                if (Columns[i] is gsFieldColumn)
                {
                    if (Columns[i].Table != null)
                    {
                        columnValues[i] = string.Concat(Columns[i].Table.TableName, ".", Columns[i].ColumnName);
                    }
                    else
                    {
                        columnValues[i] = Columns[i].ColumnName;
                    }
                }
                else if (Columns[i] is gsNumberColumn)
                {
                    columnValues[i] = Convert.ToString(Columns[i].Value);
                }
                else if (Columns[i] is gsStringColumn)
                {
                    columnValues[i] = string.Concat("'", Columns[i].Value, "'");
                }
                else
                {
                    throw new NotImplementedException($"Coalesce {Columns[i].GetType().Name} not supported");
                }
            }

            columnSqlOm = $"SqlExpression.Raw(\"COALESCE({(string.Join(", ", columnValues))})\"), {ColumnAlias.Quoted()}";
            //}
            //else {
            //    Columns.ForEach(col => col.ToStringUseExpression = true);
            //    columnSqlOm = $"SqlExpression.IfNull({Columns[0].ToString()}, {Columns[1].ToString()}), {ColumnAlias.Quoted()}";
            //}

            return(columnSqlOm);
        }