Comments (13)
- 使用like 的时候, 生成的语句在?的左右会有空格,导致找不到数据。
SELECT count(1) FROM t_test WHERE del = 0 AND TITLE LIKE '% ? %' ORDER BY create_time DESC
- or 是怎么用的? 会无端端多了一个or,其他的用了and.
RB.new_wrapper() .eq("1","1") .or() .like("TITLE",&str) .or() .like("ORIGINAL_NAME",&str)
生成的语句:
SELECT count(1) FROM t_test WHERE del = 0 AND 1 = ? OR OR TITLE LIKE '% ? %' OR OR ORIGINAL_NAME LIKE '% ? %'
这个问题已修复,待发布
from rbatis.
1.5.9 可以试试
from rbatis.
已升级到1.6.0 ,但是还有问题。
代码:
let mut wrapper = wrapper = RB.new_wrapper() .or() .like("ORIGINAL_NAME",&str) .or() .like("TITLE",&str) .order_by(false,&["create_time"]).check()?;
生成的错误sql:
SELECT count(1) FROM t_test WHERE del = 0 AND ORIGINAL_NAME LIKE '%?%' OR TITLE LIKE '%?%' ORDER BY create_time DESC
问题:
- sql的不对。2. 如果统计总数,不需要加上order by 吧。
期待生成的sql是
SELECT count(1) FROM t_test WHERE del = 0 and ( ORIGINAL_NAME LIKE '%?%' OR TITLE LIKE '%?%' )
是我用错or方法,还是说,生成sql有问题?
from rbatis.
已升级到1.6.0 ,但是还有问题。
代码:
let mut wrapper = wrapper = RB.new_wrapper() .or() .like("ORIGINAL_NAME",&str) .or() .like("TITLE",&str) .order_by(false,&["create_time"]).check()?;
生成的错误sql:
SELECT count(1) FROM t_test WHERE del = 0 AND ORIGINAL_NAME LIKE '%?%' OR TITLE LIKE '%?%' ORDER BY create_time DESC
问题:
- sql的不对。2. 如果统计总数,不需要加上order by 吧。
期待生成的sql是
SELECT count(1) FROM t_test WHERE del = 0 and ( ORIGINAL_NAME LIKE '%?%' OR TITLE LIKE '%?%' )是我用错or方法,还是说,生成sql有问题?
如果要加括号的话,你可以直接 往 Wrapper里面的sql 加括号,例如
let mut w= RB.new_wrapper()
.push_sql(" (ORIGINAL_NAME LIKE '%?%' OR TITLE LIKE '%?%' ) ")
.check()?;
w.args.push(json!("1"));
w.args.push(json!("1"));
是不是嫌麻烦?下个版本(v1.6.1)可以用push_wrapper方法(即将改名为push_wrapper,且支持push_arg):
/// for Example:
let w2 = RB.new_wrapper()
.eq("b", "2")
.and()
.push_wrapper(&RB.new_wrapper().push_sql("(").eq("a", "1").push_sql(")").check()?)
.check().unwrap();
println!("sql:{:?}", w2.sql.as_str());
// 生成sql: b = $1 AND ( AND a = $2)
println!("arg:{:?}", w2.args.clone());
// 生成args: [String("2"), String("1")]
from rbatis.
升级到1.6.2后, 使用下面的代码,还是不可以。生成的sql是没问题的,但是count的数据,都是为0. 下图是我跟踪到的代码
`let mut w= RB.new_wrapper()
.push_sql(" (ORIGINAL_NAME LIKE '%?%' OR TITLE LIKE '%?%' ) ")
.check()?;
w.args.push(json!("1"));
w.args.push(json!("1"));`
from rbatis.
完整日志打印下
from rbatis.
日志
2020-10-09T16:02:10.223826+08:00-[INFO]-[actix-rt:worker:0:123145358544896]-[rbatis::rbatis-268]: [rbatis] [] Query ==> SELECT count(1) FROM t_test WHERE del = 0 AND (ORIGINAL_NAME LIKE '%?%' OR TITLE LIKE '%?%' ) ORDER BY create_time DESC 2020-10-09T16:02:10.224026+08:00-[INFO]-[actix-rt:worker:0:123145358544896]-[rbatis::rbatis-269]: [rbatis] [] Args ==> ["un"] 2020-10-09T16:02:10.232397+08:00-[INFO]-[actix-rt:worker:0:123145358544896]-[rbatis::rbatis-291]: [rbatis] [] ReturnRows <== 1 2020-10-09T16:02:10.232673+08:00-[INFO]-[actix-rt:worker:0:123145358544896]-[test_controller-24]: vo=Ok(Page { records: [], total: 0, pages: 0, size: 2, current: 1, serch_count: true })
from rbatis.
SELECT count(1) FROM t_test WHERE del = 0 AND (ORIGINAL_NAME LIKE '%?%' OR TITLE LIKE '%?%' ) ORDER BY create_time DESC
这个sql 查了0条数据了吧? 应该是sql 写的有问题吧?到navcat或者mysqlworkbench 执行下sql看看
from rbatis.
from rbatis.
完整代码贴上来,看看。我看看你用了哪个api
from rbatis.
let req = PageRequest::new(arg.page.unwrap_or(1), arg.size.unwrap_or(20));//分页请求,页码,条数
let wrapper = RB.new_wrapper()
.push_sql(" (ORIGINAL_NAME LIKE '%?%' OR TITLE LIKE '%?%' ) ")
.order_by(false,&["create_time"]).check()?;
wrapper.args.push(json!("un"));
let mut result: Page<Test> = RB.fetch_page_by_wrapper("", &wrapper, &req).await?;
from rbatis.
好像是有这个问题,
- 一个问题是,好像预编译模式下,这样的百分号 '%?%' 不起作用,需要改成concat('%',?,'%'),或者你用Wrapper.like
from rbatis.
原因大概是Mysql预编译的话,执行的时候会把?的值 替换为 '?' .
所以你 '%?%'就变成了 '%’un‘%'这样.
所以新版本Rbatis的like()方法需要把预编译放到参数里,就是 sql: "like ?" ,参数为 “%un%”.
建议 使用concat('%',?,'%'),或者你用Wrapper.like。
还有wrapper 有push_arg()方法,不需要写w.args.push
from rbatis.
Related Issues (20)
- Upgrade Crossbeam from 0.8.2 to 0.8.4 to address "High" GitHub Dependabot alert HOT 3
- update_by_column_batch issue for mysql HOT 1
- What happened to table_sync::SqliteTableSync and table_sync::TableSync? HOT 8
- How can I return the number of records modified by the update statement? HOT 1
- Error caused by enumeration in table definition HOT 5
- About the use of htmlsql HOT 1
- About the use of htmlsql
- htmlsql file does not exist HOT 8
- All results need to be wrapped in a structure, including results with only one field HOT 9
- Query results Boolean type support HOT 3
- Ambiguous package references HOT 2
- How to determine whether the select result is no record found? HOT 12
- no method named `str` found for reference `&rbs::Value` in the current scope HOT 1
- In the generated update and insert statements, use ``` to escape the fields HOT 9
- When the DateTime field is read from the database, it will always be UTC. HOT 2
- Is there a macro to modify the name of the field in sturct? HOT 4
- After using rbatis 4, it was found that it is not compatible with the criterion bench HOT 3
- How to use the function that supports sqlite to set password? HOT 1
- How to use the function that supports sqlite to set password? HOT 7
- Transactton Token error: 'Incorrect syntax near 'begin'.' on server HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rbatis.