Lad wrote:
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.


Lad, Try

str = "INSERT INTO produkt1 (MyNumber) VALUES(%d)" % (MyNumber)
cursor.execute(str)

wes

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to