I'm making a program that is suppoused to move files and save their new paths in a database. I do, however, have great problems with putting together and executing the SQL-query that inserts them into the database.
This is the program:
#logspc.py
import os
import sqlite3 as lite
import sys
import time
def getspc(path):
dirs = os.listdir(path)
spcfiles = []
for filename in dirs:
(shortname, extension) = os.path.splitext(filename)
if extension == '.spc':
spcfiles.append(filename)
return spcfiles
src=os.path.normpath(r'C:\users\python\nonpython')
dest=os.path.normpath(r'C:\users\python\target')
files=getspc(src)
con = lite.connect('spcbase.db')
cur=con.cursor()
for mfile in files:
oldpath=os.path.normpath(os.path.join(src,mfile))
newpath=os.path.normpath(os.path.join(dest,mfile))
os.rename(oldpath,newpath)
query="INSERT INTO spectra VALUES ('" + newpath + "',SELECT date('now'))"
print query
cur.execute(query)
con.close()
It crashes on the line "cur.execute(query)", rendering this error:
Traceback (most recent call last):
File "C:/Users/Python/logspc2.py", line 27, in <module>
cur.execute(query)
OperationalError: near "SELECT": syntax error
The value of the query-variable as printed is
INSERT INTO spectra VALUES ('C:\users\python\target\Bertil.spc',SELECT date('now'))
Where do I go from here?
date('now')work?