예제 #1
0
        public static void CTest(string dbleconnStr, string mysqlconnStr, List <String> Csqlfiles, String logpath)
        {
            MySqlConnection dbleconn  = Conn.MySQLConn(dbleconnStr);
            MySqlConnection mysqlconn = Conn.MySQLConn(mysqlconnStr);

            if (dbleconn != null && mysqlconn != null)
            {
                for (int i = 0; i < Csqlfiles.Count; i++)
                {
                    //create log files as per the name of sql file
                    String   sqlpath      = Csqlfiles[i];
                    String   sqlfilename  = Path.GetFileNameWithoutExtension(sqlpath);
                    String   passlogname  = sqlfilename + "_pass.log";
                    String   faillogname  = sqlfilename + "_fail.log";
                    String[] logfilenames = { passlogname, faillogname };
                    String[] logfiles     = CreateFile.CreateFiles(logpath, logfilenames, true);

                    SetUp.IniFile("test1.txt");
                    //excute the sqls, compare and write the results to log files
                    ExecuteClient.Execute(Csqlfiles[i], logfiles, dbleconn, mysqlconn);
                    CleanUp.Rmfile("test1.txt");
                }
                //close db connections
                CleanUp.CloseConnection(dbleconn);
                CleanUp.CloseConnection(mysqlconn);
            }
        }
예제 #2
0
        public static void MTest(string dblemanagerconnStr, List <String> Msqlfiles, String logpath)
        {
            MySqlConnection dblemanagerconn = Conn.MySQLConn(dblemanagerconnStr);

            if (dblemanagerconn != null)
            {
                for (int i = 0; i < Msqlfiles.Count; i++)
                {
                    //create log files as per the name of sql file
                    String   sqlpath      = Msqlfiles[i];
                    String   sqlfilename  = Path.GetFileNameWithoutExtension(sqlpath);
                    String   passlogname  = sqlfilename + "_pass.log";
                    String   faillogname  = sqlfilename + "_fail.log";
                    String[] logfilenames = { passlogname, faillogname };
                    String[] logfiles     = CreateFile.CreateFiles(logpath, logfilenames, false);

                    ExecuteManager.Execute(Msqlfiles[i], logfiles, dblemanagerconn);
                }
                //close db connection
                CleanUp.CloseConnection(dblemanagerconn);
            }
        }
예제 #3
0
        public static void Execute(String sqlfile, String[] logfiles, MySqlConnection dblemanagerconn)
        {
            //excute the sqls one by one
            int          idNum = 1;
            string       line;
            StreamReader sr     = null;
            StreamWriter passsw = null;
            StreamWriter failsw = null;

            try
            {
                sr = new StreamReader(sqlfile);
            }
            catch (IOException ioe)
            {
                Console.WriteLine(ioe.Message);
                CleanUp.CloseStreamReader(sr);
            }
            //open log files
            try
            {
                passsw = new StreamWriter(logfiles[0], true);
            }
            catch (IOException ioe)
            {
                Console.WriteLine(ioe.Message);
                CleanUp.CloseStreamWriter(passsw);
            }

            try
            {
                failsw = new StreamWriter(logfiles[1], true);
            }
            catch (IOException ioe)
            {
                Console.WriteLine(ioe.Message);
                CleanUp.CloseStreamWriter(failsw);
            }

            while ((line = sr.ReadLine()) != null)
            {
                if (!line.StartsWith("#"))
                {
                    String exec = "===file:" + sqlfile + ",id:" + idNum + ",sql:" + line + "===";
                    line = line.ToLower();
                    //for kill command
                    //int PID = 0;
                    //if (line.StartsWith("kill"))
                    //{
                    //    try
                    //    {
                    //        string showsql = "show @@connection;";
                    //        MySqlCommand showcmd = new MySqlCommand(showsql, dblemanagerconn);
                    //        MySqlDataReader showrdr = showcmd.ExecuteReader();
                    //        //int PID = 0;
                    //        while (showrdr.Read())
                    //        {
                    //            var pid = showrdr.GetValue(1);
                    //            PID = Convert.ToInt32(pid);
                    //            break;
                    //        }
                    //        showrdr.Close();
                    //    }
                    //    catch (MySqlException e) {

                    //    }
                    //}

                    List <String> dblerslist = new List <string>();
                    try
                    {
                        MySqlCommand cmd = new MySqlCommand(line, dblemanagerconn);
                        if (dblemanagerconn.State != System.Data.ConnectionState.Open)
                        {
                            dblemanagerconn.Open();
                        }

                        MySqlDataReader rdr = cmd.ExecuteReader();
                        while (rdr.Read())
                        {
                            StringBuilder sb = new StringBuilder();
                            String        column;
                            int           fc = 0;
                            for (int i = 0; i < rdr.FieldCount; i++)
                            {
                                Type type = rdr.GetFieldType(rdr.GetName(i));
                                if (type.Name == "VarChar" || type.Name == "Char" || type.Name == "String" || type.Name == "Byte" || type.Name == "SByte")
                                {
                                    if (fc == (rdr.FieldCount - 1))
                                    {
                                        column = "\"" + rdr.GetValue(i) + "\"";
                                    }
                                    else
                                    {
                                        column = "\"" + rdr.GetValue(i) + "\",";
                                    }
                                }
                                else if (type.Name == "DateTime")
                                {
                                    if (fc == (rdr.FieldCount - 1))
                                    {
                                        column = "{" + rdr.GetValue(i) + "}";
                                    }
                                    else
                                    {
                                        column = "{" + rdr.GetValue(i) + "},";
                                    }
                                }
                                else
                                {
                                    if (fc == (rdr.FieldCount - 1))
                                    {
                                        column = rdr.GetValue(i).ToString();
                                    }
                                    else
                                    {
                                        column = rdr.GetValue(i) + ",";
                                    }
                                }
                                sb.Append(column);
                                fc++;
                            }
                            String linestr = "(" + sb.ToString() + "),";
                            //Console.WriteLine(linestr);
                            dblerslist.Add(linestr);
                        }
                        rdr.Close();

                        //write to logs
                        passsw.WriteLine(exec);
                        String listStr = ResultConvert.CovertListToString(dblerslist);
                        passsw.WriteLine("dble: [" + listStr + "]");
                    }
                    catch (MySqlException e)
                    {
                        String errMsg  = e.Message;
                        String errCode = Convert.ToString(e.ErrorCode);
                        String errStr  = "dble: [(" + errCode + ": " + errMsg + ")]";
                        failsw.WriteLine(exec);
                        failsw.WriteLine(errStr);
                    }
                }
                idNum++;
            }
            //close the opened iostream
            CleanUp.CloseStreamWriter(failsw);
            CleanUp.CloseStreamWriter(passsw);
            CleanUp.CloseStreamReader(sr);
        }
