Luke wrote:
> 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,
> 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... ill save that
> for later. (unless there is a very easy way to do it that doesnt require
> re)

     That's the whole point of SQL.  You write a SELECT statement to
extract the records you want.  A SELECT statement can select on
multiple conditions in one statement, and this is done very efficiently.
Just add a "characcount" field to your record, use one database,
and use select statements like

        cursor.execute("SELECT name, job FROM gamecharacters WHERE 
characcout=%", 
(charAccount,))

     and MySQL will do the rest.

     Your database searches will go much faster if you add some indexes.
Like

        INDEX characcount,
        INDEX name

And if you use add

        UNIQUE INDEX name

no two characters can have the same name, even if they're from different
accounts.  If you wanted to allow duplicate names from the same account,
you could write

        UNIQUE INDEX (name,characcount)

which requires that the combo of name and characcount be unique.
With that rule in the database, an INSERT that tries to insert
a duplicate name will raise an exception.

You're on the right track; you just need to understand more of what MySQL
can do for you.  Which is quite a lot.


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

Reply via email to