Esempio n. 1
0
        public static string Format(ClickHouseDbParameter parameter)
        {
            var type = string.IsNullOrWhiteSpace(parameter.ClickHouseType)
                ? TypeConverter.ToClickHouseType(parameter.Value.GetType())
                : TypeConverter.ParseClickHouseType(parameter.ClickHouseType);

            return(Format(type, parameter.Value));
        }
Esempio n. 2
0
 public override DbParameter[] GetDbParamtersByObject(string sql, object obj) =>
 Utils.GetDbParamtersByObject <DbParameter>(sql, obj, "?", (name, type, value) =>
 {
     DbParameter ret = new ClickHouseDbParameter {
         ParameterName = $"?{name}", Value = value
     };
     var tp = _orm.CodeFirst.GetDbInfo(type)?.type;
     if (tp != null)
     {
         ret.DbType = (DbType)tp.Value;
     }
     return(ret);
 });
        public override DbDataAdapter GetAdapter(string selectCommand, DbConnection connection, CommandParameterCollection parameters)
        {
            ClickHouseDataAdapter adapter = new ClickHouseDataAdapter();

            adapter.SelectCommand             = new ClickHouseCommand(connection as ClickHouseConnection);
            adapter.SelectCommand.CommandText = selectCommand;

            foreach (CommandParameter p in parameters)
            {
                ClickHouseDbParameter parameter = new ClickHouseDbParameter();
                adapter.SelectCommand.Parameters.Add(p.Name);
                parameter.Value = p.Value;
            }
            return(adapter);
        }
        public void TestParameterCollectionOperations()
        {
            var param1 = new ClickHouseDbParameter()
            {
                ParameterName = "param1", ClickHouseType = "Int32", Value = 1
            };
            var param2 = new ClickHouseDbParameter()
            {
                ParameterName = "param2", ClickHouseType = "Int32", Value = 2
            };
            var param3 = new ClickHouseDbParameter()
            {
                ParameterName = "param3", ClickHouseType = "String", Value = "ASD"
            };
            var param4 = new ClickHouseDbParameter()
            {
                ParameterName = "param4", ClickHouseType = "Nothing", Value = null
            };

            var collection = new ClickHouseParameterCollection
            {
                param1
            };

            collection.AddRange(new[] { param2, param3 });

            CollectionAssert.AllItemsAreNotNull(collection);
            CollectionAssert.AllItemsAreUnique(collection);
            Assert.AreEqual(3, collection.Count);
            Assert.IsTrue(collection.Contains(param2));
            Assert.IsTrue(collection.Contains("param3"));
            collection.CopyTo(new object[collection.Count], 0);
            Assert.AreEqual(0, collection.IndexOf(param1));
            Assert.AreEqual(2, collection.IndexOf("param3"));

            collection["param4"] = param4;
            collection.Insert(3, param2);
            Assert.AreEqual(param2, collection[3]);
            Assert.AreEqual(param4, collection["param4"]);
            collection.RemoveAt("param4");
            collection.RemoveAt(3);
            collection.Remove(param2);
            Assert.AreEqual(2, collection.Count);
            collection.Clear();
            Assert.AreEqual(0, collection.Count);
        }
Esempio n. 5
0
        public override DbParameter AppendParamter(List <DbParameter> _params, string parameterName, ColumnInfo col, Type type, object value)
        {
            if (string.IsNullOrEmpty(parameterName))
            {
                parameterName = $"p_{_params?.Count}";
            }
            var         dbtype = (DbType?)_orm.CodeFirst.GetDbInfo(type)?.type;
            DbParameter ret    = new ClickHouseDbParameter {
                ParameterName = parameterName
            };                                                                            //QuoteParamterName(parameterName)

            if (dbtype != null)
            {
                ret.DbType = dbtype.Value;
            }
            ret.Value = value;
            if (col != null)
            {
                var dbtype2 = (DbType)_orm.DbFirst.GetDbType(new DatabaseModel.DbColumnInfo {
                    DbTypeText = col.DbTypeText, DbTypeTextFull = col.Attribute.DbType, MaxLength = col.DbSize
                });
                switch (dbtype2)
                {
                case DbType.Binary:
                default:
                    dbtype = dbtype2;
                    //if (col.DbSize != 0) ret.Size = col.DbSize;
                    if (col.DbPrecision != 0)
                    {
                        ret.Precision = col.DbPrecision;
                    }
                    if (col.DbScale != 0)
                    {
                        ret.Scale = col.DbScale;
                    }
                    break;
                }
                if (value is bool)
                {
                    ret.Value = (bool)value ? 1 : 0;
                }
            }
            _params?.Add(ret);
            return(ret);
        }