MySQLdb question... using table name as arg



I have four tables that all have the same column names (50 in each.)

I have created an admin program to edit, delete and add records to the
tables and would like to use the table name as a variable in each query so
the code can be used for each of the 4 tables. Usually I would do something
like this by having 1 table with special column to categorize the records as
I am doing with each table, but this specific application requires that I do
it with 4 tables instead.

To ensure that string are quoted properly without any hassle I use the
execute function like so assuming c is my cursor object...

c.execute("update tableName set col1 = %s, col2 = %s, col3 = %s, ...",
(val1, val2, val3, ...))

But, not I want to do this with a variable tableName. If I add it to the
tuple of parameters in the second arg before val1 and replace tableName with
%s, then the tableName will be quoted in the query, causing an error.

What is the best (easiest) way for me to accomplish this? I know it may be
a stupid question but I just can't figure it out.


Thanks for any help.


.



Relevant Pages

  • Re: MySQLdb question... using table name as arg
    ... To ensure that string are quoted properly without any hassle I use the ... not I want to do this with a variable tableName. ... %s, then the tableName will be quoted in the query, causing an error. ...
    (comp.lang.python)
  • Re: Change Field Name in Table
    ... Then use an Append query to copy the data. ... Dim TableName As String ... you are using the variable TableName and not ...
    (microsoft.public.access.formscoding)
  • Re: Change Field Name in Table
    ... No query will accept them. ... Dim TableName As String ... you are using the variable TableName and not ...
    (microsoft.public.access.formscoding)
  • Re: Change Field Name in Table
    ... The Query will take the above field name ... Dim TableName As String ... you are using the variable TableName and not ...
    (microsoft.public.access.formscoding)
  • Re: UPDATE TABLE FROM UNBOUND QUERY
    ... This buttons run the TestQuery and I can see the results. ... results of the query, I want to update the main data tale with Moved = Yes, ... Rather than trying to construct the SQL, use the Design view of the query ... AddTables --> TestQuery, Tablename ...
    (microsoft.public.access.modulesdaovba)