当前位置: 首页>>代码示例>>C#>>正文


C# MySqlClient.MySqlScript类代码示例

本文整理汇总了C#中MySql.Data.MySqlClient.MySqlScript的典型用法代码示例。如果您正苦于以下问题:C# MySqlScript类的具体用法?C# MySqlScript怎么用?C# MySqlScript使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MySqlScript类属于MySql.Data.MySqlClient命名空间,在下文中一共展示了MySqlScript类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Setup

        public override void Setup()
        {
            base.Setup();

              // Replace existing listeners with listener for testing.
              Trace.Listeners.Clear();
              Trace.Listeners.Add(this.asertFailListener);

              ResourceManager r = new ResourceManager("MySql.Data.Entity.Tests.Properties.Resources", typeof(BaseEdmTest).Assembly);
              string schema = r.GetString("schema");
              MySqlScript script = new MySqlScript(conn);
              script.Query = schema;
              script.Execute();

              // now create our procs
              schema = r.GetString("procs");
              script = new MySqlScript(conn);
              script.Delimiter = "$$";
              script.Query = schema;
              script.Execute();

              //ModelFirstModel1
              schema = r.GetString("ModelFirstModel1");
              script = new MySqlScript(conn);
              script.Query = schema;
              script.Execute();

              MySqlCommand cmd = new MySqlCommand("DROP DATABASE IF EXISTS `modeldb`", rootConn);
              cmd.ExecuteNonQuery();
        }
开发者ID:schivei,项目名称:mysql-connector-net,代码行数:30,代码来源:BaseEdmTest.cs

示例2: CanCreateDBScriptWithDateTimePrecision

        public void CanCreateDBScriptWithDateTimePrecision()
        {
            if (Version < new Version(5, 6, 5)) return;

             MySqlConnection c = new MySqlConnection(conn.ConnectionString);
             c.Open();

             var script = new MySqlScript(c);
             using (var ctx = new datesTypesEntities())
             {
               MySqlCommand query = new MySqlCommand("Create database test_types", c);
               query.Connection = c;
               query.ExecuteNonQuery();
               c.ChangeDatabase("test_types");

               script.Query = ctx.CreateDatabaseScript();
               script.Execute();

               query = new MySqlCommand("Select Column_name, Is_Nullable, Data_Type, DateTime_Precision from information_schema.Columns where table_schema ='" + c.Database + "' and table_name = 'Products' and column_name ='DateTimeWithPrecision'", c);
               query.Connection = c;
               MySqlDataReader reader = query.ExecuteReader();
               while (reader.Read())
               {
              Assert.AreEqual("DateTimeWithPrecision", reader[0].ToString());
              Assert.AreEqual("NO", reader[1].ToString());
              Assert.AreEqual("datetime", reader[2].ToString());
              Assert.AreEqual("3", reader[3].ToString());
               }
               reader.Close();
               ctx.DeleteDatabase();
               c.Close();
             }
        }
开发者ID:schivei,项目名称:mysql-connector-net,代码行数:33,代码来源:DatesTypesTests.cs

