Comments (5)
database:sql server 2016.
Call to start transaction: let mut txn = CONTEXT.rb.acquire_begin().await?; Execute transaction error: Token error: 'Incorrect syntax near 'begin'.' on server WIN-B9A9 executing on line 1 (code: 102, state: 1, class: 15)
Sql server does not support 'begin'.
Added the following method: pub async fn acquire_begin_transaction(&self) -> Result<RBatisTxExecutor, Error> { let pool = self.rb.get_pool()?; let mut conn = pool.get().await?; conn.exec("BEGIN TRAN", vec![]).await?; Ok(RBatisTxExecutor { tx_id: new_snowflake_id(), conn: Mutex::new(Box::new(conn)), rb: self.rb.clone(), done: false, }) } Execute error: Token error: 'Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1.' on server WIN-B9A9 executing on line 0 (code: 266, state: 2, class: 16)
Please give me some advice?
SQL Server 2016 supports starting a transaction using BEGIN TRANSACTION
, which is used to explicitly start a transaction in SQL Server. Through BEGIN TRANSACT, you can start a new transaction and then end or roll back the transaction in either COMMIT TRANSACT or Rollback TRANSACT.
I suggest you use an interceptor to modify the transaction statement start to BEGIN TRANSACTION
#[derive(Debug)]
pub struct TxIntercept {}
#[async_trait]
impl Intercept for TxIntercept {
async fn before(
&self,
_task_id: i64,
_rb: &dyn Executor,
sql: &mut String,
_args: &mut Vec<Value>,
_result: ResultType<&mut Result<ExecResult, Error>, &mut Result<Vec<Value>, Error>>,
) -> Result<bool, Error> {
if sql.contains("begin") {
*sql = sql.replace("begin","BEGIN TRANSACTION").to_string();
} else if sql.contains("commit") {
*sql = sql.replace("commit","COMMIT TRANSACTION").to_string();
} else if sql.contains("rollback") {
*sql = sql.replace("rollback","ROLLBACK TRANSACTION").to_string();
}
Ok(true)
}
}
#[tokio::main]
pub async fn main() {
fast_log::init(fast_log::Config::new().console()).expect("rbatis init fail");
defer!(|| log::logger().flush());
let rb = RBatis::new();
rb.intercepts.push(Arc::new(TxIntercept {}));
}
from rbatis.
database:sql server 2016.
Call to start transaction: let mut txn = CONTEXT.rb.acquire_begin().await?; Execute transaction error: Token error: 'Incorrect syntax near 'begin'.' on server WIN-B9A9 executing on line 1 (code: 102, state: 1, class: 15)
Sql server does not support 'begin'.
Added the following method: pub async fn acquire_begin_transaction(&self) -> Result<RBatisTxExecutor, Error> { let pool = self.rb.get_pool()?; let mut conn = pool.get().await?; conn.exec("BEGIN TRAN", vec![]).await?; Ok(RBatisTxExecutor { tx_id: new_snowflake_id(), conn: Mutex::new(Box::new(conn)), rb: self.rb.clone(), done: false, }) } Execute error: Token error: 'Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1.' on server WIN-B9A9 executing on line 0 (code: 266, state: 2, class: 16)
Please give me some advice?
SQL Server 2016 supports starting a transaction using
BEGIN TRANSACTION
, which is used to explicitly start a transaction in SQL Server. Through BEGIN TRANSACT, you can start a new transaction and then end or roll back the transaction in either COMMIT TRANSACT or Rollback TRANSACT.I suggest you use an interceptor to modify the transaction statement start to
BEGIN TRANSACTION
#[derive(Debug)] pub struct TxIntercept {} #[async_trait] impl Intercept for TxIntercept { async fn before( &self, _task_id: i64, _rb: &dyn Executor, sql: &mut String, _args: &mut Vec<Value>, _result: ResultType<&mut Result<ExecResult, Error>, &mut Result<Vec<Value>, Error>>, ) -> Result<bool, Error> { if sql.contains("begin") { *sql = sql.replace("begin","BEGIN TRANSACTION").to_string(); } else if sql.contains("commit") { *sql = sql.replace("commit","COMMIT TRANSACTION").to_string(); } else if sql.contains("rollback") { *sql = sql.replace("rollback","ROLLBACK TRANSACTION").to_string(); } Ok(true) } } #[tokio::main] pub async fn main() { fast_log::init(fast_log::Config::new().console()).expect("rbatis init fail"); defer!(|| log::logger().flush()); let rb = RBatis::new(); rb.intercepts.push(Arc::new(TxIntercept {})); }
Thank you very much that the interceptor has taken effect.
But it still prompts this error:Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1.
from rbatis.
Thank you very much that the interceptor has taken effect.
But it still prompts this error:Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1.
did you call commit method or rollback ?
from rbatis.
call CONTEXT.rb.try_acquire_begin().await? report errorThank you very much that the interceptor has taken effect.
But it still prompts this error:Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1.
did you call commit method or rollback ?
from rbatis.
#488 Already solved
from rbatis.
Related Issues (20)
- 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
- Removed local dependencies. Re-cargo build reports an error! Version rbatis: 4.5.11 HOT 5
- method `set_timeout` is not a member of trait `Pool` HOT 17
- add duckdb support HOT 4
- Hello, I have encountered a question: functions in traits cannot be declared `async` HOT 2
- When using enumeration, can it support automatic conversion to integer when saving or updating, and automatically convert integer to enumeration when selecting? HOT 2
- Intermittent Delays in Query Execution After Periods of Inactivity HOT 4
- MSSQL using transactions error: token error: 'Incorrect syntax near 'begin'.' on server MSSQL2016 executing on line 1 (code: 102, state: 1, class: 15) HOT 2
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.