2

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?

sberry
  • 128,281
  • 18
  • 138
  • 165
cranberry
  • 55
  • 1
  • 3
  • 8

3 Answers3

4

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]
sberry
  • 128,281
  • 18
  • 138
  • 165
  • Thank you so much! That was extreme carelessness on my part, sorry for taking up your time and thank you again for the help! – cranberry Jan 11 '11 at 06:07
2

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

dan04
  • 87,747
  • 23
  • 163
  • 198
0

While sending Query Params use List not Tuple