public ExecuteQuery ( string sql ) : IDataReader | ||
sql | string | The SQL to run. |
return | IDataReader |
public virtual bool ChangelogTableExists() { using (IDataReader reader = queryExecuter.ExecuteQuery( @"SELECT table_schema FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = @1", this.changeLogTableName)) { return(reader.Read()); } }
/// <summary> /// Gets the applied changes from the database.. /// </summary> /// <returns>List of applied changes.</returns> /// <exception cref="SchemaVersionTrackingException">Could not retrieve change log from database because: + e.Message</exception> public virtual IList <ChangeEntry> GetAppliedChanges() { if (!ChangeLogTableExists()) { return(new List <ChangeEntry>()); } var changes = new List <ChangeEntry>(); try { // Find all changes that are not resolved. var sql = string.Format(CultureInfo.InvariantCulture, "SELECT ChangeId, Folder, ScriptNumber, ScriptName, ScriptStatus, ScriptOutput FROM {0}", changeLogTableName); using (var reader = queryExecuter.ExecuteQuery(sql)) { while (reader.Read()) { var folder = GetValue <string>(reader, "Folder"); var scriptNumber = GetShort(reader, "ScriptNumber"); var changeEntry = new ChangeEntry(folder, scriptNumber); changeEntry.ChangeId = GetValue <string>(reader, "ChangeId"); changeEntry.ScriptName = GetValue <string>(reader, "ScriptName"); changeEntry.Status = (ScriptStatus)GetByte(reader, "ScriptStatus"); changeEntry.Output = GetValue <string>(reader, "ScriptOutput"); changes.Add(changeEntry); } } // Make sure everything is in correct ordering. changes.Sort(); return(changes); } catch (DbException e) { throw new SchemaVersionTrackingException( "Could not retrieve change log from database because: " + e.Message, e); } }