Ejemplo n.º 1
0
        protected virtual string Insert(IFreeDocument data, List <string> keys, string dbTableName)
        {
            FreeDocument item = data.DictSerialize(Scenario.Database);
            var          sb   = new StringBuilder();

            foreach (var key in keys)
            {
                object ovalue;
                if (!data.TryGetValue(key, out ovalue))
                {
                    ovalue = "null";
                }
                string value;
                if (ovalue is DateTime)
                {
                    value = ((DateTime)ovalue).ToString("s");
                }
                else
                {
                    if (ovalue == null)
                    {
                        value = "null";
                    }
                    else
                    {
                        value = ovalue.ToString();
                    }
                }
                value = value.Replace("'", "''");
                sb.Append($"'{value}',");
            }
            sb.Remove(sb.Length - 1, 1);
            string sql = $"INSERT INTO {dbTableName} VALUES({sb})";

            return(sql);
        }