Vicheanak Vicheanak - 7 months ago 61
MySQL Question

How to Get Last Id MySQL in Scrapy?

This is the snippet of the code in my pipeline. And I want to get the last inserted ID

result = tx.execute("INSERT INTO articles(title, description, url) VALUES ('" + item['title'] + "', '" + it em['description'] + "', '" + item['url'] + "')"
print('#RESULT', result)

In here, the result printed 1L.

My Purpose: My article as many images, so I want to save them in a different table. By getting the last id of the article, I can use it as a foreign keys to the images table.

How do I do it? Or You have any other practical solutions?


Use tx.lastrowid to get the last row ID inserted