[Python-de] Formatierung von SQL-Statements
Fritz Cizmarov
fritz at sol.at
Don Jul 8 01:36:27 CEST 2004
Am Thu, 08 Jul 2004 00:35:15 +0200
Schrieb Mathias Uebel <mathias.uebel at meeloon.de>:
> Hallo Fritz
> Danke für Deine Anregung. Das ist die Lösung:
>
> def SQLInsert( self, table, list ):
> # SQL String
> tmp = [table,table,self.mytime]
> for item in list:
> tmp.append(item)
> tpl = "INSERT INTO %s VALUES ((SELECT max(id) FROM %s)+1,'%s'"
> +
> (", '%s'"*len(list))+")"
> try:
> self.cu.execute(tpl % tuple(tmp))
>
Hallo nochmal
warum die Forschleife?
def SQLInsert( self, table, list ):
# SQL String
tmp = [table,table,self.mytime]+list
tpl = "INSERT INTO %s VALUES ((SELECT max(id) FROM %s)+1,'%s'"
+ (", '%s'"*len(list))+")"
try:
self.cu.execute(tpl % tuple(tmp))
Gruß
Fritz