Hi,
My name is Chintan Vadera. I had a question regarding a problem you had before regarding Python MySQLdb. It would be great if you could help.
The thing is I have database already in place for this code. My code has the same exact logic as your did. I am getting the error which you got.
Here is the error
Traceback (most recent call last):
File "C:\Documents and Settings\axiom\Desktop\PioneerExcell\jacquestuff\t ry\UpdateDailyRecap.py", line 64, in <module>
cursor.execute(query,values)
File "C:\Python26\lib\site-packages\MySQLdb\cursors.py", line 166, in execute
self.errorhandler(self, exc, value)
File "C:\Python26\lib\site-packages\MySQLdb\connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (1054, "Unknown column 'Currency_Code' in 'field list'")
I did not understand the explanation there. It was kinda incomplete. Could you please leme know how to get rid of it. I am stuck coz of it. TIA
Here is my code -
import xlrd
-
from xlrd import open_workbook
-
import MySQLdb
-
-
-
-
b = xlrd.open_workbook('dailyrecap.20111025.xls')
-
-
sheet = b.sheet_by_index(0)
-
-
print "%s" % sheet.name
-
print "%d" % sheet.nrows
-
-
-
-
-
conn = MySQLdb.connect("10.22.8.62","chintan","password","X")
-
cursor = conn.cursor()
-
cursor.execute("""truncate master_daily""")
-
-
-
query = """insert into accounts(Currency_Code, Salesman, Account, Member_Code, Contract_Month, Contract_Year, Exchange, Futures_Code, Commodity_Name, Round_Table_Half_Turn, Put_Call, Strike_Price, But_Sell, Record_ID, Opt_Premium_and_P_and_S, Confirm_Volume, Overnight_Volume, Spread_Quantity, Day_Trade_Volume, Scratch_Volume, P_and_S_Volume, Transfer_Volume, Exercise_Assign_Volume, Expired_Volume, Comission, Clearing_Fees, Exchange_Fees, Brokerage_Fees, NFA_Fees, Other_Fees, Memo_Clearing_Fees, Memo_Exchange_Fees, Electronic_Trade, Trade_Date) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"""
-
-
-
for i in range(1,sheet.nrows):
-
-
Currency_C = sheet.cell(i,0).value
-
Salesm = sheet.cell(i,1).value
-
Accou = sheet.cell(i,2).value
-
Member_C = sheet.cell(i,3).value
-
Contract_M = sheet.cell(i,4).value
-
Contract_Y = sheet.cell(i,5).value
-
Excha = sheet.cell(i,6).value
-
Futures_C = sheet.cell(i,7).value
-
Commodity_N = sheet.cell(i,8).value
-
Round_Table_Half_T = sheet.cell(i,9).value
-
Put_C = sheet.cell(i,10).value
-
Strike_P = sheet.cell(i,11).value
-
But_S = sheet.cell(i,12).value
-
Record_I = sheet.cell(i,13).value
-
Opt_Premium_and_PS = sheet.cell(i,14).value
-
Confirm_V = sheet.cell(i,15).value
-
Overnight_V = sheet.cell(i,16).value
-
Spread_Q = sheet.cell(i,17).value
-
Day_Trade_V = sheet.cell(i,18).value
-
Scratch_V = sheet.cell(i,19).value
-
P_and_S_V = sheet.cell(i,20).value
-
Transfer_V = sheet.cell(i,21).value
-
Exercise_Assign_V = sheet.cell(i,22).value
-
Expired_V = sheet.cell(i,23).value
-
Comiss = sheet.cell(i,24).value
-
Clearing_F = sheet.cell(i,25).value
-
Exchange_F = sheet.cell(i,26).value
-
Brokerage_F = sheet.cell(i,27).value
-
NFA_Fees = sheet.cell(i,28).value
-
Other_F = sheet.cell(i,29).value
-
Memo_Clearing_F = sheet.cell(i,30).value
-
Memo_Exchange_F = sheet.cell(i,31).value
-
Electronic_T = sheet.cell(i,32).value
-
Trade_D = sheet.cell(i,33).value
-
-
values = (Currency_C, Salesm, Accou, Member_C, Contract_M, Contract_Y, Excha, Futures_C, Commodity_N, Round_Table_Half_T, Put_C, Strike_P, But_S, Record_I, Opt_Premium_and_PS, Confirm_V, Overnight_V, Spread_Q, Day_Trade_V, Scratch_V, P_and_S_V, Transfer_V, Exercise_Assign_V, Expired_V, Comiss, Clearing_F, Exchange_F, Brokerage_F, NFA_Fees, Other_F, Memo_Clearing_F, Memo_Exchange_F, Electronic_T, Trade_D)
-
-
cursor.execute(query,values)
-
-
-
cursor.close()
-
conn.commit()
-
conn.close()
5 2757 bvdet 2,851
Expert Mod 2GB
Have you verified that the column "Currency_Code" actually exists in your table?
SQL databases usually support a "SHOW COLUMNS" syntax, i.e. SHOW COLUMNS FROM 'accounts', which will return the column names, but that syntax may be "mis-remembered" so it may require some Googling on your part. There is also a "SHOW DATABASES" if you are not sure that "accounts" is the correct name for the table.
Also, you should be able to do something along the lines of - values = tuple([sheet.cell(i,ctr).value for ctr in range(34)])
bvdet 2,851
Expert Mod 2GB
Good advice dwblas, especially the list comprehension. You should never have to create that many variables to hold temporary data. I checked, and the column names can be directly read from the table, as dwblas mentioned, and paired with the data directly read from the excel file if ordered properly in the excel file. Example reading column names: - import MySQLdb
-
-
db = MySQLdb.Connection(db="aisc")
-
c1 = MySQLdb.cursors.Cursor(db)
-
-
c1.execute("SHOW COLUMNS FROM aisc_v13_1_1")
-
-
print "\n".join([item[0] for item in c1.fetchall()])
-
-
c1.close()
-
db.close()
The above lists the column names in order. - >>> TYPE
-
EDI_STD
-
AISC_MAN
-
T_F
-
W
-
A
-
D
-
DDET
-
HT
-
OD
-
BF
-
BFDET
-
B
-
ID
-
TW
-
TWDET
-
TWDET_2
-
TF
-
TFDET
-
T
-
TNOM
-
TDES
-
KDES
-
KDET
-
K1
-
X
-
Y
-
EO
-
XP
-
YP
-
BF_2TF
-
B_T
-
H_TW
-
H_T
-
D_T
-
IX
-
ZX
-
SX
-
RX
-
IY
-
ZY
-
SY
-
RY
-
RZ
-
SZ
-
J
-
CW
-
C
-
WNO
-
SW
-
QF
-
QW
-
RO
-
H
-
TAN_ALPHA
-
QS
-
>>>
The example reads version 13 of the AISC structural shapes database.
Hey Guys,
Thank you for a prompt reply. There was a typo. I am really sorry for wasting your time. I hate it when errors do not convey properly.
Thanks again!
bvdet 2,851
Expert Mod 2GB
No problem. Thanks for responding and "fessing up". Besides, it wasn't a total waste for me because I learned a couple of things.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Igor Prischepoff |
last post by:
Hi,
Is someone have an expierience in distributing
python app with mysqldb module on Win platforms?
I'd like to know, how you packaged and delivered your solution.
Which tool to use, how to...
|
by: sandy |
last post by:
Hi All,
I am a newbie to MySQL and Python. At the first place, I would like to
know what are the general performance issues (if any) of using MySQL
with Python.
By performance, I wanted to...
|
by: ajikoe |
last post by:
Hello I need to build table which need searching data which needs more
power then dictionary or list in python, can anyone help me what kind
of database suitable for python light and easy to learn....
|
by: Aquarius |
last post by:
I appologize in advance for this strange (and possibly stupid)
question.
I want to know if there is a way to interface a MySQL database without
Python-MySQL or without installing anything that...
|
by: Cousin Stanley |
last post by:
Greetings ....
I'm using a commercial web host running FreeBSD
that fortunately has Python and MySQL,
but no python-mysqldb module ....
Before begging the host to install it
I thought I...
|
by: Fred |
last post by:
I hope someone can help me with the below problem...
Thanks,
Fred
My enviroment:
--------------------------
Slackware Linux 10.2
Python 2.4.2
MySql version 4.1.14
|
by: jgarber |
last post by:
Hello,
I just upgraded MySQLdb to the 1.2.0 version provided by Redhat
Enterprise Linux ES4. At that point I began to get segfaults when
importing twisted after MySQLdb, but not before.
--...
|
by: Mark Tarver |
last post by:
How do you compare Python to Lisp? What specific advantages do you
think that one has over the other?
Note I'm not a Python person and I have no axes to grind here. This is
just a question for...
|
by: Gerard M |
last post by:
Hi guys I have a big problem with this wrapper im using Ubuntu 7.04
and I want to install python-MySQLdb, I used synaptics and it is
installed, but when I try to do
and I get this error:
...
|
by: jpuopolo |
last post by:
All:
I am using Python to read some records from the MySQL database. I am
using the mysqldb library, and things are working well.
Now, I would like to pass back the results of the query to a...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |