curOuter = db.cursor()
rows = []
for row in curOuter.execute('SELECT * FROM myConnections'):
    id = row[0]
scList = retrieve_shared_connections(id)
for sc in scList:
    rows.append((id, sc))
curOuter.executemany(
    'INSERT INTO sharedConnections(IdConnectedToMe, IdShared) VALUES (?,?)',
    rows)
db.commit()
Using multiple cursors in a nested loop in sqlite3 from python-2.7