I've got some problem with making database work with webiopi. I'm already import sqlite3 and change folder permission but when I'm run webiopi nothing had been create. However, other function after f.write('This is a test\n')
every process work normally and repeat the loop. Hope you can help me?
def loop():
db = sqlite3.connect('schedule.db')
db.execute('DROP TABLE IF EXISTS schedule')
db.execute('CREATE TABLE schedule (hour int, minute int, second int, status text)')
db.execute('INSERT INTO schedule (hour,minute,second,status) VALUES (?,?,?,?)',(sche.get('hour'),sche.get('minute'),sche.get('second'),"yes"))
db.commit()
f = open('workfile', 'w')
f.write('This is a test\n')
loop1=1
while ((now.minute >= minute_ON) and (now.minute < minute_OFF) and (loop1<stepping)):
step()
loop1=loop1+1
Thank you
For database, you may use cursor and conn for better. See doc for more.
For file, you may close()
it when you don't use it for write data.
The code below may helps:
def loop():
db = sqlite3.connect('schedule.db')
cur = db.cursor() # create a cursor
cur.execute('DROP TABLE IF EXISTS schedule')
cur.execute('CREATE TABLE schedule (hour int, minute int, second int, status text)')
cur.execute('INSERT INTO schedule (hour,minute,second,status) VALUES (?,?,?,?)',(sche.get('hour'),sche.get('minute'),sche.get('second'),"yes"))
db.commit()
cur.close() # close cursor
db.close() # close connection to sqlite3
f = open('workfile', 'w')
f.write('This is a test\n')
f.close() # close file to write data
loop1=1
while ((now.minute >= minute_ON) and (now.minute < minute_OFF) and (loop1<stepping)):
step()
loop1=loop1+1