The AsyncDistributedConnection class represents a distributed SQL connection. It provides the single methods
execute()
:AsyncDistributedConnection.execute( queries, args)The arguments
queries
andargs
are arrays of values. Thequeries
array contains the SQL statements to be executed while theargs
array contains the parameter values to be inserted into the SQL statement wherever the question mark character "?
" appears. For example, the following code snippet prepares twoinsert
statements:nWorkers = 2 q = ["INSERT INTO MyTable(pk, value, u2, i1, i2, i4, i8, flt, dbl) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"] * nWorkers args = [] for i in xrange(nWorkers): args.append((i*100, 'str%s' % i, i, i, i, i, i, i*100, i*100.9))For SQL
insert
,update
ordelete
statements, the execute() method returns an integer value indicating the number of rows affected. For example, the following code snippet would print out the number of rows inserted by the twoinsert
statements created above:r = conn.execute(q, args) print "len(r)=", len(r) for k in range(len(r)): pprint.pprint(r[k])For SQL
select
statements (queries), theexecute()
method returns result sets. For example, the following code snippet executes four queries (that do not require arguments) then displays their result sets:q = [ "SELECT COUNT(*) FROM MyTable", "SELECT SUM(pk) FROM MyTable", "SELECT SUM(i1) FROM MyTable", "SELECT SUM(i2) FROM MyTable" ] r = conn.execute(q, None) print "len(r)=", len(r) for k in range(len(r)): pprint.pprint(r[k])