Example #1
0
 private DbSlc(string type, DbSlc s1, DbSlc s2)
 {
     init();
     this.type = type.ToUpper().Trim();
     //string s = Db._sql(s2);
     parts.Push(s1);
     parts.Push(s2);
 }
Example #2
0
 public string sql(Db db)
 {
     if (grid == null)
     {
         if (into.Trim().Length == 0)
         {
             return("");
         }
         string ret = "INSERT INTO " + db.dbTable(into) + " (";
         foreach (DbField f in fields)
         {
             ret += f.sql(db) + ", ";
         }
         if (!ret.EndsWith(" ("))
         {
             ret = ret.Substring(0, ret.Length - 2);
         }
         if (slc == null)
         {
             ret += " ) \r\nVALUES ("; foreach (string v in values)
             {
                 ret += v + ", ";
             }
             ret = ret.Substring(0, ret.Length - 2) + " )";
         }
         else
         {
             if (!ret.EndsWith(" ("))
             {
                 ret += " ) \r\n";
             }
             ret += slc.sql(db);
         }
         return(ret);
     }
     else
     {
         DbSlcBlock slc = new DbSlcBlock(" <|> ");
         foreach (ObjPile raw in datSet.Raws)
         {
             string fld = "";
             foreach (object obj in raw)
             {
                 Type t = obj.GetType();
                 if (t == typeof(Reach))
                 {
                     fld += (Reach)obj + ", ";
                 }
                 if (t == typeof(string))
                 {
                     fld += db.ds((string)obj) + ", ";
                 }
                 if ((t == typeof(double)) || (t == typeof(float)))
                 {
                     fld += ("" + obj).Replace(",", ".") + ", ";
                 }
                 if ((t == typeof(long)) || (t == typeof(int)))
                 {
                     fld += "" + obj + ", ";
                 }
             }
             fld = fld.Substring(0, fld.Length - 2);
             if (db.avoidEmptyStrings)
             {
                 slc.Push(new DbGrid(".all_tables").sR(db.cd("table_name").EQ(new DbGrid(".all_tables").sC("Min(table_name)").SLC)).sC(fld).SLC);
             }
             else
             {
                 slc.Push(new DbGrid("").sC(fld).SLC);
             }
         }
         return(grid.INS(db.SlcOR(slc.array())).sql(db));
         //return sql(i.grid.INS(slc.val(this)));  //slc.val(this) is a string - so the INS does not create "insert into .... select ..." but it creates insert into .... values .....
     }
 }