problem:import csv data

Ê

ÊØÖê´ýÍÃ

import sqlite3
con = sqlite3.connect('/home/stock.db')
cur = con.cursor()
cur.execute('''CREATE TABLE quote (ticker TEXT,date TEXT, popen TEXT, high TEXT, low TEXT,vol TEXT,adjclose TEXT);''')
i=/tmp/data.csv
cur.execute('.separator "," ')
cur.execute('.import %s quote' % i)
con.commit()
cur.close()
con.close()

the output is :
cur.execute('.separator"," ')
sqlite3.OperationalError: near ".": syntax error

how to fix it?
 
M

Miki Tebeka

..separator (and .import) are not SQL commands but "sqlite3" commands.
You can get the same effect with the following code:

with open('/tmp/data.csv') as fo:
reader = csv.reader(fo)
cur.executemany('INSERT INTO quote VALUES (?, ?, ?, ?, ?, ?, ?)'), reader)

HTH
 
M

Miki Tebeka

..separator (and .import) are not SQL commands but "sqlite3" commands.
You can get the same effect with the following code:

with open('/tmp/data.csv') as fo:
reader = csv.reader(fo)
cur.executemany('INSERT INTO quote VALUES (?, ?, ?, ?, ?, ?, ?)'), reader)

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top