예제 #1
0
        public int GetInt(int column)
        {
            Contract.Requires(Valid);
            Contract.Ensures(State == RSState.read);

            state = RSState.read;
            return(column);
        }
예제 #2
0
        public bool Next()
        {
            Contract.Requires(IsOpen);
            Contract.Ensures(Contract.Result <bool>() && State == RSState.unread ||
                             !Contract.Result <bool>() && State == RSState.end);

            state = RSState.unread;
            return(true);
        }
예제 #3
0
        public Recordset(string Sql, cDataAccess da) : base()
        {
            string _stage = "Creating object";

            try
            {
                SQL   = Sql;
                DA    = da;
                State = RSState.Closed;
            }
            catch (Exception ex)
            {
                throw new Exception($"[{this.GetType().Name}/{System.Reflection.MethodBase.GetCurrentMethod().Name}#{_stage}] {ex.Message}");
            }
        }
예제 #4
0
        // Constructor
        public Recordset() : base()
        {
            string _stage = "Creating object";

            try
            {
                DR      = null;
                Command = new SqlCommand();
                State   = RSState.Closed;
            }
            catch (Exception ex)
            {
                throw new Exception($"[{this.GetType().Name}/{System.Reflection.MethodBase.GetCurrentMethod().Name}#{_stage}] {ex.Message}");
            }
        }
예제 #5
0
        public void Close()
        {
            string _stage = "Closing recordset";

            try
            {
                DR.Close();
                DR      = null;
                Command = null;
                Result  = null;
                State   = RSState.Closed;
            }
            catch (Exception ex)
            {
                throw new Exception($"[{this.GetType().Name}/{System.Reflection.MethodBase.GetCurrentMethod().Name}#{_stage}] {ex.Message}");
            }
        }
예제 #6
0
 public virtual void Move(int Idx, bool silent = true)
 {
     if (RecordCount == 0)
     {
         EOF = true;
         BOF = true;
         return;
     }
     if (Idx < 0)
     {
         Index = 0;
         EOF   = false;
         BOF   = true;
         if (!silent)
         {
             throw new Exception("Current record is the first one.");
         }
     }
     if (Idx > RecordCount - 1)
     {
         Index = RecordCount - 1;
         EOF   = true;
         BOF   = false;
         if (!silent)
         {
             throw new Exception("Current record is the last one.");
         }
     }
     if (Idx < RecordCount)
     {
         EOF = false;
     }
     mState = RSState.Fetching;
     Index  = Idx;
     mState = RSState.Open;
 }
예제 #7
0
        private async Task Execute(bool async = false)
        {
            string _stage = "Checking connection";

            try
            {
                //
                ConnectionState prevState = DA.Conn.State;
                if (prevState != ConnectionState.Open)
                {
                    if (!async)
                    {
                        DA.Conn.Open();
                    }
                    else
                    {
                        await DA.Conn.OpenAsync();
                    }
                }

                //
                _stage  = "Creating command object";
                Command = new SqlCommand(SQL, DA.Conn);
                State   = RSState.Executing;

                //
                _stage = "Executing reader";
                if (!async)
                {
                    DR = Command.ExecuteReader();
                }
                else
                {
                    DR = await Command.ExecuteReaderAsync();
                }

                //
                _stage = "Getting fields list";
                Fields = DR.GetSchemaTable().Rows.OfType <DataRow>().Select(r => r["ColumnName"].ToString()).ToList();

                //
                _stage = "Loading data table";
                DT     = new DataTable();
                if (!async)
                {
                    DT.Load(DR);
                }
                else
                {
                    await Task.Run(() => DT.Load(DR));
                }

                //
                _stage = "Creating list of results";
                Result = DT.Rows.OfType <DataRow>().ToList();
                EOF    = Result.Count() == 0;
                Index  = 0;
                State  = RSState.Open;

                // Close the connection in case it was closed before this execution (leave things as they were)
                if (prevState != ConnectionState.Open)
                {
                    _stage = "Closing connection";
                    DA.Conn.Close();
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"[{this.GetType().Name}/{System.Reflection.MethodBase.GetCurrentMethod().Name}#{_stage}] {ex.Message}");
            }
        }
예제 #8
0
 public void Close()
 {
     Contract.Ensures(State == RSState.closed);
     state = RSState.closed;
 }
예제 #9
0
 public void Close()
 {
   Contract.Ensures(State == RSState.closed);
   state = RSState.closed;
 }
예제 #10
0
    public int GetInt(int column)
    {
      Contract.Requires(Valid);
      Contract.Ensures(State == RSState.read);

      state = RSState.read;
      return column;
    }
예제 #11
0
    public bool Next()
    {
      Contract.Requires(IsOpen);
      Contract.Ensures(Contract.Result<bool>() && State == RSState.unread ||
                       !Contract.Result<bool>() && State == RSState.end);

      state = RSState.unread;
      return true;
    }