public void UpdateDatabaseTester() { //arrange string scriptsDirectory = Path.Combine("Scripts", GetType().Name.Replace("Tester", "")); var settings = new ConnectionSettings(".\\sqlexpress", "aliasqltest", true, null, null); new DbUpdater().UpdateDatabase(new ConnectionStringGenerator().GetConnectionString(settings, true), RequestedDatabaseAction.Drop, scriptsDirectory); //act bool success = new DbUpdater().UpdateDatabase(new ConnectionStringGenerator().GetConnectionString(settings, true), RequestedDatabaseAction.Create, scriptsDirectory).Success; //assert int records = 0; AssertUsdAppliedDatabaseScriptTable(settings, reader => { while (reader.Read()) { records++; reader["ScriptFile"].ShouldEqual("0001-Update.sql"); } }); success.ShouldEqual(true); records.ShouldEqual(1); }
protected void Application_Start() { var builder = new ContainerBuilder(); builder.RegisterControllers(typeof(MvcApplication).Assembly); builder.RegisterType <DbContextProvider>().As <IDbContextProvider>().InstancePerRequest(); builder.RegisterType <ShopRepository>().As <IShopRepository>().InstancePerRequest(); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); Database.SetInitializer(new ShopDBInitializer()); EntityDbContext context = new EntityDbContext(); context.Database.Initialize(true); var grabber = new SourceGrabber(); var updater = new DbUpdater(); var parser = new XmlParser(); updater.AddOrUpdateItems(context, grabber, parser, ConfigurationManager.AppSettings["SourceURL"]); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
private static void BindUpdateParameters(DomainIgnore domainIgnore, DbUpdater updater, bool includeId = true) { if (includeId) { updater.BindParameter("domain_ignore_id", System.Data.DbType.Int32, domainIgnore.DomainIgnoreId); } updater.BindParameter("domain_to_ignore", System.Data.DbType.String, domainIgnore.DomainToIgnore); updater.BindParameter("domain_id", System.Data.DbType.Int32, domainIgnore.DomainId); }
private static void BindUpdateParameters(Subdomain subdomain, DbUpdater updater, bool includeId = true) { if (includeId) { updater.BindParameter("sub_domain_id", System.Data.DbType.Int32, subdomain.SubdomainId); } updater.BindParameter("sub_domain_name", System.Data.DbType.String, subdomain.SubdomainName); updater.BindParameter("domain_id", System.Data.DbType.Int32, subdomain.DomainId); updater.BindParameter("date_found", System.Data.DbType.DateTime, subdomain.DateFound); updater.BindParameter("found_type", System.Data.DbType.String, subdomain.FoundType); }
private static int Main() { const string connectionStringName = "BibleTraining"; var scriptVariables = ConfigurationVariables.ToDictionary(s => s, s => ConfigurationManager.AppSettings[s]); var env = EnvParser.Parse(scriptVariables["Env"]); var shouldSeedData = env == Env.LOCAL; var dbName = ConfigurationManager.AppSettings["DbName"]; var dbUpdater = new DbUpdater(Assembly.GetExecutingAssembly(), "Scripts", dbName, connectionStringName, scriptVariables, shouldSeedData, env); return(dbUpdater.Run() ? 0 : -1); }
private static void BindUpdateParameters(Clark.Domain.Data.Domain domain, DbUpdater updater, bool includeId = true) { if (includeId) { updater.BindParameter("domain_id", System.Data.DbType.Int32, domain.DomainId); } updater.BindParameter("domain_name", System.Data.DbType.String, domain.DomainName); updater.BindParameter("bounty_url", System.Data.DbType.String, domain.BountyURL); updater.BindParameter("bounty_end_date", System.Data.DbType.DateTime, domain.BountyEndDate); updater.BindParameter("last_scan", System.Data.DbType.DateTime, domain.LastScan); updater.BindParameter("private", System.Data.DbType.Boolean, domain.Private); updater.BindParameter("platform", System.Data.DbType.String, domain.Platform); }
public void PendingChangesTester() { //arrange string scriptsDirectory = Path.Combine("Scripts", GetType().Name.Replace("Tester", "")); var settings = new ConnectionSettings(".\\sqlexpress", "aliasqltest", true, null, null); new DbUpdater().UpdateDatabase(new ConnectionStringGenerator().GetConnectionString(settings, true), RequestedDatabaseAction.Drop, scriptsDirectory); bool updated = new DbUpdater().UpdateDatabase(new ConnectionStringGenerator().GetConnectionString(settings, true), RequestedDatabaseAction.Update, scriptsDirectory).Success; //act List <string> pendingChanges = new DbUpdater().PendingChanges(new ConnectionStringGenerator().GetConnectionString(settings, true), scriptsDirectory.Replace("DbUpdater", "NewEverytimeScript")); //assert pendingChanges.Count.ShouldEqual(1); }
private void bConfirmClick(object sender, EventArgs e) { StringBuilder builder = new StringBuilder(); Importer importer = new Importer(); DbUpdater dbUpdater = new DbUpdater(connection); try { string commandText = $"UPDATE {tableName} SET {columnToUpdate} = @value WHERE {keyColumn} = @id"; dbUpdater.StartTransacation(); // Two column are in ID as is one and the value to be updated is second. foreach (var value in importer.ImportValues(filePath)) { if (dbUpdater.ExecuteUpdate( commandText, new List <Tuple <string, object> >() { Tuple.Create("@id", (object)value.Item1), Tuple.Create("@value", (object)value.Item2), }) != 1) { builder.AppendLine($"Neuspešno importovanje za ID {value.Item1} na vrednost {value.Item2}."); } } string outputLog = builder.ToString(); if (string.IsNullOrEmpty(outputLog)) { MessageBox.Show("Uspešno izvršene izmene."); dbUpdater.CommitChanges(); } else { MessageBox.Show("Neuspešno izvršene izmene. Pogledajte log."); File.WriteAllText("ImportData.txt", outputLog); dbUpdater.RollBackChanges(); } } catch (Exception ex) { MessageBox.Show("Neuspešno izvršene izmene. Pogledajte log."); File.WriteAllText("ImportData.txt", string.Join("\n", ex, builder.ToString())); dbUpdater.RollBackChanges(); } }
public static IServiceCollection ConfigureDatabase(this IServiceCollection services, IConfiguration configuration) { var connectionString = configuration["Database:ConnectionString"]; if (string.IsNullOrWhiteSpace(connectionString)) { Log.Fatal("Neither Database connection nor Api url was configured in appsettings.json"); throw new ApplicationException("Neither Database connection nor Api url was configured in appsettings.json"); } services.AddSingleton(_ => new DatabaseConnectionString(connectionString)); Log.Information("Database connection string: '{ConnectionString}'", connectionString.MaskDbConnectionString()); DbUpdater.CheckAndUpdateDatabaseVersion(connectionString); return(services); }
public void DatabaseVersionTester() { //arrange string scriptsDirectory = Path.Combine("Scripts", GetType().Name.Replace("Tester", "")); var settings = new ConnectionSettings(".\\sqlexpress", "aliasqltest", true, null, null); new DbUpdater().UpdateDatabase(new ConnectionStringGenerator().GetConnectionString(settings, true), RequestedDatabaseAction.Drop, scriptsDirectory); int dbversionbeforeupdate = new DbUpdater().DatabaseVersion(new ConnectionStringGenerator().GetConnectionString(settings, true)); bool updated = new DbUpdater().UpdateDatabase(new ConnectionStringGenerator().GetConnectionString(settings, true), RequestedDatabaseAction.Update, scriptsDirectory).Success; //act int dbversionafterupdate = new DbUpdater().DatabaseVersion(new ConnectionStringGenerator().GetConnectionString(settings, true)); //assert dbversionbeforeupdate.ShouldEqual(0); dbversionafterupdate.ShouldEqual(1); }
public UpdateResult Insert(Subdomain subdomain) { var result = new UpdateResult(); try { DbUpdater updater = new DbUpdater(); BindUpdateParameters(subdomain, updater, false); result.Id = updater.Insert("sub_domain"); } catch (Exception ex) { result.Error = true; result.Message = ex.Message; if (ex.InnerException != null) { result.Message += " Inner: " + ex.InnerException.Message; } } return(result); }
public UpdateResult Update(DomainIgnore domainIgnore) { var result = new UpdateResult(); try { DbUpdater updater = new DbUpdater(); BindUpdateParameters(domainIgnore, updater, false); result.Id = updater.Update("domain_ignore", "domain_ignore_id", domainIgnore.DomainIgnoreId); } catch (Exception ex) { result.Error = true; result.Message = ex.Message; if (ex.InnerException != null) { result.Message += " Inner: " + ex.InnerException.Message; } } return(result); }