LAST_INSERT_ID() always returns 0 (RMySQL) - separate connection issue

前端 未结 3 1173
猫巷女王i
猫巷女王i 2021-01-18 14:49

Original example as found in some post

According to this post the following SQL statements should give me a vector 1, 2, 2, 2, 2 in the end:



        
3条回答
  •  余生分开走
    2021-01-18 15:22

    We found a very interesting solution:

    res <- dbSendQuery(con, "INSERT INTO t VALUES (5);")
    res <- dbSendQuery(con, "SELECT LAST_INSERT_ID();")
    fetch(res)
    

    If it does not work, use a dbClearResult(res) before sending the last id request. For us it worked out.

提交回复
热议问题