title: SQLite insert or ignore and return original _rowid_
body: <p>I've spent some time reading the SQLite <a href="http://www.sqlite.org/lang_conflict.html">docs</a>, various questions and answers here on Stack Overflow, and <a href="http://sqlite.1065341.n5.nabble.com/Keeping-ROWID-for-INSERT-OR-REPLACE-td34237.html">this thing</a>, but have not come to a full answer.</p>
  
  <p>I know that there is no way to do something like <code>INSERT OR IGNORE INTO foo VALUES(...)</code> with SQLite and get back the rowid of the original row, and that the closest to it would be <code>INSERT OR REPLACE</code> <strong>but that deletes the entire row and inserts a new row and thus gets a new rowid</strong>.</p>
  
  <p>Example table:</p>
  
  <pre><code>CREATE TABLE foo(
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      data TEXT
  );
  </code></pre>
  
  <p>Right now I can do:</p>
  
  <pre><code>sql = sqlite3.connect(":memory:")
  # create database
  sql.execute("INSERT OR IGNORE INTO foo(data) VALUES(?);", ("Some text.", ))
  the_id_of_the_row = None
  for row in sql.execute("SELECT id FROM foo WHERE data = ?", ("Some text.", )):
      the_id_of_the_row = row[0]
  </code></pre>
  
  <p>But something ideal would look like:</p>
  
  <pre><code>the_id_of_the_row = sql.execute("INSERT OR IGNORE foo(data) VALUES(?)", ("Some text", )).lastrowid
  </code></pre>
  
  <p><strong>What is the best (read: most efficient) way to insert a row into a table and return the rowid, or to ignore the row if it already exists and just get the rowid?</strong> Efficiency is important because this will be happening quite often.</p>
  
  <p><strong>Is there a way to <code>INSERT OR IGNORE</code> and return the rowid of the row that the ignored row was compared to?</strong> This would be great, as it would be just as efficient as an insert.</p>