Valid SQLite rowid range?

I am creating a SQLite C API wrapper. And I want to return rowid as an integer type. To flag the error, I need an invalid rowid value. Invalid SQLite rowid value? Or are all values ​​in signed 64-bit integers valid for rowid? (because, if so, I have to choose a different way to implement the case of labeling error)

+6
source share
1 answer

String identifiers are signed 64-bit integers, so the maximum is 0x7FFFFFFFFFFFFFFFFFLL. But if the identifier of a negative or zero line is entered explicitly, the automatically generated line identifiers are always greater than zero. If you can be sure that line identifiers will always be generated automatically, then zero or -1 will be safe values ​​to return the error status.

Thinking more, I understand that calling the sqlite3_last_insert_rowid API call returns zero if nothing has ever been inserted into the table, which makes zero de facto an "invalid" row identifier.

+13
source

Source: https://habr.com/ru/post/906622/


All Articles