Created
September 25, 2018 15:01
-
-
Save jO-Osko/d6e0c5727ff0d13f9e90bafefae03340 to your computer and use it in GitHub Desktop.
Baze in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
# Povezemo se na bazo | |
conn = sqlite3.connect("baza.sqlite") | |
cursor = conn.cursor() | |
cursor.execute(""" | |
SELECT COUNT(*), cas_vpisa FROM MERITVE | |
GROUP BY cas_vpisa | |
""") | |
for st, cas in cursor: | |
print(st, cas) | |
# Zapremo povezavo | |
conn.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
# Povezemo se na bazo | |
conn = sqlite3.connect("baza.sqlite") | |
cursor = conn.cursor() | |
cursor.execute(""" | |
CREATE TABLE IF NOT EXISTS MERITVE( | |
id INTEGER PRIMARY KEY, | |
vrednost INTEGER, | |
id_senzorja INTEGER, | |
cas_vpisa TEXT DEFAULT (DATETIME('now')) | |
) | |
""") | |
for j in range(10): | |
cursor.execute(""" | |
INSERT INTO MERITVE (ime, id_senzorja) | |
VALUES (?,?) | |
""", (j*2, 1)) | |
# Shranimo rezultate | |
conn.commit() | |
# Zapremo povezavo | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment