fix(android): TiDatabaseProxy track lastInsertRowId/rowsAffected per-execute and null out closed cursor#14517
Open
mbender74 wants to merge 1 commit into
Open
fix(android): TiDatabaseProxy track lastInsertRowId/rowsAffected per-execute and null out closed cursor#14517mbender74 wants to merge 1 commit into
mbender74 wants to merge 1 commit into
Conversation
… out closed cursor
Contributor
|
Test code: var win = Ti.UI.createWindow({});
win.open();
var db = Ti.Database.open('db_test');
// Clean slate
db.execute('DROP TABLE IF EXISTS people');
db.execute('CREATE TABLE people (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)');
Ti.API.info('=== Testing lastInsertRowId / rowsAffected ===');
// ------------------------------
// INSERT #1
// ------------------------------
db.execute('INSERT INTO people (name) VALUES (?)', 'Alice');
Ti.API.info('Insert #1');
Ti.API.info('lastInsertRowId = ' + db.lastInsertRowId);
Ti.API.info('rowsAffected = ' + db.rowsAffected);
// Expect:
// lastInsertRowId = 1
// rowsAffected = 1
// ------------------------------
// INSERT #2
// ------------------------------
db.execute('INSERT INTO people (name) VALUES (?)', 'Bob');
Ti.API.info('Insert #2');
Ti.API.info('lastInsertRowId = ' + db.lastInsertRowId);
Ti.API.info('rowsAffected = ' + db.rowsAffected);
// Expect:
// lastInsertRowId = 2
// rowsAffected = 1
// ------------------------------
// UPDATE
// ------------------------------
db.execute('UPDATE people SET name=? WHERE id=?', 'Bobby', 2);
Ti.API.info('Update');
Ti.API.info('lastInsertRowId = ' + db.lastInsertRowId);
Ti.API.info('rowsAffected = ' + db.rowsAffected);
// Expect:
// rowsAffected = 1
// lastInsertRowId should still reflect the most recent statement's state
// (typically unchanged for UPDATE depending on platform behavior).
// ------------------------------
// UPDATE affecting no rows
// ------------------------------
db.execute('UPDATE people SET name=? WHERE id=?', 'Nobody', 999);
Ti.API.info('Update (no rows)');
Ti.API.info('rowsAffected = ' + db.rowsAffected);
// Expect:
// rowsAffected = 0
// (Previously this might incorrectly remain 1 if stale.)
// ------------------------------
// DELETE
// ------------------------------
db.execute('DELETE FROM people WHERE id=?', 1);
Ti.API.info('Delete');
Ti.API.info('rowsAffected = ' + db.rowsAffected);
// Expect:
// rowsAffected = 1
// ------------------------------
// SELECT
// ------------------------------
var rs = db.execute('SELECT * FROM people');
Ti.API.info('Reading ResultSet');
while (rs.isValidRow()) {
Ti.API.info(
rs.fieldByName('id') + ' : ' +
rs.fieldByName('name')
);
rs.next();
}
Ti.API.info('Closing ResultSet...');
rs.close();
Ti.API.info('=== Testing use-after-close ===');
try {
Ti.API.info('Calling isValidRow() after close...');
Ti.API.info(rs.isValidRow());
} catch (e) {
Ti.API.error('Expected exception: ' + e);
}
try {
Ti.API.info('Calling fieldByName() after close...');
Ti.API.info(rs.fieldByName('name'));
} catch (e) {
Ti.API.error('Expected exception: ' + e);
}
try {
Ti.API.info('Calling next() after close...');
rs.next();
Ti.API.info('next() returned normally');
} catch (e) {
Ti.API.error('Expected exception: ' + e);
}
db.close();
Ti.API.info('Done.');will crash with in 13.3.0 and works find with this PR 👍 |
m1ga
self-requested a review
July 16, 2026 16:24
m1ga
approved these changes
Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TiDatabaseProxynow trackslastInsertRowIdandrowsAffectedper-execute so they reflect the most recent statement, not a stale value from an earlier execute.TiResultSetProxynulls out its closed cursor to prevent use-after-close crashes.