public IRow Select() { if (_cursor != null) { return(_cursor.Select()); } else { return(null); } }
public static object Evaluate(Program program, string expression, Schema.TableVar tableVar, DataParams dataParams) { IServerExpressionPlan plan = ((IServerProcess)program.ServerProcess).PrepareExpression(expression, dataParams); try { plan.CheckCompiled(); IServerCursor cursor = plan.Open(dataParams); try { NativeTable nativeTable = new NativeTable(program.ValueManager, tableVar); while (cursor.Next()) { using (IRow row = cursor.Select()) { nativeTable.Insert(program.ValueManager, row); } } return(new TableValue(program.ValueManager, nativeTable.TableType, nativeTable)); } finally { plan.Close(cursor); } } finally { ((IServerProcess)program.ServerProcess).UnprepareExpression(plan); } }
/// <summary> Creates this nodes immediate children. Avoids duplication. </summary> public void BuildChildren() { // Open a dynamic navigable browse cursor on the child expression IServerCursor cursor = DBTreeView.OpenChildCursor(_key); try { DBTreeNode existingNode; Row key; string text; int index = 0; int columnIndex; while (cursor.Next()) { key = new Row(DBTreeView._process.ValueManager, new Schema.RowType(((TableDataSet)DBTreeView.Source.DataSet).Order.Columns)); try { using (IRow row = cursor.Select()) { row.CopyTo(key); columnIndex = row.DataType.Columns.IndexOf(DBTreeView.ColumnName); if (columnIndex < 0) { throw new ControlsException(ControlsException.Codes.DataColumnNotFound, DBTreeView.ColumnName); } if (row.HasValue(columnIndex)) { text = ((IScalar)row.GetValue(columnIndex)).AsDisplayString; } else { text = DBTreeView.NoValueText; } existingNode = FindChild(key); if (existingNode != null) { existingNode.Text = text; existingNode.SetKey(key); index = existingNode.Index; } else { Nodes.Insert(index, new DBTreeNode(text, key)); } index++; } } catch { key.Dispose(); throw; } } } finally { DBTreeView.CloseChildCursor(cursor); } }
public static object EvaluateSingleton(Program program, string expression, DataParams dataParams) { IServerExpressionPlan plan = ((IServerProcess)program.ServerProcess).PrepareExpression(expression, dataParams); try { plan.CheckCompiled(); IServerCursor cursor = plan.Open(dataParams); try { if (cursor.Next()) { return(cursor.Select()); } else { return(null); } } finally { plan.Close(cursor); } } finally { ((IServerProcess)program.ServerProcess).UnprepareExpression(plan); } }
private string SaveDeviceSettings(ServerProcess process) { D4TextEmitter emitter = new D4TextEmitter(); Block block = new Block(); IServerProcess localProcess = (IServerProcess)process; IServerCursor cursor = localProcess.OpenCursor("select Devices { ID }", null); try { using (IRow row = cursor.Plan.RequestRow()) { while (cursor.Next()) { cursor.Select(row); Schema.Device device = process.CatalogDeviceSession.ResolveCatalogObject((int)row[0 /*"ID"*/]) as Schema.Device; if ((device != null) && (device.ClassDefinition.Attributes.Count > 0)) { block.Statements.Add(SaveSystemDeviceSettings(device)); } } } } finally { localProcess.CloseCursor(cursor); } return(new D4TextEmitter().Emit(block) + "\r\n"); }
public static int ResultsFromCursor(IServerCursor cursor, StringBuilder results) { DAE.Schema.IRowType rowType = ((DAE.Schema.TableType)cursor.Plan.DataType).RowType; ResultColumn[] resultColumns = BuildResultColumns(rowType); int rowCount; try { using (DAE.Runtime.Data.Row row = new DAE.Runtime.Data.Row(cursor.Plan.Process.ValueManager, rowType)) { while (cursor.Next()) { cursor.Select(row); ReadRow(row, resultColumns); } } } finally { // Even if something fails (or aborts) build what we can rowCount = BuildResults(resultColumns, results); } return(rowCount); }
public void BuildTree() { ClearNodes(); if (IsFieldActive() && (Source.DataView.State != DAE.Client.DataSetState.Insert)) { // Open a dynamic navigable browse cursor on the root expression PrepareRootPlan(); IServerCursor cursor = _rootPlan.Open(_rootParams); try { DAE.Runtime.Data.IRow key; int columnIndex; string text; while (cursor.Next()) { key = new DAE.Runtime.Data.Row(_process.ValueManager, new DAE.Schema.RowType(Source.DataView.Order.Columns)); try { using (DAE.Runtime.Data.IRow row = cursor.Select()) { row.CopyTo(key); columnIndex = row.DataType.Columns.IndexOf(ColumnName); if (row.HasValue(columnIndex)) { text = ((DAE.Runtime.Data.Scalar)row.GetValue(columnIndex)).AsDisplayString; } else { text = Strings.Get("NoValue"); } } Nodes.Add(new TreeNode(this, text, key, 0, null)); } catch { key.Dispose(); throw; } } } finally { _rootPlan.Close(cursor); } foreach (TreeNode node in Nodes) { node.BuildChildren(); } SelectNode(Source.DataView.GetKey()); } }
public Bundle GetNextPage(int pageSize) { var bundle = new Bundle(); var rowCount = 0; var row = _cursor.Plan.RequestRow(); try { _cursor.Plan.Process.BeginTransaction(IsolationLevel.Browse); try { while (_cursor.Next()) { _cursor.Select(row); var resource = row["Content"] as Resource; bundle.AddResourceEntry(resource, resource.ResourceIdentity().ToString()); rowCount++; if (rowCount >= pageSize) { break; } } } finally { _cursor.Plan.Process.CommitTransaction(); } } finally { _cursor.Plan.ReleaseRow(row); } // TODO: Set bundle.NextLink using __cursorId as a parameter bundle.Total = rowCount; return(bundle); }
public void SetFormDesigner() { using (DAE.Runtime.Data.Scalar nodeTable = DataSession.Evaluate(FormDesignerNodeTypesExpression)) { NodeTypeTable.Clear(); NodeTypeTable.LoadFromString(nodeTable.AsString); } // Load the files required to register any nodes, if necessary if (DataSession.Server is DAE.Server.LocalServer) { IServerCursor cursor = DataSession.OpenCursor(GetFormDesignerLibraryFilesExpression); try { using (DAE.Runtime.Data.IRow row = cursor.Plan.RequestRow()) { bool shouldLoad; List <string> filesToLoad = new List <string>(); while (cursor.Next()) { cursor.Select(row); string fullFileName = ((DAE.Server.LocalServer)DataSession.Server).GetFile ( (DAE.Server.LocalProcess)cursor.Plan.Process, (string)row["Library_Name"], (string)row["Name"], (DateTime)row["TimeStamp"], (bool)row["IsDotNetAssembly"], out shouldLoad ); if (shouldLoad) { filesToLoad.Add(fullFileName); } } // Load each file to ensure they can be reached by the assembly resolver hack (see AssemblyUtility) foreach (string fullFileName in filesToLoad) { Assembly.LoadFrom(fullFileName); } } } finally { DataSession.CloseCursor(cursor); } } }
/// <summary> Creates this nodes immediate children. Avoids duplication. </summary> public void BuildChildren() { // Open a dynamic navigable browse cursor on the child expression IServerCursor cursor = Tree.OpenChildCursor(_key); try { DAE.Runtime.Data.Row key; string text; int index = 0; int columnIndex; while (cursor.Next()) { key = new DAE.Runtime.Data.Row(Tree.Process.ValueManager, new RowType(Tree.Source.DataView.Order.Columns)); try { using (DAE.Runtime.Data.IRow row = cursor.Select()) { row.CopyTo(key); columnIndex = row.DataType.Columns.IndexOf(Tree.ColumnName); if (row.HasValue(columnIndex)) { text = ((DAE.Runtime.Data.Scalar)row.GetValue(columnIndex)).AsDisplayString; } else { text = Strings.Get("NoValue"); } } if (FindChild(key) == null) { Nodes.Insert(index, new TreeNode(Tree, text, key, _depth + 1, this)); } index++; } catch { key.Dispose(); throw; } } } finally { Tree.CloseChildCursor(cursor); } }
public static NativeValue ServerCursorToNativeValue(IServerProcess process, IServerCursor cursor) { NativeTableValue nativeTable = TableVarToNativeTableValue(process, cursor.Plan.TableVar); List <object[]> nativeRows = new List <object[]>(); IRow currentRow = cursor.Plan.RequestRow(); try { bool[] valueTypes = new bool[nativeTable.Columns.Length]; for (int index = 0; index < nativeTable.Columns.Length; index++) { valueTypes[index] = currentRow.DataType.Columns[index].DataType is IScalarType; } while (cursor.Next()) { cursor.Select(currentRow); object[] nativeRow = new object[nativeTable.Columns.Length]; for (int index = 0; index < nativeTable.Columns.Length; index++) { if (valueTypes[index]) { nativeRow[index] = currentRow[index]; } else { nativeRow[index] = DataValueToNativeValue(process, currentRow.GetValue(index)); } } nativeRows.Add(nativeRow); } } finally { cursor.Plan.ReleaseRow(currentRow); } nativeTable.Rows = nativeRows.ToArray(); return(nativeTable); }
protected void BuildParentPath(DAE.Runtime.Data.IRow key, ArrayList path) { foreach (DAE.Runtime.Data.Row localKey in path) { if (KeysEqual(key, localKey)) { throw new WebClientException(WebClientException.Codes.TreeViewInfiniteLoop); } } path.Add(key); IServerCursor cursor = OpenParentCursor(key); try { if (cursor.Next()) { key = new DAE.Runtime.Data.Row(_process.ValueManager, new RowType(Source.DataView.Order.Columns)); using (DAE.Runtime.Data.IRow selected = cursor.Select()) selected.CopyTo(key); } else { key = null; } } finally { CloseParentCursor(cursor); } if (key != null) { if (FindChild(key) == null) { BuildParentPath(key, path); } else { path.Add(key); } } }
public override bool Read() { if (_cursor.Next()) { if (_internalRow == null) { _internalRow = new DAE.Runtime.Data.Row(_cursor.Plan.Process.ValueManager, ((TableType)_cursor.Plan.DataType).RowType); } _cursor.Select(_internalRow); if (!_cursor.EOF()) { _rowCount++; } return(!_cursor.EOF()); } else { return(false); } }
protected void BuildParentPath(IRow key, ArrayList path) { foreach (IRow localKey in path) { if (CompareKeys(key, localKey)) { throw new ControlsException(ControlsException.Codes.TreeViewInfiniteLoop); } } path.Add(key); IServerCursor cursor = OpenParentCursor(key); try { if (cursor.Next()) { key = new Row(_process.ValueManager, new RowType(((TableDataSet)Source.DataSet).Order.Columns)); cursor.Select().CopyTo(key); } else { key = null; } } finally { CloseParentCursor(cursor); } if (key != null) { if (FindChild(key) == null) { BuildParentPath(key, path); } else { path.Add(key); } } }
public static IEnumerable <object> ServerCursorToValue(IServerProcess process, IServerCursor cursor) { NativeTableValue nativeTable = NativeMarshal.TableVarToNativeTableValue(process, cursor.Plan.TableVar); var table = new List <object>(); IRow currentRow = cursor.Plan.RequestRow(); try { bool[] valueTypes = new bool[nativeTable.Columns.Length]; for (int index = 0; index < nativeTable.Columns.Length; index++) { valueTypes[index] = currentRow.DataType.Columns[index].DataType is IScalarType; } while (cursor.Next()) { cursor.Select(currentRow); var row = new Dictionary <string, object>(); for (int index = 0; index < nativeTable.Columns.Length; index++) { if (valueTypes[index]) { row.Add(nativeTable.Columns[index].Name, currentRow[index]); } else { row.Add(nativeTable.Columns[index].Name, DataValueToValue(process, currentRow.GetValue(index))); } } table.Add(row); } } finally { cursor.Plan.ReleaseRow(currentRow); } return(table); }
/// <summary> Prepares for opening a document in the specified application. </summary> /// <returns> The starting document configured for the application. </returns> public virtual string SetApplication(string applicationID, string clientType) { DAE.Runtime.DataParams paramsValue = new DAE.Runtime.DataParams(); paramsValue.Add(DAE.Runtime.DataParam.Create(Pipe.Process, "AApplicationID", applicationID)); paramsValue.Add(DAE.Runtime.DataParam.Create(Pipe.Process, "AClientType", clientType)); // Get the node types table using (DAE.Runtime.Data.Scalar nodeTable = DataSession.Evaluate(ApplicationNodeTableExpression, paramsValue)) { NodeTypeTable.Clear(); NodeTypeTable.LoadFromString(nodeTable.AsString); } ValidateNodeTypeTable(); // Prepare the application and get name of the starting document string documentString = null; using (DAE.Runtime.Data.Scalar startingDocument = DataSession.Evaluate(PrepareApplicationExpression, paramsValue)) { documentString = startingDocument.AsString; } // Load the files required to register any nodes, if necessary if (DataSession.Server is DAE.Server.LocalServer) { IServerCursor cursor = DataSession.OpenCursor(GetLibraryFilesExpression, paramsValue); try { using (DAE.Runtime.Data.IRow row = cursor.Plan.RequestRow()) { #if !SILVERLIGHT bool shouldLoad; List <string> filesToLoad = new List <string>(); while (cursor.Next()) { cursor.Select(row); string fullFileName = ((DAE.Server.LocalServer)DataSession.Server).GetFile ( (DAE.Server.LocalProcess)cursor.Plan.Process, (string)row["Library_Name"], (string)row["Name"], (DateTime)row["TimeStamp"], (bool)row["IsDotNetAssembly"], out shouldLoad ); if (shouldLoad) { filesToLoad.Add(fullFileName); } } // Load each file to ensure they can be reached by the assembly resolver hack (see AssemblyUtility) foreach (string fullFileName in filesToLoad) { Assembly.LoadFrom(fullFileName); } #else while (cursor.Next()) { cursor.Select(row); ((DAE.Server.LocalServer)DataSession.Server).LoadAndRegister ( (DAE.Server.LocalProcess)cursor.Plan.Process, cursor.Plan.Catalog.ClassLoader, (string)row["Library_Name"], (string)row["Name"], (bool)row["ShouldRegister"] ); } #endif } } finally { DataSession.CloseCursor(cursor); } } return(documentString); }
/// <summary> Creates root nodes and their immediate children. </summary> protected void BuildTree() { if ((!_link.Active) || _link.DataSet.IsEmpty() || !IsSetup()) { ClearTree(); } else { if (_link.DataSet.State != DataSetState.Insert) { BeginUpdate(); try { EnsureParamsValid(); // Open a dynamic navigable browse cursor on the root expression PrepareRootPlan(); IServerCursor cursor = _rootPlan.Open(_rootParams); try { Row key; int columnIndex; string text; while (cursor.Next()) { key = new Row(_process.ValueManager, new Schema.RowType(((TableDataSet)_link.DataSet).Order.Columns)); try { using (IRow row = cursor.Select()) { row.CopyTo(key); columnIndex = row.DataType.Columns.IndexOf(ColumnName); if (row.HasValue(columnIndex)) { text = ((IScalar)row.GetValue(columnIndex)).AsDisplayString; } else { text = NoValueText; } } Nodes.Add(new DBTreeNode(text, key)); } catch { key.Dispose(); throw; } } } finally { _rootPlan.Close(cursor); } foreach (DBTreeNode node in Nodes) { node.BuildChildren(); } } finally { EndUpdate(); } } } }
protected override void InternalSelect(Row ARow) { FSourceCursor.Select(ARow); }
public void TestCLI() { IServerProcess LProcess = DataSession.ServerSession.StartProcess(new ProcessInfo(DataSession.SessionInfo)); try { var LFetchCount = DataSession.ServerSession.SessionInfo.FetchCount; LProcess.Execute("create table Test { ID : Integer, key { ID } };", null); LProcess.Execute(String.Format("for var LIndex := 1 to {0} do insert row {{ LIndex ID }} into Test;", LFetchCount.ToString()), null); IServerCursor LCursor = LProcess.OpenCursor("select Test order by { ID } capabilities { navigable, backwardsnavigable, bookmarkable, searchable, updateable }", null); try { var LCounter = 0; while (LCursor.Next()) { using (IRow LRow = LCursor.Select()) { LCounter += (int)LRow[0]; } } if (LCounter != (LFetchCount * (LFetchCount + 1)) / 2) { throw new Exception("Fetch count summation failed"); } LCursor.Reset(); LCounter = 0; while (LCursor.Next()) { using (IRow LRow = LCursor.Select()) { LCounter++; if (LCounter != (int)LRow[0]) { throw new Exception("Select failed"); } } } LCursor.Reset(); LCounter = 0; LCursor.Next(); LCursor.Next(); using (IRow LRow = LCursor.Select()) { LRow[0] = -1; LCursor.Update(LRow); } using (IRow LRow = LCursor.Select()) { if ((int)LRow[0] != -1) { throw new Exception("Update failed"); } } LCursor.Delete(); using (IRow LRow = LCursor.Select()) { if ((int)LRow[0] != 1) { throw new Exception("Delete failed"); } LRow[0] = 2; LCursor.Insert(LRow); } using (IRow LRow = LCursor.Select()) { if ((int)LRow[0] != 2) { throw new Exception("Insert failed"); } } LCursor.Reset(); LCounter = 0; Guid LBookmark = Guid.Empty; while (LCursor.Next()) { using (IRow LRow = LCursor.Select()) { LCounter++; if (LCounter == 5) { LBookmark = LCursor.GetBookmark(); } } } if (!LCursor.GotoBookmark(LBookmark, true)) { throw new Exception("GotoBookmark failed"); } using (IRow LRow = LCursor.Select()) { if ((int)LRow[0] != 5) { throw new Exception("GotoBookmark failed"); } } LCursor.DisposeBookmark(LBookmark); } finally { LProcess.CloseCursor(LCursor); } LProcess.Execute("delete Test;", null); LFetchCount *= 10; LProcess.Execute(String.Format("for var LIndex := 1 to {0} do insert row {{ LIndex ID }} into Test;", LFetchCount.ToString()), null); LCursor = LProcess.OpenCursor("select Test order by { ID } capabilities { navigable, backwardsnavigable, bookmarkable, searchable, updateable }", null); try { var LCounter = 0; while (LCursor.Next()) { using (IRow LRow = LCursor.Select()) { LCounter += (int)LRow[0]; } } if (LCounter != (LFetchCount * (LFetchCount + 1)) / 2) { throw new Exception("Fetch count summation failed"); } LCursor.Reset(); LCounter = 0; while (LCursor.Next()) { using (IRow LRow = LCursor.Select()) { LCounter++; if (LCounter != (int)LRow[0]) { throw new Exception("Select failed"); } } } } finally { LProcess.CloseCursor(LCursor); } } finally { DataSession.ServerSession.StopProcess(LProcess); } }
private void WriteElement(Program program, XmlTextWriter writer, Guid elementID) { // Write the element header DataParams paramsValue = new DataParams(); paramsValue.Add(DataParam.Create(program.ServerProcess, "AElementID", elementID)); using ( IRow element = (IRow)((IServerProcess)program.ServerProcess).Evaluate ( "row from (XMLElement where ID = AElementID)", paramsValue ) ) { string namespaceAlias = (string)element["NamespaceAlias"]; if (namespaceAlias != String.Empty) { namespaceAlias = namespaceAlias + ":"; } writer.WriteStartElement(namespaceAlias + (string)element["Name"]); } // Write any default namespace changes IScalar defaultValue = (IScalar)((IServerProcess)program.ServerProcess).Evaluate ( "URI from row from (XMLDefaultNamespace where Element_ID = AElementID)", paramsValue ); if (defaultValue != null) { writer.WriteAttributeString("xmlns", defaultValue.AsString); } // Write namespace aliases IServerCursor aliases = (IServerCursor)((IServerProcess)program.ServerProcess).OpenCursor ( "XMLNamespaceAlias where Element_ID = AElementID", paramsValue ); try { while (aliases.Next()) { using (IRow row = aliases.Select()) writer.WriteAttributeString("xmlns:" + (string)row["NamespaceAlias"], (string)row["URI"]); } } finally { ((IServerProcess)program.ServerProcess).CloseCursor(aliases); } // Write the attributes IServerCursor attributes = (IServerCursor)((IServerProcess)program.ServerProcess).OpenCursor ( "XMLAttribute where Element_ID = AElementID", paramsValue ); try { while (attributes.Next()) { using (IRow row = attributes.Select()) { string alias = (string)row["NamespaceAlias"]; if (alias != String.Empty) { alias = alias + ":"; } writer.WriteAttributeString(alias + (string)row["Name"], (string)row["Value"]); } } } finally { ((IServerProcess)program.ServerProcess).CloseCursor(attributes); } // Write the child content and elements IServerCursor children = (IServerCursor)((IServerProcess)program.ServerProcess).OpenCursor ( @" (XMLContent where Element_ID = AElementID over { Element_ID, Sequence }) union ( XMLElementParent where Parent_Element_ID = AElementID over { Parent_Element_ID, Sequence } rename { Parent_Element_ID Element_ID } ) left join (XMLContent rename { Element_ID Content_Element_ID, Sequence Content_Sequence }) by Element_ID = Content_Element_ID and Sequence = Content_Sequence left join (XMLElementParent rename { Element_ID Child_Element_ID, Sequence Child_Sequence }) by Element_ID = Parent_Element_ID and Sequence = Child_Sequence order by { Element_ID, Sequence } " , paramsValue ); try { while (children.Next()) { using (IRow row = children.Select()) { if (row.HasValue("Content_Element_ID")) // Content { if ((byte)row["Type"] == 0) { writer.WriteString((string)row["Content"]); } else { writer.WriteCData((string)row["Content"]); } } else // Child element { WriteElement(program, writer, (Guid)row["Child_Element_ID"]); } } } } finally { ((IServerProcess)program.ServerProcess).CloseCursor(children); } // Write the end element writer.WriteEndElement(); }