天道酬勤,学无止境

transactions

NOW() for DATETIME InnoDB Transaction guaranteed?

Does using NOW() in 2+ queries in a single InnoDB transaction guarantee that the inserted datetime value will be exact in the database? In other words, is the NOW(), even if you have more than 20 queries in a single transaction using it always going to be the same, or will it change?

2021-06-21 13:04:46    分类:问答    php   mysql   transactions   innodb

为什么使用 SELECT FOR UPDATE?(Why use SELECT FOR UPDATE?)

问题 我对我们使用SELECT FOR UDPATE目的有疑问? 它具体有什么作用? 我有 2 个表,从中我需要从表中选择行并更新相同的行。 例如: 选择查询 SELECT * from t1 WHERE city_id=2 for update 更新查询 UPDATE t1 SET final_balance = final_balance - 100 WHERE city_id ='2' 我的问题- 这是否真的锁定读取操作直到我的更新完成,或者它究竟处理什么? 我的想法是在我的更新完成之前,没有人可以读取/更新此行。 谢谢! 回答1 SELECT ... FOR UPDATE将使用写(独占)锁锁定记录,直到事务完成(提交或回滚)。 要选择一条记录并确保它在更新之前不被修改,您可以启动一个事务,使用SELECT ... FOR UPDATE选择记录,进行一些快速处理,更新记录,然后提交(或回滚)事务. 如果在事务之外使用SELECT ... FOR UPDATE (autocommit ON),那么锁仍然会被立即释放,所以一定要使用事务来保留锁。 出于性能考虑,不要让事务长时间保持打开状态,因此应立即进行更新。 回答2 不过,我们使用 SELECT FOR UPDATE 而不是 UPDATE 的目的是什么? 选择背后的基本理性是什么? 以下是我的想法 - SELECT

2021-06-21 10:57:03    分类:技术分享    mysql   transactions   innodb

Executing an SQLCommand without specifying a Transaction

We have some lists of data being fetched in our application via a SqlCommand performing a SELECT query on a SQL Server database. We do not explicitly setup a transaction on the SqlCommand, instead just passing it a SqlConnection and running it. Is it the case that when no transaction is specified that SQL Server will initiate and use a default transaction with the default IsolationLevel of ReadCommitted?

2021-06-21 09:31:32    分类:问答    sql-server   transactions   sqlcommand

What is the mechanism for Transaction Rollback in sql server?

What is the mechanism for Transaction Rollback in sql server?

2021-06-15 10:36:23    分类:问答    sql-server   transactions   rollback

MySQL locking in Duplicate Key Error

From the docs: If a duplicate-key error occurs, a shared lock on the duplicate index record is set. This use of a shared lock can result in deadlock should there be multiple sessions trying to insert the same row if another session already has an exclusive lock. This can occur if another session deletes the row. Going with the example in the docs, Suppose that an InnoDB table t1 has the following structure: CREATE TABLE t1 (i INT, PRIMARY KEY (i)) ENGINE = InnoDB; Now suppose that three sessions perform the following operations in order: Session 1: START TRANSACTION; INSERT INTO t1 VALUES(1)

2021-06-15 06:26:38    分类:问答    mysql   concurrency   transactions   locking

Update multiple records in one ActiveRecord transaction in Rails

How can I update/save multiple instances of a model in one shot, using a transaction block in Rails? I would like to update values for hundreds of records; the values are different for each record. This is not a mass-update situation for one attribute. Model.update_all(attr: value) is not appropriate here. MyModel.transaction do things_to_update.each do |thing| thing.score = rand(100) + rand(100) thing.save end end save seems to issue it's own transaction, rather than batching the updates into the surrounding transaction. I want all the updates to go in one big transaction. How can I

2021-06-15 05:35:17    分类:问答    ruby-on-rails   ruby   postgresql   activerecord   transactions

How do I properly add multiple fragments to a fragment transition?

I recently asked a question about fragments here: After a lot of messing around I found what the problem was, but after more fooling around, and research (in which correct code seemed identical to mine), i cant figure out what my problem is. After everything is created, I find that only the last fragment added to the transaction is visible. This is my code to add them: FragmentManager manager = getFragmentManager(); FragmentTransaction trans = manager.beginTransaction(); UrlListFragment urlfragment = new UrlListFragment(); MyWebFragment webfragment = new MyWebFragment(); trans.add(R.id

2021-06-15 04:55:19    分类:问答    layout   view   transactions   fragment

Mixing isolation levels in PostgreSQL

Does it matter for a SERIALIZABLE transaction if any other session uses e.g. autocommit or the READ COMMITED isolation level? In other words is there any danger in mixing isolation levels (& autocommit) when accessing a database from multiple processes/threads (or anything else to watch out for)? Note that I'm aware of the "ordinary" issues, like SERIALIZABLE transactions asking for a retry etc. I'm asking for anything non-obvious that can happen when one is mixing different isolation levels. EDIT: From http://www.postgresql.org/docs/9.4/static/transaction-iso.html: Consistent use of

2021-06-15 03:07:05    分类:问答    postgresql   transactions   isolation-level

Transactional integrity Sharepoint List

Is it possibly to guarantee transactional integrity when storing information in a Sharepoint list (SP 2010)?

2021-06-15 02:14:37    分类:问答    database   sharepoint   sharepoint-2010   transactions

What is the default value of sqlite3_busy_timeout?

This seems like it should be really easy to find out, but I don't see it documented anywhere. If I open a sqlite connection and begin a transaction without specifying a timeout by calling sqlite3_busy_timeout, what default value is used? Or will this somehow cause undefined behavior? The documentation of this method doesn't say. My specific use case is the version bundled with iOS, but I'm guessing the answer is pretty much the same across platforms.

2021-06-14 22:08:02    分类:问答    sqlite   transactions