Python sqlite

From Teknologisk videncenter
Revision as of 15:44, 16 June 2024 by Heth (talk | contribs)
Jump to: navigation, search

Just som play notes

import sqlite3
db=sqlite3.connect(':memory')

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")