Problem w/ MySQLdb

Victor Subervi victorsubervi at gmail.com
Tue Feb 15 21:24:57 CET 2011


Hi;
I have a function that calls the following class:

#!/usr/bin/python

import sys,os
sys.path.append(os.getcwd())
import MySQLdb
from login import login
import re, string

def buildTableColorShortOptions():
  user, passwd, db, host = login()
  database = MySQLdb.connect(host, user, passwd, db)
  cursor = database.cursor()
  cursor.execute('''create table if not exists colorShortOptions (
    Color varchar(40) not null,
    Value bool not null default '0'
    ) engine=innodb''')
  cursor.execute("insert into colorShortOptions (Color) values ('indigo')")
  cursor.execute("insert into colorShortOptions (Color) values ('maroon')")
  cursor.execute("insert into colorShortOptions (Color) values ('violet')")
  cursor.execute("insert into colorShortOptions (Color) values ('tan')")
  cursor.execute("insert into colorShortOptions (Color) values ('lime')")
  cursor.execute("insert into colorShortOptions (Color) values ('blue')")
  cursor.execute("insert into colorShortOptions (Color) values ('fuchsia')")
  cursor.execute("insert into colorShortOptions (Color) values ('cobalt
blue')")
  cursor.execute("insert into colorShortOptions (Color) values ('black')")
  cursor.execute("insert into colorShortOptions (Color) values ('rose
pink')")
  cursor.execute("insert into colorShortOptions (Color) values ('air force
blue')")
  cursor.execute("insert into colorShortOptions (Color) values ('orange')")
  cursor.execute("insert into colorShortOptions (Color) values ('white')")
  cursor.execute("insert into colorShortOptions (Color) values ('red')")
  cursor.execute("insert into colorShortOptions (Color) values ('yellow
green')")
  cursor.execute("insert into colorShortOptions (Color) values ('navy
blue')")
  cursor.execute("insert into colorShortOptions (Color) values ('salmon')")
  cursor.execute("insert into colorShortOptions (Color) values ('yellow')")
  cursor.execute("insert into colorShortOptions (Color) values ('olive')")
  cursor.execute("insert into colorShortOptions (Color) values ('sky
blue')")
  cursor.execute("insert into colorShortOptions (Color) values ('silver')")
  cursor.execute("insert into colorShortOptions (Color) values ('gray')")
  cursor.execute("insert into colorShortOptions (Color) values ('green')")
  cursor.execute("insert into colorShortOptions (Color) values ('teal')")
  cursor.close()

It builds the table but fails from the first insertion. Trying to insert
using that code directly in MySQL does indeed work. Why?
TIA,
Beno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110215/f8c176ad/attachment.html>


More information about the Python-list mailing list