コード例 #1
0
 public DataReader(Resultset rs)
 {
     _rs = rs;
     _binder = new Binder(rs);
     _rct = rs.RowType;
     _result_f = true;
 }
コード例 #2
0
 public DataReader(Resultset rs, QueryContext context)
 {
     _rs = rs;
     _context = context;
     _binder = new Binder(rs);
     _rct = rs.RowType;
     _result_f = true;
 }
コード例 #3
0
 private String WriteExpr(Binder binder, DataProviderHelper helper, object lval, 
     Object[] parameters, DbCommand command)
 {
     if (Lisp.IsNode(lval))
     {
         if (Lisp.IsAtom(lval))
         {
             ATOM a = (ATOM)lval;
             string name;
             if (a.parts.Length == 1)
                 name = a.parts[0];
             else
                 name = a.parts[1];
             ColumnBinding b = binder.Get(name);
             if (b == null)
                 throw new ESQLException(Properties.Resources.InvalidIdentifier, name);
             RowType.TypeInfo ti = TableType.TableRowType.Fields[b.rnum];
             if (ti.ProviderColumnName != null)
                 return helper.FormatIdentifier(ti.ProviderColumnName);
             else
                 return helper.FormatIdentifier(ti.Name);
         }
         else
             return WriteLiteral(helper, lval);
     }
     else
     {
         object head = Lisp.Car(lval);
         if (Lisp.IsCons(head))
         {
             object[] list = Lisp.ToArray(lval);
             return WriteList(binder, helper, list, parameters, command);
         }
         else
         {
             object[] args = Lisp.ToArray(Lisp.Cdr(lval));
             if (head.Equals(ID.Like1))
             {
                 StringBuilder sb = new StringBuilder();
                 sb.AppendFormat("{0} LIKE {1}", WriteExpr(binder, helper, args[0], parameters, command),
                     WriteExpr(binder, helper, args[1], parameters, command));
                 if (args.Length > 2)
                     sb.AppendFormat(" ESCAPE {0}", WriteExpr(binder, helper, args[2], 
                         parameters, command));
                 return sb.ToString();
             }
             else if (head.Equals(Funcs.List))
                 return WriteList(binder, helper, args, parameters, command);
             else if (head.Equals(ID.Member))
                 return String.Format(" {0} IN {1}",
                     WriteExpr(binder, helper, args[0], parameters, command),
                     WriteExpr(binder, helper, args[1], parameters, command));
             else if (head.Equals(ID.Between))
                 return String.Format(" BETWEEN {0} AND {1}",
                     WriteExpr(binder, helper, args[0], parameters, command),
                     WriteExpr(binder, helper, args[1], parameters, command));
             else if (head.Equals(Funcs.Not))
                 return String.Format(" NOT {0}", WriteExpr(binder, helper, args[0], parameters, command));
             else if (head.Equals(ID.IsNull))
                 return String.Format(" {0} IS NULL", WriteExpr(binder, helper, args[0], parameters, command));
             else if (head.Equals(Funcs.And))
                 return String.Format(" ({0}) AND ({1})",
                     WriteExpr(binder, helper, args[0], parameters, command),
                     WriteExpr(binder, helper, args[1], parameters, command));
             else if (head.Equals(Funcs.Or))
                 return String.Format(" ({0}) OR ({1})",
                     WriteExpr(binder, helper, args[0], parameters, command),
                     WriteExpr(binder, helper, args[1], parameters, command));
             else if (head.Equals(ID.LT))
                 return String.Format(" {0} < {1}",
                     WriteExpr(binder, helper, args[0], parameters, command),
                     WriteExpr(binder, helper, args[1], parameters, command));
             else if (head.Equals(ID.GT))
                 return String.Format(" {0} > {1}",
                     WriteExpr(binder, helper, args[0], parameters, command),
                     WriteExpr(binder, helper, args[1], parameters, command));
             else if (head.Equals(ID.EQ))
                 return String.Format(" {0} = {1}",
                     WriteExpr(binder, helper, args[0], parameters, command),
                     WriteExpr(binder, helper, args[1], parameters, command));
             else if (head.Equals(ID.NE))
                 return String.Format(" {0} <> {1}",
                     WriteExpr(binder, helper, args[0], parameters, command),
                     WriteExpr(binder, helper, args[1], parameters, command));
             else if (head.Equals(ID.LE))
                 return String.Format(" {0} <= {1}",
                     WriteExpr(binder, helper, args[0], parameters, command),
                     WriteExpr(binder, helper, args[1], parameters, command));
             else if (head.Equals(ID.GE))
                 return String.Format(" {0} >= {1}",
                     WriteExpr(binder, helper, args[0], parameters, command),
                     WriteExpr(binder, helper, args[1], parameters, command));
             else if (head.Equals(ID.Concat))
                 return String.Format("CONCAT({0},{1})",
                     WriteExpr(binder, helper, args[0], parameters, command),
                     WriteExpr(binder, helper, args[1], parameters, command));
             else if (head.Equals(Funcs.Add))
                 return String.Format(" {0}+{1}",
                     WriteExpr(binder, helper, args[0], parameters, command),
                     WriteExpr(binder, helper, args[1], parameters, command));
             else if (head.Equals(Funcs.Sub))
                 return String.Format(" {0}-{1}",
                     WriteExpr(binder, helper, args[0], parameters, command),
                     WriteExpr(binder, helper, args[1], parameters, command));
             else if (head.Equals(Funcs.Mul))
                 return String.Format(" ({0})*({1})",
                     WriteExpr(binder, helper, args[0], parameters, command),
                     WriteExpr(binder, helper, args[1], parameters, command));
             else if (head.Equals(Funcs.Div))
                 return String.Format(" ({0})/({1})",
                     WriteExpr(binder, helper, args[0], parameters, command),
                     WriteExpr(binder, helper, args[1], parameters, command));
             else if (head.Equals(ID.ParamRef))
             {
                 DbParameter parameter = command.CreateParameter();
                 parameter.ParameterName = helper.FormatParameter(
                     String.Format("p{0}", command.Parameters.Count));
                 parameter.Value = parameters[(int)args[0] - 1];
                 parameter.Direction = ParameterDirection.Input;
                 command.Parameters.Add(parameter);
                 return parameter.ParameterName;
             }
             else
                 throw new UnproperlyFormatedExpr(Lisp.Format(lval));
         }
     }
 }
