示例#1
0
        public static string GetOrderSql(ArrayList orderList, ClassMap cm)
        {
            AttributeMap am;
            OrderEntry   order;
            string       orderString = "";

            for (int i = 0; i < orderList.Count; i++)
            {
                order = (OrderEntry)orderList[i];
                am    = cm.GetAttributeMap(order.AttributeName);
                //如果是升序
                if (order.IsAscend)
                {
                    orderString += cm.GetFullyQualifiedName(am.Column.Name) + " ASC,";
                }
                else
                {
                    orderString += cm.GetFullyQualifiedName(am.Column.Name) + " DESC,";
                }
            }
            orderString = orderString.Substring(0, orderString.Length - 1);
            return(" ORDER BY " + orderString);
        }
示例#2
0
文件: Query.cs 项目: gangqiang/xihuan
        /// <summary>
        ///		等值连接一个Query类对象
        /// </summary>
        /// <param name="fromAttribute"></param>
        /// <param name="q"></param>
        /// <param name="toAttribute"></param>
        public void AddJoinQuery(string fromAttribute, Query q, string toAttribute)
        {
            this.AddQueryIn(q);

            q.m_FatherQuery = this;

            ClassMap     cm     = q.QueryClassMap;
            AttributeMap amFrom = this.queryClass.GetAttributeMap(fromAttribute, false);
            AttributeMap amTo   = cm.GetAttributeMap(toAttribute, false);

            this.m_Querys.AddRange(q.Querys);

            this.whereClause += " AND " + queryClass.GetFullyQualifiedName(amFrom.Column.Name) + "="
                                + cm.GetFullyQualifiedName(amTo.Column.Name);
        }
示例#3
0
        public string AsSqlClause()
        {
            string s;
            string columnName = clsMap.GetFullyQualifiedName(this._atrribute.Column.Name);

            s = columnName;
            switch (type)
            {
            case SelectionTypes.EqualTo:
                //tintown 添加的用于Null值处理
                if (attrValue == System.DBNull.Value)
                {
                    s += " is null";
                }
                else
                {
                    s += "=";
                }
                break;

            case SelectionTypes.GreaterThan:
                s += ">";
                break;

            case SelectionTypes.GreaterThanAndEqualTo:
                s += ">=";
                break;

            case SelectionTypes.NotEqualTo:
                if (attrValue == System.DBNull.Value)
                {
                    s += " is not null";
                }
                else
                {
                    s += "<>";
                }
                break;

            case SelectionTypes.LessThan:
                s += "<";
                break;

            case SelectionTypes.LessThanAndEqualTo:
                s += "<=";
                break;

            case SelectionTypes.Match:
            case SelectionTypes.MatchSuffix:
            case SelectionTypes.MatchPrefix:
                s += " LIKE ";
                break;

            case SelectionTypes.NotMatch:
            case SelectionTypes.NotMatchPrefix:
            case SelectionTypes.NotMatchSuffix:
                s += " NOT LIKE ";
                break;

//				case SelectionTypes.MatchPrefix:
//					s += " LIKE ";
//					break;
//				case SelectionTypes.NotMatchPrefix:
//					s += " NOT LIKE ";
//					break;
            case SelectionTypes.In:
                s += " IN (";
                object[] list = (object[])this.attrValue;
                s += this.StringOfInCrtieria(list) + ")";
                return(s);

            case SelectionTypes.NotIn:
                s += " NOT IN (";
                object[] list1 = (object[])this.attrValue;
                s += this.StringOfInCrtieria(list1) + ")";
                return(s);

            default:
                s += "";
                break;
            }
            //add by tintown
            if (this._isFieldToField)            //如果是字段与字段比较
            {
                s = s + clsMap.GetFullyQualifiedName(this._attribute2.Column.Name);
            }
            else             //接正常的方式进行
            {
                if (attrValue != System.DBNull.Value)
                {
                    switch (_atrribute.SqlValueStringType)
                    {
                    case SqlValueTypes.PrototypeString:
                        if (type == SelectionTypes.Match || type == SelectionTypes.MatchPrefix)
                        {
                            s = s + "'" + attrValue.ToString() + "'";
                        }
                        else
                        {
                            s = s + attrValue.ToString();
                        }

                        break;

                    case SqlValueTypes.SimpleQuotesString:
                        s = s + "'" + attrValue.ToString() + "'";
                        break;

                    case SqlValueTypes.String:
                        s = s + "'" + attrValue.ToString().Replace("'", "''") + "'";
                        break;

                    case SqlValueTypes.BoolToInterger:
                    case SqlValueTypes.BoolToString:
                        s = s + "'" + Convert.ToInt32(attrValue).ToString() + "'";
                        break;

                    case SqlValueTypes.AccessDateString:
                        s = s + "#" + attrValue.ToString().Replace("'", "''") + "#";
                        break;

                    case SqlValueTypes.OracleDate:
                        s = s + "to_date('" + attrValue.ToString().Replace("'", "''") + "','yyyy-mm-dd hh24:mi:ss')";
                        break;

                    case SqlValueTypes.NotSupport:
                        string err = "不支持用属性" + this._atrribute.Name + "的数据类型来建立搜索条件!";
                        throw new PlException(err, ErrorTypes.PesistentError);

                    default:
                        break;
                    }
                }
            }
            return(s);
        }
