I'm having a trouble when trying to use function to query data in MSSQL using pyodbc, the function is:
def getUserList(connection):
li = []
cur = connection.cursor()
query = 'select username, password, firstname, lastname, description, phone,'+
'email, isAdmin, isAutoBoot from users_tbl'
cur.execute(query)
for usr, pwd, fn, ln, des, ph, em, ad, au in cur.fetchall():
temp = User(usr, pwd, fn, ln, des, ph, em, ad, au)
cur.close()
#con.close()
return li
When I import the module and run this function, it encounter the TypeError:
Traceback (most recent call last):
File "<pyshell#71>", line 1, in <module>
import_user.getUserList(s_con)
File "c:/python27/mymodule\import_user.py", line 12, in getUserList
cur.execute(query)
TypeError: string indices must be integers
However if i copy and run each of these line in Python IDLE, it runs fine and no error when execute the cursor. It happens both when I pass pyodbc or sqlite connection as input parameter.
Thanks
+.