表达式类的设计

所有的表达式对象都具有接口:IExpression

IExpression接口的定义:

    Public Interface IExpression
        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' 返回条件语句字符串
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        '''  [zqonline] 2006-06-06 Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Function Expression() As String
        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' 返回条件语句所对应的Command参数列表
        ''' </summary>
        ''' <value></value>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        '''  [zqonline] 2006-06-06 Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        ReadOnly Property Parameters() As DBAccessLayer.Parameters

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' 设置此条件类所对应的数据源
        ''' </summary>
        ''' <value></value>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        '''  [zqonline] 2006-06-06 Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Property DataBaseType() As DBAccessLayer.DataBaseTypeEnum

    End Interface

    表达式类(也就是代码sql语句的一个条件)
    当前系统有:
    CustomExpression自定条件语句执行比较复杂的条件,如:select 1 from table1 where table1.id=table2.id
    FieldExpression字段与字段的条件,如:select * from table1 as a,table2 as b where a.id=b.id
    ValueExpression 字段与值的条件,如:select * from table where id=2
     FunExpression 实现在函数的条件,如:select * from table where left(name,2)='zq'    or  select * from table1 as a,table2 as b where left(a.name,2)=left(b.name,2)
    命名空间: Expression.Fun定义了常用的sql函数类如:sum,count,avg,left,right,substring,replace,year,month,day它们都需要实现其接口:ISQLFunction

    Public Interface ISQLFunction
        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' 返回函数对应的语句
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        '''  [zqonline] 2006-06-06 Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Function FunctionDefine() As String

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' 返回或设置数据源类型
        ''' </summary>
        ''' <value></value>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        '''  [zqonline] 2006-06-06 Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Property DataBaseType() As DBAccessLayer.DataBaseTypeEnum
    End Interface

这样对于系统没有实现的函数,以后可以扩展。
 

ExpressionGroup类是一个特殊的表达式类,也实现了接口IExpression。具有两个方法一个是Add(byval ie as IExpression),另一个是AddGroup(byval ie as IExpression)
ADD添加一个表达式到ExpressionGroup中,语句示例:where a.name=b.name and a.id>b.id
AddGroup添加一个表达式到ExpressionGroup中,并打上括号,可以实现这样的语句,语句示例:where a.name=b.name and (a.id>b.id or a.age>b.age)
由于ExpressionGroup对象也实现了接口IExpression.所以也可以添加ExpressionGroup
  
嗯,今天就完成了这部份的设计
     

原文地址:https://www.cnblogs.com/zqonline/p/419024.html