Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4fe5a08

Browse files
committed
fix intercept_page.rs
1 parent6e421d9 commit4fe5a08

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

‎Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ members = [
77

88
[package]
99
name ="rbatis"
10-
version ="4.6.5"
10+
version ="4.6.6"
1111
description ="The Rust SQL Toolkit and ORM Library. An async, pure Rust SQL crate featuring compile-time Dynamic SQL"
1212
readme ="Readme.md"
1313
authors = ["ce <zhuxiujia@qq.com>"]

‎src/plugin/intercept/intercept_page.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::sync::Arc;
99

1010
/// make count sql remove `limit`
1111
/// make select sql append limit ${page_no},${page_size}
12-
/// notice:
12+
/// notice:
1313
/// ```log
1414
/// sql must be starts with 'select ' and ' from '
1515
/// this PageIntercept only support sqlite,mysql,mssql,postgres...
@@ -48,6 +48,14 @@ impl PageIntercept {
4848
count_ids:Arc::new(SyncHashMap::new()),
4949
}
5050
}
51+
52+
//driver_type=['postgres','pg','mssql','mysql','sqlite'...],but sql default is use '?'
53+
pubfncount_param_count(&self,_driver_type:&str,sql:&str) ->usize{
54+
sql.replace("$","?")
55+
.replace("@p","?")
56+
.matches('?')
57+
.count()
58+
}
5159
}
5260
#[async_trait]
5361
implInterceptforPageIntercept{
@@ -56,7 +64,7 @@ impl Intercept for PageIntercept {
5664
_task_id:i64,
5765
executor:&dynExecutor,
5866
sql:&mutString,
59-
_args:&mutVec<Value>,
67+
args:&mutVec<Value>,
6068
result:ResultType<&mutResult<ExecResult,Error>,&mutResult<Vec<Value>,Error>>,
6169
) ->Result<Option<bool>,Error>{
6270
ifletResultType::Exec(_) = result{
@@ -73,6 +81,14 @@ impl Intercept for PageIntercept {
7381
*sql =(&sql[..idx]).to_string();
7482
}
7583
ifletSome(idx) = sql.rfind(" order by "){
84+
//remove args(args.pop())
85+
let order_by_clause =&sql[idx..];
86+
let driver_type = executor.driver_type().unwrap_or_default();
87+
let param_count =self.count_param_count(driver_type,&order_by_clause);
88+
// 移除对应的参数
89+
for _in0..param_count{
90+
args.pop();
91+
}
7692
*sql =(&sql[..idx]).to_string();
7793
}
7894
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp