8

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)

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
eonil
  • 83,476
  • 81
  • 317
  • 516

1 Answers1

16

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.

Borodin
  • 126,100
  • 9
  • 70
  • 144
  • 1
    Thanks for mentioning about explicit zero and negative values can be inserted. I will go something other mechanism. :) – eonil Jan 23 '12 at 04:44