2
votes

apologies if this is redundant, I spent a good deal of time trying to find the answer but none of the tricks supplied seemed to do anything. I am trying to use Python to read into SQLite a csv document of stock data (yahoo finance):

Ticker  Open    High   Low    Close  Volume  AdjClose  
AA      1/5/11  16.34  16.59  16.11  16.56   48278700  16.56

I am using the following commends:

to_db = [(i['Ticker'], i['Open'], i['High'], i['Low'],i['Close'], i['Volume'], i['AdjClose']) for i in dr]
c.executemany("insert into stock_test1 (Ticker, Date, Open, High, Low, Close, Volume, AdjClose) values ( ?, ?, ?, ?, ?, ?, ?, ?);", to_db)

and I get:

sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 8, and there are 7 supplied.

Where am I going wrong on this?

3

3 Answers

4
votes

Now that it is reformatted I think the problem becomes apparent.

to_db has 7 items, not 8. So you are trying to fill in eight bindings with only 7 arguments. Just a guess, but maybe it is supposed to be

Ticker  Date    Open   High   Low    Close   Volume    AdjClose  
AA      1/5/11  16.34  16.59  16.11  16.56   48278700  16.56

which would make to_db change like this:

to_db = [(i['Ticker'], i['Date'], i['Open'], i['High'], i['Low'],i['Close'], i['Volume'], i['AdjClose']) for i in dr]
2
votes

You have one too many ?s. Or one too few items in the tuple.

0
votes

While sending Query Params use List not Tuple