[Tutor] How to create a sqlite table schema dynamically

Mark Lawrence breamoreboy at yahoo.co.uk
Wed Mar 19 16:54:27 CET 2014


On 19/03/2014 12:19, 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)''')
>
> But I don't know how to pass the os key to the sqlite command.
>
> Thank you in advance for any help,
> Kind regards,
>
>

http://docs.python.org/3/library/sqlite3.html#module-sqlite3 the 7th 
paragraph describes 'parameter substitution'

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com




More information about the Tutor mailing list