title: Inserting and returning autoidentity in SQLite3
body: <p>I'm trying to figure out the best approach to getting the last ID when I insert a row into the database.</p>
  
  <p>It's for a basic library which logs Exception and program state data into a SQLite database, using <code>System.Data.SQLite</code>.</p>
  
  <p>The library could be called from console apps, forms apps, websites, services, single threaded, multi-threaded - so while this library is very small and simple, it's important that each call to it is stateless, stable and accurate.</p>
  
  <p>In my main SQL libraries I use <code>OUTPUT inserted.id</code>, which keeps things very simple, but as far as I can tell, this is not available in SQLite. I did find one or two people mentioning it, but it doesn't seem to work for me.</p>
  
  <p>If not, I see another approach is to <a href="https://stackoverflow.com/questions/6242756/how-to-retrieve-inserted-id-after-inserting-row-in-sqlite-using-python">create a cursor and use that to track the last inserted id</a>. However, that's listed as an extension and I can't seem to find any sign of it in the .NET library.</p>
  
  <p>The <a href="https://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c-sharp">most relevant .NET example I could find</a> used the second command approach which worries me.</p>
  
  <p>My concern is that when exceptions are raised and logged, often a lot are raised very quickly, and I want to be 100% sure I'm linking up the InnerException chain correctly.</p>
  
  <hr>
  
  <ul>
  <li>Am I right in thinking <code>INSERT INTO</code>...<code>OUTPUT inserted.id</code> is not supported in SQLite?</li>
  <li>Assuming not, is the cursor the best way to get the last inserted id with no chance of problems with concurrent requests?</li>
  <li>If that is the best approach, is <code>SELECT last_insert_rowid()</code> limited to the current cursor?</li>
  </ul>