internal override Sql.Builder Output(Sql.Builder sb)
 {
     if (List.Count < 2)
     {
         if (List.Count == 0) return sb;
         List[0].Output(sb);
     }
     else
     {
         for (int i = 0; i < List.Count; i++)
         {
             if (i > 0)
                 sb.Append(')').Append(Ops);
             sb.Append('(');
             List[i].Output(sb);
         }
         sb.Append(')');
     }
     return sb;
 }
 protected override Sql.Builder Output(Sql.Builder sb)
 {
     sb.Append("select ");
     sb.SelectList(_cols).Append(" from ", _table_name);
     // generate query conditions, if any.
     if (_where != null)
     {
         sb.Append(" where ");
         _where.Output(sb);
     }
     // add order by/group by/etc items.
     if (!string.IsNullOrEmpty(_suffix)) sb.Append(_suffix);
     return sb;
 }
 protected override Sql.Builder Output(Sql.Builder sb)
 {
     sb.Append("delete from ", _table_name);
     if (_where == null) return sb;
     sb.Append(" where ");
     _where.Output(sb);
     return sb;
 }
 protected override Sql.Builder Output(Sql.Builder sb)
 {
     sb.Append("insert into ", _table_name, " (");
     int pos = 0;
     for (SqlBind cl = _cols; cl != null; cl = cl.Next)
     {
         if (pos++ > 0) sb.Comma();
         sb.Append(cl.Column.Name);
     }
     sb.psingle = pos;
     //TODO!!! add const value fields.
     sb.Append(") values ");
     for (int i = 0; i < Math.Max(1, sb.Context.Boost); i++)
     {
         if (i > 0) sb.Comma();
         pos = 0;
         sb.Append('(');
         for (SqlBind cl = _cols; cl != null; cl = cl.Next)
         {
             if (pos++ > 0) sb.Comma();
             //-sb.AppendParam(cl);
         }
         sb.Append(')');
     }
     return sb;
 }
 protected override Sql.Builder Output(Sql.Builder sb)
 {
     sb.Append("update ", _table_name, " set ");
     int pos = 0;
     if (_update != null) sb.Append(_update);
     else
         for (SqlBind cl = _cols; cl != null; cl = cl.Next)
         {
             if (pos++ > 0) sb.Comma();
             sb.Append(cl.Column.Name).Append('=');
             //-sb.AppendParam(cl);
         }
     if (_where == null) return sb;
     sb.Append(" where ");
     _where.Output(sb);
     return sb;
 }
 internal override Sql.Builder Output(Sql.Builder sb)
 {
     sb.Append(FieldName, Ops);
     //sb.AppendParam( ParamName, 0 );
     return sb;
 }
 protected virtual Sql.Builder Output(Sql.Builder sb)
 {
     string s = SQL;
     char quot = sb.Context.GetMarker(false);
     SqlColumn scds = null;
     int bp = 0, cp = 1;
     while (cp < s.Length)
     {
         char ch = s[cp];
         switch (ch)
         {
             case '#':
                 sb.Append(s, bp, cp - 1);
                 for (ch = s[cp - 1], bp = ++cp; cp < s.Length; cp++) if (s[cp] == '#') break;
                 if (cp == s.Length) throw new NotSupportedException("incomplete markup section");
                 int np = bp; while (s[np] <= ' ') np++;
                 //bp = ++cp;
                 int ep = np, xp = cp;
                 while (ep < cp) if (s[ep] != ':') ep++; else { xp = ep + 1; break; }
                 while (s[xp] <= ' ') xp++;
                 while (ep > np && s[ep - 1] <= ' ') ep--;
                 string pname = ep > np ? s.Substring(np, ep - np) : null;
                 ep = cp; while (ep > np && s[ep - 1] <= ' ') ep--;
                 string opts = ep > xp ? s.Substring(xp, ep - xp) : null;
                 if (scds == null) scds = new SqlColumn();
                 scds.Parse(opts);
                 sb.AppendParam(pname, scds);
                 bp = ++cp; continue;
             case '-': // singleline comment 
                 if (++cp == s.Length || s[cp] != '-') break;
                 while (++cp < s.Length)
                     if (s[cp] == '\n') { cp += 2; break; }
                 continue;
             case '/': // muiltiline comment, may contain useful info, like hints 
                 if (++cp == s.Length || s[cp] != '*') break;
                 while (++cp < s.Length)
                     if (s[cp] == '*' && (cp + 1 < s.Length) && s[cp + 1] == '/') { cp += 2; break; }
                 continue;
             default:
                 if (ch != quot) break;
                 while (++cp < s.Length && s[cp] != quot) ;
                 break;
         }
         cp++;
     }
     sb.Append(s, bp, cp);
     return sb;
 }
 internal override void Output(Sql.Builder sb)
 {
     int boost = sb.Context.Boost;
     if (boost < 2) { OutputEx(sb); return; }
     sb.psingle = 1;
     if (_keys.Next == null)
     {
         sb.Append(_keys.Column.Name, " in (");
         for (int i = 0; i < boost; i++)
         {
             if (i > 0) sb.Comma();
             //sb.AppendParam(_keys);
         }
         sb.Append(')');
         return;
     }
     for (SqlBind ls = _keys; (ls = ls.Next) != null; sb.psingle++) ;
     sb.Append('(');
     for (int i = 0; i < boost; i++)
     {
         if (i > 0) sb.Append(")or(");
         OutputEx(sb);
     }
     sb.Append('(');
 }
 internal sealed override Sql.Builder Output(Sql.Builder sb)
 {
     sb.Append(Text);
     return sb;
 }
 internal void OutputEx(Sql.Builder sb)
 {
     if (_keys.Next == null) { add_key(sb, _keys); return; }
     int pos = 0;
     for (SqlBind sc = _keys; sc != null; sc = sc.Next)
     {
         sb.Append(pos++ == 0 ? "(" : "and(");
         add_key(sb, sc);
         sb.Append(')');
     }
 }
 protected Sql.Builder add_key(Sql.Builder sb, SqlBind bi)
 {
     sb.Append(bi.Column.Name, "=");
     //sb.AppendParam(bi);
     return sb;
 }
 internal sealed override void Output(Sql.Builder sb)
 {
     if (count < 2 || expr.priority > priority)
         for (int i = 0; i < count; i++)
         {
             if (i > 0) sb.Append(' ').Append(ops).Append(' ');
             expr.Output(sb);
         }
     else
     {
         for (int i = 0; i < count; i++)
         {
             if (i > 0) sb.Append(')').Append(ops);
             sb.Append('(');
             expr.Output(sb);
         }
     }
 }
 internal sealed override void Output(Sql.Builder sb)
 {
     if (left.priority >= priority)
         left.Output(sb);
     else
     {
         sb.Append('(');
         left.Output(sb);
         sb.Append(')');
     }
     // insert sql operator text.
     sb.Space().Append(ops).Space();
     // wrap right expression, if needed.
     if (right.priority >= priority)
         right.Output(sb);
     else
     {
         sb.Append('(');
         right.Output(sb);
         sb.Append(')');
     }
 }
 internal sealed override void Output(Sql.Builder sb)
 {
     if (pretext == null)
         if (left != null) sb.Append(left.Name);
         else { /* some expressions like  .. exists have no left side */ }
     else sb.Append(pretext);
     sb.Append(ops);
     //if( value == null )
     //    sb.AppendParam( right.name, right.size );
     //else sb.AppendValue( value );
 }