示例#1
0
 private void EnsureUpdateCursor()
 {
     if (_updateCursor == null)
     {
         _updateCursor = Plan.Open(_params);
     }
 }
示例#2
0
        /// <summary> Opens a remote, server-side cursor based on the prepared statement this plan represents. </summary>
        /// <returns> An <see cref="IRemoteServerCursor"/> instance for the prepared statement. </returns>
        public IRemoteServerCursor Open(ref RemoteParamData paramsValue, out ProgramStatistics executeTime, ProcessCallInfo callInfo)
        {
            _process.ProcessCallInfo(callInfo);

            try
            {
                DataParams         localParamsValue = _process.RemoteParamDataToDataParams(paramsValue);
                IServerCursor      serverCursor     = ServerExpressionPlan.Open(localParamsValue);
                RemoteServerCursor cursor           = new RemoteServerCursor(this, (ServerCursor)serverCursor);
                try
                {
                    cursor.Open();
                    _process.DataParamsToRemoteParamData(localParamsValue, ref paramsValue);
                    executeTime = ServerExpressionPlan.ProgramStatistics;
                    return(cursor);
                }
                catch
                {
                    Close(cursor, _process.EmptyCallInfo());
                    throw;
                }
            }
            catch (Exception E)
            {
                throw WrapException(E);
            }
        }
示例#3
0
        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);
            }
        }
示例#4
0
            public void Open()
            {
                if (_shouldOpen && (_cursor == null))
                {
                    if (_plan == null)
                    {
                        try
                        {
                            _cursor = _process.OpenCursor(_expression, _params);
                        }
                        catch (Exception exception)
                        {
                            CompilerMessages messages = new CompilerMessages();
                            messages.Add(exception);
                            ErrorsOccurred(messages);
                            throw exception;
                        }

                        _plan     = _cursor.Plan;
                        _tableVar = _plan.TableVar;
                        ErrorsOccurred(_plan.Messages);
                    }
                    else
                    {
                        _cursor = _plan.Open(_params);
                    }
                }
            }
示例#5
0
        public void TestDeleteAtBOF()
        {
            ExecuteScript("create table TestDeleteAtBOF { ID : Integer, Name : String, key { ID } };");
            ExecuteScript("insert row { 1 ID, 'Joe' Name } into TestDeleteAtBOF;");
            ExecuteScript("insert row { 2 ID, 'John' Name } into TestDeleteAtBOF;");

            IServerCursor LCursor = Process.OpenCursor("select TestDeleteAtBOF browse by { ID } capabilities { navigable, backwardsnavigable, bookmarkable, searchable, updateable } isolation browse", null);

            try
            {
                var LRow = LCursor.Plan.RequestRow();
                try
                {
                    LCursor.Last();
                    LCursor.Prior();
                    LCursor.Prior();
                    LCursor.Delete();
                    if (LCursor.BOF() && !LCursor.Next())
                    {
                        throw new Exception("Delete At BOF Failed");
                    }
                }
                finally
                {
                    LCursor.Plan.ReleaseRow(LRow);
                }
            }
            finally
            {
                Process.CloseCursor(LCursor);
            }
        }
示例#6
0
        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);
            }
        }
示例#7
0
        /// <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 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);
        }
示例#9
0
        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");
        }
示例#10
0
 public void Unprepare()
 {
     if (_plan != null)
     {
         if (_cursor != null)
         {
             try
             {
                 _process.CloseCursor(_cursor);
             }
             finally
             {
                 _cursor = null;
             }
         }
         else
         {
             try
             {
                 _process.UnprepareExpression(_plan);
             }
             finally
             {
                 _plan = null;
             }
         }
     }
 }
示例#11
0
        /// <summary>Closes the given cursor.</summary>
        public void CloseCursor(IServerCursor cursor)
        {
            IServerExpressionPlan plan = cursor.Plan;

            plan.Close(cursor);
            plan.Process.UnprepareExpression(plan);
        }
示例#12
0
 private void CloseUpdateCursor()
 {
     if (_updateCursor != null)
     {
         _plan.Close(_updateCursor);
         _updateCursor = null;
     }
 }
示例#13
0
 public void Close()
 {
     if (_cursor != null)
     {
         var session = _cursor.Plan.Process.Session;
         _cursor.Plan.Process.CloseCursor(_cursor);
         session.Server.Disconnect(session);
         _cursor = null;
     }
 }
示例#14
0
        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());
            }
        }
示例#15
0
 /// <summary>Closes a server-side cursor previously created using Open.</summary>
 /// <param name="cursor">The cursor to close.</param>
 public void Close(IServerCursor cursor)
 {
     try
     {
         _plan.Close(((LocalCursor)cursor).RemoteCursor, _process.GetProcessCallInfo());
     }
     catch
     {
         // ignore exceptions here
     }
     ((LocalCursor)cursor).Dispose();
 }
示例#16
0
        protected internal DAEDataReader(IServerCursor cursor, DAECommand command)
        {
            _cursor  = cursor;
            _command = command;

            // Cache native types
            _nativeTypes = new ArrayList();
            foreach (TableVarColumn column in _cursor.Plan.TableVar.Columns)
            {
                _nativeTypes.Add(GetNativeType(column.DataType, column, _cursor.Plan.Process.DataTypes));
            }
        }
示例#17
0
        public void CloseCursor(IServerCursor cursor)
        {
            IServerExpressionPlan plan = cursor.Plan;

            try
            {
                plan.Close(cursor);
            }
            finally
            {
                UnprepareExpression(plan);
            }
        }
示例#18
0
        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);
                }
            }
        }
