コード例 #1
0
        public DataMig(Config.ImportActionModel actmodel)
        {
            this.actmodel = actmodel;
            using (var dbconn1 = DbConn.CreateConn(DbType.SQLSERVER, actmodel.database1.source, actmodel.database1.port, actmodel.database1.database, actmodel.database1.userid, actmodel.database1.password))
            {
                dbconn1.Open();
                DbStructure.IDbStructure dbstru = new DbStructure.DbStructureSqlServer();
                tables = dbstru.GetTables(dbconn1);
            }

            if (actmodel.excepttables != null)
            {
                foreach (var a in actmodel.excepttables)
                {
                    tables.RemoveAll(x => x.name == a);
                }
            }
            foreach (var a in tables)
            {
                TableMig tm = new TableMig(actmodel, a.name);
                tablemigs.Add(tm);
            }
        }
コード例 #2
0
        public void Step1_Syn()
        {
            using (var dbconn1 = DbConn.CreateConn(DbType.SQLSERVER, actmodel.database1.source, actmodel.database1.port, actmodel.database1.database, actmodel.database1.userid, actmodel.database1.password))
                using (var dbconn2 = DbConn.CreateConn(DbType.MYSQL, actmodel.database2.source, actmodel.database2.port, actmodel.database2.database, actmodel.database2.userid, actmodel.database2.password))
                {
                    dbconn1.Open();
                    dbconn2.Open();

                    DbStructure.DbStructureSqlServer mssqlstr = new DbStructure.DbStructureSqlServer();
                    tablestru = mssqlstr.GetTableStructure(dbconn1, tablename);
                    string sql = "select count(1) as cc from " + tablename + " ";
                    allitemcount = (int)dbconn1.ExecuteScalar(sql, null);
                    successcount = (int)((long)dbconn2.ExecuteScalar(sql, null));

                    // (tablestru.identityattribute != null && tablestru.identityattribute.Count == 1)
                    if (tablestru.primarykey != null)
                    {
                        List <string> pkcol   = new List <string>();
                        List <string> pkorder = new List <string>();
                        if (tablestru.primarykey != null)
                        {
                            foreach (var a in tablestru.primarykey.columns)
                            {
                                pkcol.Add(a.name);
                                pkorder.Add(a.name + " desc ");
                            }
                        }
                        //else// if (tablestru.identityattribute != null && tablestru.identityattribute.Count == 1)
                        //{
                        //    pkcol.Add(tablestru.identityattribute[0].column.name);
                        //    pkorder.Add(tablestru.identityattribute[0].column.name + " desc ");
                        //}
                        //else
                        //{
                        //    pkcol.Add(tablestru.columns.First().name);
                        //    pkorder.Add(tablestru.columns.First().name + " desc ");
                        //}
                        string sqltop = "select   {0} from {1} order by {2} limit 0,1;";
                        sqltop = string.Format(sqltop, string.Join(",", pkcol), tablename, string.Join(",", pkorder));



                        DataTable tboftop = dbconn2.SqlToDataTable(sqltop, null);

                        if (tboftop.Rows.Count == 1)
                        {
                            List <ProcedureParameter> parasofgetrownum = new List <ProcedureParameter>();
                            string        sqlofpno        = "select top 1 A.rownumber from ( SELECT ROW_NUMBER() over (order by {0}) as rownumber,{1} from {2} ) A where {3}";
                            List <string> getrownum_order = new List <string>();
                            List <string> getrownum_where = new List <string>();

                            foreach (string s in pkcol)
                            {
                                object value = tboftop.Rows[0][s];
                                if (value != null)
                                {
                                    if (value.GetType() == typeof(MySql.Data.Types.MySqlDateTime))
                                    {
                                        MySql.Data.Types.MySqlDateTime nvalue = (MySql.Data.Types.MySqlDateTime)value;
                                        string sofmydatetime = value.ToString();
                                        if (string.IsNullOrEmpty(sofmydatetime))
                                        {
                                            value = System.DBNull.Value;
                                        }
                                        else
                                        {
                                            value = Convert.ToDateTime(sofmydatetime);
                                        }
                                    }
                                }

                                getrownum_order.Add(s + " asc");
                                getrownum_where.Add(s + "=@" + s);
                                parasofgetrownum.Add(new ProcedureParameter("@" + s, value));
                            }
                            sqlofpno = string.Format(sqlofpno, string.Join(",", getrownum_order), string.Join(",", pkcol), tablename, string.Join(" and ", getrownum_where));

                            object prerownum = dbconn1.ExecuteScalar(sqlofpno, parasofgetrownum, 2);
                            if (prerownum != null && prerownum.GetType() != typeof(System.DBNull))
                            {
                                beginindex = Convert.ToInt32(prerownum);
                            }
                        }
                    }
                    else
                    {
                        beginindex = (int)successcount;
                    }
                }
        }