File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed
Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -3023,3 +3023,14 @@ You can run a SQL file using `.read file_name.sql` inside Sqlite.
30233023` SELECT * from table_name WHERE column_name IS NOT value AND column_name2 IS NOT value2; `
30243024
30253025` SELECT * FROM table_name WHERE column_name LIKE %value% ` ;
3026+
3027+ ### Connecting to a Database with Python
3028+
3029+ Python comes with a built-in library to communicate with Sqlite.
3030+
3031+ ``` python
3032+ import sqlite3
3033+ conn = sqlite3.connect(" example.db" )
3034+ ```
3035+
3036+
Original file line number Diff line number Diff line change 1+ import sqlite3
2+ conn = sqlite3 .connect ("my_friends.db" )
3+ # create cursor object
4+ c = conn .cursor ()
5+ # execute some sql
6+ # c.execute("CREATE TABLE friends (first_name TEXT, last_name TEXT, closeness INTEGER);")
7+ # insert_query = "INSERT INTO friends VALUES ('Merry', 'Brandybuck', 7);"
8+ # form_first = "Dana"
9+ # query = f"INSERT INTO friends (first_name) VALUES (?)"
10+ # c.execute(query, (form_first,))
11+
12+ data = ("Steve" , "Irwin" , 9 )
13+ query = "INSERT INTO friends VALUES (?,?,?)"
14+ c .execute (query , data )
15+ # commit changes
16+ conn .commit ()
17+ conn .close ()
You can’t perform that action at this time.
0 commit comments