SQT
A C++ ORM framework for SQLite
Loading...
Searching...
No Matches

◆ AutoIncInsert()

template<EntityValueType ENTITY>
std::int64_t sqt::DataContext< ENTITY >::AutoIncInsert ( const ENTITY & entity)

Inserts the specified entity into the database table, automatically generating the primary key value.

Parameters
entityThe entity to be inserted.
Returns
The generated row ID of the inserted entity.
Exceptions
sqt::SQLErrorThrown if the insertion fails.

This method is similar to the Insert() method, expect that the primary key value in the entity is ignored and automatically generated.

To avoid unique constraint violations due to unique indexes, use the AutoIncReplace() method to replace the existing row instead.

Note
This method is only available if the entity type has an auto-incremented primary key. Use the SQT_PRIMARY_KEY_AUTO_INC macro to define an auto-incremented primary key.

For more control over the conflict action, use the more flexible MakeAutoIncInserter() method from the complex style interface.

See also
sqt::DataContext<>::AutoIncReplace()
sqt::DataContext<>::Insert()
sqt::DataContext<>::MakeAutoIncInserter()
SQT_PRIMARY_KEY_AUTO_INC