Python - Using ADO and RecordSet in testcomplete scripts
Two questions I have regarding the ADO interface with Python:
1. When I do:
rec_set = conn.Execute_("SELECT A, B FROM C WHERE D='E")
... there's no problem, but if I do:
rec_set = conn.Execute_("SELECT * FROM C WHERE D='E'")
... I get a RuntimeError - Unspecified error exception window?
2. I'm not sure how to iterate through and get rows from a RecordSet. Assuming rec_set above is populated from a successful query, how do you extract each row and put them in a list of dicts (where the dict keys are the column names, each row in the list is a row in the RecordSet). The examples one example I've seen in:
doesn't really cover this in detail.
thanks,
Here is an approach I used for something similar. It basically will take a record set and build an array of objects with their properties being the column names / values. It's javascript, but shouldn't be hard to do a similar approach in python.
function recordToObjectArray(rec) { let retVal = []; try { while(!rec.EOF) { let currObj = {}; for(var i = 0; i < rec.Fields.Count; i++) { currObj[rec.Fields.Item(i).Name] = rec.Fields.Item(i).Value; } retVal.push(currObj); rec.MoveNext(); } } catch(err) { Log.Warning("There was an error building object. See additional information", err.message + "\n" + err.stack); } finally { return retVal; } }