Esempio n. 1
0
        void ImportToDB()
        {
            if (!entities.EntityList.Any())
            {
                return;
            }
            OracleConPara para = new OracleConPara()
            {
                HostName    = Task.To.HostName,
                Password    = Task.To.Password,
                Port        = Task.To.Port,
                ServiceName = Task.To.ServiceName,
                UserID      = Task.To.UserID
            };
            var           obj    = entities.EntityList.First();
            var           dict   = (IDictionary <string, object>)obj;
            List <string> cols   = Task.From.Columns.Any(a => a == "*") ? ((IDictionary <string, object>)entities.EntityList.First()).Keys.ToList() : Task.From.Columns;
            string        sql    = string.Format("insert into {0} ({1})", Task.To.Table, string.Join(",", cols));
            List <string> values = new List <string>();

            foreach (IDictionary <string, object> item in entities.EntityList)
            {
                List <string> list = new List <string>();
                foreach (string c in cols)
                {
                    list.Add(FixSqlValue(item[c]));
                }
                values.Add(string.Join(",", list));
            }
            sql = string.Format("{0} values ({1})", sql, string.Join("),(", values));
            List <string> sqls = new List <string>();

            if (string.IsNullOrEmpty(Task.From.Sequence))
            {
                sqls.Add(string.Format("delete from {0}", Task.To.Table));
            }
            else if (fixSeqValue.Trim('\'') != "")
            {
                sqls.Add(string.Format("delete from {0} where {1} > {2}", Task.To.Table, Task.From.Sequence, fixSeqValue));
            }
            sqls.Add(sql);
            if (Task.To.DBType.ToLower() == "db2")
            {
                DB2Util db2 = new DB2Util(para);
                db2.UpdateBatchCommand(sqls);
            }
            else if (Task.To.DBType.ToLower() == "oracle")
            {
                OracleUtil oracle = new OracleUtil(para);
                oracle.UpdateBatchCommand(sqls);
            }
            else if (Task.To.DBType.ToLower() == "sqlserver")
            {
                MsUtil ms = new MsUtil(para);
                ms.UpdateBatchCommand(sqls);
            }
            WriteSeqValue();
        }