public static bool ExecuteSqlFile(this ICakeContext context, FilePath path, SqlQuerySettings settings) { if (path == null) { throw new ArgumentNullException("path"); } if (settings == null) { throw new ArgumentNullException("settings"); } ICakeLog log = settings.AllowLogs ? context.Log : new Logging.QuietLog(); IFile file = context.FileSystem.GetFile(path); if (file.Exists) { string query = file.ReadBytes().GetString(); return(context.ExecuteSqlQuery(query, settings)); } else { log.Error("Missing sql file {0}", path.FullPath); return(false); } }
public static bool ExecuteSqlQuery(this ICakeContext context, string query, SqlQuerySettings settings) { if (String.IsNullOrEmpty(query)) { throw new ArgumentNullException("query"); } if (settings == null) { throw new ArgumentNullException("settings"); } ICakeLog log = settings.AllowLogs ? context.Log : new Logging.QuietLog(); ISqlQueryRepository repository = null; switch (settings.Provider) { case "MsSql": repository = new MsSqlQueryRepository(log); break; case "MySql": repository = new MySqlQueryRepository(log); break; case "Npgsql": repository = new NpgsqlQueryRepository(log); break; } if (repository != null) { return(repository.Execute(settings.ConnectionString, query)); } else { log.Error("Unknown sql provider {0}", settings.Provider); return(false); } }