protected void TranslateOrder(CatalogDevicePlan devicePlan, CatalogDevicePlanNode devicePlanNode, TableNode tableNode) { if (devicePlanNode.WhereCondition.Length > 0) { devicePlanNode.Statement.AppendFormat(" where {0}", devicePlanNode.WhereCondition.ToString()); } if ((tableNode.Order != null) && (tableNode.Order.Columns.Count > 0)) { devicePlanNode.Statement.AppendFormat(" order by "); for (int index = 0; index < tableNode.Order.Columns.Count; index++) { OrderColumn orderColumn = tableNode.Order.Columns[index]; if (index > 0) { devicePlanNode.Statement.Append(", "); } if (devicePlan.TableContext != null) { devicePlanNode.Statement.Append(Schema.Object.EnsureUnrooted(MetaData.GetTag(devicePlan.TableContext.Columns[orderColumn.Column.Name].MetaData, "Storage.Name", orderColumn.Column.Name))); } else { devicePlanNode.Statement.Append(Schema.Object.EnsureUnrooted(orderColumn.Column.Name)); } if (!orderColumn.Ascending) { devicePlanNode.Statement.Append(" desc"); } } } }
protected void TranslateRestrictNode(CatalogDevicePlan devicePlan, CatalogDevicePlanNode devicePlanNode, RestrictNode restrictNode) { if ((restrictNode.SourceNode is BaseTableVarNode) && (restrictNode.Nodes[1] is InstructionNodeBase)) { TranslateBaseTableVarNode(devicePlan, devicePlanNode, (BaseTableVarNode)restrictNode.SourceNode); if (devicePlan.IsSupported) { if (devicePlanNode.WhereCondition.Length > 0) { devicePlanNode.WhereCondition.Insert(0, "("); devicePlanNode.WhereCondition.AppendFormat(") and "); } TranslateExpression(devicePlan, devicePlanNode, restrictNode.Nodes[1]); if (devicePlan.IsSupported) { restrictNode.CursorType = restrictNode.SourceNode.CursorType; restrictNode.RequestedCursorType = restrictNode.SourceNode.RequestedCursorType; restrictNode.CursorCapabilities = restrictNode.SourceNode.CursorCapabilities; restrictNode.CursorIsolation = restrictNode.SourceNode.CursorIsolation; restrictNode.Order = restrictNode.SourceNode.Order; } } } else { devicePlan.IsSupported = false; } }
protected void TranslateScalarParameter(CatalogDevicePlan devicePlan, CatalogDevicePlanNode devicePlanNode, PlanNode planNode) { SQLType type = null; switch (planNode.DataType.Name) { case "System.String": case "System.Name": case "System.UserID": type = new SQLStringType(200); break; case "System.Integer": type = new SQLIntegerType(4); break; case "System.Boolean": type = new SQLIntegerType(1); break; } if (type != null) { string parameterName = String.Format("P{0}", devicePlanNode.PlanParameters.Count + 1); devicePlanNode.PlanParameters.Add(new CatalogPlanParameter(new SQLParameter(parameterName, type, null), planNode)); devicePlanNode.WhereCondition.AppendFormat("@{0}", parameterName); } else { devicePlan.IsSupported = false; } }
protected void TranslateBaseTableVarNode(CatalogDevicePlan devicePlan, CatalogDevicePlanNode devicePlanNode, BaseTableVarNode baseTableVarNode) { Tag tag = MetaData.GetTag(baseTableVarNode.TableVar.MetaData, "Catalog.CacheLevel"); if (tag != Tag.None) { if ((tag.Value == "StoreTable") || (tag.Value == "StoreView")) { devicePlan.TableContext = baseTableVarNode.TableVar; baseTableVarNode.CursorType = CursorType.Dynamic; baseTableVarNode.RequestedCursorType = devicePlan.Plan.CursorContext.CursorType; baseTableVarNode.CursorCapabilities = CursorCapability.Navigable | (devicePlan.Plan.CursorContext.CursorCapabilities & CursorCapability.Updateable); baseTableVarNode.CursorIsolation = devicePlan.Plan.CursorContext.CursorIsolation; baseTableVarNode.Order = Compiler.OrderFromKey(devicePlan.Plan, Compiler.FindClusteringKey(devicePlan.Plan, baseTableVarNode.TableVar)); if (tag.Value == "StoreTable") { devicePlanNode.Statement.AppendFormat("select * from DAE{0}", Schema.Object.Unqualify(baseTableVarNode.TableVar.Name)); } else { GetViewDefinition(Schema.Object.Unqualify(baseTableVarNode.TableVar.Name), devicePlanNode.Statement, devicePlanNode.WhereCondition); } } else { devicePlan.IsSupported = false; } } else { devicePlan.IsSupported = false; } }
protected void TranslateOrderNode(CatalogDevicePlan devicePlan, CatalogDevicePlanNode devicePlanNode, OrderNode orderNode) { TranslatePlanNode(devicePlan, devicePlanNode, orderNode.SourceNode); if (devicePlan.IsSupported) { orderNode.CursorType = orderNode.SourceNode.CursorType; orderNode.RequestedCursorType = orderNode.SourceNode.RequestedCursorType; orderNode.CursorCapabilities = orderNode.SourceNode.CursorCapabilities; orderNode.CursorIsolation = orderNode.SourceNode.CursorIsolation; } }
protected void TranslatePlanNode(CatalogDevicePlan devicePlan, CatalogDevicePlanNode devicePlanNode, PlanNode planNode) { if (planNode is BaseTableVarNode) { TranslateBaseTableVarNode(devicePlan, devicePlanNode, (BaseTableVarNode)planNode); } else if (planNode is RestrictNode) { TranslateRestrictNode(devicePlan, devicePlanNode, (RestrictNode)planNode); } else if (planNode is OrderNode) { TranslateOrderNode(devicePlan, devicePlanNode, (OrderNode)planNode); } else { devicePlan.IsSupported = false; } }
protected override DevicePlanNode InternalPrepare(DevicePlan devicePlan, PlanNode planNode) { CatalogDevicePlan localDevicePlan = (CatalogDevicePlan)devicePlan; CatalogDevicePlanNode devicePlanNode = new CatalogDevicePlanNode(planNode); TranslatePlanNode(localDevicePlan, devicePlanNode, planNode); if (planNode is TableNode) { TranslateOrder(localDevicePlan, devicePlanNode, (TableNode)planNode); } if (localDevicePlan.IsSupported) { return(devicePlanNode); } else { return(base.InternalPrepare(devicePlan, planNode)); } }
protected void TranslateExpression(CatalogDevicePlan devicePlan, CatalogDevicePlanNode devicePlanNode, PlanNode planNode) { InstructionNodeBase instructionNode = planNode as InstructionNodeBase; if (instructionNode != null) { if ((instructionNode.DataType != null) && (instructionNode.Operator != null)) { switch (Schema.Object.Unqualify(instructionNode.Operator.OperatorName)) { case Instructions.And: case Instructions.Equal: case Instructions.NotEqual: case Instructions.Greater: case Instructions.InclusiveGreater: case Instructions.Less: case Instructions.InclusiveLess: case Instructions.Like: TranslateExpression(devicePlan, devicePlanNode, instructionNode.Nodes[0]); devicePlanNode.WhereCondition.AppendFormat(" {0} ", GetInstructionKeyword(Schema.Object.Unqualify(instructionNode.Operator.OperatorName))); TranslateExpression(devicePlan, devicePlanNode, instructionNode.Nodes[1]); return; case "ReadValue": TranslateExpression(devicePlan, devicePlanNode, instructionNode.Nodes[0]); return; default: devicePlan.IsSupported = false; return; } } } ValueNode valueNode = planNode as ValueNode; if (valueNode != null) { TranslateScalarParameter(devicePlan, devicePlanNode, planNode); return; } StackReferenceNode stackReferenceNode = planNode as StackReferenceNode; if (stackReferenceNode != null) { TranslateScalarParameter(devicePlan, devicePlanNode, new StackReferenceNode(stackReferenceNode.DataType, stackReferenceNode.Location - 1)); return; } StackColumnReferenceNode stackColumnReferenceNode = planNode as StackColumnReferenceNode; if (stackColumnReferenceNode != null) { if (stackColumnReferenceNode.Location == 0) { if (devicePlan.TableContext != null) { devicePlanNode.WhereCondition.Append(Schema.Object.EnsureUnrooted(MetaData.GetTag(devicePlan.TableContext.Columns[stackColumnReferenceNode.Identifier].MetaData, "Storage.Name", stackColumnReferenceNode.Identifier))); } else { devicePlanNode.WhereCondition.Append(Schema.Object.EnsureUnrooted(stackColumnReferenceNode.Identifier)); } } else { TranslateScalarParameter(devicePlan, devicePlanNode, new StackColumnReferenceNode(stackColumnReferenceNode.Identifier, stackColumnReferenceNode.DataType, stackColumnReferenceNode.Location - 1)); } return; } devicePlan.IsSupported = false; }
public CatalogDeviceTable(CatalogDevicePlanNode devicePlanNode, Program program, ServerCatalogDeviceSession session) : base(devicePlanNode.Node as TableNode, program) { _devicePlanNode = devicePlanNode; _session = session; }