|
James Paige
jamesp at westcoastaerospace.com
Wed Feb 1 12:00:04 EST 2006
Luis M. Gonzalez wrote:
> Hi folks,
>
> First of all, let me apologize for asking a question that is not specific to mod_python,
> but I think that it could be of interest to many of you:
>
> I wrote a script that creates authomatic administration pages for databases.
> For a given database, whose name is pased as parameter to the script, a fully functional administration interface is created.
> This interface allows me to insert, update or delete records in any table of the database, and all these actions are accessed through a web page with links
> to each of the database's tables.
>
> There's only one problem with it.
> The script assumes that the first field of each table is a primary key, and this is necessary for performing updates on the table.
> In those cases where the tables don't have a primary key, or when the primary key is composed of two fields, the update cannot be performed correctly.
>
> The question is:
> Is there any way to figure out the primary key of a table?
> Perhaps through a special type of query or function?
> I've been reading the mysql documentation but I couldn't find any solution, although I'm sure there might be a simple way to do it...
>
> Any hint would be highly appreciated...
> If anyone wants to check the script, I'd be glad to send it by email.
>
> Regards,
> Luis
You are really asking a database question, not a mod_python question,
but I think what you are looking for is the SQL DESCRIBE command. Call
.execute('DESCRIBE tablename') on a cursor, and it will give you results
which contain information about the table, including which (if any)
fields are keys.
Your script does sound cool, and yes, I would be interested in seeing it.
---
James Paige
|