public int GetInt(int column) { Contract.Requires(Valid); Contract.Ensures(State == RSState.read); state = RSState.read; return(column); }
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); }
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}"); } }
// 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}"); } }
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}"); } }
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; }
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}"); } }
public void Close() { Contract.Ensures(State == RSState.closed); state = RSState.closed; }
public int GetInt(int column) { Contract.Requires(Valid); Contract.Ensures(State == RSState.read); state = RSState.read; return column; }
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; }