刚刚插入id lua-sqlite3

时间:2016-03-14 22:02:48

标签: sqlite lua

我试图刚刚插入autoincremented id:

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

# Get the row for 11:00:00
time_row = self.browser.find_element_by_css_selector('tr[data-time="11:00:00"]')
action = ActionChains(self.browser)

# Select the day by moving a fraction of the width of the <tr>
# In this case, I am moving to Wed on the 7-day agendaWeek view.
action.move_to_element_with_offset(time_row, time_row.rect['width']/2, time_row.rect['height']/2)
action.click()
action.perform()

如何获取最后插入的ID?我认为插入函数应该只返回插入的id,但它不会。

1 个答案:

答案 0 :(得分:1)

你可以这样做(我正在使用lsqlite3,所以相应调整):

db = sqlite3.open(':memory:')

db:execute [[
create table xxx(xxx);
insert into xxx values('one');
insert into xxx values('two');
insert into xxx values('three');
]]

sql = [[select last_insert_rowid() as num;]]
for ans in db:nrows(sql) do
  print(ans.num)
end
相关问题