///// <summary> ///// 根据数据库类型指定变量类型 ///// </summary> ///// <param name="type"></param> //private void SetType(DbType type) //{ // if (type == DbType.AnsiString || type == DbType.AnsiStringFixedLength || type == DbType.String || // type == DbType.StringFixedLength) // { // this.ValueDataType = DefaultType.StringType; // } // else if (type == DbType.Int64 || // type == DbType.Int32 || type == DbType.Int16 || type == DbType.SByte) // { // this.ValueDataType = DefaultType.IntType; // } // else if (type == DbType.UInt32 || type == DbType.UInt64 || type == DbType.UInt16 || type == DbType.Byte || type == DbType.Boolean) // { // this.ValueDataType = DefaultType.IntType; // } // else if (type == DbType.Decimal || type == DbType.Double || type == DbType.Double // || type == DbType.Currency || type == DbType.VarNumeric) // { // this.ValueDataType = DefaultType.DecimalType; // } // else if (type == DbType.DateTime || type == DbType.Time || type == DbType.Date) // { // this.ValueDataType = DefaultType.DateTimeType; // } //} internal override string DisplayValue(KeyWordInfomation info) { string pValue1 = value.DisplayValue(info); if (funHandle2 != null) { return(funHandle2(pValue1, format, info.DBInfo)); } else { return(funHandle1(pValue1, _valueDbType, info.DBInfo)); } }
internal override string DisplayValue(KeyWordInfomation info) { if (_handle != null) { if (_query != null) { KeyWordConver conver = new KeyWordConver(); KeyWordInfomation qInfo = info.Clone() as KeyWordInfomation; return("(" + _handle(_sourceHandle.DisplayValue(info), new string[] { conver.ToConver(_query, qInfo).GetSql(false) }, info.DBInfo) + ")"); } else if (_paramList != null) { List <string> lstPrm = new List <string>(); foreach (object item in _paramList) { lstPrm.Add(BQLValueItem.ToValueItem(item).DisplayValue(info)); } return("(" + _handle(_sourceHandle.DisplayValue(info), lstPrm.ToArray(), info.DBInfo) + ")"); } } return(null); }
internal override string DisplayValue(KeyWordInfomation info) { StringBuilder sb = new StringBuilder(); if (!Buffalo.Kernel.CommonMethods.IsNull(Previous)) { sb.Append(Previous.DisplayValue(info)); } sb.Append(" when "); sb.Append(whenValue.DisplayValue(info)); sb.Append(" then "); sb.Append(thenValue.DisplayValue(info)); return(sb.ToString()); }
internal override string DisplayValue(KeyWordInfomation info) { StringBuilder sb = new StringBuilder(); if (!Buffalo.Kernel.CommonMethods.IsNull(Previous)) { sb.Append(Previous.DisplayValue(info)); } sb.Append("case "); if (!CommonMethods.IsNull(itemValue)) { sb.Append(itemValue.DisplayValue(info) + " "); } //return sb.ToString(); return(sb.ToString()); }
public override string ToString() { BQLValueItem qvalue = value1 as BQLValueItem; if (!CommonMethods.IsNull(qvalue)) { return(qvalue.DisplayValue(BQLValueItem.GetKeyInfo())); } else { string pName = propertyName; DbType dbType = DbType.AnsiString; if (value1 != null) { dbType = DefaultType.ToDbType(value1.GetType()); } return(DataAccessCommon.FormatScorp(this, null, pName, dbType, 0, null)); } return(base.ToString()); }
internal override void Tran(KeyWordInfomation info) { StringBuilder condition = new StringBuilder(); List <DbType> lstParamType = info.Condition.ParamTypes; for (int i = 0; i < valueHandles.Length; i++) { BQLValueItem vItem = valueHandles[i]; if (lstParamType != null && lstParamType.Count > i) { vItem.ValueDbType = lstParamType[i]; } condition.Append(vItem.DisplayValue(info)); condition.Append(','); } condition.Append(IdentityValueString(info)); if (condition.Length > 0) { condition.Remove(condition.Length - 1, 1); } info.Condition.SqlValues.Append(condition.ToString()); //return " values (" + condition.ToString()+")"; }
/// <summary> /// 进行插入操作 /// </summary> /// <param name="obj">要插入的对象</param> /// <param name="fillIdentity">是否要填充刚插入的实体的ID</param> /// <returns></returns> protected internal int DoInsert(EntityBase obj, ValueSetList setList, bool fillIdentity) { StringBuilder sqlParams = new StringBuilder(1000); StringBuilder sqlValues = new StringBuilder(1000); ParamList list = new ParamList(); string param = null; string svalue = null; List <EntityPropertyInfo> identityInfo = new List <EntityPropertyInfo>(); KeyWordInfomation keyinfo = BQLValueItem.GetKeyInfo().Clone() as KeyWordInfomation; keyinfo.ParamList = list; foreach (EntityPropertyInfo info in EntityInfo.PropertyInfo) { //EntityPropertyInfo info = enums.Current.Value; object curValue = info.GetValue(obj); if (info.Identity) { if (info.SqlType == DbType.Guid && info.FieldType == DefaultType.GUIDType) { curValue = Guid.NewGuid(); info.SetValue(obj, curValue); DBParameter prm = list.NewParameter(info.SqlType, curValue, EntityInfo.DBInfo); sqlParams.Append(","); sqlParams.Append(EntityInfo.DBInfo.CurrentDbAdapter.FormatParam(info.ParamName)); sqlValues.Append(","); sqlValues.Append(prm.ValueName); continue; } else { if (fillIdentity) { identityInfo.Add(info); } param = EntityInfo.DBInfo.CurrentDbAdapter.GetIdentityParamName(info); if (!string.IsNullOrEmpty(param)) { sqlParams.Append(","); sqlParams.Append(param); } svalue = EntityInfo.DBInfo.CurrentDbAdapter.GetIdentityParamValue(EntityInfo, info); if (!string.IsNullOrEmpty(svalue)) { sqlValues.Append(","); sqlValues.Append(svalue); } continue; } } else if (info.IsVersion) //版本初始值 { object conValue = curValue; if (conValue == null) { conValue = GetDefaultConcurrency(info); } if (conValue != null) { DBParameter prm = list.NewParameter(info.SqlType, conValue, EntityInfo.DBInfo); sqlParams.Append(","); sqlParams.Append(EntityInfo.DBInfo.CurrentDbAdapter.FormatParam(info.ParamName)); sqlValues.Append(","); sqlValues.Append(prm.ValueName); continue; } } else { BQLValueItem bvalue = null; if (setList != null && setList.TryGetValue(info.PropertyName, out bvalue)) { sqlParams.Append(","); sqlParams.Append(EntityInfo.DBInfo.CurrentDbAdapter.FormatParam(info.ParamName)); sqlValues.Append(","); sqlValues.Append(bvalue.DisplayValue(keyinfo)); continue; } else if (curValue == null) { continue; } else { DBParameter prmValue = list.NewParameter(info.SqlType, curValue, EntityInfo.DBInfo); sqlParams.Append(","); sqlParams.Append(EntityInfo.DBInfo.CurrentDbAdapter.FormatParam(info.ParamName)); sqlValues.Append(","); sqlValues.Append(prmValue.ValueName); } } } if (sqlParams.Length > 0) { sqlParams.Remove(0, 1); } else { return(0); } if (sqlValues.Length > 0) { sqlValues.Remove(0, 1); } else { return(0); } InsertCondition con = new InsertCondition(EntityInfo.DBInfo); con.Tables.Append(EntityInfo.DBInfo.CurrentDbAdapter.FormatTableName(EntityInfo.TableName)); con.SqlParams.Append(sqlParams.ToString()); con.SqlValues.Append(sqlValues.ToString()); int ret = -1; con.DbParamList = list; using (BatchAction ba = _oper.StarBatchAction()) { string sql = con.GetSql(true); Dictionary <string, bool> cacheTables = null; cacheTables = _oper.DBInfo.QueryCache.CreateMap(EntityInfo.TableName); ret = ExecuteCommand(sql, list, CommandType.Text, cacheTables); if (identityInfo.Count > 0 && fillIdentity) { foreach (EntityPropertyInfo pkInfo in identityInfo) { sql = EntityInfo.DBInfo.CurrentDbAdapter.GetIdentitySQL(pkInfo); using (IDataReader reader = _oper.Query(sql, new ParamList(), null)) { if (reader.Read()) { if (!reader.IsDBNull(0)) { EntityInfo.DBInfo.CurrentDbAdapter.SetObjectValueFromReader(reader, 0, obj, pkInfo, !pkInfo.TypeEqual(reader, 0)); //obj.PrimaryKeyChange(); ret = 1; } } } } } } return(ret); }