Beispiel #1
0
        private void Create()
        {
            StatusInfo = string.Empty;

            if (!sqlStatement.StartsWith("SELECT", StringComparison.CurrentCultureIgnoreCase))
            {
                StatusInfo = LocalisationHelper.GetString("ViewGeneralTab_InvalidStatement");
                return;
            }

            var exectuableSql = QueryBuilder.CreateView(ViewName)
                                .IfNotExists(IsIfNotExists)
                                .As(sqlStatement)
                                .Build();

            using (var dbHandler = new DatabaseHandler(selectedDatabase.DatabasePath))
            {
                try
                {
                    dbHandler.ExecuteNonQuery(exectuableSql);
                    StatusInfo = LocalisationHelper.GetString("ViewCreator_ViewCreateSuccess");
                    MainTreeHandler.AddView(viewName, selectedDatabase.DatabasePath);
                }
                catch (Exception ex)
                {
                    logger.Error("A view could not be created.", ex);
                    StatusInfo = ex.Message.Replace("SQL logic error or missing database\r\n", "SQL-Error - ");
                }
            }
        }
        public void AddView_WithValidDatabasePath_DoesNotAddViewToDifferentDatabase()
        {
            MainTreeHandler.AddView("NewView", DATABASEPATH1);

            var result = TreeSearcher.DatabaseHoldsItem <ViewFolderItem>(testTree, "NewView", DATABASEPATH2);

            Assert.IsFalse(result);
        }
        public void AddView_WithValidDatabasePath_AddsViewToSpecifiedDatabase()
        {
            MainTreeHandler.AddView("NewView", DATABASEPATH1);

            var result = TreeSearcher.DatabaseHoldsItem <ViewFolderItem>(testTree, "NewView", DATABASEPATH1);

            Assert.IsTrue(result);
        }
 public void AddView_WithInvalidDatabasePath_DoesNotThrowException()
 {
     Assert.DoesNotThrow(
         () => MainTreeHandler.AddView("NewView", "InvalidPath"));
 }