关于SQL语句的自动生成!(四)

25 篇文章 0 订阅
11 篇文章 0 订阅

作者PeterXu  来源:Blog.CSDN  Blog: http://blog.csdn.net/peterreg/
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。
本文地址:http://blog.csdn.net/peterreg/archive/2008/04/02/2243130.aspx

接我的上一篇文章《关于SQL语句的自动生成!(三)》,各派生类的具体实现

       private   class  Insert : BaseClause
        
{
            
private string m_strName;
            
private string m_strValue;

            
public override void Add(string name, object val)
            
{
                
if (val == null)
                
{
                    
this.Add(name, "null"false);
                }

                
else
                
{
                    
this.Add(name, val.ToString(), val is string || val is DateTime);
                }

            }


            
private void Add(string name, string val, bool isref)
            
{
                
if (isref)
                
{
                    val 
= "'" + val + "'";
                }

                
if (this.m_strName == string.Empty)
                
{
                    
this.m_strName = "[" + name + "]";
                    
this.m_strValue = val;
                }

                
else
                
{
                    
this.m_strName += ",[" + name + "]";
                    
this.m_strValue += "," + val;
                }

            }


            
protected override string ToStr
            
{
                
get return "INSERT INTO [" + base.TableName + "] ( " + this.m_strName + " ) values ( " + this.m_strValue + " )"; }
            }


            
protected override void auxClear()
            
{
                
this.m_strValue = string.Empty;
                
this.m_strName = string.Empty;
            }

        }


        
private   class  Delete : BaseClause
        
{
            
public Delete()
            
{
            }


            
protected override string ToStr
            
{
                
get return "DELETE FROM [" + base.TableName + "]"; }
            }

        }


        
private   class  Update : BaseClause
        
{
            
private string m_strUpdate;

            
public override void Add(string name, object val)
            
{
                
if (val == null)
                
{
                    
this.Add(name, "null"false);
                }

                
else
                
{
                    
this.Add(name, val.ToString(), val is string || val is DateTime);
                }

            }


            
private void Add(string name, string val, bool isref)
            
{
                
if (isref)
                
{
                    val 
= "'" + val + "'";
                }

                
if (this.m_strUpdate == string.Empty)
                
{
                    
this.m_strUpdate = "[" + name + "]=" + val;
                }

                
else
                
{
                    
this.m_strUpdate += ",[" + name + "]=" + val;
                }

            }


            
protected override string ToStr
            
{
                
get return "UPDATE [" + base.TableName + "] SET " + this.m_strUpdate; }
            }


            
protected override void auxClear()
            
{
                
this.m_strUpdate = string.Empty;
            }

        }


        
private   class  Select : BaseClause
        
{
            
private string m_strSelect;

            
public override void Add(string name, object alis)
            
{
                
if (alis == null)
                
{
                    
this.Add(name, name, false);
                }

                
else
                
{
                    
this.Add(name, alis.ToString(), false);
                }

            }


            
private void Add(string name, string alis, bool isref)
            
{
                
if (this.m_strSelect == string.Empty)
                
{
                    
this.m_strSelect = "[" + name + "] as [" + alis + "]";
                }

                
else
                
{
                    
this.m_strSelect += ",[" + name + "] as [" + alis + "]";
                }

            }


            
protected override string ToStr
            
{
                
get
                
{
                    
if (this.m_strSelect == string.Empty)
                    
{
                        
this.m_strSelect = "*";
                    }

                    
return "SELECT " + this.m_strSelect + " FROM [" + base.TableName + "]";
                }

            }


            
protected override void auxClear()
            
{
                
this.m_strSelect = string.Empty;
            }

        }


        
private   class  Where
        
{
            
private string m_strWhere;

            
public Where()
            
{
                
this.Clear();
            }


            
public void Add(string name, object val)
            
{
                
if (val == null)
                
{
                    
this.Add(name, "null"false);
                }

                
else
                
{
                    
this.Add(name, val.ToString(), val is string || val is DateTime);
                }

            }


            
private void Add(string name, string val, bool isref)
            
{
                
if (isref)
                
{
                    val 
= "'" + val + "'";
                }

                
if (this.m_strWhere == string.Empty)
                
{
                    
this.m_strWhere = "[" + name + "]=" + val;
                }

                
else
                
{
                    
this.m_strWhere += " and [" + name + "]=" + val;
                }

            }


            
public override string ToString()
            
{
                
string strRet = string.Empty;
                
if (this.m_strWhere != string.Empty)
                
{
                    strRet 
= " Where " + this.m_strWhere;
                }

                
return strRet;
            }


            
public void Clear()
            
{
                
this.m_strWhere = string.Empty;
            }

        }

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值