Exemplo n.º 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);
        }
Exemplo n.º 2
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));
            }
        }