Rashawn L Knapp wrote:
With some work, I got it:
def enterResourceAVs(self, id, AVs):
  try:
    if len(AVs) > 0:
      newList = []
        for x in AVs:
dc = {"rid":id,"name":x['name'], "value":x['value'], type":"string"}
          newList.append(dc)
        self.cursor.executemany("insert into resource_attribute \
             (resource_id, name, value, attr_type) values \
             (%(rid)s, %(name)s, %(value)s, %(type)s)", newList)
  except:
    raise

You don't need to do it so complicated. The following should work, too:

def enterResourceAVs(self, id, AVs):
    if len(AVs) > 0:
        query = "insert into resource_attribute " +\
                "(resource_id, name, value, attr_type) "
        query += "values (%d, %%(name)s, %%(value)s, 'string')" % id
        self.cursor.executemany(query, AVs)

The duplicate '%' effects that the '%' is inserted literally in the first step where you insert the id. It is later interpreted as parameter indicator in the executemany command.

-- Christoph
_______________________________________________
PyGreSQL mailing list
[email protected]
http://mailman.vex.net/mailman/listinfo/pygresql

Reply via email to