예제 #4
0
        public static void Execute(String sqlfile, String[] logfiles, MySqlConnection dbleconn, MySqlConnection mysqlconn)
        {
            //excute the sqls one by one
            int          idNum = 1;
            string       line;
            StreamReader sr     = null;
            StreamWriter passsw = null;
            StreamWriter failsw = null;

            try
            {
                sr = new StreamReader(sqlfile);
            }
            catch (IOException ioe)
            {
                Console.WriteLine(ioe.Message);
                CleanUp.CloseStreamReader(sr);
                Environment.Exit(-1);
            }
            //open the log files
            try
            {
                passsw = new StreamWriter(logfiles[0], true);
            }
            catch (IOException ioe)
            {
                Console.WriteLine(ioe.Message);
                CleanUp.CloseStreamWriter(passsw);
                Environment.Exit(-1);
            }

            try
            {
                failsw = new StreamWriter(logfiles[1], true);
            }
            catch (IOException ioe)
            {
                Console.WriteLine(ioe.Message);
                CleanUp.CloseStreamWriter(failsw);
                Environment.Exit(-1);
            }

            while ((line = sr.ReadLine()) != null)
            {
                if (!line.StartsWith("#"))
                {
                    bool allow_diff = false;
                    if (line.Contains("allow_diff"))
                    {
                        allow_diff = true;
                    }

                    String exec = "===file:" + sqlfile + ",id:" + idNum + ",sql:" + line + "===";
                    line = line.ToLower().Trim();
                    //dble
                    List <String> dblerslist = new List <string>();
                    try
                    {
                        MySqlCommand dblecmd = new MySqlCommand(line, dbleconn);
                        if (dbleconn.State != System.Data.ConnectionState.Open)
                        {
                            dbleconn.Open();
                        }


                        if (line.Contains("insert") || line.Contains("update") || line.Contains("delete"))
                        {
                            int    count    = dblecmd.ExecuteNonQuery();
                            String countStr = Convert.ToString(count);
                            dblerslist.Add(countStr);
                        }
                        else if (line.StartsWith("select") || line.StartsWith("show") || line.StartsWith("check") || line.Contains("union"))
                        {
                            MySqlDataReader rdr = dblecmd.ExecuteReader();
                            while (rdr.Read())
                            {
                                StringBuilder sb = new StringBuilder();
                                String        column;
                                int           fc = 0;
                                for (int i = 0; i < rdr.FieldCount; i++)
                                {
                                    Type type = rdr.GetFieldType(rdr.GetName(i));
                                    if (type.Name == "VarChar" || type.Name == "Char" || type.Name == "String" || type.Name == "Byte" || type.Name == "SByte")
                                    {
                                        if (fc == (rdr.FieldCount - 1))
                                        {
                                            column = "\"" + rdr.GetValue(i) + "\"";
                                        }
                                        else
                                        {
                                            column = "\"" + rdr.GetValue(i) + "\",";
                                        }
                                    }
                                    else if (type.Name == "DateTime")
                                    {
                                        if (fc == (rdr.FieldCount - 1))
                                        {
                                            column = "{" + rdr.GetValue(i) + "}";
                                        }
                                        else
                                        {
                                            column = "{" + rdr.GetValue(i) + "},";
                                        }
                                    }
                                    else
                                    {
                                        if (fc == (rdr.FieldCount - 1))
                                        {
                                            column = rdr.GetValue(i).ToString();
                                        }
                                        else
                                        {
                                            column = rdr.GetValue(i) + ",";
                                        }
                                    }
                                    sb.Append(column);
                                    fc++;
                                }
                                String linestr = "(" + sb.ToString() + "),";
                                //Console.WriteLine(linestr);
                                dblerslist.Add(linestr);
                            }
                            rdr.Close();
                        }
                        else
                        {
                            object result = dblecmd.ExecuteScalar();
                            if (result == null)
                            {
                                dblerslist.Add("null");
                            }
                            else
                            {
                                String resultstr = Convert.ToString(result);
                                dblerslist.Add(resultstr);
                            }
                        }
                    }
                    catch (MySqlException ex)
                    {
                        String errMsg = ex.Number + ": " + ex.Message;
                        dblerslist.Add(errMsg);
                    }

                    //mysql
                    List <String> mysqlrslist = new List <string>();
                    try
                    {
                        MySqlCommand mysqlcmd = new MySqlCommand(line, mysqlconn);
                        if (mysqlconn.State != System.Data.ConnectionState.Open)
                        {
                            mysqlconn.Open();
                        }

                        if (line.Contains("insert") || line.Contains("update") || line.Contains("delete"))
                        {
                            int    count    = mysqlcmd.ExecuteNonQuery();
                            String countStr = Convert.ToString(count);
                            mysqlrslist.Add(countStr);
                        }
                        else if (line.StartsWith("select") || line.StartsWith("show") || line.StartsWith("check") || line.Contains("union"))
                        {
                            MySqlDataReader rdr = mysqlcmd.ExecuteReader();
                            while (rdr.Read())
                            {
                                StringBuilder sb = new StringBuilder();
                                String        column;
                                int           fc = 0;
                                for (int i = 0; i < rdr.FieldCount; i++)
                                {
                                    Type type = rdr.GetFieldType(rdr.GetName(i));
                                    if (type.Name == "VarChar" || type.Name == "Char" || type.Name == "String" || type.Name == "Byte" || type.Name == "SByte")
                                    {
                                        if (fc == (rdr.FieldCount - 1))
                                        {
                                            column = "\"" + rdr.GetValue(i) + "\"";
                                        }
                                        else
                                        {
                                            column = "\"" + rdr.GetValue(i) + "\",";
                                        }
                                    }
                                    else if (type.Name == "DateTime")
                                    {
                                        if (fc == (rdr.FieldCount - 1))
                                        {
                                            column = "{" + rdr.GetValue(i) + "}";
                                        }
                                        else
                                        {
                                            column = "{" + rdr.GetValue(i) + "},";
                                        }
                                    }
                                    else
                                    {
                                        if (fc == (rdr.FieldCount - 1))
                                        {
                                            column = rdr.GetValue(i).ToString();
                                        }
                                        else
                                        {
                                            column = rdr.GetValue(i) + ",";
                                        }
                                    }
                                    sb.Append(column);
                                    fc++;
                                }
                                String linestr = "(" + sb.ToString() + "),";
                                //Console.WriteLine(linestr);
                                mysqlrslist.Add(linestr);
                            }
                            rdr.Close();
                        }
                        else
                        {
                            object result = mysqlcmd.ExecuteScalar();
                            if (result == null)
                            {
                                mysqlrslist.Add("null");
                            }
                            else
                            {
                                String resultstr = Convert.ToString(result);
                                mysqlrslist.Add(resultstr);
                            }
                        }
                    }
                    catch (MySqlException ex)
                    {
                        String errMsg = ex.Number + ": " + ex.Message;
                        mysqlrslist.Add(errMsg);
                    }

                    //compare and write to logs
                    bool same = CompareRs.CompareRS(dblerslist, mysqlrslist, allow_diff);
                    if (same)
                    {
                        passsw.WriteLine(exec);
                        String pass    = ResultConvert.CovertListToString(dblerslist);
                        String passstr = "dble: [(" + pass + ")]";
                        passsw.WriteLine(passstr);
                    }
                    else
                    {
                        String dblefailstr  = ResultConvert.CovertListToString(dblerslist);
                        String mysqlfailstr = ResultConvert.CovertListToString(mysqlrslist);
                        String failstr      = "dble: [(" + dblefailstr + ")]\r\nmysql: [(" + mysqlfailstr + ")]";
                        failsw.WriteLine(exec);
                        failsw.WriteLine(failstr);
                    }
                }
                idNum++;
            }
            //close the opened iostream
            CleanUp.CloseStreamWriter(failsw);
            CleanUp.CloseStreamWriter(passsw);
            CleanUp.CloseStreamReader(sr);
        }