Android Question DBUtils.UpdateRecord

sivakrith

Member
Licensed User
Longtime User
1. I need to update multiple records using dbutils.UpdateRecord. Should I use multiple lines for the same, like this ?
B4X:
lm_where as map
lm_where. initialize
lm_where.put("key1", keyvalue1)
dbutils.updaterecord(sql, 'table1', 'field1', 'value1', lm_where)
dbutils.updaterecord(sql, 'table1', 'field2', 'value2', lm_where)

2. How to update multiple tables with multiple fields using dbutils.UpdateRecord ? Of course need to check for any dberrors while updating the values ? ie should rollback all the updates if any errors occurs.
 

udg

Expert
Licensed User
Longtime User
To update multiple fields of the same record(s), just use:
B4X:
' updates multiple fields in a record
' in the Fields map the keys are the column names
Public Sub UpdateRecord2(SQL As SQL, TableName As String, Fields As Map, WhereFieldEquals As Map)

Based on the criteria exposed in the WhereFieldEquals, the above will update a set of records (from zero to n).
You could copy (and rename) any function you find in DbUtils; once it's in your code module you can extend, modify, put logs..
 
Last edited:
Upvote 0
Top