How to return the value of AUTO INCREMENT column in SQLite with VB6

时光毁灭记忆、已成空白 提交于 2019-11-28 08:31:54
bendewey

Does SQLite support SCOPE_IDENTITY?

Check out the FAQ. The sqlite3_last_insert_rowid() function will do it. Careful of triggers though

Not tested, but you should be able to send both statements in one call. It's been a while since I wrote any VB6. Also this is not SQL injection safe.

Dim oRs as Recordset
dim sSql as String
sSql = "INSERT INTO EventType (EventTypeName) VALUES ('blah'); SELECT last_insert_rowid() FROM EventType"
oRs.Open sSql oConn

Run this query inside of your code:

SELECT SEQ from sqlite_sequence WHERE name='tablename'

I don't use VB, so I don't know the interface you're using with your database, but, as bendewey said, there is a function in the c API called sqlite3_last_insert_rowid() that will return the primary integer key for the last inserted row, so you could look for a similar function in your interface.

If that doesn't work, you can use the SQLite-specific query:

SELECT last_insert_rowid()

You can call SELECT last_insert_rowid() after your insert

sgarcia

If use

SELECT last_insert_rowid() 

returns the last rowid, you can use :

SELECT last_insert_rowid() AS rowid FROM table_name LIMIT 1

for obtain the last rowid for an individual table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!