Webkit (on iPhone and Safari, at least) supports HTML5's database storage via SQLite.
I'm trying to figure out how best to get the insert ID (there's an autoincrement field 'id' in the database) for the following transaction.
db.transaction(function(tx) {
tx.executeSql("INSERT INTO teams (name) VALUES (?)", [$('#team_name').val()]);
});
The code sample below is from Apple's documentation, I know it works on iPhone and Safari, and probably WebKit. You can get the insert id from the resultSet response object by using resultSet.insertId
Also, you can get the number of affected rows, for an update query for example by using the rowsAffected property of the resultSet object.
db.transaction(
function (transaction) {
transaction.executeSql('INSERT into tbl_a (name) VALUES ( ? );',
[ document.getElementById('nameElt').innerHTML ],
function (transaction, resultSet) {
if (!resultSet.rowsAffected) {
// Previous insert failed. Bail.
alert('No rows affected!');
return false;
}
alert('insert ID was '+resultSet.insertId);
transaction.executeSql('INSERT into tbl_b (name_id, color) VALUES (?, ?);',
[ resultSet.insertId,
document.getElementById('colorElt').innerHTML ],
nullDataHandler, errorHandler);
}, errorHandler);
}, transactionErrorCallback, proveIt);
Apple's HTML5 Database Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With