3

When running the following Python 2.7 script, I am getting a pyodbc.Error. The Excel spreadsheet I am using has 4 lines in it.

import pyodbc
from mmap import mmap,ACCESS_READ
import xlrd
import os

#for row_index in range(1,sheet0.nrows):

cnxn = pyodbc.connect('driver={DB};NetworkAddress=DB_Address,Port;Db=DB;uid=login;pwd=password')
cursor = cnxn.cursor()

book=xlrd.open_workbook("I:\\CNLD.xlsx")
sheet=book.sheet_by_index(0)
cell=sheet.cell(1,1)

for rownum in range(sheet.nrows):
    print sheet.row_values(rownum)

print sheet.nrows 

update_dyna = "insert into tempdb..cm_dyna(secsym,pvsym,min_bid_off,min_bid_offpt,min_ask_off,min_ask_offpt,max_bid_off,max_bid_offpt,max_ask_off,max_ask_offpt) values(?,?,?,?,?,?,?,?,?,?)"

for row_index in range(1, sheet.nrows):
    row_num         = row_index
    secsym          = sheet.cell(row_index,0).value
    pvsym           = sheet.cell(row_index,1).value
    min_bid_off     = sheet.cell(row_index,2).value
    min_bid_offpt   = sheet.cell(row_index,3).value
    min_ask_off     = sheet.cell(row_index,4).value
    min_ask_offpt   = sheet.cell(row_index,5).value
    max_bid_off     = sheet.cell(row_index,6).value
    max_bid_offpt   = sheet.cell(row_index,7).value
    max_ask_off     = sheet.cell(row_index,8).value
    max_ask_offpt   = sheet.cell(row_index,9).value
    values = (secsym,pvsym,min_bid_off,min_bid_offpt,min_ask_off,min_ask_offpt,max_bid_off,max_bid_offpt,max_ask_off,max_ask_offpt)
    cursor.execute(update_dyna,values)    

cursor.close()
cnxn.commit()
cnxn.close()

Here is the error message that is getting kicked out:

cursor.execute(update_dyna,values)    
pyodbc.Error: ('HY000', '[HY000] [DataDirect][ODBC Sybase Wire Protocol driver]Data type for parameter 2 has changed since first SQLExecute call. (0) (SQLExecDirectW)')

cursor.execute is a part of the loop, so I am not sure why I am not able to update a spreadsheet that has 4 lines in it.

1 Answer 1

1

The error message is telling you that you've got a different data type between one call to cursor.execute and then next - and that Sybase doesn't allow this.

A quick workaround may be to commit the transaction inside the loop. I don't have Sybase handy to test this.

Alternatively, force your data into the correct format. I suspect you've got a mix of strings, ints, and floats. But you can force it something like:

min_bid_off     = float(sheet.cell(row_index,2).value)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.