コード例 #1
0
ファイル: SqlServerHelper.cs プロジェクト: Genri1996/FastSql
        /// <summary>
        /// Checks if login exists
        /// </summary>
        /// <param name="login">login name</param>
        /// <returns></returns>
        public bool IsLoginExists(string login)
        {
            string    strQuery = $"USE MASTER SELECT [dbo].[LoginExists]('{login}') AS [exists]";
            DataTable dt;

            using (SqlServerExecutor executor = new SqlServerExecutor(_masterConnectionString))
            {
                dt = executor.ExecuteQueryAsDataTable(strQuery);
            }
            return((bool)dt.Rows[0]["exists"]);
        }
コード例 #2
0
        private bool HasColumnDefaultValue(DataColumn column)
        {
            string query =
                $"SELECT COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '{_dataTable.TableName}' AND COLUMN_NAME = '{column.ColumnName}'";
            DataTable      dtResult;
            IQueryExecutor exe;

            using (exe = new SqlServerExecutor(_dbInfo.ConnectionString))
            {
                dtResult = exe.ExecuteQueryAsDataTable(query);
            }

            return(dtResult.Rows[0][0].GetType() != typeof(DBNull));
        }
コード例 #3
0
        public ActionResult QueryExecutor(QueryExecutorVm vm)
        {
            //Find user
            AppUser      user    = _userManager.FindById(User.Identity.GetUserId());
            DataBaseInfo foundDb = DataBasesManager.GetDbInfos(user.Id).Single(m => m.Id == vm.DbId);

            //TODO: Think, if i need different executors for each DBMS or not

            using (IQueryExecutor executor = new SqlServerExecutor(foundDb.ConnectionString))
            {
                vm.DataTable = executor.ExecuteQueryAsDataTable(vm.Query);
            }
            return(PartialView("QueryResults", vm.DataTable));
        }
コード例 #4
0
        public ActionResult QueryExecutorWithCs(QueryExecutorVm vm)
        {
            var connectionString = Request["conStr"].Trim();

            vm.DataTable = new DataTable();
            var errorDataColumn = new DataColumn("FastSqlQueryErrMessages", typeof(string));

            vm.DataTable.Columns.Add(errorDataColumn);

            //Check if connection string is empty
            if (string.IsNullOrEmpty(connectionString))
            {
                var row = vm.DataTable.NewRow();
                row[0] = "Ваша строка подключения пуста!";
                vm.DataTable.Rows.Add(row);
                return(PartialView("QueryResults", vm.DataTable));
            }
            //Try to establish connection
            IQueryExecutor executor = null;

            try
            {
                executor = new SqlServerExecutor(connectionString);
            }
            catch
            {
                var row = vm.DataTable.NewRow();
                row[0] = "Не удалось установить соеденение.";
                vm.DataTable.Rows.Add(row);
                executor?.Dispose();
                return(PartialView("QueryResults", vm.DataTable));
            }
            //receive data
            vm.DataTable = executor.ExecuteQueryAsDataTable(vm.Query);
            executor.Dispose();

            return(PartialView("QueryResults", vm.DataTable));
        }