Esempio n. 1
0
            private void ExecuteScripts(IEnumerable <string> scripts, bool throwExceptions)
            {
                if (scripts == null)
                {
                    return;
                }
                var            sqlExecutor = new SQLExecutor(BootstrapServices);
                IList <string> errors      = new List <string>();

                foreach (var sql in scripts)
                {
                    try {
                        if (ExecuteScriptsWithoutTransaction)
                        {
                            sqlExecutor.ExecuteNonQueryWithoutTransaction(sql);
                        }
                        else
                        {
                            sqlExecutor.ExecuteNonQuery(sql);
                        }
                    } catch (Exception e) {
                        errors.Add(e.Message);
                    }
                }
                if (throwExceptions && errors.Count > 0)
                {
                    throw new Exception(
                              string.Format("Error executing scripts for provider '{0}' with connection string '{1}':{2}{3}",
                                            BootstrapServices.DatabaseConfiguration.DatabaseProvider.Properties.DisplayName,
                                            BootstrapServices.DatabaseConfiguration.ConnectionString,
                                            Environment.NewLine,
                                            string.Join(Environment.NewLine, errors.ToArray())));
                }
            }
Esempio n. 2
0
        public void Insert(T model)
        {
            string sql  = ORMUtil.ConstructInsertStatement(model.GetType());
            var    objs = GetStatementParamArray(model);

            SQLExecutor.ExecuteNonQuery(sql, _connectionString, objs.ToArray());
        }
Esempio n. 3
0
        protected void DeleteByKey(IDictionary <string, object> conditions)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(ORMUtil.ConstructDeleteStatement(typeof(T)));
            sb.Append(ConstructWhereByDictionary(conditions));
            SQLExecutor.ExecuteNonQuery(sb.ToString(), _connectionString, conditions.Values.ToArray());
        }
Esempio n. 4
0
        public void Update(T model)
        {
            string sql = ORMUtil.ConstructUpdateStatement(model.GetType());

            var objs = GetAllParamArrays(model);

            SQLExecutor.ExecuteNonQuery(sql, _connectionString, objs.ToArray());
        }
Esempio n. 5
0
        public static void IntialDB()
        {
            string connectionString = ConfigurationManager.AppSettings["ConnectionString"];
            string sql = @"if not exists (select * from dbo.sysobjects where id = object_id(N'[Employee]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE Employee(
	Id INT IDENTITY NOT NULL PRIMARY KEY ,
	FirstName VARCHAR(100) NOT NULL,
	MiddleName VARCHAR(100)  NULL,
	LastName VARCHAR(100)  NULL,
	DateOfBirth DATETIME NOT NULL
);";

            SQLExecutor.ExecuteNonQuery(sql, connectionString);
        }
        public void TestSetBigParameterStringValues(DatabaseProviderTestCase tc)
        {
            IDatabaseServices databaseServices = tc.Services;
            var sqlExecutor = new SQLExecutor(databaseServices);

            string sql = String.Format(
                "INSERT INTO {0} (ID, VAL_SMALL1, VAL_SMALL2, VAL_BIG1, VAL_BIG2) VALUES (1, {1})",
                databaseServices.DMLService.Identifiers.EscapeIdentifier("BIG_DATA" + MachineName),
                Enumerable.Range(0, 4).Select(i => sqlExecutor.GetParameterName(i, typeof(string))).StrCat(", "));

            const string verySmallStr = "a";
            string       smallStr = NSizedString(50), mediumStr = NSizedString(4000), bigStr = NSizedString(20000);

            var paramValuesInTests = new string[][] {
                new string[] { verySmallStr, verySmallStr, verySmallStr, verySmallStr }, // First test will very small strings
                new string[] { smallStr, smallStr, mediumStr, mediumStr },               // Small and medium strings
                new string[] { smallStr, smallStr, bigStr, bigStr },                     // Small and big strings
            };

            foreach (object[] paramValues in paramValuesInTests)
            {
                Assert.AreEqual(1, sqlExecutor.ExecuteNonQuery(sql, paramValues));
            }
        }