MySQLdb syntax issues - HELP

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Mon Dec 17 14:09:49 EST 2007


Luke a écrit :
> Bruno Desthuilliers wrote:
> 
> 
>>Luke a écrit :
> 
>  (snip)   
> 
>>>    cursor.execute("""
>>>        CREATE TABLE %s
>>>        (
>>>         name     CHAR(40),
>>>         gender   CHAR(40),
>>>         job      CHAR(40),
>>>         level    TEXT,
>>>         str      TEXT,
>>>         dex      TEXT,
>>>         intel    TEXT,
>>>         cha      TEXT,
>>>         luc      TEXT
>>>        )
>>>    """ % CharAccount)
>>
>>Err... Are you sure you want a new table here ?
> 
>  (snip)
> 
> yes, thats the easier way i can think of for now since i am so new to SQL,

Then keep away from Python long enough to learn the most basic features 
of SQL.

> eventually im sure i will put all the characters into one larger table
> though... but for now i just dont feal like figuring out how to scan the
> table for the records i need based on name of character...

What you think SQL is for ? Selecting a given record (or a given set of 
record) is actually the most basic SQL operation.

> ill save that
> for later. 

You should not.

> (unless there is a very easy way to do it that doesnt require
> re)

WTF would you want to use regexps here ???

(snip)

>>
>>What you want here is:
>>
>>sql = """
>>INSERT INTO %s (name, gender, job, level, str, dex, intel, cha, luc)
>>VALUES (%%s, %%s, %%s, %%s, %%s, %%s, %%s, %%s, %%s)
>>""" % CharAccount
>>
>>cursor.execute(sql,  (CharName, CharGender, CharJob, CharLevel,
>>Strength, Dexterity, Inteligence, Charm, Luck))
> 
> 
> wow, i was so focused on learning the MySQLdb module i have been overlooking
> simply escaping my % signs the whole time... nice catch, thanks alot. it
> works like a charm now.

Not as far as I'm concerned !-)

> 
> PROBLEM SOLVED, BUT IF YOU WANT TO ADD ANYTHING, FEEL FREE...

Yes : do what everyone here already told you : learn SQL !-)



More information about the Python-list mailing list