Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using MySql.Data.MySqlClient;
- using System.Collections.Generic;
- using System.IO;
- namespace MySqlTableCompare
- {
- public class fTable
- {
- public UInt32 ID;
- public UInt32[] KillCredit;
- public UInt32[] ModelID;
- public string IconName;
- public UInt32 Rank;
- public UInt32 Family;
- public UInt32 Type;
- public UInt32 TypeFlag;
- public UInt32 MovementID;
- public float HealthMod; //need convert to Float or double
- public float ManaMod; //need convert to Float or double
- public UInt32 RacialLider;
- public UInt32[] QuestItem;
- public fTable()
- {
- KillCredit = new UInt32[2];
- ModelID = new UInt32[4];
- QuestItem = new UInt32[6];
- }
- };
- public class sTable
- {
- public UInt32 ID;
- public UInt32[] KillCredit;
- public UInt32[] ModelID;
- public string IconName;
- public UInt32 Rank;
- public UInt32 Family;
- public UInt32 Type;
- public UInt32 TypeFlag;
- public UInt32 MovementID;
- public float HealthMod; //need convert to Float or double
- public float ManaMod; //need convert to Float or double
- public UInt32 RacialLider;
- public UInt32[] QuestItem;
- public sTable()
- {
- KillCredit = new UInt32[2];
- ModelID = new UInt32[4];
- QuestItem = new UInt32[6];
- }
- };
- public static class Program
- {
- const string connectionInfo = ("host=127.0.0.1;" + "port = '3306';" + "database='world';" + "UserName='root';" + "Password='mangos'");
- public static StreamWriter Log = new StreamWriter("sql_log.txt", true);
- public static MySqlCommand fcommand;
- public static MySqlCommand scommand;
- public static MySqlConnection connect = new MySqlConnection(connectionInfo);
- public static List<fTable> fTables = new List<fTable>();
- public static List<sTable> sTables = new List<sTable>();
- static void Main(string[] args)
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + "Programm is open!");
- ToLog("Programm is open!");
- if (!TryCon())
- return;
- Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + "Get DB struct?");
- string variant = Console.ReadLine();
- if (variant == "y")
- {
- Console.WriteLine(">>Get DB struct...");
- ToLog(">>Get DB struct...");
- tGetStr();
- Console.WriteLine(">>Start compare...");
- ToLog(">>Start compare...");
- tCompare();
- }
- else if (variant == "n")
- {
- Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + "Press any key for exit");
- connect.Close();
- }
- else
- Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + "Neee press 'y' or 'n'");
- Console.ReadKey();
- }
- public static void ToLog(string text)
- {
- Log.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + text); Log.Flush();
- }
- public static uint ToUInt32(this object val)
- {
- uint num;
- uint.TryParse(val.ToString(), out num);
- return num;
- }
- public static float ToFloat(this object val)
- {
- float num;
- float.TryParse(val.ToString(), out num);
- return num;
- }
- public static void tGetStr()
- {
- connect.Close();
- connect.Open();
- string fSelect = "SELECT * FROM world.creature_template";
- string sSelect = "SELECT * FROM world.creature_template1";
- fcommand = new MySqlCommand(fSelect, connect);
- scommand = new MySqlCommand(sSelect, connect);
- fTables.Clear();
- sTables.Clear();
- using (var fDBstructur = fcommand.ExecuteReader())
- {
- while(fDBstructur.Read())
- {
- fTable table1 = new fTable();
- table1.ID = fDBstructur[0].ToUInt32();
- table1.KillCredit[0] = fDBstructur[4].ToUInt32(); //kill credit 1,2
- table1.KillCredit[1] = fDBstructur[5].ToUInt32();
- table1.ModelID[0] = fDBstructur[6].ToUInt32(); //modelid1 id 1-4
- table1.ModelID[1] = fDBstructur[7].ToUInt32();
- table1.ModelID[2] = fDBstructur[8].ToUInt32();
- table1.ModelID[3] = fDBstructur[9].ToUInt32();
- table1.IconName = fDBstructur[12].ToString();
- table1.Rank = fDBstructur[23].ToUInt32(); //rank
- table1.Family = fDBstructur[34].ToUInt32(); //family
- table1.Type = fDBstructur[42].ToUInt32(); //type
- table1.TypeFlag = fDBstructur[43].ToUInt32();//type flag
- table1.MovementID = fDBstructur[66].ToUInt32(); //movement id
- table1.HealthMod = fDBstructur[68].ToFloat(); //health mod
- table1.ManaMod = fDBstructur[69].ToFloat(); //power(mana) mod
- table1.RacialLider = fDBstructur[71].ToUInt32(); //racial leader
- table1.QuestItem[0] = fDBstructur[72].ToUInt32(); //quest item 1-6
- table1.QuestItem[1] = fDBstructur[73].ToUInt32();
- table1.QuestItem[2] = fDBstructur[74].ToUInt32();
- table1.QuestItem[3] = fDBstructur[75].ToUInt32();
- table1.QuestItem[4] = fDBstructur[76].ToUInt32();
- table1.QuestItem[5] = fDBstructur[77].ToUInt32();
- fTables.Add(table1);
- }
- }
- using (var sDBstructur = scommand.ExecuteReader())
- {
- while(sDBstructur.Read())
- {
- sTable table2 = new sTable();
- table2.ID = sDBstructur[0].ToUInt32();
- table2.KillCredit[0] = sDBstructur[4].ToUInt32(); //kill credit 1,2
- table2.KillCredit[1] = sDBstructur[5].ToUInt32();
- table2.ModelID[0] = sDBstructur[6].ToUInt32(); //modelid1 id 1-4
- table2.ModelID[1] = sDBstructur[7].ToUInt32();
- table2.ModelID[2] = sDBstructur[8].ToUInt32();
- table2.ModelID[3] = sDBstructur[9].ToUInt32();
- table2.IconName = sDBstructur[12].ToString();
- table2.Rank = sDBstructur[23].ToUInt32(); //rank
- table2.Family = sDBstructur[34].ToUInt32(); //family
- table2.Type = sDBstructur[42].ToUInt32(); //type
- table2.TypeFlag = sDBstructur[43].ToUInt32();//type flag
- table2.MovementID = sDBstructur[66].ToUInt32(); //movement id
- table2.HealthMod = sDBstructur[68].ToFloat(); //health mod
- table2.ManaMod = sDBstructur[69].ToFloat(); //power(mana) mod
- table2.RacialLider = sDBstructur[71].ToUInt32(); //racial leader
- table2.QuestItem[0] = sDBstructur[72].ToUInt32(); //quest item 1-6
- table2.QuestItem[1] = sDBstructur[73].ToUInt32();
- table2.QuestItem[2] = sDBstructur[74].ToUInt32();
- table2.QuestItem[3] = sDBstructur[75].ToUInt32();
- table2.QuestItem[4] = sDBstructur[76].ToUInt32();
- table2.QuestItem[5] = sDBstructur[77].ToUInt32();
- sTables.Add(table2);
- }
- }
- }
- public static void tCompare()
- {
- int m = 0;
- int q = 0;
- string update = "update creature_template SET";
- for (int i = 0; i <= 5; ++i)
- {
- if (fTables[i].KillCredit[0] != sTables[i].KillCredit[0])
- Console.WriteLine("{0} KillCredit1 = {1} WHERE entry = {2};", update, sTables[i].KillCredit[0], fTables[i].ID);
- if (fTables[i].KillCredit[1] != sTables[i].KillCredit[1])
- Console.WriteLine("{0} KillCredit2 = {1} WHERE entry = {2};", update, sTables[i].KillCredit[1], fTables[i].ID);
- //model ID
- for (m = 0; m < 3; ++m);
- {
- string ModelID = "modelid1";
- switch (m)
- {
- case 0: ModelID = "modelid1"; break;
- case 1: ModelID = "modelid2"; break;
- case 2: ModelID = "modelid3"; break;
- }
- if(fTables[i].ModelID[m] != sTables[i].ModelID[m])
- Console.WriteLine("{0} {1} = {2} WHERE entry = {3}", update,ModelID,sTables[i].ModelID[m], fTables[i].ID);
- }
- if (fTables[i].IconName != sTables[i].IconName)
- Console.WriteLine("{0} IconName = '{1}' WHERE entry = {2}", update, sTables[i].IconName, fTables[i].ID);
- if (fTables[i].Rank != sTables[i].Rank)
- Console.WriteLine("{0} rank = {1} WHERE entry = {2}", update, sTables[i].Rank, fTables[i].ID);
- if (fTables[i].Family != sTables[i].Family)
- Console.WriteLine("{0} family = {1} WHERE entry = {2}", update, sTables[i].Family, fTables[i].ID);
- if (fTables[i].Type != sTables[i].Type)
- Console.WriteLine("{0} type = {1} WHERE entry = {2}", update, sTables[i].Type, fTables[i].ID);
- if (fTables[i].TypeFlag != sTables[i].TypeFlag)
- Console.WriteLine("{0} type_flags = {1} WHERE entry = {2}", update, sTables[i].TypeFlag, fTables[i].ID);
- if (fTables[i].MovementID != sTables[i].MovementID)
- Console.WriteLine("{0} MovementID = {1} WHERE entry = {2}", update, sTables[i].MovementID, fTables[i].ID);
- if (fTables[i].HealthMod != sTables[i].HealthMod)
- Console.WriteLine("{0} Health_Mod = {1} WHERE entry = {2}", update, sTables[i].HealthMod, fTables[i].ID);
- if (fTables[i].ManaMod != sTables[i].ManaMod)
- Console.WriteLine("{0} Mana_Mod = {1} WHERE entry = {2}", update, sTables[i].ManaMod, fTables[i].ID);
- if (fTables[i].RacialLider != sTables[i].RacialLider)
- Console.WriteLine("{0} RacialLeader = {1} WHERE entry = {2}", update, sTables[i].RacialLider, fTables[i].ID);
- for (q = 0; q < 6; q++) ;
- {
- string QuestItem = "questItem1";
- switch (q)
- {
- case 0: QuestItem = "questItem1"; break;
- case 1: QuestItem = "questItem2"; break;
- case 2: QuestItem = "questItem3"; break;
- case 3: QuestItem = "questItem4"; break;
- case 4: QuestItem = "questItem5"; break;
- case 5: QuestItem = "questItem6"; break;
- }
- if (fTables[i].QuestItem[q] != sTables[i].QuestItem[q])
- Console.WriteLine("{0} {1} = {2} WHERE entry = {3}", update, QuestItem, sTables[i].QuestItem[q], fTables[i].ID);
- }
- }
- }
- public static bool TryCon()
- {
- try
- {
- MySqlConnection connect = new MySqlConnection(connectionInfo);
- connect.Open();
- connect.Close();
- return true;
- }
- catch
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + "Check your MySQL server");
- ToLog("MySQL Server is not running");
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement