Id in database using qt -


i new qt. have created table in sql, , i'm trying give id whenever user adds data. first thing inserted 1, second 2 , on. how check number last one? should create query.prepare(sql statement) or there other way?

the method you're looking qsqlquery::lastinsertid(). quote the documentation:

returns object id of recent inserted row if database supports it. invalid qvariant returned if query did not insert value or if database not report id back. if more 1 row touched insert, behavior undefined.

i can confirm experience functionality indeed supported sqlite databases in qt.

you can convert variant database id so:

qint64 insertid = query.lastinsertid().tolonglong(); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -