Exemplo n.º 1
0
        // 添加到设计界面
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (tvw.SelectedNode != null)
            {
                string      schemaName  = tvw.SelectedNode.Text;
                MySQLSchema mysqlSchema = _SelectedFields.Find(t => t.tbname.Equals(schemaName, StringComparison.CurrentCultureIgnoreCase));

                if (splitContainer1.Panel1.Controls.Find(mysqlSchema.tbnick, false).Length > 0)
                {
                    return;
                }

                UC_Table uctable = new UC_Table(mysqlSchema);
                uctable.Name        = mysqlSchema.tbnick;
                uctable.Close      += Uctable_Close;
                uctable.ClickField += Uctable_ClickField;
                uctable.AddJoin    += Uctable_AddJoin;

                splitContainer1.Panel1.Controls.Add(uctable);
                if (uctable.IsAccessible == false)
                {
                    uctable.BringToFront();
                }

                BuildSelect();
                AddSubMenu();
            }
        }
Exemplo n.º 2
0
        public void Run_all_MySQL_integration_tests_work()
        {
            // Arrange
            var    cnn        = _dbContainer.CreateDbConnection();
            var    wcnn       = new WrappedConnection(cnn).AssertDatabaseServerType(DBMS.MySQL);
            var    db         = DatabaseHelperFactory.GetDatabaseHelper(DBMS.MySQL, wcnn);
            string schemaName = "My metadata schema";
            var    schema     = new MySQLSchema(schemaName, wcnn);

            // Assert
            schema.AssertIsNotExists();
            schema.AssertCreation();
            schema.AssertExists();
            schema.AssertIsEmpty();

            db.AssertDefaultSchemaName(MySQLContainer.DbName)
            .AssertApplicationLock(_dbContainer.CreateDbConnection())
            .AssertMetadataTableCreation(schemaName, "change log")
            .AssertMetadataTableLock()
            .AssertSchemaIsDroppableWhenNewSchemaFound(schemaName) // id:1
            .AssertVersionedMigrationSave()                        // id:2
            .AssertVersionedMigrationChecksumUpdate()
            .AssertRepeatableMigrationSave();                      // id:3

            schema.AssertIsNotEmpty();
            schema.Erase();
            schema.AssertIsEmpty();
            schema.Drop();
            schema.AssertIsNotExists();

            db.AssertCloseConnection();
        }
Exemplo n.º 3
0
        private void Uctable_ClickField(string tbname, string fieldname, bool clicked)
        {
            // 更新选择状态
            MySQLSchema mysqlSchema = _SelectedFields.Find(t => t.tbname.Equals(tbname, StringComparison.CurrentCultureIgnoreCase));

            mysqlSchema.tbfields.Find(x => x.FieldName.Equals(fieldname, StringComparison.CurrentCultureIgnoreCase)).Checked = clicked;

            Application.DoEvents();
            BuildSQL();
        }
Exemplo n.º 4
0
        public UC_Table(MySQLSchema mysqlSchema)
        {
            InitializeComponent();
            this.mysqlSchema = mysqlSchema;

            this.tipInfo.Text = mysqlSchema.tbname + "(" + mysqlSchema.tbnick + ")";
            int flagPos = this.tipInfo.Text.IndexOf("(");

            if (flagPos != -1)
            {
                this.tipInfo.LinkArea = new LinkArea(flagPos + 1, this.tipInfo.Text.Length - flagPos - 2);
            }

            checkedListBox1.Items.Clear();
            foreach (MySQLField sqlField in mysqlSchema.tbfields)
            {
                checkedListBox1.Items.Add(sqlField.FieldName);
            }
        }
