逆向而行—ASP的O/R MAPPING
您看的没错,是ASP not ASP.Net 我也没有发疯,我的目标就是实现一个简单的ASP环境下的O/R MAPPING,用Visual Basic 6.0来实现.当然,由于Visual Basic毕竟不如C#,VB.net哪么强大,甚至它是否真正的面向对象也存在争论。所以 实现起来还是有一定的难度。
我想和我一样,很多ASP的程序员,也饱受SQL语句之苦。特别是一些表单特别多的程序, 不断的做着重复的工作,就是 画表单,写SQL,然后插入,更新,删除,套用一句流行话语“我最烦这些SQL语句,一点技术含量都没有”。如果 表的字段一多的话,哪简直就是写的昏天暗地。写好了还不一定对,调试SQL又是一个艰苦的工作。特别容易出错,不小心少了个’号什么的,有时候找都找不出来。可是ASP程序员做得最多的就是这些。重复做除了字段不一样,其它都一样的工作。
当我接触了一些 .Net 和 Java的O/R Mapping以后,最让我激动的不是其强大的功能,支持事务等等一些优秀功能,而是,终于不用在写SQL了,爽啊,真得想就此放弃了ASP投入.Net的怀抱,但是没有办法, 现在还有很多项目 ,需要用ASP来实现,也还有很多同胞挣扎在ASP中。所以 要是有一个ASP下的的O/R Mapping工具改是多么美妙啊, 但是翻遍了互联网也没有找到,所以才出此下策,不如自己写一个试试。
一开始目标,我也不想强求我的ASP O/R Mapping有多么强大,所以在设计的时候,组件就提供了 add update delete三个方法,至少,insert ,update,delete语句不用写sql了,呵呵。实体文件我用vbscript的类来实现,例如:
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
关于实体文件没有什么过多可以解释的,反正 和数据库里的各个字段对映就可以了,而且vbscript不是强类型的语言,都不用指定数据类型。
接下来就是 映射文件了,当来xml文件是首选
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
这里的设计想法是
<table>中是一个表的字段描述
Id name article addtime 都是字段名,
Type 指定 该数据类型是文本,还是数字型的,这个的作用其实很简单,就是在生成sql的时候判断要不要加上单引号,本来打算是type是指定各个字段的数据类型的。但是后来一想没有一个毕要,哪样做反而麻烦,所以就简单至上了。
Iskey 属性是指定是否用关键字段。
还有一个就是配置文件了
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
整个的功能实现做成了AcitveX来实现,这是一个简单的类图,第一次画,有很多错误还请指出
到现在为此这里的功能基本完成,但是还有很多需要优化和加强的地方。Bug也很多。先放出我昨天晚上编译的版本,这个也只是用于调试的版本。放出来是让大家帮我试试,给我提点意见,让我能更好的完善他,还有如果有什么好的建议,新的功能。也可以提出来,我们一起来实现。
测试下载
http://www.chinasunflower.com/test.rar