Пример #1
0
        public string GetInsertSqliteSql(SqliteEntity obj)
        {
            StringBuilder sbInsert = new StringBuilder();

            sbInsert.Append("INSERT INTO ");
            sbInsert.Append(ClassAttribute.TableName);
            sbInsert.Append(" (");
            for (int i = 0; i < ar.Count; i++)
            {
                if (!"id".Equals(this[i].PropertyAttribute.AttributeName.ToLower()) && string.IsNullOrEmpty(this[i].PropertyAttribute.DefaultValue))
                {
                    sbInsert.Append(this[i].PropertyAttribute.AttributeName);
                    if (i < ar.Count - 2)
                    {
                        sbInsert.Append(", ");
                    }
                }
            }
            sbInsert.Append(" )VALUES( ");
            for (int i = 0; i < ar.Count; i++)
            {
                if (!"id".Equals(this[i].PropertyAttribute.AttributeName.ToLower()) && string.IsNullOrEmpty(this[i].PropertyAttribute.DefaultValue))
                {
                    sbInsert.Append(this[i].GetValue(obj));
                    if (i < ar.Count - 2)
                    {
                        sbInsert.Append(",");
                    }
                }
            }
            sbInsert.Append(")");
            return(sbInsert.ToString());
        }
Пример #2
0
 /// <summary>
 /// 添加数据对象
 /// </summary>
 /// <param name="entity"></param>
 public void Add(SqliteEntity entity)
 {
     try
     {
         if (_queueGroupList == null || _queueGroupList.Count < 1)
         {
             throw new ApplicationException("无法添加数据,队列未正确初始化");
         }
         Type   type      = entity.GetType();
         string tableName = Class2DbHelper.Instance[type].ClassAttribute.TableName;
         if (!_typeDic.ContainsKey(tableName))
         {
             _typeDic[tableName] = type;
         }
         int queueIndex = _entityIndex % _queueGroupList.Count;
         if (!_queueGroupList[queueIndex].QueueDic.ContainsKey(type))
         {
             _queueGroupList[queueIndex].QueueDic[type] = new Queue();
         }
         _queueGroupList[queueIndex].QueueDic[type].Enqueue(entity);
         _entityIndex++;
         if (_entityIndex == _queueGroupList.Count)
         {
             _entityIndex = 0;
         }
     }
     catch (Exception ex)
     {
         Logger.WriteErrorFmt(Log.AddEntity, "Sqlite添加数据对象时出现异常,异常信息:{0}", ex);
     }
 }
Пример #3
0
        public string GetWhereConditionSql(SqliteEntity obj)
        {
            string strWhere = "";

            for (int i = 0; i < ar.Count; i++)
            {
                if (this[i].PropertyAttribute.IsKey || this[i].PropertyInfo.Name == "UpdateTime")
                {
                    if (strWhere != "")
                    {
                        strWhere += " AND ";
                    }
                    strWhere += this[i].PropertyAttribute.AttributeName;
                    strWhere += " = ";
                    strWhere += this[i].GetValue(obj);
                }
            }
            return(strWhere);
        }
Пример #4
0
        public string GetValue(SqliteEntity obj)
        {
            object val        = this.PropertyInfo.GetValue(obj, null);
            string fieldValue = "";

            if (val != null)
            {
                switch (PropertyAttribute.DataType)
                {
                case DataType.Date:
                    fieldValue = "'" + ((DateTime)val).ToString("s") + "'";
                    break;

                case DataType.Interger:
                    if (val is bool)
                    {
                        fieldValue = ((bool)val) ? "1" : "0";
                    }
                    else
                    {
                        fieldValue = val.ToString();
                    }
                    break;

                case DataType.Varchar2:
                    fieldValue = "'" + DB.ReplaceInvalidSQL(val.ToString()) + "'";
                    //fieldValue = DB.DBManager.FormatEscapeChar(fieldValue);
                    break;

                case DataType.Boolean:
                    fieldValue = ((bool)val) ? "1" : "0";
                    break;

                case DataType.LongString:
                    fieldValue = DB.ReplaceInvalidSQL(val.ToString());
                    break;

                case DataType.Enum:
                    fieldValue = ((int)val).ToString();
                    break;

                case DataType.XmlObject:
                    fieldValue = "'" + DB.ReplaceInvalidSQL(XmlObjectConvertor.GetXml(val)) + "'";
                    fieldValue = DB.DBManager.FormatEscapeChar(fieldValue);
                    break;

                case DataType.Double:
                    fieldValue = ((double)val).ToString();
                    break;

                case DataType.Byte:
                    fieldValue = val.ToString();
                    break;

                case DataType.Long:
                    fieldValue = ((long)val).ToString();
                    break;

                case DataType.Decimal:
                    fieldValue = ((decimal)val).ToString();
                    break;

                default:
                    fieldValue = "";
                    break;
                }
            }
            else
            {
                fieldValue = "NULL";
            }
            return(fieldValue);
        }