Exemplo n.º 1
0
        public void GerarArquivoDumpView(string view, string fileName)
        {
            try
            {
                using (_exportToFile = new ExportToFile(fileName))
                {
                    _exportToFile.ExportHeaderDatabase();

                    _exportToFile.ExportWriteLine(string.Format("DROP TABLE IF EXISTS `{0}`;", view));
                    _exportToFile.ExportWriteLine(string.Format("DROP VIEW IF EXISTS `{0}`;", view));

                    _exportToFile.ExportWriteComment("");
                    _exportToFile.ExportWriteComment(string.Format("Definições da View  '{0}'", view));
                    _exportToFile.ExportWriteComment("");


                    var sqlCreateView = FactorySql.SqlCreateView(view);
                    _exportToFile.ExportWriteLine(sqlCreateView);

                    _exportToFile.Export_EndInfo();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 2
0
        public void GerarArquivoDumpEvent(string eventName, string fileName)
        {
            try
            {
                using (_exportToFile = new ExportToFile(fileName))
                {
                    var queryExpress = VariaveisGeral.Container.GetInstance <IQueryExpress>();

                    var sqlDefiner = FactorySql.SqlGetAllEvents();
                    var definer    = queryExpress.ExecuteScalarString(sqlDefiner, "Definer");

                    _exportToFile.ExportHeaderDatabase();

                    _exportToFile.ExportWriteLine(string.Format("DROP EVENT IF EXISTS `{0}`;", eventName));

                    _exportToFile.ExportWriteComment("");
                    _exportToFile.ExportWriteComment(string.Format("Definições do Event  '{0}'", eventName));
                    _exportToFile.ExportWriteComment("");

                    var sqlCreateProcedure = FactorySql.SqlCreateEvent(eventName: eventName, definer: definer) + ";";


                    _exportToFile.ExportWriteLine(sqlCreateProcedure);

                    _exportToFile.Export_EndInfo();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 3
0
        public void GerarArquivoDumpTrigger(string trigger, string fileName)
        {
            try
            {
                using (_exportToFile = new ExportToFile(fileName))
                {
                    var queryExpress = VariaveisGeral.Container.GetInstance <IQueryExpress>();

                    var sqlDefiner = FactorySql.SqlGetAllTriggers;

                    var definer = queryExpress.ExecuteScalarString(sqlDefiner, "Definer");

                    _exportToFile.ExportHeaderDatabase();

                    _exportToFile.ExportWriteLine(string.Format("DROP TRIGGER  `{0}`;", trigger));

                    _exportToFile.ExportWriteComment("");
                    _exportToFile.ExportWriteComment(string.Format("Definições da Trigger  '{0}'", trigger));
                    _exportToFile.ExportWriteComment("");

                    var sqlCreateTrigger = FactorySql.SqlCreateTrigger(trigger: trigger, definer: definer) + ";";
                    _exportToFile.ExportWriteLine(sqlCreateTrigger);

                    _exportToFile.Export_EndInfo();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 4
0
 public void ExportarLinhasTable(ExportToFile exportToFile, string table)
 {
     try
     {
         exportToFile.ExportWriteComment("");
         exportToFile.ExportWriteComment(string.Format("Dumping data for table {0}", table));
         exportToFile.ExportWriteComment("");
         ExportarLinhasTableDados(exportToFile, table);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Exemplo n.º 5
0
        public bool GerarArquivoCriacaoTable(string table, string fileName)
        {
            try
            {
                using (_exportToFile = new ExportToFile(fileName))
                {
                    _exportToFile.ExportHeaderDatabase();

                    _exportToFile.ExportWriteLine();

                    _exportToFile.ExportLinhaTracejada();

                    _exportToFile.ExportWrite(string.Format("USE {0};", VariaveisGeral.Database));

                    _exportToFile.ExportLinhaTracejada();

                    var headerTable = HeaderTable();

                    _exportToFile.ExportLinhaTracejada();

                    _exportToFile.ExportWrite(headerTable);

                    _exportToFile.ExportLinhaTracejada();

                    var sqlDropIfExiste = SqlDropTableIfExiste(table);

                    _exportToFile.ExportWrite(sqlDropIfExiste);

                    _exportToFile.ExportLinhaTracejada();

                    var sqlCreate = FactorySql.SqlCreateTable(table);

                    _exportToFile.ExportWrite(sqlCreate);

                    _exportToFile.ExportWriteLine();

                    _exportToFile.ExportLinhaTracejada();

                    _exportToFile.Export_EndInfo();
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
                return(false);
            }


            return(true);
        }
        internal static bool GerarArquivoCriacaoDatabase(this MySqlDatabase database, string fileName, string sql)
        {
            try
            {
                using (_exportToFile = new ExportToFile(fileName))
                {
                    _exportToFile.ExportHeaderDatabase();
                    _exportToFile.ExportWrite(sql);

                    _exportToFile.Export_EndInfo();
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
                return(false);
            }


            return(true);
        }
Exemplo n.º 7
0
        public void ExportarLinhasTableDados(ExportToFile exportToFile, string table)
        {
            var mySqlConnection = BackupMySqlConnection.CriarConexao();
            var sql             = string.Format("SELECT * FROM `{0}`;", table);

            try
            {
                if (mySqlConnection.State != ConnectionState.Open)
                {
                    mySqlConnection.Open();
                }

                using (var command = new MySqlCommand(sql, mySqlConnection))
                {
                    var rdr        = command.ExecuteReader();
                    var totalBytes = default(int);

                    if (!rdr.HasRows)
                    {
                        return;
                    }

                    _exportToFile.ExportWriteLine();
                    _exportToFile.ExportWriteLine(string.Format("LOCK TABLES `{0}` WRITE;", table));
                    _exportToFile.ExportWriteLine();


                    exportToFile.ExportWriteLine();
                    exportToFile.ExportWriteLine(string.Format("/*!40000 ALTER TABLE `{0}` DISABLE KEYS */;", table));
                    exportToFile.ExportWriteLine();


                    exportToFile.ExportWriteLine();
                    ExcluirIndex(table);
                    exportToFile.ExportWriteLine();


                    while (rdr.Read())
                    {
                        try
                        {
                            var sqlDataRow = GetValueString(rdr, table);

                            exportToFile.ExportWriteLine(sqlDataRow);

                            totalBytes += sqlDataRow.Length;

                            if (totalBytes < VariaveisGeral.LimiteCommit)
                            {
                                continue;
                            }

                            exportToFile.ExportWriteCommit();
                            totalBytes = 0;
                        }
                        catch (Exception e)
                        {
                            Console.Write("tabela ==> " + table);
                            Console.WriteLine(e);
                        }
                    }

                    exportToFile.ExportWriteLine();
                    exportToFile.ExportWriteLine(string.Format("/*!40000 ALTER TABLE `{0}` ENABLE KEYS */;", table));
                    exportToFile.ExportWriteLine();


                    IncluirIndex(table);

                    _exportToFile.ExportWriteLine();
                    _exportToFile.ExportWriteLine("UNLOCK TABLES;");
                    _exportToFile.ExportWriteLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 8
0
        public bool GerarArquivoDumpTable(string table, string fileName)
        {
            try
            {
                using (_exportToFile = new ExportToFile(fileName))
                {
                    _exportToFile.ExportHeaderDatabase();

                    _exportToFile.ExportWriteComment("");
                    _exportToFile.ExportWriteComment(string.Format("Definições da table  '{0}'", table));
                    _exportToFile.ExportWriteComment("");

                    _exportToFile.ExportWriteLine();

                    _exportToFile.ExportWriteLine();

                    _exportToFile.ExportLinhaTracejada();

                    _exportToFile.ExportWrite(string.Format("USE {0};", VariaveisGeral.Database));

                    _exportToFile.ExportLinhaTracejada();

                    var headerTable = HeaderTable();

                    _exportToFile.ExportLinhaTracejada();

                    _exportToFile.ExportWrite(headerTable);

                    _exportToFile.ExportLinhaTracejada();

                    var sqlDropIfExiste = SqlDropTableIfExiste(table);

                    _exportToFile.ExportWrite(sqlDropIfExiste);

                    _exportToFile.ExportWriteLine();

                    var sqlCreate = FactorySql.SqlCreateTable(table);

                    _exportToFile.ExportWrite(sqlCreate);

                    _exportToFile.ExportWriteLine();



                    _exportToFile.ExportWriteLine("/*!40101 SET character_set_client = @saved_cs_client */;");

                    _exportToFile.ExportWriteLine();

                    _exportToFile.ExportLinhaTracejada();

                    ExportarLinhasTable(_exportToFile, table);

                    ExportEndDump();

                    _exportToFile.Export_EndInfo();
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
                return(false);
            }


            return(true);
        }