public ICollection <DatabaseFile> GetDatabaseFiles() { string sql = "SELECT name, physical_name, state_desc, (size * 8.0)*1000 AS size, CASE WHEN max_size = -1 THEN 9999999 ELSE (max_size * 8.0)*1000 END AS max_size FROM sys.database_files;"; SqlCommand command = new SqlCommand(sql); IDataReader reader = SqlServerCommandHelper.ExecuteSqlQuery(command); var items = new List <DatabaseFile>(); while (reader.Read()) { items .Add ( new DatabaseFile ( name: reader.GetColumnValue("name").ToString(), physicalFileName: reader.GetColumnValue("physical_name").ToString(), sizeInBytes: Convert.ToInt64(reader.GetColumnValue("size")), stateDesc: reader.GetColumnValue("state_desc").ToString() ) ); } return(items); }
public bool Exists(int id) { string sql = "select 1 from " + GetTableName() + WhereIdEquals(); SqlCommand command = new SqlCommand(sql); AddIdParameterToCommand(command, id); IDataReader reader = SqlServerCommandHelper.ExecuteSqlQuery(command); return(reader.Read()); }
public bool InUse(string userId) { string sql = "select 1 from vw_user_ids_in_use where userid = @userid"; SqlCommand command = new SqlCommand(sql); command.Parameters.AddWithValue("@userid", userId); IDataReader reader = SqlServerCommandHelper.ExecuteSqlQuery(command); return(reader.Read()); }
public T Get(int id) { string sql = GetSelectStatement() + WhereIdEquals(); SqlCommand command = new SqlCommand(sql); AddIdParameterToCommand(command, id); IDataReader reader = SqlServerCommandHelper.ExecuteSqlQuery(command); reader.Read(); return(GetItemFromDataReader(reader)); }
public ICollection <T> GetAll() { string sql = GetSelectStatement() + ";"; SqlCommand command = new SqlCommand(sql); IDataReader reader = SqlServerCommandHelper.ExecuteSqlQuery(command); var items = new List <T>(); while (reader.Read()) { T item = GetItemFromDataReader(reader); items.Add(item); } return(items); }
public ICollection <T> GetMatchingOn(int foreignKeyId) { string sql = GetSelectStatement() + WhereForeignKeyEquals() + ";"; SqlCommand command = new SqlCommand(sql); AddIdParameterToCommand(command, foreignKeyId); IDataReader reader = SqlServerCommandHelper.ExecuteSqlQuery(command); var items = new List <T>(); while (reader.Read()) { T item = GetItemFromDataReader(reader); items.Add(item); } return(items); }