Exemple #1
0
 /// <summary>
 /// Initialize
 /// </summary>
 /// <param name="returnColumnNames">if null or empty, will select all columns</param>
 public SqlSelectBuilder(SqlFlavorizer sqlFlavor, string mainTable, string sortColName, List <string> returnColumnNames)
 {
     SqlFlavor         = sqlFlavor;
     MainTable         = mainTable;
     SortColumnName    = sortColName;
     ReturnColumnNames = returnColumnNames;
     if (ReturnColumnNames == null || ReturnColumnNames.Count == 0)
     {
         ReturnColumnNames = new[] { "*" }
     }
Exemple #2
0
 public SqlInsertBuilder(SqlFlavorizer sqlFlavor, Func <string, string> sqlCustomizer) : base(sqlFlavor, sqlCustomizer)
 {
 }
Exemple #3
0
 public SqlWriteBuilder(SqlFlavorizer sqlFlavor, Func <string, string> sqlCustomizer)
 {
     SqlFlavor     = sqlFlavor;
     SqlCustomizer = sqlCustomizer;
 }
Exemple #4
0
 public void Initialize(SqlFlavorizer.VendorKind sqlVendor)
 {
     SqlFlavor = new SqlFlavorizer(sqlVendor);
 }
        public void ExportWhereClause(SqlSelectBuilder.Where w, SqlFlavorizer sqlFlavor)
        {
            //numeric ranges
            if (Utils.IsSupportedNumericType(ColDef.CSType))
            {
                try
                {
                    (string lo, string hi) = SplitOnTilde(PackedValue);
                    if (lo != null)
                    {
                        decimal dlo = decimal.Parse(lo);
                        w.AddWhere($"{ColDef.Name}>={w.NextParameterName()}", dlo);
                    }
                    if (hi != null)
                    {
                        decimal dhi = decimal.Parse(hi);
                        w.AddWhere($"{ColDef.Name}<={w.NextParameterName()}", dhi);
                    }
                }
                catch
                {
                    throw new Exception($"Misformatted numeric parameter: {PackedValue}");
                }
            }

            //dates and times
            else if (ColDef.CSType == typeof(DateTime))
            {
                bool isDateOnly = ColDef.WireType == Constants.TYPE_DATE;
                (string lo, string hi) = SplitOnTilde(PackedValue);
                if (lo != null)
                {
                    var dlo = Retrovert.ParseRetroDateTime(lo, isDateOnly);
                    w.AddWhere($"{ColDef.Name}>={w.NextParameterName()}", dlo);
                }
                if (hi != null)
                {
                    var dhi = Retrovert.ParseRetroDateTime(hi, isDateOnly);
                    w.AddWhere($"{ColDef.Name}<={w.NextParameterName()}", dhi);
                }
            }

            else if (ColDef.CSType == typeof(bool))
            {
                bool b;
                if (PackedValue == "0")
                {
                    b = false;
                }
                else if (PackedValue == "1")
                {
                    b = true;
                }
                else
                {
                    throw new Exception($"Boolean parameter must be 0 or 1: {PackedValue}");
                }
                w.AddWhere($"{ColDef.Name}={w.NextParameterName()}", b);
            }

            else if (ColDef.CSType == typeof(string))
            {
                w.AddWhere($"{ColDef.Name} {sqlFlavor.LikeOperator()} {w.NextParameterName()}", sqlFlavor.LikeParamValue(PackedValue));
            }

            else
            {
                throw new Exception($"Type {ColDef.CSType.Name} not supported as a viewon parameter");
            }
        }