自定义实体的代码自动生成
来源:互联网 发布:mac自带压缩软件 编辑:程序博客网 时间:2024/04/29 07:36
if(object_id('generatecode')) is not null drop proc generatecode
go
CREATE proc generatecode
@table varchar(50)
as
declare @sqlstr varchar(2000)
create table #tmp
(
column_name varchar(20),
type_name varchar(20),
length varchar(10)
)
create table #text(n_text varchar(1000))
select @sqlstr ='
insert into #tmp (column_name,type_name,length) select name,type_name,a.prec
from syscolumns a ,master.dbo.spt_datatype_info b
where id = object_id(N'''+@table+''')
and OBJECTPROPERTY(id, N''IsUserTable'') =1
and a.xtype=b.ss_dtype
and a.length = isnull(b.fixlen, a.length)
AND isnull(b.AUTO_INCREMENT,0) = isnull(ColumnProperty (a.id, a.name, ''IsIdentity''),0)
AND (b.ODBCVer is null or b.ODBCVer = 2)
'
execute(@sqlstr)
declare @name varchar(20)
declare @type varchar(20)
declare cur cursor scroll for select column_name,type_name from #tmp
open cur
fetch next from cur into @name,@type
while @@fetch_status = 0
begin
insert into #text values('private '+ case when @type='varchar' or @type='nvarchar' or @type='char' or @type='text' or @type='ntext' then 'String ' + @name + ';'
when @type='int' or @type='int identity' then 'int ' + @name + ';'
when @type='datetime' or @type='smalldatetime' then 'DateTime ' + @name + ';'
when @type='bit' then 'bool ' + @name + ';'
when @type='decimal' or @type='numeric' or @type='money' or @type='smallmoney' then 'decimal ' + @name + ';'
when @type='float' then 'double ' + @name + ';'
when @type='binary' or @type='image' or @type='varbinary' or @type='timestamp' then 'byte[] ' + @name + ';'
when @type='real' then 'single ' + @name + ';'
end
)
fetch next from cur into @name,@type
end
fetch absolute 1 from cur into @name,@type
while @@fetch_status = 0
begin
insert into #text values('public '+ case when @type='varchar' or @type='nvarchar' or @type='char' or @type='text' or @type='ntext' then 'String ' + upper(@name)
when @type='int' or @type='int identity' then 'int ' + upper(@name)
when @type='datetime' or @type='smalldatetime' then 'DateTime ' + upper(@name)
when @type='bit' then 'bool ' + upper(@name)
when @type='decimal' or @type='numeric' or @type='money' or @type='smallmoney' then 'decimal ' + @name
when @type='float' then 'double ' + @name
when @type='binary' or @type='image' or @type='varbinary' or @type='timestamp' then 'byte[] ' + @name
when @type='real' then 'single ' + @name
end
)
insert into #text values('{')
insert into #text values('get{return this.' + @name + ';}')
insert into #text values('set{this.' + @name + ' = value;}')
insert into #text values('}')
fetch next from cur into @name,@type
end
close cur
deallocate cur
select * from #text
drop table #tmp
drop table #text
GO
exec generatecode 'userinfo'
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1181548
[点击此处收藏本文] guoguo19811025发表于 2006年09月05日 21:17:00
emo 发表于2006-09-06 11:53:00 IP: 61.29.197.*
恩,有个小错误,@type='numberic' ,应该是numeric吧?
vfp_system 发表于2006-09-06 22:58:00 IP: 58.20.32.*
不错,省了我好多事啦。生成的代码只要小小改动即可用。
蝈蝈 发表于2006-09-07 08:12:00 IP: 221.6.19.*
感谢emo帮我指出错误,即刻更改,谢谢!
- 自定义实体的代码自动生成
- 自定义实体的代码自动生成
- CodeSmith自动生成业务实体类的模板代码
- 自动生成MVC中的model实体类的核心代码
- 实体标识的自动生成
- Models--自动生成实体层代码
- MyBatis Generator自动生成实体代码
- 自动生成实体,Dao层代码
- MyBatis-Generator自动生成实体代码
- codesmith 自动生成实体类的模板
- JPA实体标识的自动生成
- JPA实体标识的自动生成
- JPA实体标识的自动生成
- 自动生成实体类的网站
- 利用动软代码生成器 自动生成LINQ需要用的数据实体类
- Maven插件之mybatis-generator(mybatis自动生成实体代码的插件)
- Maven插件之mybatis-generator(mybatis自动生成实体代码的插件)
- MyBatis自动生成实体类、DAO接口和Mapping映射文件的代码(逆向工程)
- COM 原理与应用
- Hide IP Platinum 3.0 (latest version)
- DLL注入
- 串口通讯
- Windows Media Player 11.0.5358 & Useful Codecs - All-In-One
- 自定义实体的代码自动生成
- 斗争与妥协
- spirntf,你知道多少?
- 外匯市場心理行為分析
- JSP1.0/JSP2.0
- 大家给点办公自动化软件推广意见,谢谢
- 美元與石油
- Microsoft Office 2003 All-in-one, by Joe Habraken
- invokeNative_i386.S的分析小记