[DB-SIG] inserting strings into postgres db using pgdb (escaping quotes automagically)

Nathan Clegg nathan-pydb at geerbox.com
Wed Jun 18 10:05:36 EDT 2003


> If anyone can point to a more elegant solution, then great, but 
> otherwise thanks for the rapid help, I can live with this.


Well I'm not sure why you are forcing your lists into dictionaries.
How about this:


def sqlInsert(self,table,values,data):
    if self.dbtype == 'postgresql':
        cmd = 'insert into %s (%s) values (%s)' % (
            table,
            ', '.join(values),
            ', '.join(('%s',) * len(values)),
            )
        self.cur.execute(cmd, data)



-- 
Nathan Clegg
GeerBox




More information about the DB-SIG mailing list