![]() | 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 多数据库支持的语法解析说明
Guide |
|
|
| #TopicOwner |
CYQ.Data是支持多数据库,意味着你可用它操作不同的数据。 通常情况下,在一个项目中,如果此项目可能运行在不同的数据库,通常情况写,由于各不同数据库的语法差别的原因,需要编写不同的代码来适应不同的数据库。 而CYQ.Data 支持将同一种函数语法自动解析,这意味着,你的代码只写一次,就可以适应不同的数据库,而不需要编写多种语法,但这需要你掌握以下内容: CYQ.Data 多数据库支持的语法解析说明 说明:为了对同一条语句可以在多个数据库下执行,推了关键字函数解析说明
目前系统定义的关键字如下:[语法以MSSQL为标准] 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]"; public const string Case= "[#Case]"; public const string CaseWhen= "[#CaseWhen]"; } 关键字使用手法都是在原始函数上套上[#函数名],成为关键字替换,以下进行具体解析说明: 1:排序关键字:[#DESC]与[#ASC] 说明:
由于Access/MSSQL/Oracle/SQLite/MySql在对Bit类型的处理方式不同,导致排序相反的问题。 access的bit类型为true与false,排序时会与其它数据库刚好相反 因此,采用(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 说明: 1:[#DATADIFF]和正常函数名称一样 2:[#d]在不同数据库下被解析成'd'或d,标准解析如下:[#yyyy], [#q], [#m], [#y],[#d],[#h],[#ww], [#n], [#s] 3:采用了Access与Oracle的共同参数表达式解析。 4:[#GETDATE]是不同数据库解析成now(),getdate(),sysdate 5:[#CASE] 解析示例 select A= [#CASE] [#WHEN] languageID=1 [#THEN] {2} [#ELSE] 0 [#END] from ATable Access数据库则解析为IIF函数替换。 如何测试? 仅需要在不同数据库下输出DebugInfo,即可看到不同的数据库语句解析后的语句。 ![]() |
游客[注册][116.54.28.*]2011/8/20 22:36:03 | #1 | |
![]() | 虚长几岁,胡乱点评下,有则改之无则加勉,不在乎对错。 可惜了,看得出来你很执着——这很宝贵,技术功底也不错,但方向走偏了 看你回复留言,感觉性格有点偏激。其实把视野放开一点,把你宝贵的天赋和精力用在更合适的方向上,成就会更大,甚至不可限量。 reply: 谢谢你的留言,有机会多交流,偶尔会对来的太直接评论回复的直接了点,其它情况情绪还好,不过这年头不执着点不行,太多人喜欢打击人,我得增强抗击打能力。 |
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.