[Tutor] How to create a sqlite table schema dynamically

Toni Fuente tonifuente at yahoo.co.uk
Thu Mar 20 15:19:41 CET 2014


* Mark Lawrence <breamoreboy at yahoo.co.uk> [2014-03-19 15:54:27 +0000]:

> 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
> 

Thank you Mark.

I forgot to say that I am using python 2.4.3, but that helped me.

-- 
Toni

Por los defectos de los demás el sabio corrige los propios.
		-- Publio Siro. 


More information about the Tutor mailing list