2015-01-24 2 views
0

나는 webiopi로 데이터베이스 작업에 문제가있다. 나는 이미 sqlite3을 가져오고 폴더 권한을 변경하지만 webiopi를 실행하면 아무것도 생성되지 않았습니다. 그러나 f.write('This is a test\n') 이후의 다른 모든 기능은 정상적으로 작동하고 루프를 반복합니다. 너 내가 도와 줄 수 있길 바래? Webiopi (Raspberry pi) with sql or sqlite

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 

+0

아무 것도 만들지 않았다는 것을 의미합니까? 파일 workfile 또는 schedule.db 파일? –

+0

둘 다. 스테핑 모터를 제어하는 ​​데 사용하는 단계()는 잘 작동하므로 데이터베이스 또는 텍스트 파일이 생성되지 않은 이유를 정말로 혼동합니다. – Pound19

답변

0

데이터베이스를 들어, 커서를 사용할 수 있으며, 더 나은 코네티컷 감사드립니다. 자세한 내용은 doc을 참조하십시오.

파일의 경우 쓰기 데이터로 사용하지 않으면 close()이됩니다. 아래 코드는 도움이 될 수 있습니다.

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 
+0

감사합니다! close() 데이터베이스는 내 모든 문제를 해결합니다. – Pound19

+0

안녕하세요. –