SQL Artisan组件之编译检测
为了能够明确地进行数据库操作,组件提供了对应数据库表和字段的对象类型;不同的字段类型实现了不同运算的重载,因此当程序在编译过程中就会对组件相关的数据库操作对象进行编译检测;当你编写的字段对象不存在这 种运算或值类型比较时编译过程就会告诉你问题所在的地方。
比较类型检测
以上实际运行的SQL语句是:select * from Orders where OrderID >10300;
由于OrderID定义为整型字段因此不能和字符进行比较操作。
把字符修改成整数问题就解决了,同样对于In操作和其他操作也是一样。
除了比较测外,组件对数据插入和修改时所设置的值也会进行检测操作。
语法错误检测
虽然通过组件能够实现上面所说的功能,但前提是必须建立数据结构和程序映射关系类。以下是Orders表的映射结构:
public class Orders
{
public Orders()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private static HFSoft.Data.Expressions.Table mTBL= new HFSoft.Data.Expressions.Table("Orders");
public static HFSoft.Data.Expressions.Table TBL
{
get
{
return mTBL;
}
}
private static HFSoft.Data.Expressions.ObjectField mALL = new HFSoft.Data.Expressions.ObjectField("*");
public static HFSoft.Data.Expressions.ObjectField ALL
{
get
{
return mALL;
}
}
private static HFSoft.Data.Expressions.IntField mOrderID = new HFSoft.Data.Expressions.IntField("OrderID");
public static HFSoft.Data.Expressions.IntField OrderID
{
get
{
return mOrderID;
}
}
private static HFSoft.Data.Expressions.StringField mCustomerID = new HFSoft.Data.Expressions.StringField("CustomerID");
public static HFSoft.Data.Expressions.StringField CustomerID
{
get
{
return mCustomerID;
}
}
private static HFSoft.Data.Expressions.IntField mEmployeeID = new HFSoft.Data.Expressions.IntField("EmployeeID");
public static HFSoft.Data.Expressions.IntField EmployeeID
{
get
{
return mEmployeeID;
}
}
private static HFSoft.Data.Expressions.DateTimeField mOrderDate = new HFSoft.Data.Expressions.DateTimeField("OrderDate");
public static HFSoft.Data.Expressions.DateTimeField OrderDate
{
get
{
return mOrderDate;
}
}
private static HFSoft.Data.Expressions.DateTimeField mRequiredDate = new HFSoft.Data.Expressions.DateTimeField("RequiredDate");
public static HFSoft.Data.Expressions.DateTimeField RequiredDate
{
get
{
return mRequiredDate;
}
}
private static HFSoft.Data.Expressions.DateTimeField mShippedDate = new HFSoft.Data.Expressions.DateTimeField("ShippedDate");
public static HFSoft.Data.Expressions.DateTimeField ShippedDate
{
get
{
return mShippedDate;
}
}
private static HFSoft.Data.Expressions.IntField mShipVia = new HFSoft.Data.Expressions.IntField("ShipVia");
public static HFSoft.Data.Expressions.IntField ShipVia
{
get
{
return mShipVia;
}
}
private static HFSoft.Data.Expressions.DecimalField mFreight = new HFSoft.Data.Expressions.DecimalField("Freight");
public static HFSoft.Data.Expressions.DecimalField Freight
{
get
{
return mFreight;
}
}
private static HFSoft.Data.Expressions.StringField mShipName = new HFSoft.Data.Expressions.StringField("ShipName");
public static HFSoft.Data.Expressions.StringField ShipName
{
get
{
return mShipName;
}
}
private static HFSoft.Data.Expressions.StringField mShipAddress = new HFSoft.Data.Expressions.StringField("ShipAddress");
public static HFSoft.Data.Expressions.StringField ShipAddress
{
get
{
return mShipAddress;
}
}
private static HFSoft.Data.Expressions.StringField mShipCity = new HFSoft.Data.Expressions.StringField("ShipCity");
public static HFSoft.Data.Expressions.StringField ShipCity
{
get
{
return mShipCity;
}
}
private static HFSoft.Data.Expressions.StringField mShipRegion = new HFSoft.Data.Expressions.StringField("ShipRegion");
public static HFSoft.Data.Expressions.StringField ShipRegion
{
get
{
return mShipRegion;
}
}
private static HFSoft.Data.Expressions.StringField mShipPostalCode = new HFSoft.Data.Expressions.StringField("ShipPostalCode");
public static HFSoft.Data.Expressions.StringField ShipPostalCode
{
get
{
return mShipPostalCode;
}
}
private static HFSoft.Data.Expressions.StringField mShipCountry = new HFSoft.Data.Expressions.StringField("ShipCountry");
public static HFSoft.Data.Expressions.StringField ShipCountry
{
get
{
return mShipCountry;
}
}
}
SQL Artisan组件还在完善当中,在这里希望有兴趣的朋友多提意见。在此先多谢双鱼座兄的建议。