Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- def create_table(db_name, table_name, columns):
- connection = sqlite3.connect(db_name)
- cursor = connection.cursor()
- query = f'CREATE TABLE IF NOT EXISTS {table_name} ('
- query += ', '.join(' '.join(i) for i in columns) + ')'
- cursor.execute(query)
- cursor.execute(f'SELECT * FROM {table_name}')
- print(cursor.fetchall())
- connection.close()
- col = [('id', 'INTEGER', 'PRIMARY KEY'),
- ('login', 'VARCHAR(25)', 'UNIQUE', 'NOT NULL'),
- ('password', 'VARCHAR(50)', 'NOT NULL'),
- ('email', 'VARCHAR(40)', 'UNIQUE', 'NOT NULL'),
- ('about', 'TEXT')]
- create_table('users.sqlite', 'Users2', col)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement