![]() | CYQ.Data componentsCYQ.Data support multi-database application [Txt,Xml,Access, MSSQL, Oracle,SQLite,MySql], help easily and quickly to develop your project |
CYQ.Data 数据框架 版本发布 V3.5
Platform for dynamic |
|
|
| #TopicOwner |
前言: 继正式发布V3.0到现在,刷的一下又20天过去了,而框架随着“路过秋天版博客”的开发,始终没停下,一直在前进!!! 目前博客正在慢悠悠的开发着~~~最近花了很多时间看动漫去了,哈哈~~~~ 下面就整体介绍下V3.5的更新,及V3.0中没介绍的新语法内容。 本次版本升级内容大体说明: ![]() ![]() 1:修正access 日期时间的处理[之前值只有Date,无Time] 2:加强对所有执行语句where条件关键字过滤,加强了安全性 3:MAction 增加事务RollBack方法,MProc增加与MAction一致的事务方法 4:MDataTable:增加静态LoadFromJson方法,允许从json字符串还原成MDataTable 5:Xml名称空间下xml操作类细节语法处理,加强对异常的处理。 6:多数据库支持,自定语法介绍 以下对重点进行详细解析说明
一:外部输入where条件关键字处理说明
1:框架对所有的SQL执行语句对外部where条件进行了严格的关键字处理,直接从底层拒绝SQL注入 过滤的关键字: {"select","master","delete","drop","update","truncate","create","exists","insert","asc(","while","xp_cmdshell","add","declare","exec","ch","ch(","delay","waitfor","sleep"}; 而换之而来的,就是对外部where条件无法再使用类似以下的子查询,例如: MAction action=new MAction("Users"); int count=0; action.Select(1,10,“where ID in(select ID from xxx)”,out count); 由于select被过滤,所以查询结果将导致失败,同样对于其它关键字也同样。 解决方法? 可以使用自定义Table语法: MAction action=new MAction("(select * from Users where id in(select id from xxx)) v"); int count=0; action.Select(1,10,"",out count); 系统仅对自定义表进行基础过滤及多数据库支持转换,因此,外部条件带有有子查询及过滤关键字时,可考虑转成自定义表的形式。
示例: ![]() ![]() MAction action=new MAction(表名); int count=0; string json=action.Select(1,10,"",out count).ToJson();//转成json字符串 MDataTable table=MDataTable.LoadFromJson(json);//从json还原为MDataTable; List<实体> entityList=table.ToList<实体>();//从MDataTable转泛型实体列表。 三:多数据库支持的语法解析说明 说明:为了对同一条语句可以在多个数据库下执行,推了关键字函数解析说明 目前系统定义的关键字如下: ![]() ![]() public class DalValue//名称空间CYQ.Data.DAL { /// /// 对于Bit类型[是/否] 类型的排序 /// public const string Desc = "[#DESC]"; public const string Asc = "[#ASC]"; /// /// 对于Bit类型[是/否] 的条件值 /// public const string True = "[#TRUE]"; public const string False = "[#FALSE]"; public const string Len = "[#LEN]";//length public const string Substring = "[#SUBSTRING]";//substr public const string GetDate = "[#GETDATE]";//length public const string Year = "[#YEAR]";//length public const string Month = "[#MONTH]";//length public const string Day = "[#DAY]";//length public const string CharIndex = "[#CHARINDEX]"; public const string DateDiff = "[#DATEDIFF]"; } 关键字使用手法都是在原始函数上套上[#函数名],成为关键字替换,以下进行具体解析说明: 1:排序关键字:[#DESC]与[#ASC] 说明:这是由于Access/MSSQL/Oracle在对bit类型的处理方式不同,导致排序的问题。 access的bit类型为true与false,排序时会与mssql/oracel刚好相反 因此,采用(select * from xxx order by istop [#DESC]),系统内部会解析不同的数据库类型,进行正确的解析还原。 2:关键值替换:[#TRUE]与[#FALSE] 说明:还是由于Access对bit类型的处理方式不同引起的, access的bit类型在查询时为IsTop=true,成mssql与oracle为IsTop=1。 因此,采用(select * from xxx where istop=[#TRUE]),系统内部会解析不同的数据库类型,进行正确的解析还原。 3:标准函数替换 [#LEN]、[#SUBSTRING]、[#GETDATE]、[#YEAR]、[#MONTH]、[#DAY]、[#CHARINDEX] ![]() ![]() 说明:这个就是各个数据库使用的函数不同,需要进行不同的解析。 如在不同的数据库使用分别为:len(xx)与length(xx) 、sub(...)与substring(...)等名称区别 因此,采用(select * from xxx where [#LEN](body)>10),系统内部会解析不同的数据库类型,进行正确的解析还原。 特殊:对于CharIndex函数,对于不同的数据库顺序参数位置刚好又不同,这里采用mssql为标准,其它类型数据库会反转参数,Oracle会替换成instr。 简单说用法就是:[#CHARINDEX]('要找点什么','很长很长的文本,原始文本') 一切的用法还是和以前一样,只是函数名称加了[# ] 4:特殊的[#DATEDIFF] ![]() ![]() 说明:由于此函数差异较大,所以需要单独说明一下。 access与mssql存在使用区别,一是类型需要引号和不需要引号,二是参数表达有所不同。 同时,Oracle中不存在此函数,如果用到,请自行创建DateDiff函数/存储过程。 使用示例:select * from users where [#DATEDIFF]([#d],CreateTime,[#GETDATE])<3 说明: [#DATADIFF]和正常函数名称一样 [#d]在不同数据库下被解析成'd'或d,标准解析如下:[#yyyy], [#q], [#m], [#y],[#d],[#h],[#ww], [#n], [#s] 采用了access与oracle的共同参数表达式解析。 [#GETDATE]是不同数据库解析成now(),getdate(),sysdate 框架下载地址:CYQ.Data 数据框架 下载 后言: 路过秋天版博客 正是基于这样一种方式的语法替换,对多数据库特别语法进行替换,从而在切换数据库时,只需要替换数据库链接,而不用修改任何语句或代码。 目前博客的开发,正在开发新的首页中......相信很快会推出下一版本,敬请期待~~~ ![]() |
Post Comment
Bulletin
Article Search
Categories
- Platform for dynamic (20)
- Feedback (9)
- Guide (33)
- Principles (19)
- Project-Case (8)
- Business & Buy (2)
- Technology exchange (45)
New Article
- CYQ.Data Components Getting Started Guide [Part 5]-[MProc Execute Stored Procedures or SQL]
- CYQ.Data Components Getting Started Guide [Part 4]-[MAction Insert Delete Update]
- CYQ.Data Components Getting Started Guide [Part 3]-[MAction Get And Set Value]
- CYQ.Data Components Getting Started Guide [Part 2]-[MAction Data Query- Fill And Select]
- CYQ.Data Components Getting Started Guide [Part 1]
New Comment
- When some one searches for his necessary thing, therefore he/she wishes to be available that in detail, so that thing is maintained over here.
- This is my first time pay a quick visit at here and i am in fact happy to read everthing at alone place.
- I truly appreciate this blog article.Really thank you! Cool.
- please pay a visit to the web sites we follow, like this one particular, as it represents our picks in the web
- Really enjoyed this post.Really thank you!
- Really enjoyed this article.Really looking forward to read more. Great.
- poker bonuses What are the norms of copyright of web content? How as it different from Patent?
- Wow! Thank you! I permanently needed to write on my blog something like that. Can I implement a fragment of your post to my site?
- This website was how do I say it? Relevant!! Finally I ave found something that helped me. Cheers!
- I was reading through some of your content on this internet site and I believe this web site is very informative ! Continue posting.