Exemplo n.º 1
0
        private void SavePairs(Solution solution, ICollection collection, string table, Dictionary <string, object> additional, GenerateSavePair generator, ref IDbCommand cmd)
        {
            List <object> vals    = new List <object>();
            StringBuilder builder = null;
            StringBuilder values  = null;

            if (cmd == null)
            {
                builder = new StringBuilder();
                builder.AppendFormat("INSERT INTO `{0}` (`iteration`", table);

                values = new StringBuilder();
                values.Append("VALUES(@0");
            }

            vals.Add(Job.Optimizer.CurrentIteration);

            int i = 1;

            if (solution != null)
            {
                if (cmd == null)
                {
                    builder.Append(", `index`");
                    values.Append(", @1");
                }

                vals.Add(solution.Id);
                ++i;
            }

            if (additional != null)
            {
                foreach (KeyValuePair <string, object> pair in additional)
                {
                    if (cmd == null)
                    {
                        builder.AppendFormat(", `{0}`", pair.Key);
                        values.AppendFormat(", @{0}", i);
                    }

                    vals.Add(pair.Value);
                    ++i;
                }
            }

            foreach (object o in collection)
            {
                string name;
                object val;

                if (generator(o, out name, out val))
                {
                    if (cmd == null)
                    {
                        builder.AppendFormat(", `{0}`", NormalizeName(name));
                        values.AppendFormat(", @{0}", i);
                    }

                    vals.Add(val);
                    ++i;
                }
            }

            string q = null;
            var    v = vals.ToArray();

            if (cmd == null)
            {
                builder.Append(") ").Append(values).Append(")");
                q = builder.ToString();
                Query(ref cmd, q, v);
            }
            else
            {
                Query(ref cmd, v);
            }
        }
Exemplo n.º 2
0
        private void SavePairs(Solution solution, ICollection collection, string table, Dictionary <string, object> additional, GenerateSavePair generator)
        {
            IDbCommand cmd = null;

            SavePairs(solution, collection, table, additional, generator, ref cmd);

            cmd.Dispose();
            cmd = null;
        }