示例#4
0
文件: Query.cs 项目: gangqiang/xihuan
        /// <summary>
        ///增加一个属性,并以属性名作为返回DataTable的列名
        /// </summary>
        /// <param name="attributeName"></param>
        public void AddAttribute(string attributeName)
        {
            AttributeMap am = this.queryClass.GetAttributeMap(attributeName, true);

            selectClause += "," + queryClass.GetFullyQualifiedName(am.Column.Name) + sTemp + am.Name + endQuostationMarks;
        }
示例#5
0
        private AttributeMap GetAttributeMap(XmlReader reader, ClassMap clsMap, TableMap tblMap, int colIndex)
        {
            string attrName      = reader.GetAttribute("name");                         //类属性名
            string attrColumn    = reader.GetAttribute("column");                       //属性对应列名
            string attrKey       = reader.GetAttribute("key");                          //键类型
            string attrReference = reader.GetAttribute("reference");                    //引用父类属性
            string dataType      = reader.GetAttribute("type");                         //数据类型
            string autoIncrement = reader.GetAttribute("increment");                    //是否自动增加
            string timestamp     = reader.GetAttribute("timestamp");                    //时间戳
            string autoValue     = reader.GetAttribute("auto");                         //是否自动值

            AttributeMap attrMap = null;

            if (attrName != null)
            {
                ColumnMap colMap = null;
                //生成一个AttributeMap
                attrMap = new AttributeMap(attrName);
                if (attrColumn != null)
                {
                    colMap = new ColumnMap(attrColumn, tblMap);

                    if (attrKey != null)
                    {
                        //设置键类型
                        if (attrKey.ToUpper() == "PRIMARY")
                        {
                            colMap.KeyType = ColumnKeyTypes.PrimaryKey;
                        }
                        else if (attrKey.ToUpper() == "FOREIGN")
                        {
                            colMap.KeyType = ColumnKeyTypes.ForeignKey;
                        }
                    }
                    if (dataType == null)
                    {
                        string s = "不能确定列" + clsMap.GetFullyQualifiedName(colMap.Name) + "的数据类型!";
                        throw new PlException(s, ErrorTypes.XmlError);
                    }
                    //确定数据列的数据类型
                    //Xml中所有数据类型为OleDbType中的枚举类型
                    //将其映射到 DbType
                    switch (dataType.ToLower())
                    {
                    case "boolean":
                        colMap.Type = DbType.Boolean;
                        attrMap.SqlValueStringType = clsMap.RelationalDatabase.SqlValueType(DbType.Boolean);
                        break;

                    //Map to Int64
                    case "bigint":
                        colMap.Type = DbType.Int64;
                        break;

                    //Map to Binary
                    case "binary":
                        colMap.Type = DbType.Binary;
                        attrMap.SqlValueStringType = SqlValueTypes.NotSupport;
                        break;

                    //Map to Decimal
                    case "currency":
                        colMap.Type = DbType.Currency;
                        break;

                    //Map to DateTime
                    case "date":
                        //对Access的数据库做特殊处理
                        if (clsMap.RelationalDatabase.Vendor == MsAccess.VENDOR_NAME)
                        {
                            colMap.Type = DbType.Object;
                            attrMap.SqlValueStringType = SqlValueTypes.AccessDateString;
                        }
                        else if (clsMap.RelationalDatabase.Vendor == DatabaseVendor.Oracle)                              //如果是oracle的话,则会对日期使用to_date转换
                        {
                            colMap.Type = DbType.DateTime;
                            attrMap.SqlValueStringType = SqlValueTypes.OracleDate;
                        }
                        else
                        {
                            colMap.Type = DbType.DateTime;
                            attrMap.SqlValueStringType = SqlValueTypes.SimpleQuotesString;
                        }
                        break;

                    //Mapt to Date
                    case "dbdate":
                        colMap.Type = DbType.Date;
                        attrMap.SqlValueStringType = SqlValueTypes.SimpleQuotesString;
                        break;

                    //Map to Decimal
                    case "decimal":
                        colMap.Type = DbType.Decimal;
                        break;

                    //Map to Double
                    case "double":
                        colMap.Type = DbType.Double;
                        break;

                    //Map to Guid
                    case "guid":
                        colMap.Type = DbType.Guid;
                        attrMap.SqlValueStringType = SqlValueTypes.SimpleQuotesString;
                        break;

                    //Map to Object
                    case "object":
                        colMap.Type = DbType.Object;
                        attrMap.SqlValueStringType = SqlValueTypes.NotSupport;
                        break;

                    //Map to Single
                    case "single":
                        colMap.Type = DbType.Single;
                        break;

                    //Map to Int16
                    case "smallint":
                        colMap.Type = DbType.Int16;
                        break;

                    //Map to SBtype
                    case "tinyint":
                        colMap.Type = DbType.Byte;
                        break;

                    //Map to Int32
                    case "integer":
                        colMap.Type = DbType.Int32;
                        break;

                    //Map to String
                    case "varchar":
                    case "string":
                        colMap.Type = DbType.String;
                        attrMap.SqlValueStringType = SqlValueTypes.String;
                        break;


                    default:
                        throw new PlException("目前仍不支持的数据类型!", ErrorTypes.XmlError);
                    }
                    //该列不是自动增加
                    if (autoIncrement != null && autoIncrement.ToLower() == "true")
                    {
                        colMap.IsAutoValue           = true;
                        tblMap.AutoIdentityIndex     = colIndex;
                        clsMap.AutoIdentityAttribute = attrName;
                    }

                    //是不是timestamp
                    if (timestamp != null && timestamp.ToLower() == "true")
                    {
                        tblMap.TimestampColumn = attrColumn;
                        if (clsMap.RelationalDatabase.Vendor == DatabaseVendor.MySql)
                        {
                            tblMap.TimestampParameter = "?" + tblMap.TimestampColumn;
                        }
                        else
                        {
                            tblMap.TimestampParameter = "@" + tblMap.TimestampColumn;
                        }
                        //tblMap.TimestampParameter = "@" + tblMap.TimestampColumn ;
                        clsMap.TimestampAttribute = attrMap;
                        colMap.IsAutoValue        = true;
                    }

                    //是不是自动值
                    if (autoValue != null)
                    {
                        colMap.IsAutoValue = true;
                    }
                }                // end of if (column!=null)

                attrMap.Column = colMap;

                if ((attrReference != null) && (clsMap.SuperClass != null))
                {
                    //若该属性来自父类,则它的Reference属性指向父类的AttributeMap
                    AttributeMap r = clsMap.SuperClass.GetAttributeMap(attrReference, true);
                    if (r != null)
                    {
                        attrMap.Reference = r;
                    }
                }
            }
            return(attrMap);
        }