Louis Zirkel wrote:
Rashawn L Knapp wrote:

enterResourceAVs() is defined as this:
def enterResourceAVs(self, id, AVs):
    """Takes an entry identifier, a list of dictionaries of
    (name,value). It enters the AVs list into resource attribute
    with idName = id. Currently enters all attr_type fields as
    "string"
     Returns: nothing
    """

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


It's been my experience that using bind type variables (:name or :value) with a preceeding : doesn't work properly. I spent a good day or two tracking down many issues with getting bind variables to work. I ended up determining that you can use the normal string syntax (i.e. %s or %d) in place of the actual bind variable names and it works... at least some of the time. I've experience problems with data type conversions as well but I've not had time to investigate all that needs to be done to truly fix the module. I was going to submit a patch but haven't had the time of late.

One thing to note is that I was just using execute and not executemany, but the latter is just a call to the prior IIRC.


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


Thanks for the feedback,
Rashawn


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

Reply via email to