示例#19
0
        protected override void InternalClose()
        {
            if (FSourceRow != null)
            {
                Process.RowManager.ReleaseRow(FSourceRow);
                FSourceRow = null;
            }

            if (FSourceCursor != null)
            {
                Process.ServerSession.RemoteConnect(Node.ServerLink).GetPlan(Node).Dispose();
                FSourceCursor = null;
            }
        }
示例#20
0
        /// <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);
            }
        }
        private static int ReadResult(StringBuilder LResult, IServerExpressionPlan LPlan)
        {
            int rowCount;

            if (LPlan.DataType is DAE.Schema.ITableType)
            {
                IServerCursor cursor = LPlan.Open(null);
                try
                {
                    rowCount = ResultsFromCursor(cursor, LResult);
                    LResult.Append("\r\n");
                }
                finally
                {
                    LPlan.Close(cursor);
                }
            }
            else
            {
                IDataValue value = LPlan.Evaluate(null);
                rowCount = -1;                 // row count not applicable
                if ((value == null) || value.IsNil)
                {
                    LResult.Append(Strings.Get("NoValue"));
                }
                else
                if (LPlan.DataType is DAE.Schema.IRowType)
                {
                    ResultsFromRow((IRow)value, LResult);
                }
                else if (LPlan.DataType is DAE.Schema.IListType)
                {
                    ResultsFromList((ListValue)value, LResult);
                }
                else if (LPlan.DataType is DAE.Schema.IScalarType)
                {
                    LResult.Append(((IScalar)value).AsDisplayString);
                }
                else
                {
                    LResult.Append(String.Format("<Unknown Result Type: {0}>", LPlan.DataType.Name));
                }
                LResult.Append("\r\n");
            }
            return(rowCount);
        }
示例#22
0
        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);
        }
示例#23
0
            public void Close()
            {
                CloseUpdateCursor();

                if (_cursor != null)
                {
                    if (_plan != null)
                    {
                        try
                        {
                            _plan.Close(_cursor);
                        }
                        finally
                        {
                            _cursor = null;
                        }
                    }
                }
            }
示例#24
0
        public void Close(IServerCursor cursor)
        {
            Exception exception    = null;
            int       nestingLevel = _process.BeginTransactionalCall();

            try
            {
                ((ServerCursor)cursor).Dispose();
            }
            catch (Exception E)
            {
                exception = E;
                throw WrapException(E);
            }
            finally
            {
                _process.EndTransactionalCall(nestingLevel, exception);
            }
        }
示例#25
0
 protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
 {
     //This if statement fixes a problem in DbDataAdapter Update abstraction.
     //The ExecuteReader method calls ExecuteNonQuery if the the DAEDataAdapter is performing an Update.
     //It also returns a special DataReader where RecordsAffected is 1.
     //This satisfies the DbDataAdapter.Update abstraction requirements.
     //Without this if statement there is a lot of code to reproduce.
     //To remove this if statement, override DbDataAdapter.Update(DataRow[] ADataRows, DataTableMapping ATableMapping).
     if (_dataAdapterInUpdate)
     {
         ExecuteNonQuery();
         return(new DAEDataReader(this));
     }
     Prepare();
     _behavior = behavior;
     if (_plan == null)
     {
         _plan = _connection.ServerProcess.PrepareExpression(PreparedCommandText, _dAERuntimeParams);
     }
     try
     {
         IServerCursor cursor = ((IServerExpressionPlan)_plan).Open(_dAERuntimeParams);
         try
         {
             _parameters.UpdateParams(_dAERuntimeParams);
             return(new DAEDataReader(cursor, this));
         }
         catch
         {
             ((IServerExpressionPlan)_plan).Close(cursor);
             throw;
         }
     }
     catch
     {
         if (_plan != null)
         {
             _connection.ServerProcess.UnprepareExpression((IServerExpressionPlan)_plan);
         }
         throw;
     }
 }
示例#26
0
        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);
                }
            }
        }
示例#27
0
        public void TestDeleteAtBOF()
        {
            IServerProcess LProcess = DataSession.ServerSession.StartProcess(new ProcessInfo(DataSession.SessionInfo));

            try
            {
                var LFetchCount = DataSession.ServerSession.SessionInfo.FetchCount;
                LProcess.Execute("create table TestDeleteAtBOF { ID : Integer, Name : String, key { ID } };", null);
                LProcess.Execute("insert row { 1 ID, 'Joe' Name } into TestDeleteAtBOF;", null);
                LProcess.Execute("insert row { 2 ID, 'John' Name } into TestDeleteAtBOF;", null);

                IServerCursor LCursor = LProcess.OpenCursor("select TestDeleteAtBOF browse by { ID } capabilities { navigable, backwardsnavigable, bookmarkable, searchable, updateable } isolation browse", null);
                try
                {
                    var LRow = LCursor.Plan.RequestRow();
                    try
                    {
                        LCursor.Last();
                        LCursor.Prior();
                        LCursor.Prior();
                        LCursor.Delete();
                        if (LCursor.BOF() && !LCursor.Next())
                        {
                            throw new Exception("Delete At BOF failed");
                        }
                    }
                    finally
                    {
                        LCursor.Plan.ReleaseRow(LRow);
                    }
                }
                finally
                {
                    LProcess.CloseCursor(LCursor);
                }
            }
            finally
            {
                DataSession.ServerSession.StopProcess(LProcess);
            }
        }
示例#28
0
        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);
                }
            }
        }
示例#29
0
 public override void Close()
 {
     if (!IsClosed)
     {
         try
         {
             DisposeRow();
         }
         finally
         {
             try
             {
                 _cursor.Plan.Close(_cursor);
             }
             finally
             {
                 _cursor = null;
             }
         }
     }
 }
示例#30
0
        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);
            }
        }