示例#1
0
        public int findCount(QueryBuilder.Where wh = null)
        {
            QueryBuilder.Select select = new QueryBuilder.Select(this.table);
            select.addField("COUNT(1) AS C");
            if (wh != null)
            {
                select.setWhere(wh);
            }


            var group_records = db.select(select.get());

            int c = 0;

            if (group_records.Count > 0)
            {
                var records = group_records["0"];
                if (records.Count > 0)
                {
                    var record = records[0];
                    c = int.Parse(record["C"].ToString());
                }
            }

            return(c);
        }
示例#2
0
        public Dictionary <String, List <Dictionary <String, Object> > > find(QueryBuilder.Select select)
        {
            this.beforeFind(select);
            var q = select.get();

            var records = db.select(q);

            return(records);
        }
示例#3
0
        public bool insertOrUpdate(SortedDictionary <Object, Object> record)
        {
            this.setData(record);

            QueryBuilder.Where wh = new QueryBuilder.Where();

            if (this.uniqueFields.Count == 0)
            {
                throw new Exception("Unique Fields are empty");
            }

            foreach (String field in this.uniqueFields)
            {
                if (!this.data.ContainsKey(field))
                {
                    throw new Exception(field + " not found in record");
                }

                wh.add(field, this.data[field]);
            }

            QueryBuilder.Select s = new QueryBuilder.Select(this.table);
            s.addField(this.primaryField);
            s.setWhere(wh);

            long id            = 0;
            var  group_records = this.find(s);

            if (group_records.Count > 0)
            {
                var records = group_records[this.table];

                if (records.Count > 0)
                {
                    var r = records[0];
                    id = long.Parse(r[this.primaryField].ToString());
                }
            }

            if (id > 0)
            {
                return(this.update(record, id));
            }
            else
            {
                return(this.insert(record));
            }
        }
示例#4
0
 public Join(Model m, String f, QueryBuilder.Select s) : this(m, f)
 {
     this.select = s;
 }
示例#5
0
 protected void beforeFind(QueryBuilder.Select select)
 {
 }