Example #1
0
        public string AsSql()
        {
            StringBuilder result = new StringBuilder();

            this.SetDBType();

            this.varPrefix = DBUtil.GetDBParamFlag(this.dbType);

            result.Append("select * from ");
            result.Append(this.GetTableName());
            result.Append(" where ");

            int size = this.KeyNames.Count;

            for (int i = 0; i < size; i++)
            {
                if (i != 0)
                {
                    result.Append(" and ");
                }

                result.Append(this.KeyNames[i]);
                result.Append("=");
                result.Append(varPrefix);
                result.Append(this.KeyNames[i]);
            }

            return(result.ToString());
        }
Example #2
0
        public string AsSql()
        {
            this.SetDBType();

            this.varPrefix = DBUtil.GetDBParamFlag(this.dbType);

            StringBuilder updateSQL = new StringBuilder();

            updateSQL.Append("update ").Append(this.GetTableName());

            int size = this.ParameterNames.Count;

            for (int i = 0; i < size; i++)
            {
                if (i == 0)
                {
                    updateSQL.Append(" set ");
                }
                else
                {
                    updateSQL.Append(", ");
                }
                updateSQL.Append(
                    this.ParameterNames[i]).Append("=").Append(this.varPrefix).Append(this.ParameterNames[i]);
            }

            size = this.KeyNames.Count;
            for (int i = 0; i < size; i++)
            {
                if (i != 0)
                {
                    updateSQL.Append(", ");
                }
                else
                {
                    updateSQL.Append(" where ");
                }

                updateSQL.Append(this.KeyNames[i]).Append("=").Append(this.varPrefix).Append(this.KeyNames[i]);
            }

            return(updateSQL.ToString());
        }
Example #3
0
        public string AsSql()
        {
            this.SetDBType();

            this.varPrefix = DBUtil.GetDBParamFlag(this.dbType);

            StringBuilder insertSQL = new StringBuilder();
            StringBuilder valueSQL  = new StringBuilder();

            insertSQL.Append("insert into ").Append(this.GetTableName()).Append("(");
            valueSQL.Append(")values(");


            int size = this.ParameterNames.Count;

            for (int i = 0; i < size; i++)
            {
                if (i != 0)
                {
                    insertSQL.Append(", ");
                    valueSQL.Append(", ");
                }

                insertSQL.Append(this.ParameterNames[i]);
                valueSQL.Append(varPrefix).Append(this.ParameterNames[i]);
            }

            size = this.KeyNames.Count;
            for (int i = 0; i < size; i++)
            {
                if (this.KeyValues[i] == null)
                {
                    continue;// skip null PK
                }

                hasPK = true;
                insertSQL.Append(", ").Append(this.KeyNames[i]);
                valueSQL.Append(", ").Append(varPrefix).Append(this.KeyNames[i]);
            }
            insertSQL.Append(valueSQL).Append(")");

            return(insertSQL.ToString());
        }
Example #4
0
        public void parse(object entity)
        {
            this.SetDBType();

            this.varPrefix = DBUtil.GetDBParamFlag(this.dbType);

            IDictionary <string, object> entityDict = entity as IDictionary <string, object>;

            output = new StringBuilder();

            if (entityDict == null || entityDict.Count == 0)
            {
                return;
            }
            output.Append(" where 1=1");

            this._entity = entity;


            //获得实体的属性集合
            ICollection <string> props = entityDict.Keys;

            this.ParameterNames  = new List <String>(props.Count);
            this.ParameterValues = new List <Object>(props.Count);

            foreach (string prop in props)
            {
                output.Append(" and ");

                string[] keyWithOper = prop.Split('$');
                string   colName     = keyWithOper[0];
                object   colValue    = entityDict[prop];

                if (null == colValue)
                {
                    continue;
                }

                string operatorName            = "=";
                ICollection <object> colValues = this.Conver2ObjectCollection(colValue);
                bool isArray = (colValues != null);// colValue is ICollection<object>;
                if (keyWithOper.Length == 1)
                {
                    operatorName = isArray ? "in" : "=";
                }
                else
                {
                    operatorName = keyWithOper[1];
                }


                if (isArray)
                {
                    if (colValues.Count != 0)
                    {
                        output.Append(colName).Append(" ").Append(operatorName).Append("(");

                        int i = 0;
                        foreach (object colValueI in colValues)
                        {
                            if (i != 0)
                            {
                                output.Append(", ");
                            }
                            string colNameI = colName + "_" + (i++);
                            output.Append(this.varPrefix).Append(colNameI);
                            this.ParameterNames.Add(colNameI);
                            this.ParameterValues.Add(colValueI);
                        }

                        output.Append(")");
                    }
                }
                else
                {
                    output.Append(colName).Append(operatorName);

                    output.Append(this.varPrefix).Append(colName);
                    this.ParameterNames.Add(colName);
                    this.ParameterValues.Add(colValue);
                }
            }
        }