Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import sqlite3
- from pprint import pprint
- conn = sqlite3.connect("database.db")
- cur = conn.cursor()
- # Создание таблицы
- # cur.execute("CREATE TABLE IF NOT EXISTS users("
- # "userid INT PRIMARY KEY, "
- # "hp FLOAT, "
- # "dmg INT, "
- # "castle TEXT, "
- # "sleep BOOLEAN)")
- # Запись
- # for i in range(100):
- # cur.execute("INSERT or REPLACE into users VALUES(?,?,?,?,?)", (
- # random.randint(0, 1000000000),
- # random.randint(1, 100),
- # random.randint(20, 40),
- # random.choice(["Дол Гулдур", 'Эребор']),
- # random.choice([True, False])
- # ))
- # Чтение
- # cur.execute("SELECT * FROM users WHERE hp = ?")
- # result = cur.fetchall()
- # pprint(result)
- # conn.commit()
- # Создание таблицы с AUTOINCREMENT
- # cur.execute("CREATE TABLE IF NOT EXISTS peoples(number INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, last_login TEXT)")
- # for _ in range(1000):
- # cur.execute("INSERT or REPLACE into peoples VALUES(?, ?, ?)", (None, 'Иоганн Бах', '1827'))
- # conn.commit()
- # # Удаление строки
- # cur.execute("DELETE FROM peoples where name = 'Иоганн Бах'")
- # conn.commit()
- # Удаление таблицы
- # cur.execute("DROP TABLE users")
- # conn.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement