[Tutor] How to create a sqlite table schema dynamically

bob gailer bgailer at gmail.com
Thu Mar 20 16:38:47 CET 2014


On 3/19/2014 8:19 AM, Toni Fuente wrote:
> Hello everyone,
>
> I am stack with a problem that I can't find a solution:
>
> I need to create a sqlite schema dynamically, I've got a dictionary with
> text keys: "RedHat", "CentOS", "SLES9",..., "etc", "etc"
>
> My intention was at the time of creating the table schema run a loop
> through the dictionary keys and incorporate them to the schema:
>
> for os in osDict.items():
>     cur.execute('''CREATE TABLE mytable(week INTEGER NOT NULL, os TEXT NOT NULL, number INTEGER NOT NULL)''')
IMHO you are mixing data with column names. Usually the column name in 
this case would be just os.

What is your use case for this?
> But I don't know how to pass the os key to the sqlite command.
>
> Thank you in advance for any help,
> Kind regards,
>
>



More information about the Tutor mailing list