Esempio n. 1
0
        private void Create()
        {
            StatusInfo = string.Empty;

            if (SelectedDatabase == null)
            {
                StatusInfo = LocalisationHelper.GetString("TableCreator_NoDatabaseSelected");
                return;
            }

            if (!string.IsNullOrEmpty(SqlStatement))
            {
                var database = SelectedDatabase as DatabaseSelectItem;
                using (var dbHandler = new DatabaseHandler(database.DatabasePath))
                {
                    try
                    {
                        dbHandler.ExecuteNonQuery(SqlStatement);
                        StatusInfo = LocalisationHelper.GetString("TableCreator_TableCreateSuccess");

                        MainTreeHandler.AddTable(tableName, selectedDatabase.DatabasePath);
                    }
                    catch (Exception ex)
                    {
                        logger.Error("An error occured when the user tried to create a table from the TableCreator.", ex);
                        StatusInfo = ex.Message.Replace("SQL logic error or missing database\r\n", "SQL-Error - ");
                    }
                }
            }
        }
Esempio n. 2
0
        public void AddTable_WithValidDatabasePath_DoesNotAddTableToDifferentDatabase()
        {
            MainTreeHandler.AddTable("NewTable", DATABASEPATH1);

            var result = TreeSearcher.DatabaseHoldsItem <TableFolderItem>(testTree, "NewTable", DATABASEPATH2);

            Assert.IsFalse(result);
        }
Esempio n. 3
0
        public void AddTable_WithValidDatabasePath_AddsTableToSpecifiedDatabase()
        {
            MainTreeHandler.AddTable("NewTable", DATABASEPATH1);

            var result = TreeSearcher.DatabaseHoldsItem <TableFolderItem>(testTree, "NewTable", DATABASEPATH1);

            Assert.IsTrue(result);
        }
Esempio n. 4
0
        private void CopyTable()
        {
            logger.Info("Copying table '" + tableName + "' as '" + TargetTableName
                        + "' from database " + Environment.NewLine + sourceDatabase + Environment.NewLine
                        + " to database " + Environment.NewLine + selectedDatabase.DatabasePath);

            bool isSuccessfullTableCopy = false;

            try
            {
                using (var sourceTableHandler = new TableHandler(sourceDatabase))
                    using (var targetDbHandler = new DatabaseHandler(selectedDatabase.DatabasePath))
                    {
                        var originalTable   = sourceTableHandler.GetTable(tableName);
                        var createStatement = originalTable.CreateStatement.Replace(tableName, TargetTableName);

                        targetDbHandler.ExecuteNonQuery(createStatement);

                        MainTreeHandler.AddTable(TargetTableName, selectedDatabase.DatabasePath);

                        StatusInfo             = LocalisationHelper.GetString("TableMigrator_CopySuccess");
                        isSuccessfullTableCopy = true;
                        logger.Info("Successfully copied table structure to target database.");
                    }
            }
            catch (Exception ex)
            {
                logger.Error("A table could not be copied.", ex);
                StatusInfo = ex.Message.Replace("SQL logic error or missing database\r\n", "SQL-Error - ");
            }

            if (!IsOnlyStructure && isSuccessfullTableCopy)
            {
                CopyValues();
            }
        }
Esempio n. 5
0
 public void AddTable_WithInvalidDatabasePath_DoesNotThrowException()
 {
     Assert.DoesNotThrow(
         () => MainTreeHandler.AddTable("NewTable", "InvalidPath"));
 }