110,499
社区成员
发帖
与我相关
我的任务
分享
//
string count = "select * from user where delete = 0 order by id desc limit {0}, {1}".Count();
Assert.IsTrue(count == "select count(*) from user where delete = 0");
count = "select * from user where delete = 0".Count();
Assert.IsTrue(count == "select count(*) from user where delete = 0");
count = "select * from user".Count();
Assert.IsTrue(count == "select count(*) from user");
count = "select id, name, dept from user where delete = 0 order by id desc limit {0}, {1}".Count();
Assert.IsTrue(count == "select count(*) from user where delete = 0");
count = "select id, name, dept from user where delete = 0".Count();
Assert.IsTrue(count == "select count(*) from user where delete = 0");
count = "select id, name, dept from user".Count();
Assert.IsTrue(count == "select count(*) from user");
//
string and = "select * from user where delete = 0 order by id desc limit {0}, {1}".And("status = 1");
Assert.IsTrue(and == "select * from user where delete = 0 and status = 1 order by id desc limit {0}, {1}");
and = "select * from user order by id desc limit {0}, {1}".And("status = 1");
Assert.IsTrue(and == "select * from user where status = 1 order by id desc limit {0}, {1}");
and =
@"select * from user
order by id desc
limit {0}, {1}".And("status = 1");
Assert.IsTrue(and ==
@"select * from user where status = 1
order by id desc
limit {0}, {1}");
and = "SELECT * FROM USER ORDER BY ID DESC LIMIT {0}, {1}".And("status = 1");
Assert.IsTrue(and.CompareIgnoreCase("select * from user where status = 1 order by id desc limit {0}, {1}"));
[quote=引用 17 楼 From_TaiWan 的回复:] 回来再补充一点,本人在实际项目中,从来不用什么EF、linq to sql之类的,尽管理论上知道些
[quote=引用 8 楼 hanjun0612 的回复:] 闭包客,我觉得你可以直接从 Expression入手啊。 linq中的 表达式树就是你想做的事情吧。
闭包客,我觉得你可以直接从 Expression入手啊。 linq中的 表达式树就是你想做的事情吧。
“倾向于手写”跟首先研究人家成熟的类库的源代码并不矛盾。 如果你谈论的是语义分析、语法分析系统的术语,而不是什么“拿正则匹配的方法试了一下”,这就说明你上道、在那一个真正有行动力圈子里。
不知道你想要做什么事情 如果 SQL 指令已经存在了,自己写个语法分析器似乎并无此必要。毕竟 SQL 指令的语法简单,约束也大。能写出来,就不大会有语法错的 如果是想设计一个结构,方便组织 SQL 指令的成分,以便于 SQL 指令的生成。却又说 不需要拼接字符串(机器拼也是拼),不觉得自相矛盾吗 不借助第三方工具,解析简单语法的最佳方法是通过 Trie 树,生成树和查询的代码也就 二、三十行。 而且对正文只需做一遍扫描,而正则需要多趟扫描