Ejemplo n.º 1
0
        /// <summary>
        /// Executes the query, and returns the first column of the first row in the
        /// result set returned by the query. Extra columns or rows are ignored.
        /// </summary>
        public static object ExecuteScalar(SqlConnection connection, string sqlCommandText, int commandTimeOut = 30)
        {
            ArgumentValidation.CheckForEmptyString(sqlCommandText, "sqlCommandText");

            using (SqlCommand cmd = GetCommandObject(connection, sqlCommandText, commandTimeOut))
            {
                return(cmd.ExecuteScalar());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes commands such as Transact-SQL INSERT, DELETE, UPDATE, and SET statements.
        /// </summary>
        public static void Execute(SqlConnection connection, string sqlCommandText, int?commandTimeOut = null)
        {
            ArgumentValidation.CheckForEmptyString(sqlCommandText, "sqlCommandText");

            if (commandTimeOut == null)
            {
                // Assume infinite timeout in this case for now
                commandTimeOut = 0;
            }

            using (SqlCommand cmd = GetCommandObject(connection, sqlCommandText, commandTimeOut.Value))
            {
                cmd.ExecuteNonQuery();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Deploys test scripts to a database and creates a model directly against this DB.
        /// Since this is a RuleTest we load the model as script backed to ensure that we have file names,
        /// source code positions, and that programmability objects (stored procedures, views) have a full SQLDOM
        /// syntax tree instead of just a snippet.
        /// </summary>
        private TSqlModel CreateDatabaseModel()
        {
            ArgumentValidation.CheckForEmptyString(DatabaseName, "DatabaseName");
            SqlTestDB db = TestUtils.CreateTestDatabase(TestUtils.DefaultInstanceInfo, DatabaseName);

            _trash.Add(db);

            TestUtils.ExecuteNonQuery(db, TestScripts.Select(t => t.Item1).SelectMany(s => TestUtils.GetBatches(s)).ToList());

            TSqlModel model = TSqlModel.LoadFromDatabase(db.BuildConnectionString(), new ModelExtractOptions {
                LoadAsScriptBackedModel = true
            });

            AssertModelValid(model);
            return(model);
        }