コード例 #4
0
 private String WriteList(Binder binder, DataProviderHelper helper, object[] list,
     Object[] parameters, DbCommand command)
 {
     StringBuilder sb = new StringBuilder();
     sb.Append("(");
     for (int k = 0; k < list.Length; k++)
     {
         if (k > 0)
             sb.Append(", ");
         sb.Append(WriteExpr(binder, helper, list[k], parameters, command));
     }
     sb.Append(")");
     return sb.ToString();
 }
コード例 #5
0
 protected override void PrepareCommand(RowType.TypeInfo[] fields, DbCommand command, Object[] parameters)
 {            
     DataProviderHelper helper = new DataProviderHelper(_providerInvariantName, _connectionString);
     Binder binder = new Binder(fields);
     StringBuilder sb = new StringBuilder();
     sb.Append("SELECT ");
     for (int k = 0; k < fields.Length; k++)
     {
         if (k > 0)
             sb.Append(", ");
         if (fields[k].ProviderColumnName != null)
             sb.Append(helper.FormatIdentifier(fields[k].ProviderColumnName));
         else
             sb.Append(helper.FormatIdentifier(fields[k].Name));
     }
     sb.AppendLine();
     sb.Append(" FROM ");
     sb.Append(TableType.ToString(helper));
     if (TableType.Smart)
     {
         if (FilterPredicate != null || AccessPredicate != null)
             sb.AppendLine(" WHERE ");
         if (FilterPredicate != null)
         {
             if (AccessPredicate != null)
                 sb.Append("(");
             command.Parameters.Clear();
             sb.AppendLine(WriteExpr(binder, helper, FilterPredicate, 
                 parameters, command));
             if (AccessPredicate != null)
                 sb.Append(")");
         }
         if (AccessPredicate != null)
         {
             if (FilterPredicate != null)
                 sb.AppendLine(" AND (");
             for (int s = 0; s < AccessPredicateValues.Length; s++)
             {
                 if (s > 0)
                     sb.Append(" OR ");
                 sb.Append("(");
                 for (int k = 0; k < AccessPredicate.Length; k++)
                 {
                     if (k > 0)
                         sb.Append(" AND ");
                     sb.Append(helper.FormatIdentifier(AccessPredicate[k]));
                     Object predicateValue = AccessPredicateValues[s][k];
                     if (predicateValue == DBNull.Value)
                         sb.Append(" IS NULL");
                     else
                     {
                         sb.Append("=");
                         sb.Append(WriteLiteral(helper, predicateValue));
                     }
                 }
                 sb.Append(")");
             }
             if (FilterPredicate != null)
                 sb.Append(")");
         }
     }
     if (SortColumns != null)
     {
         sb.AppendLine(" ORDER BY ");
         for (int k = 0; k < SortColumns.Length; k++)               
             {
                 if (k > 0)
                     sb.Append(", ");
                 sb.Append(helper.FormatIdentifier(SortColumns[k].ColumnName));
                 if (SortColumns[k].Direction == SortDirection.Descending)
                     sb.Append(" DESC");
             }
         sb.AppendLine();
     }
     command.CommandText = sb.ToString();            
 }
コード例 #6
0
 public DataResolver(Binder binder)
 {
     _binder = binder;
     _bindings_t = new Dictionary<Object, ColumnBinding>();
 }
コード例 #7
0
 public SelectorResolver(Binder binder)
     : base(binder)
 {
     Resultsets = new List<object>();
 }
コード例 #8
0
 public override Resultset Get(QueryContext queryContext, object[] parameters)
 {
     Resultset source = ChildNodes[0].Get(queryContext, parameters);
     RowType.Locator[] locator = new RowType.Locator[_columns.Length];
     int[] way = new int[_columns.Length];
     Binder binder = new Binder(source);
     for (int k = 0; k < _columns.Length; k++)
     {
         Column col = _columns[k];
         locator[k] = col.Name is String ? binder.GetLocator((string)col.Name) :
             binder.GetLocator(((int)col.Name) - 1);
         way[k] = col.Direction ==
            SortDirection.Descending ? -1 : 1;
     }
     return new Resultset(source.RowType, new SorterContext(source, 
         new ComplexComparer(locator, way)));
 }