Ejemplo n.º 1
0
        public DbSlc(Reach smb)
        {
            Db db = new Db(new ctx().DbDrivers);

            init();
            DbSlc ret = new DbGrid(smb.before(-1, ".SL")).SLC;

            smb = smb.after(-1, ".SL");
            if (smb.startsWith("D"))
            {
                ret = ret.DST;
            }
            smb = smb.from(3);
            while (smb.len > 0)
            {
                if (smb.startsWith("DST"))
                {
                    ret = ret.DST; smb = smb.from(5); continue;
                }
                if (smb.startsWith("TOP("))
                {
                    ret = ret.TOP(long.Parse(smb.from(5).before(1, ")").text)); smb = smb.after(1, ")").from(2); continue;
                }
                if (smb.startsWith("ORD("))
                {
                    ret = ret.ORD(smb.from(5).before(1, ")").after(1, "\"").before(1, "\"").text); smb = smb.after(1, ")").from(2); continue;
                }
            }
            this.count  = ret.count;
            this.fields = ret.fields.Clone(); //new Pile<string>(ret.fieldNames);
            this.from   = new KeyPile <string, string>(ret.from);
            this.join   = ret.join.Clone();   //new Pile<Cnd>(ret.join);
            this.where  = ret.where.Clone();  //new Pile<Cnd>(ret.where);
            this.order  = ret.order;
        }
Ejemplo n.º 2
0
 private DbGrid(string type, DbGrid s1, DbGrid s2)
 {
     init();
     this.type = type.ToUpper().Substring(0, 1);
     parts.Push(s1);
     parts.Push(s2);
     if ((parts[1].db != null) && (parts[2].db != null))
     {
         if (parts[1].db != parts[2].db)
         {
             throw new Exception("Unable to merge grids from different data sources in INTERSECT or EXCEPT or UNION");
         }
     }
     if ((parts[1].db == null) || (parts[2].db == null))
     {
         if (parts[2].db == null)
         {
             this.db = parts[1].db;
         }
         else
         {
             this.db = parts[2].db;
         } parts[1].db = this.db; parts[2].db = this.db;
     }
 }
Ejemplo n.º 3
0
        /// <summary> sR ("select Rows") extends the WHERE clause with addinitional AND condition(s).</summary>
        public DbGrid sR(params DbCnd[] restrictions)
        {
            DbGrid ret = new DbGrid(this);

            ret.allFields = ret.fields.Clone(); //new Pile<string> (ret.fieldNames);
            ret.selCnd.Add(restrictions);
            return(ret);
        }
Ejemplo n.º 4
0
        internal DbIns(Reach smb)
        {
            init();
            //TBD
            Db    db        = new Db(new ctx().DbDrivers);
            DbIns ret       = null;
            Zone  bktFilter = new Zone(new Pile <string>(), new Pile <string>("", true, "(", ")", "||:0"));
            Zone  strFilter = new Zone(new Pile <string>(), new Pile <string>("", true, "\"", "\"", "||:1"));

            /*
             * string insstr = "Grid(\"prdrln\").sC(\"sbj, obj, vb, rul, steps, excerpt, trust\").INS(XXXX)";
             * insstr = insstr.Replace("XXXX", "Grid(\"prdrln p1, prdvrb pv1, prdrln p2, prdvrb pv2, kndrln sc, itmrln si, prdvrb pv, prdrul pr, itmrln oi, kndrln oc\", cd(\"p1.obj\").EQ(\"p2.sbj\")).sC(\"si.id, oi.id, pv.id, pr.id, 0, '', 0.5\").sR(XXXX).SLD");
             * insstr = insstr.Replace("XXXX", "cd(\"0\").EQ(Grid(\"prdrln prdrln\").sC(\"count(*)\").sR(cd(\"sbj\").EQ(\"si.id\"), cd(\"obj\").EQ(\"oi.id\"), cd(\"vb\").EQ(\"pr.vb\")).SLC ), XXXX");
             * insstr = bktFilter.on(insstr).text;
             * insstr = insstr.Replace("XXXX", "cd(\"0\").EQ(Grid(\"prdrln prdrln\").sC(\"count(*)\").sR(cd(\"sbj\").EQ(\"si.id\"), cd(\"obj\").EQ(\"oi.id\"), cd(\"vb\").EQ(\"pr.vb\")).SLC ), XXXX");
             */

            Reach gridDef = smb - bktFilter.on(smb);
            Reach ins     = gridDef.at(".INS(");

            if (ins.len == 0)
            {
                throw new Exception("DbIns Constructor: invalid symbolic Definition");
            }
            DbGrid res = db.Grid(smb.before(ins));

            smb = smb.after(ins).before(-1, ")");
            if (smb.startsWith("Grid("))
            {
                ret = res.INS(new DbSlc(smb));
            }
            else
            {
                Pile <string> val = new Pile <string>();
                while (smb.len > 0)
                {
                    if (smb.startsWith("ds("))
                    {
                        val.Push(db.ds(smb.after(1, "\"").before(1, "\""))); smb = smb.after(1, "),").Trim();
                    }
                    else
                    {
                        val.Push(smb.before(1, ",").Trim()); smb = smb.after(1, ",").Trim();
                    }
                }
                ret = res.INS(val.array());
            }
            into   = ret.into;
            fields = ret.fields.Clone(); //new Pile<string>(ret.fieldNames);
            values = ret.values;
            slc    = ret.slc;
        }
