The Python connection.commit() function in SQLite is used to save the current state of the database. This function permanently saves all changes from the last commit or rollback. If the commit() function is not specified, then whatever changes are made in the function will not be saved, and the connection will be lost if a rollback is performed.
In SQLite, a connection refers to an active link between the application and database. This connection allows us to execute SQL commands and queries in the database.
The commit function is used to save all changes made within the current transaction. In a database, a transaction is a sequence of operations that is performed as a single logical unit of work.
SyntaxFollowing is the syntax for the connection.commit() function.
conn.commit()Parameter
This function doesn't accept any parameters.
Return ValueReturn Values
This connection.commit() function has no return value.
Example 1In the below example, we are inserting two values into the table using the connection.commit() function.
cursor.execute("INSERT INTO employees(first_name) VALUES(%s), (%s)", ('Shiny', 'Varsha')) conn.commit()Output
We will get the output as follows −
first_name ------------- Shiny VarshaExample 2
Now, we are deleting one of the values from the above example using the connection.commit() function.
cursor.execute("DELETE FROM employees WHERE first_name = ? ", ('Varsha,')) conn.commit()Output
The result is produced as follows −
first_name ----------- ShinyExample 3
Here, we are inserting new values into a table using the connection.commit() function.
cursor.execute("UPDATE employees SET first_name = ?", ('John', 'Shiny')) conn.commit()Output
The output will be displayed as follows −
first_name ----------- Varsha John
python_modules.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4