Exemplo n.º 5
0
        public void Run_all_MySQL_integration_tests_work()
        {
            // Open a connection to the PostgreSQL database
            var cnn = new MySqlConnection($"Server=127.0.0.1;Port={_fixture.MySql.HostPort};Database={_fixture.MySql.DbName};Uid={_fixture.MySql.DbUser};Pwd={_fixture.MySql.DbPwd};");

            cnn.Open();
            Assert.True(cnn.State == ConnectionState.Open, "Cannot open a connection to the database.");

            // Initiate a connection to the database
            var wcnn = new WrappedConnection(cnn);

            // Validate DBMS.MySQL_MariaDB
            Assert.Equal(DBMS.MySQL_MariaDB, wcnn.GetDatabaseServerType());

            // Init the DatabaseHelper
            DatabaseHelper db = DatabaseHelperFactory.GetDatabaseHelper(DBMS.MySQL_MariaDB, wcnn);

            // Get default schema name
            Assert.True(db.GetCurrentSchemaName() == _fixture.MySql.DbName, $"The default MySQL schema should be '{_fixture.MySql.DbName}'.");

            // Create schema
            string metadataSchemaName = "My metadata schema";
            Schema metadataSchema     = new MySQLSchema(metadataSchemaName, wcnn);

            Assert.False(metadataSchema.IsExists(), $"The schema [{metadataSchemaName}] should not already exist.");
            Assert.True(metadataSchema.Create(), $"Creation of the schema [{metadataSchemaName}] failed.");
            Assert.True(metadataSchema.IsExists(), $"The schema [{metadataSchemaName}] should be created.");
            Assert.True(metadataSchema.IsEmpty(), $"The schema [{metadataSchemaName}] should be empty.");

            // Get MetadataTable
            string metadataTableName = "change log";
            var    metadata          = db.GetMetadataTable(metadataSchemaName, metadataTableName);

            // Create MetadataTable
            Assert.False(metadata.IsExists(), "MetadataTable sould not already exist.");
            Assert.True(metadata.CreateIfNotExists(), "MetadataTable creation failed.");
            Assert.True(metadata.IsExists(), "MetadataTable sould exist.");
            Assert.False(metadata.CreateIfNotExists(), "MetadataTable already exists. Creation should return false.");
            Assert.True(metadata.GetAllMigrationMetadata().Count() == 0, "No migration metadata should be found.");

            // Lock MetadataTable
            metadata.Lock();

            // Save NewSchema metadata
            metadata.Save(MetadataType.NewSchema, "0", "New schema created.", metadataSchemaName);
            Assert.True(metadata.CanDropSchema(metadataSchemaName), $"[{metadataSchemaName}] should be droppable.");
            Assert.False(metadata.CanEraseSchema(metadataSchemaName), $"[{metadataSchemaName}] should not be erasable.");

            // Add metadata migration
            var migrationScript = new FileMigrationScript(TestContext.EmptyMigrationScriptPath, "1_3_2", "Migration_description");

            metadata.SaveMigration(migrationScript, true);
            var migrationMetadata = metadata.GetAllMigrationMetadata().FirstOrDefault();

            Assert.True(migrationMetadata != null, "One migration metadata should be found.");
            Assert.True(migrationMetadata.Version == migrationScript.Version, "Metadata version is not the same.");
            Assert.True(migrationMetadata.Checksum == migrationScript.CheckSum, "Metadata checksum is not the same.");
            Assert.True(migrationMetadata.Description == migrationScript.Description, "Metadata descritpion is not the same.");
            Assert.True(migrationMetadata.Name == migrationScript.Name, "Metadata name is not the same.");
            Assert.True(migrationMetadata.Success == true, "Metadata success is not true.");
            Assert.True(migrationMetadata.Id > 0, "Metadata id is not set.");
            Assert.True(migrationMetadata.InstalledOn.Date == DateTime.Now.Date, "Installed date is not set.");

            // Update checksum
            metadata.UpdateChecksum(migrationMetadata.Id, "Hi !");
            Assert.Equal("Hi !", metadata.GetAllMigrationMetadata().First().Checksum);

            // Assert metadata schema is not empty
            Assert.False(metadataSchema.IsEmpty(), $"[{metadataSchemaName}] should not be empty.");

            // Erase schema
            metadataSchema.Erase();
            Assert.True(metadataSchema.IsEmpty(), $"The schema [{metadataSchemaName}] should be empty.");
            Assert.True(metadataSchema.IsExists(), $"The schema [{metadataSchemaName}] should exist.");

            // Drop schema
            metadataSchema.Drop();
            Assert.False(metadataSchema.IsExists(), $"The schema [{metadataSchemaName}] should not exist.");
        }
Exemplo n.º 6
0
        private void tvw_AfterSelect(object sender, TreeViewEventArgs e)
        {
            mysqlFields.Clear();

            tbx_TableName.Text = e.Node.Text;
            dt.Rows.Clear();
            //dgv.Rows.Clear();
            MySqlConnection dbConn = new MySqlConnection();

            try {
                dbConn.ConnectionString = getConnectionString();
                dbConn.Open();

                string       schemaName = e.Node.Text;
                MySqlCommand dbCmd      = new MySqlCommand();
                dbCmd.CommandText = "SHOW full COLUMNS FROM " + schemaName;
                dbCmd.Connection  = dbConn;

                MySqlDataAdapter dbAdapter = new MySqlDataAdapter(dbCmd);
                dbAdapter.Fill(dt);
                dt.TableName = Guid.NewGuid().ToString().Replace("-", "");

                dgv.DataSource = dt;
                List <MySQLField> _addFields = new List <MySQLField>();
                foreach (DataRow row in dt.Rows)
                {
                    MySQLField field = new MySQLField();
                    field.FieldName = row["field"].ToString();
                    field.Type      = row["type"].ToString();
                    field.Key       = row["key"].ToString();
                    field.Comment   = row["comment"].ToString();

                    mysqlFields.Add(field);
                    _addFields.Add(field);
                }


                if (_SelectedFields.Exists(t => t.tbname.Equals(schemaName, StringComparison.CurrentCultureIgnoreCase)) == false)
                {
                    string tpnick = "a";
                    //NickIndex index = nickIndex.Find(t => t.Name.Equals(schemaName));
                    //if(index == null) {
                    //    index = new NickIndex();
                    //    index.Name = schemaName;
                    //    index.Index = newNickIndex++;

                    //    nickIndex.Add(index);
                    //}
                    //tpnick += index.Index;

                    MySQLSchema mysqlSchema = new MySQLSchema();
                    mysqlSchema.tbname   = schemaName;
                    mysqlSchema.tbnick   = tpnick;
                    mysqlSchema.tbfields = _addFields;

                    _SelectedFields.Add(mysqlSchema);
                }
                //if(_SelectedFields.ContainsKey(e.Node.Text)== false) {
                //    _SelectedFields.Add(e.Node.Text,_addFields);
                //}
                //if(e.Node.Tag == null) {
                //    e.Node.Tag = mysqlFields;
                //}
            } catch (Exception exc) {
                Console.WriteLine(exc.ToString());
            } finally {
                dbConn.Close();
                dbConn = null;
            }

            if (tabControl2.SelectedTab == tp_selectBuilder && e.Node.Level >= 1)
            {
                contextMenuStrip1.Show(tvw, tvw.PointToClient(MousePosition));
            }
        }