escape single and double quotes
Leif B. Kristensen
abuse at solumslekt.org
Thu Mar 24 14:16:10 EST 2005
First, thanks to all who have replied. I learned a lot more than I had
expected :-)
This is a small part of a major project; converting my genealogy
database from a commercial FoxPro application to my homegrown Python /
PostgreSQL app. I'm still in a phase where I'm experimenting with
different models, hence the need for shuffling data between two tables.
Now, the script in its refined form looks like this:
#! /usr/bin/env python
# name_convert.py - populate "names" with values from "name_parts"
import psycopg
name_part = ('prefix','given','surname','suffix','patronym','toponym')
connection = psycopg.connect("dbname=slekta", serialize=0)
sql = connection.cursor()
sql.execute("select name_id, name_part_type, name_part from name_parts")
result = sql.fetchall()
for row in result:
query = "update names set %s=%%s where name_id=%%s" % \
name_part[row[1]-1]
sql.execute(query, (row[2], row[0]))
sql.commit()
connection.close()
--
Leif Biberg Kristensen
http://solumslekt.org/
More information about the Python-list
mailing list