i am using SQLite3 and pyodbc on Windows with python.
i have an ID(321) wich has multiple neighbours (0-3 neighbours).
ID 320
322 327 325
321 323 238 329
What i want is a list in my SQlite db wich looks like
321 322 327 320
321 322 327 325
321 323 328 329
To get the next neighbour i have to execute a query wich returns the next neighbours and stores it in a seperat database. I have to do this step 3 times to get all neighbours i need.
The Problem at the moment is, that i´m saving the neighbours by executing an Update Statement in the database, wich returns me only one neighbour.
Example: 321 323 328 329
That´s how i get the next neighbour (get_neighbours()):
cursor = conn.cursor()
cursor.execute("""SELECT m2.link_id, m1.link_id
FROM database1.rdf_link AS m1
INNER JOIN database2.rdf_link AS m2
ON m1.nonref_node_id = m2.ref_node_id
WHERE m1.link_id IN {}""".format(get_link0()))
rows = cursor.fetchall()
return rows
database1 and database2 are the same database i´m just INNER JOIN, because i need to check nonref with ref (neighbour1.ref = neighbour2.nonref) That´s how i can check for neighbours
After executing i get something like that:
[(64438719, 67618608), (727938246, 727938245)]
I insert the values with the UPDATE Statement(wich only inserts the last Value):
cursor = conn2.cursor()
cursor.executemany("""UPDATE database SET link_id1 = ? WHERE link_id = ?""", get_neighbours())
conn2.commit()
I also tried with the INSERT Statement but it inserted the values into new rows. The script works fine if there is only one neighbour but if i have more than one i only collect the last updatet statement and i need every neighbour.
Thanks for your help
Comments
Post a Comment