MySQL problem

Lad python at hope.cz
Thu Mar 17 11:32:00 EST 2005


I have the following
program( only insert a record)
################
import MySQLdb
conn = MySQLdb.connect (host = "localhost",user = "", passwd =
"",db="dilynamobily")
cursor = conn.cursor ()
cursor.execute("""CREATE TABLE produkt1 (
  id int(10) unsigned NOT NULL auto_increment,
  MyNumber varchar(30) NOT NULL default '',
  PRIMARY KEY  (id))
  """)

#MyValue=111
cursor.execute ("""INSERT INTO produkt1
(MyNumber)
	VALUES(111)
	""")
#################
It works. But If I change the program like the following ( only use a
variable MyValue in INSERT statement it does not work.
##########THIS DOES NOT WORK########
import MySQLdb,re,string
conn = MySQLdb.connect (host = "localhost",user = "", passwd =
"",db="dilynamobily")
cursor = conn.cursor ()
cursor.execute("""CREATE TABLE produkt1 (
  id int(10) unsigned NOT NULL auto_increment,
  MyNumber varchar(30) NOT NULL default '',
  PRIMARY KEY  (id))
  """)

MyValue=111
cursor.execute ("""INSERT INTO produkt1
(MyNumber)
	VALUES(MyValue)
	""")
#################
Program says
OperationalError: (1054, "Unknown column 'MyValue' in 'field list'")
Where is a problem. Thanks for help
Lad.




More information about the Python-list mailing list