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)
            Asked
            
        
        
            Active
            
        
            Viewed 4,394 times
        
    8
            
            
        - 
                    Here's spec about rowid: http://www.sqlite.org/autoinc.html – eonil Jan 23 '12 at 04:43
1 Answers
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
- 
                    1Thanks for mentioning about explicit zero and negative values can be inserted. I will go something other mechanism. :) – eonil Jan 23 '12 at 04:44
 
    