Ejemplo n.º 5
0
        public DbGrid sC(params DbField[] fields)
        {
            DbGrid ret = new DbGrid(this);

            ret.fields = new Pile <DbField>();
            foreach (DbField fld in fields)
            {
                ret.fields.Add(fld);
            }
            ret.allFields = ret.fields;
            //if (!fields.Trim().Equals("*")) { ret.fieldNames.clear(); ret.fieldTypes.clear(); while (fields.Trim().Length > 0) { ret.fieldTypes.Add(""); ret.fieldNames.Add(utl.cutl(ref fields, ",").Trim()); } } //AttGeTr: no type information is added for each field !!! / ToBeSolved !!!
            return(ret);
        }
Ejemplo n.º 6
0
        //public Pile<DbObject> dbrGetAll() {Pile<DbObject> ret = new Pile<DbObject>(); foreach(Pile<Reach> row in db.exec(bscTbl.SELECT).Rows) ret.Push(row2Instance(row)); return ret; }

        public DbObj(DbGrid bscTbl, DbGrid vrbTbl)
        {
            init();
            //rows.Push(this);
            this.bscTbl = bscTbl;
            this.vrbTbl = vrbTbl;
            this.db     = bscTbl.Db;
            if (this.db == null)
            {
                this.db = vrbTbl.Db;
            }
            bscTbl.Db = this.db;
            vrbTbl.Db = this.db;
            isDirty   = false;
        }
Ejemplo n.º 7
0
 public DbSlc(DbGrid g)
 {
     init();
     if (g.type.Length == 0)
     {
         init(g.Fields, g.From, g.Join, g.Where);
         //string sql = Db._sql(this);
     }
     else
     {
         type = g.type;
         parts.Push(new DbSlc(g.parts[1]));
         parts.Push(new DbSlc(g.parts[2]));
     }
 }
Ejemplo n.º 8
0
        public void addTables(string tables)
        {
            tables = tables.Trim();
            while (tables.Length > 0)
            {
                string tableShort = utl.cutl(ref tables, ",").Trim().ToLower();
                tables = tables.Trim();
                string tableName = utl.cutl(ref tableShort, " ").Trim().ToLower();
                if (tableShort.Length == 0)
                {
                    tableShort = tableName;
                }
                //if ((this.tables.Len() == 0) && (tables.Length == 0)) {this.Name = tableName; this.Short = tableShort;  return; }

                if (currentState() == 0) // state is "empty", this DbGrid does not even contain a single table ...
                {
                    Name  = tableName;
                    Short = tableShort;
                    //dbdb if (db.Tables.hasKey(Name)) fields = new KeyPile<string, string>(db.Tables[Name].fields);
                    for (int i = 1; i <= fields.Len; i++)
                    {
                        fields[i] = new DbField(Short + "." + fields[i].sql());
                    }
                }
                else
                {
                    DbGrid g = new DbGrid(this);
                    if (currentState() == 1)
                    {
                        this.tables.Add(Name + " " + Short, new DbGrid(this));
                    }
                    this.tables.Add(tableName + " " + tableShort, new DbGrid(tableName + " " + tableShort));
                    Name   = "";
                    Short  = "";
                    fields = new Pile <DbField>();
                    foreach (DbGrid tab in this.tables)
                    {
                        foreach (DbField x in tab.Fields)
                        {
                            fields.Add(new DbField(tab.Short + "." + x.sql()));
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        // Ideen:
        // Eine Projektion aus joined Tables könnte etwa so definiert werden ......
        // Join jtb = new Join("mitarbeiter m, ProcessInstance pi", "m.Id = pi.mitarbeiter");
        // Projection pjtb = jtb.Project("m.Id, m.nm, m.vorname, pi.nm, pi.Id, pi.StarDate");
        // pjtb.Select(true, "m.Id > 200", "m.nm LIKE '*Stefan*'");

        internal DbGrid(DbGrid cloneFrom)
        {
            init();
            db     = cloneFrom.db;
            fields = cloneFrom.fields.Clone(); if (cloneFrom.allFields == cloneFrom.fields)
            {
                allFields = fields;
            }
            else if (cloneFrom.allFields != null)
            {
                allFields = cloneFrom.allFields.Clone();
            }
            tables  = new KeyPile <string, DbGrid>(cloneFrom.tables);
            joinCnd = cloneFrom.joinCnd.Clone(); // new Pile<Cnd>(cloneFrom.joinCnd);
            selCnd  = cloneFrom.selCnd.Clone();  // new Pile<Cnd>(cloneFrom.selCnd);
            Name    = cloneFrom.Name;
            Short   = cloneFrom.Short;
        }
Ejemplo n.º 10
0
        /// <summary> sC ("select Columns") is the fields selector clause. (like in SQL Statements)</summary>
        public DbGrid sC(string allfields)
        {
            DbGrid ret = new DbGrid(this);

            ret.allFields = ret.fields.Clone(); //new Pile<string> (ret.fieldNames);
            Reach fields = new Reach(allfields + ",");

            if (!fields.Trim().equals("*,"))
            {
                ret.fields = new Pile <DbField>();
                Reach tokenMap = fields - bltZone.upon(fields - chrZone.upon(fields)); //AttGeTr: upon is too expensive!
                while (fields.Trim().len > 0)
                {
                    Reach token = tokenMap.at(1, ",");
                    ret.fields.Add(new DbField(fields.before(token).Trim().text)); //AttGeTr: no type information is added for each field !!! / ToBeSolved !!!
                    fields   = fields.after(token);
                    tokenMap = tokenMap.after(token);
                }
            }
            return(ret);
        }
Ejemplo n.º 11
0
 internal DbIns(DbGrid into, DatSet values)
 {
     init();
     grid   = into;
     datSet = values;
 }