Example #1
0
        int GetWrapperLen(IntPtr sw)
        {
            IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "len");

            if (pAddressOfFunctionToCall == IntPtr.Zero)
            {
                Trace.WriteLine("Error loading function: len");
            }
            len len =
                (len)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(len));

            return(len(sw));
        }
Example #2
0
        private static void Compare_SQL(string path1, string path2, string outpath)
        {
            try
            {
                if (Directory.Exists(outpath)) Directory.Delete(outpath, true);
                Directory.CreateDirectory(outpath);
                //比较两次,1->2,2->1
                //情况:////////////////表级别//////////////
                //-->1有2没有,2有1没有,
                if (File.Exists(outpath + @"\creatSQL.sqt")) File.Delete(outpath + @"\creatSQL.sqt");
                StreamWriter SQ = new StreamWriter(outpath + @"\creatSQL.sqt", true, Encoding.UTF8);
                List<string> file1 = File.ReadAllLines(path1 + @"\table.txt").ToList<string>();
                List<string> file2 = File.ReadAllLines(path2 + @"\table.txt").ToList<string>();

                //获取相同的
                List<string> data1and2 = file1.Intersect(file2).ToList<string>();
                //不同的表,这项直接输出就好
                //1有2没有
                List<string> data1not2 = file1.Except(file2).ToList<string>();
                //2有1没有
                List<string> data2not1 = file2.Except(file1).ToList<string>();

                if (data1not2.Count > 0) File.WriteAllLines(outpath + @"\源数据库有目标数据库没有的表.txt", data1not2.ToArray<string>());

                if (data2not1.Count > 0) File.WriteAllLines(outpath + @"\目标数据库有源数据库没有的表.txt", data2not1.ToArray<string>());
                //生成sql语句,创建源数据库有目标数据库没有的表

                //SQ.WriteLine("use DB2");
                foreach (string S in data1not2)
                {
                    SQ.WriteLine("create table " + S.Split('\b')[1] + "(SGID VARCHAR(14) DEFAULT '')");
                }

                #region  ////////////////////字段级别////////////////////-->两者不同
                //在相同的表中进行查询data1and2
                //对比字段
                List<string> field1_and = File.ReadAllLines(path1 + @"\field.txt").ToList<string>();
                List<string> field2_and = File.ReadAllLines(path2 + @"\field.txt").ToList<string>();
                //    //去除field中不是都有的表的字段,即把相同的单独拿出来
                //List<string> field1_and = new List<string>();
                //List<string> field2_and = new List<string>();
                #region 剔除两个文件中互相没有的表的字段   ------现在不用这一步,记录所有不同的为执行sql做基础
                //foreach (string f in field1)
                //{
                //    string[] fs = f.Split('\b');
                //    foreach(string t in data1and2)
                //    {
                //        if (fs[1] == t.Substring(t.IndexOf("\b")+1))
                //        {
                //            field1_and.Add(f);
                //        }
                //    }
                //}
                //foreach (string f in field2)
                //{
                //    string[] fs = f.Split('\b');
                //    foreach (string t in data1and2)
                //    {
                //        if (fs[1] == t.Substring(t.IndexOf("\b") + 1))
                //        {
                //            field2_and.Add(f);
                //        }
                //    }
                //}
                //now,field1_and,field2_and 两个数据库中都有的表中的字段
                #endregion

                List<string> jiaoji = field1_and.Intersect(field2_and).ToList<string>();
                foreach (string x in jiaoji)
                {
                    field1_and.Remove(x);
                }
                foreach (string x in jiaoji)
                {
                    field2_and.Remove(x);
                }
                //剩下的就是大家//***都有的表中**//具有差别的字段了,差别可能是类型长度、类型、字段名
                //从类型长度开始,比较出差别--->在之后的执行sql时,服务器端的长度小于目标数据库的话就忽略

                List<len> type = new List<len>();
                foreach (string f1 in field1_and)
                {//字段名相同但类型不同,可是不同的表中有相同的字段咋办@@截取的字段是表名加字段名的,要比较两词
                    //FIELDJQUEUEUSERCODEvarchar30,0
                    string fid1 = f1.Substring(0, f1.IndexOf('\b', f1.IndexOf('\b', 6) + 1));
                    foreach (string f2 in field2_and)
                    {
                        string fid2 = f2.Substring(0, f2.IndexOf('\b', f2.IndexOf('\b', 6) + 1));// FIELD\bTABLE\bCOLUMN
                        if (fid1 == fid2)
                        {   //说明数据格式不同
                            //需要加个判断varchar和demical相同的,不然比较varchar和demaical
                            len temp_len = new len();
                            //数据类型相同但精度不同//创建新表时用的是SGID
                            if (f1.Split('\b')[3] == f2.Split('\b')[3])
                            {

                                //数据格式不同的话,需要记录下可不可以忽略
                                string l1 = f1.Substring(f1.LastIndexOf('\b') + 1);
                                string l2 = f2.Substring(f2.LastIndexOf('\b') + 1);
                                //发现还有image这种格式的,需要在比较的时候设置下
                                if (l1 == "," || l2 == ",") temp_len.ignore = true;
                                else
                                {
                                    if (int.Parse(l1.Split(',')[0]) <= int.Parse(l2.Split(',')[0]) && int.Parse(l1.Split(',')[1]) <= int.Parse(l2.Split(',')[1]))
                                    {
                                        temp_len.ignore = true;
                                    }
                                    else
                                        temp_len.ignore = false;
                                }
                            }
                            //数据类型直接就不同
                            else
                            {
                                temp_len.ignore = false;
                            }
                            temp_len.server = f1;
                            temp_len.client = f2;
                            type.Add(temp_len);
                        }

                    }
                }
                foreach (string f2 in field2_and)
                {//字段名相同但类型不同,可是不同的表中有相同的字段咋办@@截取的字段是表名加字段名的,要比较两词
                    //FIELDJQUEUEUSERCODEvarchar30,0
                    string fid2 = f2.Substring(0, f2.IndexOf('\b', f2.IndexOf('\b', 6) + 1));
                    foreach (string f1 in field1_and)
                    {
                        string fid1 = f1.Substring(0, f1.IndexOf('\b', f1.IndexOf('\b', 6) + 1));// FIELD\bTABLE\bCOLUMN
                        if (fid1 == fid2)
                        {   //说明数据格式不同
                            len temp_len = new len();
                            //数据类型相同但精度不同
                            if (f1.Split('\b')[3] == f2.Split('\b')[3])
                            {

                                //数据格式不同的话,需要记录下可不可以忽略
                                string l1 = f1.Substring(f1.LastIndexOf('\b') + 1);
                                string l2 = f2.Substring(f2.LastIndexOf('\b') + 1);
                                if (l1 == "," || l2 == ",") temp_len.ignore = true;
                                else
                                {
                                    if (int.Parse(l1.Split(',')[0]) <= int.Parse(l2.Split(',')[0]) && int.Parse(l1.Split(',')[1]) <= int.Parse(l2.Split(',')[1]))
                                    {
                                        temp_len.ignore = true;
                                    }
                                    else
                                        temp_len.ignore = false;
                                }
                            }
                            //数据类型直接就不同
                            else
                            {
                                temp_len.ignore = false;
                            }
                            temp_len.server = f1;
                            temp_len.client = f2;
                            if (type.Contains(temp_len)) { continue; }
                            else
                                type.Add(temp_len);
                        }

                    }
                }
                //if(type.Count>0) File.WriteAllLines(outpath + "字段类型不同.txt",type.ToArray<string>());
                List<string> length = new List<string>();
                //length.Add("数据类型不同的字段");
                foreach (len i in type)
                {
                    field1_and.Remove(i.server);
                    field2_and.Remove(i.client);
                    length.Add(i.server + "<->" + i.client + "<->" + i.ignore.ToString());
                    if (i.ignore == false)
                    {//以服务器为标准
                        string[] alter = i.server.Split('\b');
                        //alter table table_3 alter column SGID VARCHAR(10)
                        if (alter[3] == "varchar" || alter[3] == "char")
                            SQ.WriteLine("alter table " + alter[1] + " alter column " + alter[2] + "  " + alter[3] + "(" + alter[4].Split(',')[0] + ")");
                        else if (alter[3] == "decimal" || alter[3] == "numeric")
                            SQ.WriteLine("alter table " + alter[1] + " alter column " + alter[2] + "  " + alter[3] + "(" + alter[4] + ")");
                        else
                            SQ.WriteLine("alter table " + alter[1] + " alter column " + alter[2] + "  " + alter[3]);

                    }
                }
                if (length.Count > 1) File.WriteAllLines(outpath + @"\字段类型不同.txt", length.ToArray<string>());
                //现在这里面是包含有没有的表中的不同的字段的
                if (field1_and.Count > 0) File.WriteAllLines(outpath + @"\源数据库有目标数据库没有字段.txt", field1_and.ToArray<string>());
                foreach (string S in field1_and)
                {
                    string[] alter = S.Split('\b');
                    if (alter[3] == "varchar" || alter[3] == "char")
                    {
                        if (alter[2] == "SGID") continue;
                        SQ.WriteLine("alter table " + alter[1] + " add " + alter[2] + "  " + alter[3] + "(" + alter[4].Split(',')[0] + ")  default ''");
                    }
                    else if (alter[3] == "decimal" || alter[3] == "numeric")
                        SQ.WriteLine("alter table " + alter[1] + " add " + alter[2] + "  " + alter[3] + "(" + alter[4] + ")  default 0");
                    else
                        SQ.WriteLine("alter table " + alter[1] + " add " + alter[2] + "  " + alter[3]);

                }
                if (field2_and.Count > 0) File.WriteAllLines(outpath + @"\目标数据库有源数据库没有字段.txt", field2_and.ToArray<string>());
                #endregion

                #region //比较索引咯~~~

                List<string> temp1 = File.ReadAllLines(path1 + @"\index.txt").ToList<string>();
                List<string> temp2 = File.ReadAllLines(path2 + @"\index.txt").ToList<string>();
                #region 剔除没有的表中的索引,只比较都有的表中的不同------现在不用这一步,为后续sql服务
                //List<string> temp1=new List<string>();//都有的表中的索引
                //List<string> temp2=new List<string> ();
                //foreach(string t in data1and2)
                //{
                //    foreach(string i1 in index1)
                //    {//INDGSY_TREETMPGSY2050D_WYCCODE,DOCID,LX,PCODEY

                //        if(i1.Substring(4,i1.IndexOf('\b',4)-4)==t.Substring(t.IndexOf('\b')+1))
                //        {//表名
                //            temp1.Add(i1);
                //        }
                //    }
                //    foreach (string i2 in index2)
                //    {
                //        if (i2.Substring(4, i2.IndexOf('\b', 4)-4) == t.Substring(t.IndexOf('\b') + 1))
                //        {
                //            temp2.Add(i2);
                //        }
                //    }
                //}
                #endregion
                //找出两个表中索引相同的去掉
                //List<string> injiaoji = temp1.Intersect(temp2).ToList<string>();
                //foreach(string jj in injiaoji)
                //{
                //    temp1.Remove(jj);
                //    temp2.Remove(jj);
                //}
                //找出差集,代替去相同
                List<string> temp1_2_ex = temp1.Except(temp2).ToList<string>();
                List<string> temp2_1_ex = temp2.Except(temp1).ToList<string>();
                //剩下的要么就是你有他没有,要么就是字段类型不同,反正是差集
                //List<string> typei = new List<string>();
                #region 唯一性不同的
                Dictionary<string, string> dtype_unique = new Dictionary<string, string>();
                foreach (string t1 in temp1_2_ex)
                {//索引名名、列相同,但唯一性不同
                    string i1 = t1.Substring(0, t1.LastIndexOf('\b'));
                    // INDGSY_TREETMPGSY2050D_WYCCODE,DOCID,LX,PCODEY
                    foreach (string t2 in temp2_1_ex)
                    {
                        string i2 = t2.Substring(0, t2.LastIndexOf('\b'));
                        if (i1 == i2)
                        {
                            dtype_unique.Add(t1, t2);
                        }
                    }
                }
                foreach (string t2 in temp2_1_ex)
                {//索引名名、列相同,但唯一性不同
                    string i2 = t2.Substring(0, t2.LastIndexOf('\b'));
                    // INDGSY_TREETMPGSY2050D_WYCCODE,DOCID,LX,PCODEY
                    foreach (string t1 in temp1_2_ex)
                    {
                        string i1 = t1.Substring(0, t1.LastIndexOf('\b'));
                        if (i1 == i2)
                        {
                            if (dtype_unique.Keys.Contains(t1)) continue;
                            dtype_unique.Add(t1, t2);
                        }
                    }
                }
                //剔除所有仅仅唯一性不同的项
                foreach (var u in dtype_unique.Keys)
                {
                    temp1_2_ex.Remove(u);
                }
                foreach (var u in dtype_unique.Values)
                {
                    temp2_1_ex.Remove(u);
                }
                #endregion
                #region 索引列不同的
                //索引相同但列不同的
                Dictionary<string, string> dtype_col = new Dictionary<string, string>();
                foreach (string t1 in temp1_2_ex)
                {//索引名名相同但列不同,
                    string i1 = t1.Substring(0, t1.IndexOf('\b', t1.IndexOf('\b', 4) + 1));
                    // INDGSY_TREETMPGSY2050D_WYCCODE,DOCID,LX,PCODEY
                    foreach (string t2 in temp2_1_ex)
                    {
                        string i2 = t2.Substring(0, t2.IndexOf('\b', t2.IndexOf('\b', 4) + 1));
                        if (i1 == i2)
                        {
                            dtype_col.Add(t1, t2);
                        }
                    }
                }
                foreach (string t2 in temp2_1_ex)
                {//取到列名
                    string i2 = t2.Substring(0, t2.IndexOf('\b', t2.IndexOf('\b', 4) + 1));
                    // INDGSY_TREETMPGSY2050D_WYCCODE,DOCID,LX,PCODEY
                    foreach (string t1 in temp1_2_ex)
                    {
                        string i1 = t1.Substring(0, t1.IndexOf('\b', t1.IndexOf('\b', 4) + 1));
                        if (i1 == i2)
                        {
                            if (dtype_col.Keys.Contains(t1)) continue;
                            dtype_col.Add(t1, t2);
                        }
                    }
                }
                //剔除仅仅是咧不同的
                foreach (var c in dtype_col.Keys)
                {
                    temp1_2_ex.Remove(c);
                }
                foreach (var c in dtype_col.Values)
                {
                    temp2_1_ex.Remove(c);
                }
                #endregion
                #region 索引名不同  ---这个并不需要比较,索引名不同不就是你有我没有吗,真尼玛蠢啊
                ////////////////找出索引名不同的
                //Dictionary<string, string> dtype_name = new Dictionary<string, string>();
                //foreach (string t1 in temp1_2_ex)
                //{//索引名不同
                //    string i1 = t1.Substring(0,  t1.IndexOf('\b', 4) );
                //    // INDGSY_TREETMPGSY2050D_WYCCODE,DOCID,LX,PCODEY
                //    foreach (string t2 in temp2_1_ex)
                //    {
                //        string i2 = t2.Substring(0, t2.IndexOf('\b', 4));
                //        if (i1 == i2)
                //        {
                //            dtype_name.Add(t1, t2);
                //        }
                //    }
                //}
                //foreach (string t2 in temp2_1_ex)
                //{//索引名名相同但类型不同,可是不同的表中有相同的字段咋办@@截取的字段是表名加字段名的
                //    string i2 = t2.Substring(0,  t2.IndexOf('\b', 4));
                //    // INDGSY_TREETMPGSY2050D_WYCCODE,DOCID,LX,PCODEY
                //    foreach (string t1 in temp1_2_ex)
                //    {
                //        string i1 = t1.Substring(0, t1.IndexOf('\b', 4) );
                //        if (i1 == i2)
                //        {
                //            if (dtype_col.Keys.Contains(t1)) continue;
                //            dtype_name.Add(t1, t2);
                //        }
                //    }
                //}
                ////剔除索引名不同的
                //foreach (var n in dtype_name.Keys)
                //{
                //    temp1_2_ex.Remove(n);
                //}
                //foreach (var n in dtype_name.Values)
                //{
                //    temp2_1_ex.Remove(n);
                //}
                #endregion
                /////////////////////
                //既然都是相同的表,那剩下的就是互相没有的索引了
                //输出至文件
                if (File.Exists(outpath + @"\索引不同.txt")) File.Delete(outpath + @"\索引不同.txt");
                using (StreamWriter sw = new StreamWriter(outpath + @"\索引不同.txt", true, Encoding.UTF8))
                {
                    sw.WriteLine("源数据库有而目标数据库没有的索引");
                    foreach (string ex in temp1_2_ex)
                    {
                        sw.WriteLine(ex);
                        string[] ind = ex.Split('\b');
                        if (ind[4] == "N")
                            SQ.WriteLine("create index " + ind[2] + "  on " + ind[1] + "(" + ind[3] + ")");
                        else
                            SQ.WriteLine("create unique index " + ind[2] + "  on " + ind[1] + "(" + ind[3] + ")");

                    }
                    sw.WriteLine("目标数据库有而源数据库没有的索引");
                    foreach (string ex in temp2_1_ex)
                    {
                        sw.WriteLine(ex);
                    }
                    sw.WriteLine("索引键列不同:\n");
                    foreach (string k in dtype_col.Keys)
                    {//INDGSY_TREETMPGSY2050D_WYCCODE,DOCID,LX,PCODEY
                        sw.WriteLine(k + "\b<->\b" + dtype_col[k]);
                        string[] ind = k.Split('\b');
                        SQ.WriteLine("drop index " + ind[2] + " on " + ind[1]);
                        if (ind[4] == "N")
                            SQ.WriteLine("create index " + ind[2] + "  on " + ind[1] + "(" + ind[3] + ")");
                        else
                            SQ.WriteLine("create unique index " + ind[2] + "  on " + ind[1] + "(" + ind[3] + ")");

                    }
                    sw.WriteLine("索引唯一性不同的:\n");
                    foreach (string k in dtype_unique.Keys)
                    {
                        sw.WriteLine(k + "\b<->\b" + dtype_unique[k]);
                        string[] ind = k.Split('\b');
                        SQ.WriteLine("drop index " + ind[2] + " on " + ind[1]);
                        if (ind[4] == "N")
                            SQ.WriteLine("create index " + ind[2] + "  on " + ind[1] + "(" + ind[3] + ")");
                        else
                            SQ.WriteLine("create unique index " + ind[2] + "  on " + ind[1] + "(" + ind[3] + ")");

                    }
                }
                #endregion
                SQ.Close();
                MessageBox.Show("比较完成!");
            }
            catch (Exception ex)
            {
                MessageBox.Show("比较遇到问题,请检查文件是否存在或其他未知原因!");
            }
        }
 assert_equal(len(y_test), len(y_train))
Example #4
0
 if (r.i >= int64(len(r.s)))
Example #5
0
 for i in range(len(list) - 1, -1, -1):