Exemple #1
0
        /// <summary>
        /// Build database SQL query clause for one criterion.
        /// Assumes field is date.
        /// </summary>
        /// <param name="prefix">operator to precede clause, e.g. "AND"</param>
        /// <param name="sf">StationField which describes the desired field</param>
        /// <param name="c"></param>
        /// <returns>empty string if c is null</returns>
        public static string AddSqlDateClause(string prefix, StationField sf, Criterion c)
        {
            string clause = "";
            if (c != null)
            {
                clause = " " + prefix + " ";
                if (c.IsUnaryOperator())
                {
                    clause += SqlUnaryOperation(c, sf);
                }
                else
                { // binary operator
                    // TODO Idea: recognize keyword like "TODAY", would require a special clause

                    // TODO "equals" for date doesn't work -- need to compare only the date,
                    //     not the time (or adjust the end time to 11:59:59)

                    clause += sf.Location + " ";
                    clause += SqlBinaryOperator(c.Operation) +
                        " TO_DATE('" + c.Value + "','" + SqlDateFormat(c.Value) + "') ";
                }
            }
            return clause;
        }
Exemple #2
0
 /// <summary>
 /// Build database SQL query clause for one criterion.
 /// Assumes field is numeric.
 /// </summary>
 /// <param name="prefix">operator to precede clause, e.g. "AND"</param>
 /// <param name="sf">StationField which describes the desired field</param>
 /// <param name="c"></param>
 /// <returns>empty string if c is null</returns>
 public static string AddSqlNumberClause(string prefix, StationField sf, Criterion c)
 {
     string clause = "";
     if (c != null)
     {
         clause = " " + prefix + " ";
         if (c.IsUnaryOperator())
         {
             clause += SqlUnaryOperation(c, sf);
         }
         else
         { // binary operator
             clause += sf.Location + " ";
             clause += SqlBinaryOperator(c.Operation) +
                 // still use quotes in case it's not really a number field
                 // or the operator is "LIKE"
                     " '" + c.Value + "' ";
         }
     }
     return clause;
 }
Exemple #3
0
 /// <summary>
 /// Build SQL clause for unary operation, for text fields.
 /// </summary>
 /// <returns>clause like " (COLUMN is null OR TRIM(COLUMN) = '') "</returns>
 private static string SqlUnaryTextOperation(Criterion c, StationField sf)
 {
     if (c == null || sf == null) return "";
     string clause;
     string column = sf.Location;
     if (c.Operation == (Criterion.Empty))
     {
         clause = " (" + column + " is null OR TRIM(" + column + ") = '') ";
     }
     else if (c.Operation == (Criterion.NotEmpty))
     {
         clause = " (" + column + " is not null AND TRIM(" + column + ") <> '') ";
     }
     else
     {
         throw new Exception("unrecognized unary operation: " + c.Operation);
     }
     return clause;
 }
Exemple #4
0
 /// <summary>
 /// Build database SQL query clause for one criterion.
 /// Assumes field is string or string-compatible.
 /// </summary>
 /// <param name="prefix">operator to precede clause, e.g. "AND"</param>
 /// <param name="sf">StationField which describes the desired field</param>
 /// <param name="c"></param>
 /// <returns>empty string if c is null</returns>
 public static string AddSqlTextClause(string prefix, StationField sf, Criterion c)
 {
     string clause = "";
     if (c != null)
     {
         clause = " " + prefix + " ";
         if (c.IsUnaryOperator())
         {
             clause += SqlUnaryTextOperation(c, sf);
         }
         else
         { // binary operator
             clause += sf.Location + " ";
             clause += SqlBinaryOperator(c.Operation) +
                        " '" + c.Value + "' ";
         }
     }
     return clause;
 }
        protected virtual List<StationEntity> LoadStationEntities(ConfigData configData)
        {
            var entitiesList = new List<StationEntity>();
            var entityConfigs = configData.GetConfigSections(Constants.StationEntity);
            foreach (var entityConfig in entityConfigs)
            {
                var entityName = entityConfig.RequiredValue(Constants.StationEntityName);
                var entity = new StationEntity(entityName);
                var entityLocation = entityConfig.Value(Constants.StationEntityLocation);
                entity.Location = (entityLocation);
                var fieldConfigs = entityConfig.GetConfigSections(Constants.StationField);
                foreach (var fieldConfig in fieldConfigs)
                {
                    var field = new StationField(fieldConfig.RequiredValue(Constants.StationFieldName));
                    field.Type = (fieldConfig.RequiredValue(Constants.StationFieldType));

                    // if location is empty, just use field name as default location
                    var location = fieldConfig.Value(Constants.StationFieldLocation);
                    if (location == null) location = field.Name;
                    field.Location = (location);

                    field.Level = (fieldConfig.IntValue(Constants.StationFieldLevel));
                    // TODO set other field properties -  referredEntity, referredEntityField
                    entity.AddField(field);
                }
                var sortField = entityConfig.Value(Constants.StationEntitySortField);
                if (sortField != null)
                {
                    entity.SortField = (sortField);
                    var sortOrder = entityConfig.Value(Constants.StationEntitySortOrder);
                    if (sortOrder != null && sortOrder.ToUpper().StartsWith("DESC"))
                    {
                        entity.DescendingSort = (true);
                    }
                }
                entitiesList.Add(entity);
            }
            return entitiesList;
        }
Exemple #6
0
        public void AddField(StationField field)
        {
            fields.Add(field);

            int? lev = field.Level;
            if (lev != null && lev == 1)
            {
                summaryFields.Add(field);
            }
        }