示例3: Button4_Click

 private void Button4_Click(object sender, EventArgs e)
 {
     if (
         MessageBox.Show(this,
             @"การสร้างฐานข้อมูลใหม่จะลบ ฐานข้อมูลเก่าออกทั้งหมด คุณต้องการจะดำเนินการต่อหรือไม่?",
             @"ลบฐานข้อมูล", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         try
         {
             if (_conn.State != ConnectionState.Closed)
             {
                 _conn.Close();
             }
             _conn.Open();
             var sc = new MySqlScript(_conn, Settings.Default.sql);
             if (sc.Execute() >= 1)
             {
                 MessageBox.Show(@"สร้างฐานข้อมูลสำเร็จ");
             }
             else
             {
                 MessageBox.Show(@"สร้างฐานข้อมูลล้มเหลว");
             }
         }
         catch (MySqlException ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
开发者ID:epiczeth,项目名称:ATGraphicHouse,代码行数:30,代码来源:frmMain.cs

示例4: LoadSchema

        protected void LoadSchema(int version)
        {
            if (version < 1) return;

              MySQLMembershipProvider provider = new MySQLMembershipProvider();

              ResourceManager r = new ResourceManager("MySql.Web.Properties.Resources", typeof(MySQLMembershipProvider).Assembly);
              string schema = r.GetString(String.Format("schema{0}", version));
              MySqlScript script = new MySqlScript(conn);
              script.Query = schema;

              try
              {
            script.Execute();
              }
              catch (MySqlException ex)
              {
            if (ex.Number == 1050 && version == 7)
            {
              // Schema7 performs several renames of tables to their lowercase representation.
              // If the current server OS does not support renaming to lowercase, then let's just continue.
              script.Query = "UPDATE my_aspnet_schemaversion SET version=7";
              script.Execute();
            }
              }
        }
开发者ID:schivei,项目名称:mysql-connector-net,代码行数:26,代码来源:BaseTest.cs

示例5: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("此操作会清空软件中的所有数据,如果有数据,请做好数据备份(导出)!您是否继续?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
            {
                try
                {
                    using (MySqlConnection conn = DBA.MySqlDbAccess.GetMySqlConnection())
                    {

                        conn.Open();

                        string sql = File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "xy.dll", Encoding.GetEncoding("utf-8"));
                        MySqlScript script = new MySqlScript(conn);

                        script.Query = sql;
                        int count = script.Execute();
                    }
                    MessageBox.Show("数据库已更新至最新版本!", "提示");
                    log.Info("执行数据库重置:" + DateTime.Now.ToString());
                    showversion();
                }
                catch (Exception ex)
                {
                    log.Error(ex.ToString());
                }
            }
        }
开发者ID:xy19xiaoyu,项目名称:PatSI,代码行数:27,代码来源:Version.cs

示例6: run_sql

		// http://bugs.mysql.com/bug.php?id=46429
		public override void run_sql(string sql_to_run)
		{
			if (string.IsNullOrEmpty(sql_to_run)) return;

			// TODO Investigate how pass CommandTimeout into commands which will be during MySqlScript execution.
			var connection = server_connection.underlying_type().downcast_to<MySqlConnection>();
			var script = new MySqlScript(connection, sql_to_run);
			script.Execute();
		}
开发者ID:diyan,项目名称:Roundhouse.MySQL,代码行数:10,代码来源:MySqlDatabase.cs

示例7: RecreateMysqlDatabase

 public static void RecreateMysqlDatabase()
 {
     if (!Connection.State.ToString().Equals("Open"))
     {
         Connection.Open();
     }
     var runScript = new MySqlScript(Connection, Properties.Settings.Default.WipeDatabase);
     runScript.Execute();
     Connection.Close();
 }
开发者ID:jpfrost,项目名称:CotsSalesAndInventory,代码行数:10,代码来源:DatabaseConnection.cs

示例8: ExecuteScript

        public override int ExecuteScript(DbConnection conn, string sql, string delimiter)
        {
            MySqlScript script = new MySqlScript((MySqlConnection) conn, sql);

            if (!string.IsNullOrEmpty(delimiter))
            {
                script.Delimiter = delimiter;
            }

            return script.Execute();
        }
开发者ID:ReinhardHsu,项目名称:devfw,代码行数:11,代码来源:MySqlFactory.cs

示例9: CreateDb

        private bool  CreateDb()
        {
            bool bRs = false;

            string connStr = string.Format("server={0};user={1};database=;password={2};charset=utf8;Allow User Variables=True", txbDbName.Text.Trim(), txbUs.Text.Trim(), txbPw.Text.Trim());
            MySqlConnection conn = new MySqlConnection(connStr);

            try
            {
                Console.WriteLine("Connecting to MySQL...");
                conn.Open();

                string sql = File.ReadAllText("createDb.sql");
                MySqlScript script = new MySqlScript(conn);

                script.Query = sql;
                //script.Delimiter = "??";
                int count = script.Execute();
                
                Console.WriteLine("Executed " + count + " statement(s)");
                //script.Delimiter = ";";
                conn.Close();
                Console.WriteLine("Delimiter: " + script.Delimiter);
                Console.WriteLine("Query: " + script.Query);


                /////////////
                connStr = string.Format("server={0};user={1};database=ztst;password={2};charset=utf8;Allow User Variables=True", txbDbName.Text.Trim(), txbUs.Text.Trim(), txbPw.Text.Trim());
                conn = new MySqlConnection(connStr);
                Console.WriteLine("Connecting to MySQL...");
                conn.Open();

                sql = File.ReadAllText("ztst.sql");
                script = new MySqlScript(conn);
                script.Query = sql;
                //script.Delimiter = "??";
                count = script.Execute();
                Console.WriteLine("Executed " + count + " statement(s)");
                //script.Delimiter = ";";
                conn.Close();
            }
            catch (Exception ex)
            {
                bRs = false;
                Console.WriteLine(ex.ToString());
            }

            //conn.Close();
            Console.WriteLine("Done.");
            return bRs;
        }
开发者ID:xy19xiaoyu,项目名称:PatSI,代码行数:51,代码来源:frmDbConfig.cs

示例10: CheckAndUpData

        public static bool CheckAndUpData()
        {
            DataTable dt = DBA.MySqlDbAccess.GetDataTable(CommandType.Text, "select * from cfg_dbversion");
            string[] files = Directory.GetFiles(System.AppDomain.CurrentDomain.BaseDirectory + "MySqlScript");
            List<int> versionhis = new List<int>();
            foreach (var file in files)
            {
                try
                {
                    versionhis.Add(Convert.ToInt32(Path.GetFileNameWithoutExtension(file)));
                }
                catch (Exception)
                {
                    continue;
                }
            }
            int newserion = versionhis.Max();
            int exeversion = Convert.ToInt32(dt.Rows[0]["dbversion"].ToString());
            string updatatime = dt.Rows[0]["updatetime"].ToString();
            if (newserion == exeversion)
            {
                return true;
            }
            else
            {
                using (MySqlConnection conn = DBA.MySqlDbAccess.GetMySqlConnection())
                {
                    conn.Open();
                    for (int i = exeversion + 1; i <= newserion; i++)
                    {
                        string sql = File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "MySqlScript\\" + i, Encoding.GetEncoding("utf-8"));
                        MySqlScript script = new MySqlScript(conn);
                        script.Query = sql;
                        int count = script.Execute();
                        DBA.MySqlDbAccess.ExecNoQuery(CommandType.Text, string.Format("update cfg_dbversion set dbversion={0},updatetime='{1}'", i, DateTime.Now));

                        //try
                        //{
                        //}
                        //catch (Exception ex)
                        //{
                        //    throw ex;
                        //}

                    }
                }
                return true;
            }
        }
开发者ID:xy19xiaoyu,项目名称:PatSI,代码行数:49,代码来源:DBSchemaAutoUpdata.cs

示例11: ExecuteScript

 private void ExecuteScript(string fileName)
 {
     MySqlConnection connection = (MySqlConnection)DbConnectionFactory.CreateAndOpenConnection();
     try
     {
         string fullPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\Resources\" + fileName + ".sql";
         MySqlScript script = new MySqlScript(connection, File.ReadAllText(fullPath));
         script.Delimiter = ";";
         script.Execute();
     }
     finally
     {
         DbConnectionFactory.CloseDisposeConnection(connection);
     }
 }
开发者ID:FH-Thomas-Herzog,项目名称:SemesterProject1516,代码行数:15,代码来源:CleanupDatabase.cs

示例12: SetUp

    public SetUp()
    {
      Initialize();
      LoadBaseConfiguration();

      using (MySqlConnection connection = new MySqlConnection(ConnectionStringRootMaster))
      {
        connection.Open();
        MySqlScript script = new MySqlScript(connection);

        // Sets users
        script.Query = Properties.Resources._01_Startup_root_script;
        script.Execute();

        // Sets database objects
        script.Query = string.Format(Properties.Resources._02_Startup_script, databaseName);
        script.Execute();
      }
    }
开发者ID:luguandao,项目名称:MySql.Data,代码行数:19,代码来源:SetUp.cs

示例13: ExecuteScript

        protected override void ExecuteScript(DbConnection conn, string[] script)
        {
            if (!(conn is MySqlConnection))
            {
                base.ExecuteScript(conn, script);
                return;
            }

            MySqlScript scr = new MySqlScript((MySqlConnection) conn);
            {
                foreach (string sql in script)
                {
                    scr.Query = sql;
                    string sql1 = sql;
                    scr.Error += delegate { throw new Exception(sql1); };
                    scr.Execute();
                }
            }
        }
开发者ID:JAllard,项目名称:Aurora-Sim,代码行数:19,代码来源:MySQLMigrations.cs

示例14: UpgradeToCurrent

        private static void UpgradeToCurrent(string connectionString, int version)
        {
            ResourceManager r = new ResourceManager("MySql.Web.Properties.Resources", 
                typeof(SchemaManager).Assembly);

            if (version == Version) return;

            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                connection.Open();

                for (int ver = version + 1; ver <= Version; ver++)
                {
                    string schema = r.GetString(String.Format("schema{0}", ver));
                    MySqlScript script = new MySqlScript(connection);
                    script.Query = schema;
                    script.Execute();
                }
            }
        }
开发者ID:tdhieu,项目名称:openvss,代码行数:20,代码来源:SchemaManager.cs

示例15: Setup

        public override void Setup()
        {
            base.Setup();

            ResourceManager r = new ResourceManager("MySql.Data.Entity.Tests.Properties.Resources", typeof(BaseEdmTest).Assembly);
            string schema = r.GetString("schema");
            MySqlScript script = new MySqlScript(conn);
            script.Query = schema;
            script.Execute();

            // now create our procs
            schema = r.GetString("procs");
            script = new MySqlScript(conn);
            script.Delimiter = "$$";
            script.Query = schema;
            script.Execute();

            MySqlCommand cmd = new MySqlCommand("DROP DATABASE IF EXISTS `modeldb`", rootConn);
            cmd.ExecuteNonQuery();
        }
开发者ID:elevate,项目名称:mysqlconnector-.net,代码行数:20,代码来源:BaseEdmTest.cs


注:本文中的MySql.Data.MySqlClient.MySqlScript类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。