Domanda

I'm making a wrapper of SQLite C API. And I want to return rowid as integer type. To mark error case, I need a invalid value of the rowid. Is there invalid value of SQLite rowid? Or all values in signed 64bit integers are valid for rowid? (because if it is, I have to choose another way to implement marking error case)

È stato utile?

Soluzione

Row IDs are 64-bit signed integers, so the maximum is 0x7FFFFFFFFFFFFFFFLL. But unless a negative or zero row ID has been entered explicitly, auto-generated row IDs are always greater than zero. If you can be certain that row IDs will always be generated automatically then zero or -1 would be safe values to for error status returns.

Thinking further, I realise that the sqlite3_last_insert_rowid API call returns zero if nothing has ever been inserted into the table, thus making zero a de-facto "invalid" row ID.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top