如何获取 SQLite 中最后插入的记录的自动递增值? [英] How do I get the auto-incrementing value of the last inserted record in SQLite?

查看:27
本文介绍了如何获取 SQLite 中最后插入的记录的自动递增值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 sqlite3,我在表 Foo 中插入了一个新行.

Using sqlite3, I inserted a new row into table Foo.

插入 Foo 值(colX=?, colY=? colZ=?)

INSERT INTO Foo VALUES (colX=?, colY=? colZ=?)

然后我绑定并执行查询.该表包含一个自动递增列作为主键.添加新行后如何在不执行查询的情况下获取此 ID?

Then I bind and execute the query. This table contains an auto-incrementing column as the primary key. How do I get at this ID after a new row was added without doing a query?

推荐答案

使用 sqlite3_last_insert_rowid:

Use sqlite3_last_insert_rowid:

sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);

这将获取最后插入的 id,就像你问的那样.

This gets the last inserted id, just like you asked.

http://www.sqlite.org/c3ref/last_insert_rowid.html

这篇关于如何获取 SQLite 中最后插入的记录的自动递增值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