缺省SQL Generation的快速帮助

缺省SQLGeneration的快速帮助

EDT 0.7.0版本为基于EGL的行为语句产生缺省的SQL语句提供了快速帮助:

  • ADD 语句

  • DELETE语句

  • GET语句

  • OPEN语句

  • REPLACE语句

下面用样例来说明如何在EDT中使用这种功能:


EGL 记录定义

recordProduct{@Table {name="Product"}}
    	id bigint{@Id};
	name string;
	price float;
end


上面定义了一个基本记录类型,必须使用注释@Id来指定记录的那个字段映射为表的主键,使用注释@Table来说明这个记录映射为那个表,就像上面的定义那样,不过@Table的使用是可选的。

record OrderItem type Entity{@table{name = "OrderItem"}}
        ITEM_ID int{@Id};
        NAME string{ @Column { insertable=true } };
        IMAGE string?{ @Column { updateable=true } };
        PRICE decimal(7, 2)?;
        DESCRIPTION string?;
end

上面是对应一个表的 entity 记录定义。


EGL变量定义

   basicRec Product;
   itemEntity OrderItem;
   rs SQLResultSet?; 
   ds SQLDataSource? = new      SQLDataSource("jdbc:derby:C:/databases/EGLDerbyR7;create=true");  

ADD语句

    在EGL语句的任何地方点击并按Ctrl+1,选择“AddSQL Statement建议,缺省的SQL语句将添加到已有的EGL语句中:


add basicRec to ds; //for basic record
变成:

add basicRec to ds with
			#sql{
				insert into Product
					(id, name, price)
				values
					(?, ?, ?)
			};

add itemEntity to ds; //for entity record
变成:

add itemEntity to ds with
			#sql{
				insert into OrderItem
					(ITEM_ID, Name, IMAGE, price, description)
				values
					(?, ?, ?, ?, ?)
			};


DELETE语句

delete basicRec from ds; // for basic record
变成:
delete basicRec from ds with
			#sql{
				delete from Product
				where
				    id = ?
			};

delete itemEntity from ds; //for entity record
变成:
delete itemEntity from ds with
			#sql{
				delete from OrderItem
				where
					ITEM_ID = ?
			};

GET语句

GET basicRec from ds; //for basic record
变成:
 GET basicRec from ds using basicRec.id with
			#sql{
				select
					id, rtrim(name), price
				from  Product
				where
					id = ?
			};

GET itemEntity from ds; //for entity record
变成:
GET itemEntity from ds using itemEntity.ITEM_ID  with
		#sql{
		   select
			ITEM_ID, rtrim(Name), rtrim(IMAGE), price, rtrim(description)
		   from OrderItem
		   where
			ITEM_ID = ?
		};


OPEN语句

rows OrderItem; open rs from ds for rows; 
变成:
open rs from ds using rows.ITEM_ID  with
			#sql{
				select
					ITEM_ID, rtrim(Name), rtrim(IMAGE), price, 
					rtrim(description)
				from OrderItem
				where
					ITEM_ID =  ?
			};

REPLACE语句

replace itemEntity to ds ;
变成:
replace itemEntity to ds with
			#sql{
				update OrderItem
				set
					Name = ?,
					IMAGE = ?,
					price = ?,
					description = ?
				where
					ITEM_ID = ?
			} ;











  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值