Difference between revisions of "Python sqlite"
From Teknologisk videncenter
m |
m |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | Just some play notes | ||
<source lang=python> | <source lang=python> | ||
import sqlite3 | import sqlite3 | ||
− | db=sqlite3.connect(':memory') | + | db=sqlite3.connect(':memory:') |
+ | #db=sqlite3.connect(':myname:') # ':memory:' is apparently a hardcode name in sqlite | ||
− | + | b=[['Date', 'str', '16/06/2024', 'Local date'], ['Time', 'str', '13:09:01', 'Local time'], ['Device', 'str', '68', 'Name'], ['Flow temp', 'float', 21.9, '°C'], ['Return temp', 'float', 21.83, '°C'], ['Temp diff', 'float', 0.07, '°C'], ['Power', 'int', 0, 'W'], ['Vol flow', 'float', 0.0, 'm^3'], ['Max Vol flow', 'float', 0.0, 'm^3'], ['Energy', 'int', 0, 'KWh']] | |
db.execute("create table device(name,address,count,errors,delta_value)") | db.execute("create table device(name,address,count,errors,delta_value)") | ||
Line 27: | Line 29: | ||
print("Database size = " + str(size * count) + "bytes") | print("Database size = " + str(size * count) + "bytes") | ||
+ | |||
</source> | </source> | ||
[[Category:Python]] | [[Category:Python]] |
Latest revision as of 15:52, 16 June 2024
Just some play notes
import sqlite3
db=sqlite3.connect(':memory:')
#db=sqlite3.connect(':myname:') # ':memory:' is apparently a hardcode name in sqlite
b=[['Date', 'str', '16/06/2024', 'Local date'], ['Time', 'str', '13:09:01', 'Local time'], ['Device', 'str', '68', 'Name'], ['Flow temp', 'float', 21.9, '°C'], ['Return temp', 'float', 21.83, '°C'], ['Temp diff', 'float', 0.07, '°C'], ['Power', 'int', 0, 'W'], ['Vol flow', 'float', 0.0, 'm^3'], ['Max Vol flow', 'float', 0.0, 'm^3'], ['Energy', 'int', 0, 'KWh']]
db.execute("create table device(name,address,count,errors,delta_value)")
db.execute("insert into device values ('stand1',68,1000,7,'b')")
db.execute("insert into device (name,address,count,errors,delta_value) values (?,?,?,?,?)", ('stand1',68,1000,7,str(b)))
db.commit()
for row in db.execute("select * from device"):
print(row)
db.execute("insert into device (name,address,count,errors,delta_value) values (?,?,?,?,?)", ('stand2',68,1000,7,str(b)))
for row in db.execute("select * from device where name='stand2'"):
print(row)
for row in db.execute("select address from device where name='stand2'"):
adr=row[0]
print(adr)
for row in db.execute("PRAGMA page_size"):
size=row[0]
for row in db.execute("PRAGMA page_count"):
count=row[0]
print("Database size = " + str(size * count) + "bytes")