Beispiel #1
0
        protected Dictionary <string, object> RetrieveObject(string[] key, Dictionary <string, Dictionary <string, Field> > fields, Dictionary <string, FilterSet> filters, List <string> tables)
        {
            if (key == null)
            {
                return(null);
            }
            string table = tables[0];
            string sql   = "SELECT ";

            sql += "\"" + String.Join("\",\"", fields[table].Keys) + "\"";
            sql += " FROM \"!\"";
            object[] parameters = new object[] { (object)table };
            if (!filters.ContainsKey(table))
            {
                filters[table] = new FilterSet();
            }
            if (filters [table].Or == null)
            {
                FilterSet f = filters [table];
                f.Or            = new List <Filter>();
                filters [table] = f;
            }
            filters[table].Or.Add(new Filter()
            {
                Field = key[1], Comparator = "=", Value = key[0]
            });
            AddWhereFromFilters(filters[table], ref sql, ref parameters);
            Dictionary <string, object> obj = null;
            IDataReader reader = _db.Query(sql, parameters);

            if (reader.Read())
            {
                obj = _db.FetchAssoc(reader);
                foreach (Field field in fields[table].Values)
                {
                    if (_db.IsBinaryType(field) && obj.ContainsKey(field.Name))
                    {
                        if (obj[field.Name] != DBNull.Value)
                        {
                            obj[field.Name] = Convert.ToBase64String((byte[])obj[field.Name]);
                        }
                    }
                }
                _db.Close(reader);
            }
            return(obj);
        }
Beispiel #2
0
        protected Dictionary <string, FilterSet> ProcessFiltersParameter(List <string> tables, string satisfy, string[] filters)
        {
            Dictionary <string, FilterSet> results = new Dictionary <string, FilterSet> ();
            FilterSet     filterSet = new FilterSet();
            List <Filter> result    = ConvertFilters(filters);

            if (result == null)
            {
                return(results);
            }
            if (satisfy != null && satisfy.ToLower() == "any")
            {
                filterSet.Or = result;
            }
            else
            {
                filterSet.And = result;
            }
            results.Add(tables[0], filterSet);
            return(results);
        }
 protected Dictionary<string, object> RetrieveObject(string[] key,Dictionary<string,Dictionary<string,Field>> fields,Dictionary<string,FilterSet> filters,List<string> tables)
 {
     if (key==null) return null;
     string table = tables[0];
     string sql = "SELECT ";
     sql += "\""+String.Join("\",\"",fields[table].Keys)+"\"";
     sql += " FROM \"!\"";
     object[] parameters = new object[]{ (object)table };
     if (!filters.ContainsKey(table)) filters[table] = new FilterSet();
     if (filters [table].Or == null) {
         FilterSet f = filters [table];
         f.Or = new List<Filter>();
         filters [table] = f;
     }
     filters[table].Or.Add(new Filter(){ Field = key[1], Comparator = "=", Value = key[0] });
     AddWhereFromFilters(filters[table],ref sql,ref parameters);
     Dictionary<string,object> obj = null;
     IDataReader reader = _db.Query(sql,parameters);
     if (reader.Read()) {
         obj = _db.FetchAssoc(reader);
         foreach (Field field in fields[table].Values) {
             if (_db.IsBinaryType(field) && obj.ContainsKey(field.Name)) {
                 if (obj[field.Name]!=DBNull.Value) {
                     obj[field.Name] = Convert.ToBase64String ((byte[])obj[field.Name]);
                 }
             }
         }
         _db.Close(reader);
     }
     return obj;
 }
 protected Dictionary<string, FilterSet> ProcessFiltersParameter(List<string> tables,string satisfy,string[] filters)
 {
     Dictionary<string,FilterSet> results = new Dictionary<string,FilterSet> ();
     FilterSet filterSet = new FilterSet();
     List <Filter> result = ConvertFilters(filters);
     if (result==null) return results;
     if (satisfy!=null && satisfy.ToLower () == "any") filterSet.Or = result;
     else filterSet.And = result;
     results.Add(tables[0],filterSet);
     return results;
 }
 protected void AddWhereFromFilters(FilterSet filters,ref string sql,ref object[] parameters)
 {
     bool first = true;
     List<object> parameterList = new List<object>(parameters);
     if (filters.Or != null) {
         first = false;
         sql += " WHERE (";
         for (int i=0;i<filters.Or.Count;i++) {
             Filter filter = filters.Or[i];
             sql += i==0?"":" OR ";
             sql += "\"!\" ! ?";
             parameterList.Add(filter.Field);
             parameterList.Add(filter.Comparator);
             parameterList.Add(filter.Value);
         }
         sql += ")";
     }
     if (filters.And != null) {
         for (int i=0;i<filters.And.Count;i++) {
             Filter filter = filters.And[i];
             sql += first?" WHERE ":" AND ";
             sql += "\"!\" ! ?";
             parameterList.Add(filter.Field);
             parameterList.Add(filter.Comparator);
             parameterList.Add(filter.Value);
             first = false;
         }
     }
     parameters = parameterList.ToArray();
 }