public void SqlServerBulkInsertStatements()
 {
     using (var tr = _dbSqlServer.GetTransaction())
     {
         _dbSqlServer.BulkInsertRecords(GetData(), tr, _sqlServerSyntax, useNativeSqlPlatformBulkInsert: false);
         tr.Complete();
     }
 }
 public void SqlCeOneByOne()
 {
     using (var tr = _dbSqlCe.GetTransaction())
     {
         _dbSqlCe.BulkInsertRecords(GetData(), tr, _sqlCeSyntax, useNativeSqlPlatformBulkInsert: false);
         tr.Complete();
     }
 }
        public void AddApplication(LatchApplication latchApplication)
        {
            using (var scope = db.GetTransaction())
            {
                var deleteQuery = Sql.Builder
                                  .Append("DELETE FROM LatchApplication");

                db.Execute(deleteQuery);
                Insert(latchApplication);

                scope.Complete();
            }
        }
Ejemplo n.º 4
0
 private void RemoveMigrationFromDb(UmbracoDatabase db)
 {
     using (Transaction transaction = db.GetTransaction())
     {
         db.Execute("delete from umbracoMigration where version='{0}'", Constants.Version);
         transaction.Complete();
     }
 }
Ejemplo n.º 5
0
        public void SaveUserLogins(int memberId, IEnumerable <UserLoginInfo> logins)
        {
            using (var t = _db.GetTransaction())
            {
                //clear out logins for member
                _db.Execute("DELETE FROM ExternalLogins WHERE UserId=@userId", new { userId = memberId });

                //add them all
                foreach (var l in logins)
                {
                    _db.Insert(new ExternalLoginDto
                    {
                        LoginProvider = l.LoginProvider,
                        ProviderKey   = l.ProviderKey,
                        UserId        = memberId
                    });
                }

                t.Complete();
            }
        }
        public void Can_Bulk_Insert_Native_Sql_Server_Bulk_Inserts()
        {
            //create the db
            var dbSqlServer = new UmbracoDatabase(
                "server=.\\SQLExpress;database=YOURDB;user id=YOURUSER;password=YOURPASSWORD",
                Constants.DatabaseProviders.SqlServer,
                new DebugDiagnosticsLogger());

            //drop the table
            dbSqlServer.Execute("DROP TABLE [umbracoServer]");

            //re-create it
            dbSqlServer.Execute(@"CREATE TABLE [umbracoServer](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[address] [nvarchar](500) NOT NULL,
	[computerName] [nvarchar](255) NOT NULL,
	[registeredDate] [datetime] NOT NULL CONSTRAINT [DF_umbracoServer_registeredDate]  DEFAULT (getdate()),
	[lastNotifiedDate] [datetime] NOT NULL,
	[isActive] [bit] NOT NULL,
	[isMaster] [bit] NOT NULL,
 CONSTRAINT [PK_umbracoServer] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
)");
            var data = new List <ServerRegistrationDto>();

            for (var i = 0; i < 1000; i++)
            {
                data.Add(new ServerRegistrationDto
                {
                    ServerAddress  = "address" + i,
                    ServerIdentity = "computer" + i,
                    DateRegistered = DateTime.Now,
                    IsActive       = true,
                    DateAccessed   = DateTime.Now
                });
            }

            var sqlServerSyntax = new SqlServerSyntaxProvider();

            using (var tr = dbSqlServer.GetTransaction())
            {
                dbSqlServer.BulkInsertRecords(data, tr, sqlServerSyntax, useNativeSqlPlatformBulkInsert: true);
                tr.Complete();
            }

            // Assert
            Assert.That(dbSqlServer.ExecuteScalar <int>("SELECT COUNT(*) FROM umbracoServer"), Is.EqualTo(1000));
        }
Ejemplo n.º 7
0
        public ActionResult DeleteFormSubmissionRecord(int submissionID)
        {
            bool success = true;

            using (var scope = DatabaseConnection.GetTransaction())
            {
                try
                {
                    DatabaseConnection.Execute("DELETE FROM FormStorageSubmissions WHERE submissionID=@0", submissionID);
                }
                catch (Exception ex)
                {
                    Log.Error("Unable to delete from FormStorageSubmissions table : " + ex.Message);
                    success = false;
                }
                if (success)
                {
                    try
                    {
                        DatabaseConnection.Execute("DELETE FROM FormStorageEntries WHERE submissionID=@0", submissionID);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Unable to delete from FormStorageEntries table : " + ex.Message);
                        success = false;
                    }
                }
                scope.Complete();
            }
            var result = new
            {
                success = success,
            };
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
            string resultJSON = javaScriptSerializer.Serialize(result);

            return(Content(resultJSON, "application/json"));
        }