Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to Start Simple Transaction in SQlite

I have started SQlite 2-days ago, and today i tried to learn Transactions in Sqlite3. But i am unable to even run the simplest ever transaction.

Begin;
Insert into newTable(Name,Age) values ("Adnan Ahamd KHan",24)
Insert into tbl2 (Name, FID) values ("Adnan",(Select MAx(ID) from newTable))
END Transaction;

Error Displayed is

cannot start a transaction within a transaction: Begin;
like image 948
Adnan Ahmad Khan Avatar asked Jun 26 '15 11:06

Adnan Ahmad Khan


People also ask

How do I start a transaction in SQLite?

SQLite transaction statements First, open a transaction by issuing the BEGIN TRANSACTION command. After executing the statement BEGIN TRANSACTION , the transaction is open until it is explicitly committed or rolled back. Second, issue SQL statements to select or update data in the database.

Why do we need to control transactions in SQLite?

It is important to control transactions to ensure data integrity and to handle database errors. Practically, you will club many SQLite queries into a group and you will execute all of them together as part of a transaction.

What is a transaction SQLite?

A transactional database is one in which all changes and queries appear to be Atomic, Consistent, Isolated, and Durable (ACID).

Does SQLite support nested transactions?

"Nested Android Transactions" do not use SQLites nested transaction/savepoint support. Rather a nested Android transaction suppresses manifesting a SQLite transaction. The nested transaction cannot be rolled back itself, because it does not exist apart from the outside transaction.


1 Answers

Here we go,
I found the answer to my Questio. Actually i am using DBBrowser for SQlite. And upto my knowledge, you have to commit every statement in DBBrowser for SQlite. I First created Tables, established Relationship, and without committing them all, i then tried to start that Transaction, that's why it was saying

cannot start a transaction within a transaction: Begin;

What i did, first issued a single

commit

to commit the statements which created tables, and then started Transaction. And it worked fine.

Thanks

like image 146
Adnan Ahmad Khan Avatar answered Oct 23 '22 17:10

Adnan Ahmad Khan