Esempio n. 1
0
 protected void GenerateSqlOrder(ISqlDumper dmp, IDataSynAdapter sada, SynSourceInfo info, SynQueryType qtype)
 {
     if (qtype == SynQueryType.SelectKeyMd5 || qtype == SynQueryType.SelectKeyNull)
     {
         dmp.Put(" order by %,i", (IEnumerable <string>)info.KeyCols);
     }
 }
Esempio n. 2
0
 public override void GenerateSql(ISqlDumper dmp, IDataSynAdapter sada, SynSourceInfo info, SynQueryType qtype, Action <ISqlDumper> putCondition)
 {
     GenerateSqlToFrom(dmp, sada, info, qtype);
     dmp.Put("%f", Table);
     if (putCondition != null)
     {
         putCondition(dmp);
     }
     GenerateSqlOrder(dmp, sada, info, qtype);
 }
Esempio n. 3
0
        private void DoLoadFootprint(IDatabaseSource conn, SynSourceInfo info, string cacheFile)
        {
            // HACK: external sorting must be implemented
            using (var fw = new FileStream(cacheFile, FileMode.Create))
            {
                var fts = new List <SynFootprint>();
                using (var bw = new BinaryWriter(fw))
                {
                    var sada = conn.Dialect.CreateDataSynAdapter();
                    if (sada == null)
                    {
                        throw new ExpectedError("DAE-00365 " + Texts.Get("s_dialect_doesnt_support_sync$dialect", "dialect", conn.Dialect.DisplayName));
                    }
                    var qbuf  = new StringWriter();
                    var dmp   = conn.Dialect.CreateDumper(qbuf);
                    var qtype = m_options.Update == true ? SynQueryType.SelectKeyMd5 : SynQueryType.SelectKeyNull;
                    info.Query.GenerateSql(dmp, sada, info, qtype, d2 =>
                    {
                        if (!info.SqlCondition.IsEmpty())
                        {
                            d2.Put(" ^where ");
                            d2.WriteRaw(info.SqlCondition);
                        }
                    });
                    using (var cmd = conn.Connection.SystemConnection.CreateCommand())
                    {
                        cmd.CommandText = qbuf.ToString();

                        using (IBedReader reader = conn.GetAnyDDA().AdaptReader(cmd.ExecuteReader()))
                        {
                            while (reader.Read())
                            {
                                var ft = SynFootprint.FromReader(reader, info.KeyCols.Length, m_holder, m_conv, sada);
                                fts.Add(ft);
                            }
                        }
                    }

                    fts.Sort();
                    foreach (var ft in fts)
                    {
                        bw.Write((byte)0);
                        ft.SaveToStream(bw);
                    }
                    bw.Write((byte)1);
                }
            }
        }
Esempio n. 4
0
        private void AssignColsAndQuery(SynSourceInfo source, SynSourceInfo target, IDatabaseSource srcConn, IDatabaseSource dstConn, string[] srcCols, string[] dstCols)
        {
            source.Query = Source.GetReadQuery(srcConn.Dialect, srcCols);
            target.Query = Target.GetReadQuery(dstConn.Dialect, dstCols);
            var map = new Dictionary <string, string>();

            for (int i = 0; i < srcCols.Length; i++)
            {
                map[dstCols[i]] = srcCols[i];
            }
            foreach (var c in target.KeyCols)
            {
                if (!map.ContainsKey(c))
                {
                    throw new DataSynError(String.Format("DAE-00320 Key column {0} of table {1} is not synchronized", c, Target.Table));
                }
            }
            source.KeyCols  = (from c in target.KeyCols select map[c]).ToArray();
            target.DataCols = (from c in dstCols where !target.KeyCols.Contains(c) select c).ToArray();
            source.DataCols = (from c in target.DataCols select map[c]).ToArray();
        }
Esempio n. 5
0
        protected void GenerateSqlToFrom(ISqlDumper dmp, IDataSynAdapter sada, SynSourceInfo info, SynQueryType qtype)
        {
            dmp.Put("^select %,i", (IEnumerable <string>)info.KeyCols);

            if (qtype == SynQueryType.SelectKeyMd5)
            {
                var  colexprs = new List <string>();
                bool was      = false;
                foreach (string col in info.CompareCols)
                {
                    if (was)
                    {
                        colexprs.Add("'(SEP#n3f9)'");
                    }
                    var type = info.Model.Columns[col].DataType;
                    colexprs.Add(sada.Coalesce(sada.GetHashableString(dmp.Dialect.QuoteIdentifier(col), type), "'(NULL#093foew)'"));
                    was = true;
                }
                if (colexprs.Count == 0)
                {
                    colexprs.Add("'(NONEswgg5)'");
                }
                dmp.Put(",");
                dmp.WriteRaw(sada.Md5(sada.Concat(colexprs)));
            }
            if (qtype == SynQueryType.SelectKeyNull)
            {
                dmp.Put(",^null");
            }
            if (qtype == SynQueryType.SelectAll)
            {
                if (info.DataCols.Length > 0)
                {
                    dmp.Put(",%,i", (IEnumerable <string>)info.DataCols);
                }
            }
            dmp.Put(" from ");
        }
