Python Language Sqlite3 Module Sqlite3 - Not require separate server process.


Example

The sqlite3 module was written by Gerhard Häring. To use the module, you must first create a Connection object that represents the database. Here the data will be stored in the example.db file:

import sqlite3
conn = sqlite3.connect('example.db')

You can also supply the special name :memory: to create a database in RAM. Once you have a Connection, you can create a Cursor object and call its execute() method to perform SQL commands:

c = conn.cursor()

# Create table
c.execute('''CREATE TABLE stocks
         (date text, trans text, symbol text, qty real, price real)''')

# Insert a row of data
c.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)")

# Save (commit) the changes
conn.commit()

# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn.close()
{"cc_re__cc_re__cc_by_sa_3_0": ["on Language\",\r\n    \"description\": \"Sqlite3 - Not require separate server process.\"\r\n    }\r\n</script>\r\n\r\n</div>\r\n\r\n<div class=\"site-footer\">\r\n        <div class=\"site-footer-copyright\">\r\n            <div class=\"container\">\r\n                \r\n<div>This modified text is an extract of the original <a href=\"https://archive.org/details/documentation-dump.7z\" target=\"_blank\">Stack Overflow Documentation</a> created by following <a href=\"/contributor?exampleId=25416\">contributors</a> and released under <a href=\"https://creativecommons.org/licenses/by-sa/3.0/\" target=\"_blank\" rel=\"nofollow\">CC BY-SA 3.0</a></div>\r\n<div>This website is not affiliated with <a href=\"https://stackoverflow.com/questions/tagged/python\" target=\"_blank\">Stack Overflow</a></div>\r\n\r\n            </div>\r\n        </div>\r\n\r\n    <div class=\"site-footer-link\">\r\n        <div class=\"container\">\r\n            <div class=\"row\">\r\n                <div class=\"col-lg-1\">\r\n                    <br/>\r\n                    <img src=\"/Images/logo_rip_full_white.png\" alt=\"logo rip\" height=\"64\" width=\"64\">\r\n                </div>\r"], "copyright__copyright__copyright": ["ate a Cursor object and call its execute() method to perform SQL commands:\n\nc = conn.cursor()\n\n# Create table\nc.execute('''CREATE TABLE stocks\n         (date text, trans text, symbol text, qty real, price real)''')\n\n# Insert a row of data\nc.execute(\"INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)\")\n\n# Save (commit) the changes\nconn.commit()\n\n# We can also close the connection if we are done with it.\n# Just be sure any changes have been committed or they will be lost.\nconn.close()"]}