· 5 years ago · Jun 10, 2020, 03:18 PM
1import sqlite3
2
3
4try:
5 sqliteConnection = sqlite3.connect('nowa.sql')
6 cursor = sqliteConnection.cursor()
7
8 sqlite_select_Query = "CREATE TABLE IF NOT EXISTS users (name VARCHAR(255));"
9 cursor.execute(sqlite_select_Query)
10 sqlite_select_Query = "CREATE TABLE IF NOT EXISTS groups (name VARCHAR(255));"
11 cursor.execute(sqlite_select_Query)
12 sqlite_select_Query = "CREATE TABLE IF NOT EXISTS user_groups (name VARCHAR(255));"
13 cursor.execute(sqlite_select_Query)
14
15 sqlite_select_Query = "INSERT INTO users(name))VALUES('Maciej');"
16 cursor.execute(sqlite_select_Query)
17 sqlite_select_Query = "INSERT INTO users(name)VALUES('Damian');"
18 cursor.execute(sqlite_select_Query)
19 sqlite_select_Query = "INSERT INTO users(name)VALUES('Daniel');"
20 cursor.execute(sqlite_select_Query)
21
22 sqlite_select_Query = "INSERT INTO groups(name))VALUES('Grupa1');"
23 cursor.execute(sqlite_select_Query)
24 sqlite_select_Query = "INSERT INTO groups(name))VALUES('Grupa2');"
25 cursor.execute(sqlite_select_Query)
26 sqlite_select_Query = "INSERT INTO groups(name))VALUES('Grupa3');"
27 cursor.execute(sqlite_select_Query)
28
29
30
31 record = cursor.fetchall()
32 cursor.close()
33
34except sqlite3.Error as error:
35 print("Error while connecting to dbase", error)
36finally:
37 if (sqliteConnection):
38 sqliteConnection.close()
39 print("The SQlite connection is closed")