diff options
| author | Vasu Nori <vnori@google.com> | 2010-03-16 09:55:13 -0700 |
|---|---|---|
| committer | Vasu Nori <vnori@google.com> | 2010-03-16 09:55:13 -0700 |
| commit | 5bf67247d2e299f0586de65b2d024f1f835657e0 (patch) | |
| tree | 64eb999ae35b3999fc2c0c4bf0b982a6e2e8716f /core/java/android/database/sqlite | |
| parent | 069b3cfcd477a07aafdfd343ce06353553e39082 (diff) | |
fix the way last insert rowid is returned
if insert statement doesn't succeed, last inserted rowid
shoudl return -1 - instead of returning rowid of the last
successful insert that may have occurred years before this most
recent insert statement failure.
Change-Id: Ia517292afd58fdb600da900e0ee01fe051d6e618
Diffstat (limited to 'core/java/android/database/sqlite')
| -rw-r--r-- | core/java/android/database/sqlite/SQLiteStatement.java | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/core/java/android/database/sqlite/SQLiteStatement.java b/core/java/android/database/sqlite/SQLiteStatement.java index f29b69f56152..7f484ffc0563 100644 --- a/core/java/android/database/sqlite/SQLiteStatement.java +++ b/core/java/android/database/sqlite/SQLiteStatement.java @@ -58,11 +58,10 @@ public class SQLiteStatement extends SQLiteProgram } /** - * Execute this SQL statement and return the ID of the most - * recently inserted row. The SQL statement should probably be an - * INSERT for this to be a useful call. + * Execute this SQL statement and return the ID of the row inserted due to this call. + * The SQL statement should be an INSERT for this to be a useful call. * - * @return the row ID of the last row inserted. + * @return the row ID of the last row inserted, if this insert is successful. -1 otherwise. * * @throws android.database.SQLException If the SQL string is invalid for * some reason @@ -75,7 +74,7 @@ public class SQLiteStatement extends SQLiteProgram try { native_execute(); mDatabase.logTimeStat(mSql, timeStart); - return mDatabase.lastInsertRow(); + return (mDatabase.lastChangeCount() > 0) ? mDatabase.lastInsertRow() : -1; } finally { releaseReference(); mDatabase.unlock(); |
