#
# addorg.py: add organization data using dynamic queries
#
# PostgreSQL 9 version
#
from db import conn, curs, Error, pmark

#
# Look at the code in cratdb.py, or your database, for column names
#
# We need to insert the organization name and address - the
# database should automagically provide the primary key for each row,
# and other fields will be NULL until other software changes them
#
# If you haven't provided an automatically-generated primary
# key then you may have to modify the data to include it.
#
TBL = "sponsorship_contact"
COLS = "name email orgid telephone".split()
COLS = ["cnt"+col for col in COLS]
#
# Feel free to add more data if you want to
#
data = [
    ('Steve Holden', 'steve@holdenweb.com', None, None)
    ]

# 1. Generate a comma-separated list of fieldnames
flist = ", ".join(COLS)
# 2. Generate a comma-separated list of parameter markers
plist = ", ".join([pmark] * len(COLS))
# 3. Execute an appropriate SQL INSERT statement
sql = "INSERT INTO %s (%s) VALUES (%s)" % (TBL, flist, plist)
for row in data:
    curs.execute(sql, row)

conn.commit()