Esempio n. 6
0
 // loads keys and data hash into cache file, data is ordered by keycols
 private void LoadFootprint(IDatabaseSource conn, SynSourceInfo info, string cacheFile)
 {
     conn.Connection.Invoke(() => DoLoadFootprint(conn, info, cacheFile));
 }
Esempio n. 7
0
        private string CreateQuery(IEnumerable <string[]> keys, IDatabaseSource dbconn, IDataSynAdapter sada, SynSourceInfo info)
        {
            var sw  = new StringWriter();
            var dmp = dbconn.Dialect.CreateDumper(sw);

            m_srcInfo.Query.GenerateSql(dmp, sada, info, SynQueryType.SelectAll, d => { d.Put(" where "); PutConditionList(d, keys); });
            //dmp.Put("select %,i, %,i from (%s) sub where ", m_srcInfo.KeyCols, m_srcInfo.DataCols, m_srcInfo.ReadQuery);

            //PutConditionList(dmp, keys);
            return(sw.ToString());
        }
Esempio n. 8
0
        private void FillGridTable(IEnumerable <string[]> keys, GridTable grid, IDatabaseSource conn, IDataSynAdapter sada, SynSourceInfo info)
        {
            string query = CreateQuery(keys, conn, sada, info);

            using (var cmd = conn.Connection.SystemConnection.CreateCommand())
            {
                cmd.CommandText = query;

                using (IBedReader reader = conn.GetAnyDDA().AdaptReader(cmd.ExecuteReader()))
                {
                    grid.Fill(reader);
                }
            }
        }
Esempio n. 9
0
 private void AssignCompareCols(SynSourceInfo source, SynSourceInfo target, IDatabaseSource srcConn, IDatabaseSource dstConn, string[] srcCols, string[] dstCols)
 {
     source.CompareCols = srcCols;
     target.CompareCols = dstCols;
 }
Esempio n. 10
0
        public void BuildInfo(IDatabaseSource srcConn, IDatabaseSource dstConn, out SynSourceInfo source, out SynSourceInfo target)
        {
            source = new SynSourceInfo();
            target = new SynSourceInfo();

            if (!(Source is DataSynQuerySource))
            {
                source.SqlCondition = Source.SqlCondition;
            }
            target.SqlCondition = Target.SqlCondition;

            source.Model = Source.GetModel(srcConn);
            target.Model = Target.GetModel(dstConn);

            if (KeyColsOverride != null)
            {
                target.KeyCols = KeyColsOverride.ToArray();
            }
            else
            {
                target.KeyCols = target.Model.GetPkColumns().GetNames();
            }
            if (target.KeyCols.Length == 0)
            {
                throw new DataSynError("DAE-00319 Table " + target.Model.FullName.ToString() + " has empty synchronize key or table has not primary key");
            }

            SynColMapping map = null;

            if (ColMode != ColumnMode.CustomMapping)
            {
                map = SynColMapping.CreateMapping(source.Model, target.Model);
            }
            else
            {
                map = SynColMapping.CreateMapping(SelectedMapping);
            }
            switch (ColMode)
            {
            case ColumnMode.All:
                AssignColsAndQuery(source, target, srcConn, dstConn, map.SourceCols, map.TargetCols);
                break;

            case ColumnMode.Selected:
                AssignColsAndQuery(source, target, srcConn, dstConn, map[SelectedColumns], SelectedColumns.ToArray());
                break;

            case ColumnMode.AllExceptSelected:
                string[] selcols = map.Complement(SelectedNoColumns);
                AssignColsAndQuery(source, target, srcConn, dstConn, map[selcols], selcols);
                break;

            case ColumnMode.CustomMapping:
                AssignColsAndQuery(source, target, srcConn, dstConn, SelectedMapping.Values.ToArray(), SelectedMapping.Keys.ToArray());
                break;
            }
            switch (CompareColMode)
            {
            case ColumnMode.All:
                AssignCompareCols(source, target, srcConn, dstConn, source.DataCols, target.DataCols);
                break;

            case ColumnMode.Selected:
                AssignCompareCols(source, target, srcConn, dstConn, map[CompareColsOverride], CompareColsOverride.ToArray());
                break;

            case ColumnMode.AllExceptSelected:
                string[] ccols = ArrayTool.Difference(target.DataCols, CompareNoColsOverride);
                AssignCompareCols(source, target, srcConn, dstConn, map[ccols], ccols.ToArray());
                break;
            }
        }
Esempio n. 11
0
 public abstract void GenerateSql(ISqlDumper dmp, IDataSynAdapter sada, SynSourceInfo info, SynQueryType qtype, Action <ISqlDumper> putCondition);