commit message from python script
This commit is contained in:
62
play_with_sqllite/main.py
Normal file
62
play_with_sqllite/main.py
Normal file
@@ -0,0 +1,62 @@
|
||||
#! /usr/bin/env python.3.11
|
||||
|
||||
import sqlite3, os
|
||||
|
||||
script_folder = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
def erzeuge_tabellen():
|
||||
with sqlite3.connect(script_folder + "/startegie.db") as verbindung:
|
||||
cursor = verbindung.cursor()
|
||||
sql = '''
|
||||
CREATE TABLE viren(
|
||||
name TEXT PRIMARY KEY, typ INTEGER, status TEXT);
|
||||
'''
|
||||
cursor.execute(sql)
|
||||
|
||||
sql = '''
|
||||
CREATE TABLE viren_typ(
|
||||
typ INTEGER PRIMARY KEY,groesse INT,signatur TEXT);
|
||||
'''
|
||||
cursor.execute(sql)
|
||||
verbindung.commit()
|
||||
|
||||
def schreibe_tabellen():
|
||||
with sqlite3.connect(script_folder + "/startegie.db") as verbindung:
|
||||
cursor = verbindung.cursor()
|
||||
sql = '''
|
||||
INSERT INTO viren_typ(typ, groesse, signatur)
|
||||
VALUES(1,128,'ABAABA'),(2,256,'ABAABA'),(3,256,'BCCBCB')
|
||||
'''
|
||||
cursor.execute(sql)
|
||||
|
||||
sql = '''
|
||||
INSERT INTO viren(name, typ, status)
|
||||
VALUES ('T800', 1, 'aktiv'),
|
||||
('T803', 2, 'aktiv'),
|
||||
('Bit13', 3, 'aktiv'),
|
||||
('Gorf3', 1, 'aktiv'),
|
||||
('Gorf7', 2, 'aktiv')
|
||||
'''
|
||||
|
||||
cursor.execute(sql)
|
||||
verbindung.commit()
|
||||
|
||||
|
||||
def lese_tabellen():
|
||||
with sqlite3.connect(script_folder + "/startegie.db") as verbindung:
|
||||
cursor = verbindung.cursor()
|
||||
sql = '''SELECT * FROM viren_typ;'''
|
||||
cursor.execute(sql)
|
||||
#for ergebnis in cursor:
|
||||
# print(ergebnis)
|
||||
|
||||
return cursor.fetchall()
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# erzeuge_tabellen()
|
||||
# schreibe_tabellen()
|
||||
for i in lese_tabellen():
|
||||
print(i)
|
||||
BIN
play_with_sqllite/startegie.db
Normal file
BIN
play_with_sqllite/startegie.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user